学海荡舟手机网

主页 > 实用文摘 > 教育文摘_07 > > 详细内容

简易通用型PCI接口的VHDL-CPLD设计_EDAPLD论文

 摘要:从pci时序分析入手,重点阐述了pci通用的状态机设计,说明了用vhdl语言来实现本pic通信状态机的软件设计以及进行maxplusii验证的程序和方法。用该方法所设计的接口既可支持pci常规传输,又可支持pci猝发传输。

    关键词:pci时序  cpld器件  状态图  vhdl语言  pci猝发传输

用cpld设计所构成的cpi接口系统具有简洁、可靠等优点,是一种行之有效的设计途径。很多技术杂志和网站上,都有不少用cpld设计pci常规传输系统的文章。但用这些方法在mzxplusii、fundition等环境下进行模拟仿真时,其产生的时序往往与pci规范有很大出入。虽然altera等公司推出pci核可以直接使用,但这样的内核占用cpld资源较多,且能适配的器件种类少,同时价格也高,在实际设计应用中有很大的局限性。因此,使用通用型cpld器件设计简易型pci接口有很大的现实意义。在compact接口的cpld设计中,笔者根据pci总线传输时序来进行状态机构造,并使用vhdl语言进行功能模拟和定时分析,从而达到了预期目的。用该方法设计的cpld-pci接口既可支持pci常规传输,也可支持pci猝发传输,而且在系统编程和下载器件方面,效果也都很好。

1 典型的cpld-pci接口模型简介

用cpld作pci接口所构成的系统模型如图1所示。这里,cpld/fpga用于完成pci主/从传输时序的逻辑构成与变换,并对双口ram进行适当操作。在整个系统的设计中,cpld常常使用pci总线的33mhz时钟,双口ram常常选用高速器件来简化pci传输的逻辑设计。

2 pci总线传输时序分析

pci总线传输至少需要40多条信号线,包括数据/地址线、接口控制线、仲裁、总线命令及系统线等。每次数据传输均由一个地址脉冲和一个或几个数据脉冲组成。一次传输一个地址和一个数据的称为常规传输;一次传输一个地址和一批数据的称为猝发传输。常用的控制信号有:帧同步信号frame、主设备准备好信号irdy、从设备准备好信号trdy、从设备选通信号devsel、命令/字节信号c/be等。图2 和图3分别给出了pci单数据段和猝发操作时的读写时序。

分析pci总线的传输时序,可以看出,pci总线传输有以下几个显著特点:

(1)每次数据传输时首先传出地址和命令字,从设备一般可从地址中确定是不是对本机的访问,并确定访问的首地址;而从设备则从命令字中识别该访问是读操作还是写操作;

(2)读写访问只有在信号irdy、trdy、devsel都为低状态时才能进行;

(3)猝发传输通常需要通过逻辑来实现地址的自动递加;

(4)主从设备中任一方没有准备好,操作中都需要能够引起等待状态插入的活动;

(5)系统通常在帧同步信号frame的下降沿诱发数据传输,而在上升沿指明只有一个数据或只剩下一个数据;

(6)读操作比写操作多一个中间准备过程。

图2

3 基于cpld的状态机设计

3.1 状态机的构造

根据对上述时序图的分析,完成一个简易pci总线传输需要设计六个状态:s0~s5,其中状态s0标识pci总线空闲时期;状态s1标识地址与总线命令识别阶段;状态s2标识读操作入口的准备阶段;状态s3标识读/写访问周期;状态s4标识最后一个数据传输阶段;状态s5标识操作中的等待时期。

3.2 状态功能的确定

各状态所应执行的功能如下:

状态s0~s2用于对pci总线置高信号trdy和devsel;对双口ram则置高片选信号cs,以使读/写信号处于读状态,此时地址呈现三态。此外,在s1态还应依据地址信号来确定是不是对本机的选择,并识别是不是读或写操作。

状态s3~s4用于对pci总线置低信号trdy和devsel;对双口ram则产生片选信号cs、读或写信号,同时确定适当的读写访问地址。

状态s5用于对pci总线置低信号trdy和devsel;并且对双口ram置高片选信号cs,以使读/写信号处于读状态,此时地址呈现三态。

3.3 状态变化的确定

根据对pci总线传输时序的分析,影响各个状态相互转化的因素是:帧同步信号frame、主设备准备好信号irdy、从设备选择信号cs-map、读识别信号read以及写识别信号write。这里,可用cs-map、read、write来标识状态s1产生的中间识别信号。

