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.
Here is the solution for everyone in need:
// first make an array of mailboxes
mailbox slave_mailbox [TB_SLAVES];
int out;
initial begin
for (int i = 0; i < TB_SLAVES; i++) begin
// then create the object for every mailbox
slave_mailbox[i] = new();
end
// testing if it works
slave_mailbox[0].try_put(1);
slave_mailbox[0].try_get(out);
$display("got %0d",out);
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.