我已經將這個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