2017-07-14 68 views
1

參考了問問題可變大小和在模塊端口/陣列端口的數目其是參數依賴以Verilog系統的Verilog

How to write a module with variable number of ports in Verilog

我對此另一個問題。

module my_module #(SIZEOF_LENGTH = 3, 
        LENGTH = {8,8,7})(
    input clk, 
    input rst_n, 
    input [LENGTH[0]-1:0] data_1, 
    input [LENGTH[1]-1:0] data_2, 
    input [LENGTH[2]-1:0] data_3 
); 

我基本上想要這樣的東西。大小取決於從頂部傳遞的參數,所以端口數量也是如此。這可以做到嗎?

回答

0

不在Verilog中,但可以使用模板語言,如Ruby或Perl。

或者在SystemVerilog中可以使用陣列端口: 注意這些必須是相同的寬度。

module my_module #(
    SIZEOF_LENGTH = 3, 
    LENGTH = 8)(
    input clk, 
    input rst_n, 
    input [LENGTH-1:0] data [0:SIZEOF_LENGTH-1] 
); 
+0

這個速記符號也能發揮作用 '輸入[長度1:0]數據[SIZEOF_LENGTH]' – Serge

+0

那這個問題,我想在數據部分的變量lenght。它應該是可能的,因爲它是一個HDL,但LRM不支持我的猜測。 –