简体   繁体   English

Systemverilog 生成邮箱

[英]Systemverilog Generate mailboxes

How can i generate many mailboxes, for example with generate endgenerate and the how to i put data to one for them.我如何生成多个邮箱,例如使用 generate endgenerate 以及如何为它们将数据放入一个邮箱。

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它创建了 10 个邮箱,但后来我不知道如何将数据放入其中一个我会想象像

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.每当您生成 for 循环时,您都需要为块命名,并且它是扩展为编号块的块名称。 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.然后你可以参考block_a[0].testblock_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.但是您可能不想为此使用generate块,因为您将不允许使用变量来索引块,因为该块不是常规数组。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM