【发布时间】:2014-11-28 21:36:14
【问题描述】:
我正在用 VHDL 实现一个简单的 SPI 主机。我面临的问题是在合成过程中为ss 和data_rdy 创建了两个触发器。我以为这些端口的输出总是指定的,那么为什么要创建这些寄存器,我该如何摆脱它们?
我的代码如下,省略了没有ss 或data_rdy 的状态。
实体:
library IEEE;
use IEEE.std_logic_1164.ALL;
entity mcu is
port(clk : in std_logic;
res : in std_logic;
pc : in std_logic_vector(7 downto 0);
pc_new : in std_logic;
data_ack : in std_logic;
miso : in std_logic;
data : out std_logic_vector(12 downto 0);
data_rdy : out std_logic;
mosi : out std_logic;
sclk : out std_logic;
ss : out std_logic);
end mcu;
架构:
library IEEE;
use IEEE.std_logic_1164.ALL;
architecture behaviour of mcu is
-- r: send read command
-- a: send address
-- rx: receive data
type state_t is (r0, r1, r2, r3, r4, r5, r6, r7,
a0, a1, a2, a3, a4, a5, a6, a7,
rx0, rx1, rx2, rx3, rx4, rx5, rx6, rx7, rx8, rx9, rx10, rx11, rx12,
idle, starting, done);
signal state : state_t := idle;
signal datasig : std_logic_vector(12 downto 0);
begin
sclk <= clk;
mosi <= datasig(12);
sync : process(clk) is
begin
if rising_edge(clk) then
data_rdy <= '0';
ss <= '0';
if res = '1' then
state <= idle;
else
datasig <= datasig(11 downto 0) & miso;
if pc_new = '1' then
state <= starting;
else
case state is
when idle =>
ss <= '1';
datasig <= (others => '0');
state <= idle;
...
when rx12 =>
data <= datasig;
data_rdy <= '1';
state <= done;
when done =>
if data_ack = '1' then
state <= idle;
else
state <= done;
end if;
end case;
end if;
end if;
end if;
end process sync;
end behaviour;
相关合成器输出:
===============================================================================
| Register Name | Type | Width | Bus | MB | AR | AS | SR | SS | ST |
===============================================================================
| data_rdy_reg | Flip-flop | 1 | N | N | N | N | Y | N | N |
| ss_reg | Flip-flop | 1 | N | N | N | N | Y | N | N |
| data_reg | Flip-flop | 13 | Y | N | N | N | N | N | N |
| state_reg | Flip-flop | 3 | Y | N | N | N | N | Y | N |
| state_reg | Flip-flop | 2 | N | N | N | N | Y | Y | N |
| datasig_reg | Flip-flop | 13 | Y | N | N | N | N | N | N |
===============================================================================
还有,为什么state会被分成两个寄存器?
【问题讨论】: