我还是VHDL新手,我需要在调用一个组件之前暂停我的代码。如果可以,怎么做?我感觉我做的方式不对。
这是我的最小代码:有两行错误:"rst => rst ; "我不明白为什么?我到底做错了什么?
我真的可以这样调用组件吗?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MasterOpl is
port ( rst : in std_logic;
clk : in std_logic;
en : in std_logic;
v1 : in std_logic_vector (7 downto 0);
v2 : in std_logic_vector(7 downto 0);
miso : in std_logic;
ss : out std_logic;
sclk : out std_logic;
mosi : out std_logic;
val_and : out std_logic_vector (7 downto 0);
val_or : out std_logic_vector (7 downto 0);
val_xor : out std_logic_vector (7 downto 0);
busy : out std_logic);
end MasterOpl;
architecture behavior of MasterOpl is
COMPONENT er_1octet
port ( rst : in std_logic ;
clk : in std_logic ;
en : in std_logic ;
din : in std_logic_vector (7 downto 0) ;
miso : in std_logic ;
sclk : out std_logic ;
mosi : out std_logic ;
dout : out std_logic_vector (7 downto 0) ;
busy : out std_logic);
END COMPONENT;
-- Allow to wait a determine number of clock cycles
procedure attenteCycles(
constant nbCycles : in integer;
signal clk : in std_logic)is
begin
for i in 1 to nbCycles loop
wait until rising_edge(clk);
end loop;
end attenteCycles;
COMPONENT er_1octet
port ( rst : in std_logic ;
clk : in std_logic ;
en : in std_logic ;
din : in std_logic_vector (7 downto 0) ;
miso : in std_logic ;
sclk : out std_logic ;
mosi : out std_logic ;
dout : out std_logic_vector (7 downto 0) ;
busy : out std_logic);
END COMPONENT;
begin
-- Here I'm trying to wait before calling the component
attenteCycles(10, clk);
RE1octet: er_1octet PORT MAP(
rst => rst ,
clk => clk ,
en => '1' ,
din => v1 ,
miso => miso ,
sclk => sclk ,
mosi => mosi ,
dout => val_and ,
busy => busy);
-- Here I'm trying to wait before calling the component
attenteCycles(3, clk);
RE2octet: er_1octet PORT MAP(
rst => rst ,
clk => clk ,
en => '1' ,
din => v2 ,
miso => miso ,
sclk => sclk ,
mosi => mosi ,
dout => val_or ,
busy => busy);
end behavior;
组件er_1octet 。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity er_1octet is
port ( rst : in std_logic ;
clk : in std_logic ;
en : in std_logic ;
din : in std_logic_vector (7 downto 0) ;
miso : in std_logic ;
sclk : out std_logic ;
mosi : out std_logic ;
dout : out std_logic_vector (7 downto 0) ;
busy : out std_logic);
end er_1octet;
architecture behavioral_3 of er_1octet is
-- types
type t_etat is (idle, receptionner_bit, emettre_bit);
-- signaux internes
signal etat : t_etat;
begin
traitement : process(clk, rst)
-- variables locales
variable cpt: natural;
variable registre : std_logic_vector (7 downto 0);
begin
if(rst = '0') then
etat <= idle;
busy <= '0';
registre := (others => '0');
mosi <= '0';
sclk <= '1';
dout <= (others => '0');
elsif(rising_edge(clk)) then
case etat is
when idle =>
if (en = '1') then
etat <= receptionner_bit;
registre := din;
busy <= '1';
cpt := 7;
mosi <= registre(cpt);
sclk <= '0';
end if;
when receptionner_bit =>
registre(cpt) := miso;
sclk <= '1';
if(cpt = 0) then
dout <= registre;
busy <= '0';
etat <= idle;
else
etat <= emettre_bit;
end if;
when emettre_bit =>
cpt := cpt - 1;
mosi <= registre(cpt);
sclk <= '0';
etat <= receptionner_bit;
end case;
end if;
end process traitement;
end behavioral_3;
谢谢你的帮助
回答编辑过的问题:如果你想控制一个组件做某事的时间,不要硬连接它的 en
使输入 '1'
.
带上所有的人 en
输入出自己的信号,并从状态机等进程中控制这些信号,状态机作为一个排序器。
然后当一个组件的所有输入都准备好了,就把它的 en
输入到 '1'
让它完成自己的工作,并将其设置为 '0'
当你希望它停止的时候。
具体细节取决于组件如何使用它的 en
输入:一种常见的方法是断言 en
为一个时钟周期,启动该组件的内部定序器,完成后将停止,直到 en
= '1'
再次。
另一种方法是主张 en
直到该组件宣称其 ack
输出(握手)。您的 er_1octet
组件做到了这一点(它的握手被称为 busy
不 ack
). 除非 busy
是一个有线OR信号,每个组件可能需要自己的 busy
信号,但还有其他的启用策略:请阅读你的组件文档。
但是还有其他的启用策略:请阅读你的组件的文档。