我已经将这个VHDL代码写入USB芯片。优化VHDL代码
它都在case语句中运行,其中每个操作(写入,读取等)都被执行。
下面的两个写寄存器部分是相同的,只是地址和数据不同。
这可以使用程序或其他东西简化吗?
-------- WRITE REGISTER ---------
when s10 =>
-- Txd Cmd
txdata(7 downto 6) <= "10"; -- CMD = register write
txdata(5 downto 0) <= "000100"; -- address
state := s11;
when s11 =>
-- write reg
if nxt = '1' then
txdata <= X"45"; -- output on clock rising edge when nxt is high
stp <= '1';
state := s12;
end if;
when s12 =>
stp <= '0';
txdata <= "00000000"; -- idle
state := s20;
-------- WRITE REGISTER ---------
when s20 =>
-- Txd Cmd
txdata(7 downto 6) <= "10"; -- CMD = register write
txdata(5 downto 0) <= "110101"; -- address
state := s21;
when s21 =>
-- write reg
if nxt = '1' then
txdata <= X"04";
stp <= '1';
state := s22;
end if;
when s22 =>
stp <= '0';
txdata <= "00000000"; -- idle
state := s30;
为什么你想这样做?你会使代码比需要的复杂得多。你的代码有问题吗?你需要以任何方式优化它,或者你只是想要这样做,因为......? – FarhadA
只是因为我重复我的自我,所以如果我需要改变写序列中的某些东西,我将不得不在所有写序列中改变它。 – JakobJ
[Design VHDL state machine for initialization]的可能重复项(http://stackoverflow.com/questions/11937254/design-vhdl-state-machine-for-initialization) – bstpierre