请教generate语句例化的单元中包含多bit端口?谢谢
想对同一个单元进行多次例化,但例化次数不确定,考虑用generate语句生成
在例化时,如果被例化单元中包含多bit端口,generate语句应该怎么处理?
由于verilog的端口不能声明成二维的,是否应该将二维数组拆成一维的,
然后在multi_data_in[index]中,对index处理,还是这种方法根本就不对?
非常感谢:)
module unit(
clk, rst_n,
enable, data_in, data_out
);
input wire clk;
input wire rst_n;
input wire enable;
input wire[7:0] data_in;
output wire[7:0] data_out;
//=======================================================
reg[7:0] data_out_r;
//=======================================================
always @ (posedge clk or negedge rst_n) begin
if (!rst_n) data_out_r <= 8'd0;
else if (enable) data_out_r <= data_in;
end
assign data_out = data_out_r;
endmodule
module multi_unit(
clk, rst_n,
multi_enable, multi_data_in, multi_data_out
);
//=======================================================
parameter MULTI_SIZE = 4;
//=======================================================
input wire clk;
input wire rst_n;
input wire[MULTI_SIZE-1:0] multi_enable;
input wire[7:0] multi_data_in[MULTI_SIZE-1:0];(知道不能声明二维端口,但应该如何来处理呢?)
output wire[7:0] multi_data_out[MULTI_SIZE-1:0];(同上)
//=======================================================
generate
genvar i;
for (i=0; i<MULTI_SIZE; i=i+1)
begin: unit_gen
unit unit(
.clk(clk),
.rst_n(rst_n),
.enable(multi_enable[i]),
.data_in(multi_data_in[i]),
.data_out(multi_data_out[i])
);
end
endgenerate
endmodule
input wire [8*MULTI_SIZE-1:0] multi_data_in;
output wire[8*MULTI_SIZE-1:0] multi_data_out;
wire [7:0] multi_data_in_array [MULTI_SIZE-1:0];
wire [7:0] multi_data_out_array [MULTI_SIZE-1:0];
//=======================================================
generate
genvar i;
for (i=0; i<MULTI_SIZE; i=i+1)
begin: unit_gen
assign multi_data_in_array[i] = multi_data_in[i*8+7:i*8];
assign multi_data_out[i*8+7:i*8] = multi_data_out_array[i];
unit unit(
.clk(clk),
.rst_n(rst_n),
.enable(multi_enable[i]),
.data_in(multi_data_in_array[i]),
.data_out(multi_data_out_array[i])
);
end
endgenerate
endmodule