I'm currently grappling with the problem that verilog modules only accept one-dimensional packed vectors as inputs/outputs. For example:
wire [bitWidth-1:0] data;
What I want to do is input a two-dimensional vector with one dimension packed (think array of numbers). For example:
wire [bitWidth-1:0] data [0:numData-1];
I currently have a couple of handy macros that flatten the two-dimensional vector and unflatten a one-dimensional vector. They are:
`define PACK_ARRAY(PK_WIDTH,PK_LEN,PK_SRC,PK_DEST) \
genvar pk_idx; \
generate \
for (pk_idx=0; pk_idx<(PK_LEN); pk_idx=pk_idx+1) begin : packLoop \
assign PK_DEST[((PK_WIDTH)*pk_idx+((PK_WIDTH)-1)):((PK_WIDTH)*pk_idx)] = PK_SRC[pk_idx][((PK_WIDTH)-1):0]; \
end \
endgenerate
`define UNPACK_ARRAY(PK_WIDTH,PK_LEN,PK_DEST,PK_SRC) \
genvar unpk_idx; \
generate \
for (unpk_idx=0; unpk_idx<(PK_LEN); unpk_idx=unpk_idx+1) begin : unpackLoop \
assign PK_DEST[unpk_idx][((PK_WIDTH)-1):0] = PK_SRC[((PK_WIDTH)*unpk_idx+(PK_WIDTH-1)):((PK_WIDTH)*unpk_idx)]; \
end \
endgenerate
These work great if I am only using them to deal with one output and one input to the module I am working in. The problem is that if I use either of these macros more than once in a given module then the following errors occur:
1) The genvar
s have already been declared.
2) The loop labels have already been used.
I can get around the genvar
issue by not declaring it in the macro and declaring it elsewhere, but I can't figure out how to solve the loop label issue and still be able to use a macro to keep clean code.
Any suggestions (except 'switch to system verilog' :P) are welcome! Thanks.