-2

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??

el pass
  • 37
  • 7

2 Answers2

3

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.

dave_59
  • 39,096
  • 3
  • 24
  • 63
0

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
toolic
  • 57,801
  • 17
  • 75
  • 117
el pass
  • 37
  • 7