I'm a complete beginner when it comes to Verilog. I have a block ROM which is as follows:
module CDbram_2_0_32 (clk, en, addr, dout);
input clk;
input en;
input [9:0] addr;
output [9:0] dout [0:37];
(*rom_style = "block" *) reg [9:0] data [0:37];
always @(posedge clk)
begin
if (en)
case(addr)
10'd0:data<={10'd19,10'd7,10'd27,-10'd1,10'd14,-10'd1,10'd11,10'd11,-10'd1,10'd19,-10'd1,10'd19,-10'd1,-10'd1,10'd28,10'd23,-10'd1,10'd12,-10'd1,10'd23,-10'd1,10'd4,-10'd1,10'd8,-10'd1,10'd18,-10'd1,-10'd1,10'd18,-10'd1,10'd19,-10'd1,10'd12,-10'd1,-10'd1,10'd15,-10'd1,-10'd1};
10'd1:data<={10'd22,10'd9,-10'd1,10'd1,10'd30,10'd11,10'd25,-10'd1,10'd31,10'd2,10'd19,-10'd1,10'd11,10'd30,-10'd1,10'd20,10'd26,-10'd1,10'd30,-10'd1,10'd14,-10'd1,-10'd1,-10'd1,10'd2,-10'd1,-10'd1,10'd10,-10'd1,-10'd1,-10'd1,10'd25,-10'd1,-10'd1,10'd31,-10'd1,-10'd1,10'd1};
10'd2:data<={-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,-10'd1,10'd31,-10'd1,10'd11,-10'd1,10'd29,-10'd1,10'd5,-10'd1,10'd7,-10'd1,-10'd1,10'd4,-10'd1,-10'd1,10'd6,-10'd1,-10'd1,-10'd1,10'd0,-10'd1};
....(and so on till addr 13)
endcase
end
assign dout = data;
endmodule
What I want to do is run 38 instances of a module (CN) in parallel. Each address of BROM has 38 values, so at each posedge, I want all the module instances to read their respective dout[index] and save the output in P2[index], like this:
for (j=0; j<14; j=j+1) begin: cn_instances
CN inst0 (.data_in(m[j]), .shift_amt(dout[0]), .data_out(p2_temp[0])); assign p2[0] = p2[0]^p2_temp[0];
I'm sure my code is completely wrong, but I'm not sure where. I know that generating a for loop will only generate more instances, which is not what I want, but a regular for loop doesn't run with module instances. I'm so confused.
`timescale 1ns / 1ps
module P2_inst (
input clk, // Clock signal
input rst, // Reset signal (active high)
input en, // Enable reading (active high)
input [447:0] message,
output reg [9:0] dout [0:13], // Output data from ROM
output reg [9:0] addr, // Current address
output reg [31:0] p2 [0:37]
);
reg [31:0] m [0:13];
assign {m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13] }= message;
reg [31:0] p2_temp [0:37];
CDbram_2_0_32 rom (
.clk(clk),
.en(en), // Enable ROM read
.addr(addr), // Current address
.dout(dout) // Output data
);
always @(posedge clk or posedge rst) begin
if (rst) begin
addr <= 10'd0; // Reset to address 0
end
else if (en) begin
if (addr < 10'd531) begin // Stop at last address (531)
addr <= 10'd0;
genvar j;
for (j=0; j<14; j=j+1)begin: cn_instances
j<=addr;
CN inst0 (.data_in(m[j]), .shift_amt(dout[0]), .data_out(p2_temp[0])); assign p2[0] = p2[0]^p2_temp[0];
CN inst1 (.data_in(m[j]), .shift_amt(dout[1]), .data_out(p2_temp[1])); assign p2[1] = p2[1]^p2_temp[1];
....
CN inst37 (.data_in(m[j]), .shift_amt(dout[37]), .data_out(p2_temp[37])); assign p2[37] = p2[37]^p2_temp[37];
end
else begin
addr <= 10'd0; // Wrap around (optional)
end
end
end
endmodule
Any help is appreciated.
jand use that as the index form