图3

    需要注意,在状态s1时要寄存收到的首地址,而在状态s3变化时要适时进行地址递增。

还要注意状态机设计时产生的容错问题,以便在非设计状态下能够无条件回到空闲态s0。

由于采用的是高速双口ram,并且规划分开了ram两侧的写操作区域,因此可以认为:ram是可以任意访问的。

3.4 状态图的规划

综上所述便可得出如图4所示的设计规划图。

4 vhdl语言的描述

设计时,使用三个进程和几个并行语句可实现整个cpld的功能:一个进程用于完成从设备及其读写操作的识别;一个进程用于完成操作地址的获取与地址的递增;第三个进程完成状态机的变化。用几个并行语句完成操作信号的产生时,需要注意,各状态所完成的功能要用并行语句实现,不能再用进程,否则就会引起逻辑综合的麻烦,有时甚至根本不能综合。整 个程序如下:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

enttty cpci is

port(clk,rst,frame,irdy:in std_logic;

ad_high : in std_logic_vector(31 downto 24);

ad_low : in std_logic_vector(12 downto 0);

c_be : in std_logic_vector(3 downto 0);

trdy,devsel:out std_logic;

cs, r_w :out std-logic;

addr: out std_logic_vector(12 downto 0);

end cpci;

architecture behave of cpci is

signal addr_map : std_logic_vector(12 downto 0);

signal read,write,cs-map:std_logic;

type state_type is(s0,s1,s2,s3,s4,s5);

signal state: state_type;

begin

identify: process(clk)- -读、写、从设备的识别

begin

if rising_edge(clk)then

if c_be=x"6"and ad_high=x"50"and state=s1

hten read < = '0'; - -读

write < = '1';

cs_map < ='0';

elsif c_be=x"7"and ad_high= x"50"

and state=s1 then

read < = '1'; - -写

write < = '0';

cs_map < ='0';

elsif state=s0 then

read < = '1';

write < = '1';

cs_map < ='1';

end if;

end if;

end process;

addr_count:process (clk) - -操作地址的获取与地址的递增

begin

if falling_edge(clk)then

if state=s1 then addr_map< =ad-low;

elsif state=s3 then addr_map< =addr-map+1;

end if;

end if;

end process;

- - 操作信号的产生

addr < = addr-map when state=s3 or state=s4

else "zzzzzzzzzzzzz"

trdy < = '0' when state=s3 or state=s4 or state=s5

else '1';

devsel < = '0'when state=s3 or state=s4 or state=s5

else'1';

cs < ='0'when state=s3 or state=s4 else '1';

r-w < =not clk when write='0'and (state=s3 or state=s4)else'1';

state-change:process(clk,rst) - - 状态机的变化

begin

if rst='0'then state < = s0;

elsif falling-edge(clk)then

case state is

when s0 = >

if frame='1'and irdy='1'then state < = s0;

elsif frame='0' and irdy= '1' then state < = s1;

end if;

when s1 = >

if cs_map='1'or (read='1'and write ='1')

then state < = s0;

elsif irdy='1'and read='0' then state < =s2;

elsif frame='0'and irdy='0'and write='0'

then state < = s3;

elsif frame='1'and irdy='0'and write='0'

then state < = s4;

end if;

when s2 = >

if frame='1'and irdy='1'then state < = s0;

elsif frame='0'and irdy='0'and read='0'

then state < = s3;

elsif frame='1'and irdy='0'and read='0'

then state < = s4;

end if;

when s3 = >

if frame='1'and irdy='1'then state < = s0;

elsif frame='0' and irdy= '1' then state < = s5;

elsif frame='1'and irdy='0' then state < =s4;

elsif frame='0' and irdy= '1' then state < = s3;

end if;

when s4 = >

elsif frame='1'and irdy='0'then state < = s4;

end if;

when s5 = >

if frame='1'and irdy='1'then state < = s0;

elsif frame='0' and irdy= '0'then state < = s3;

elsif frame='1'and irdy='0' then state < =s4;

else state < = s5;

end if;

when others = > state < = s0;

end case;

end if;

end process state_change;

end behave。

图5

5 maxplusii的验证

设计cpld时,可使用maxplusii软件来进行逻辑综合、功能模拟与定时分析。本例选用altera的max7000系列在系统可编程器件epm7064slc84-5。图5所示是其读写访问的仿真波形图。