How can i generate many mailboxes, for example with generate endgenerate and the how to i put data to one for them.
I tried doing
generate
for (genvar i=0; i<10; i++) begin
mailbox test = new();
end
endgenerate
and it creates 10 mailboxes but then i didn't know how to put data to one of them i would imagine something like
test[4].put(input);
but it doesnt work
any ideas??
Whenever you a generate-for loop, you need to name the block, and it is the block name that get expanded into numbered blocks. generate
for (genvar I=0; I<10; i++) begin : block_A
mailbox test;
end : block_a
endgenerate
Then you can reference block_a[0].test
, block_a[1].test
, .etc.
But you probably do not want to use a generate
block for this as you will not allowed to use a variable to index into the block since the block is not a regular array.
You can simply declare a regular carry of mailboxes.
mailbox #(int) test[10];
initial begin
foreach(mailbox[ii]) mailbox[ii] = new;
I also recommend that you parameterize your mailbox by the type of message you will bet putting into it.