Way to initialize synthesizable 2D array with constant values in Verilog

前端 未结 4 1143
陌清茗
陌清茗 2021-01-06 00:58

in VHDL, I can easily do this:

constant    cmdbytes       : bytearray(0 to Total) := (x\"05\", x\"00\", x...};

I want synthesizable constan

4条回答
  •  -上瘾入骨i
    2021-01-06 01:17

    If you're just using the array to pull out one value at a time, how about using a case statement? Granted, it's a long-winded way of doing it, but you could always write a script to write the RTL for you.

    reg [7:0] value;
    reg [7:0] i;
    
    always @(posedge clk or negedge rst_n) begin
        if(!rst_n)
            i <= 8'd0;
        else
            i <= i + 1;
    end
    
    always @(*) begin
        case(i) 
            8'h00: value = 8'd0;
            8'h01: value = 8'd34;
            ...
        endcase
    endcase
    

    Another way is to use an initial statement. As far as I'm aware, FPGA synthesis tools will allow you to set initial values for arrays in the following manner. Again, a script to write this may be the way to go.

    reg [0:35][7:0] my_array;
    
    initial begin
        my_array[0] = 8'd45;
        my_array[1] = 8'd26;
        ...
    end
    

    And if your FGPA synthesis tools support some SystemVerilog, you'll be able to initialise the array like so:

    reg [0:34][7:0] my_array = '{ 8'd90, 8'd34, ... }; // note the '{
    

提交回复
热议问题