2012-08-25 159 views
0

我已经将这个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; 
+3

为什么你想这样做?你会使代码比需要的复杂得多。你的代码有问题吗?你需要以任何方式优化它,或者你只是想要这样做,因为......? – FarhadA

+0

只是因为我重复我的自我,所以如果我需要改变写序列中的某些东西,我将不得不在所有写序列中改变它。 – JakobJ

+0

[Design VHDL state machine for initialization]的可能重复项(http://stackoverflow.com/questions/11937254/design-vhdl-state-machine-for-initialization) – bstpierre

回答

0

我建议你使用地址和数据值的寄存器。然后你必须描述实际写作只有一个,其他的只是一个寄存器内容的变化。这可以在你开始写作之前的状态下完成...