我可以在生成语句中使用变量吗?

发布于 2024-10-22 22:29:37 字数 727 浏览 1 评论 0原文

我想知道是否可以在生成语句中使用变量。

signal bitmap_nodes : std_logic_vector(0 to NB_NODES-1) := (others => '0');

CIRCULAR: if (CLOCKWISE = 0) generate
    variable index : integer := 0;
    begin
    GENERATE_NODE : for i in NB_NODES-1 to 0 generate
    begin        
        node_inst: node
        port map (                    
            rx_bitmap => bitmap_nodes(index)
        );

        -- Increment index
        index := index + 1;

    end generate GENERATE_NODE;

end generate CIRCULAR;

这里,该变量仅用于向量切片。它将执行以下操作(假设 NB_NODES 等于 4):

NODE0 -> bitmap_nodes(3)
NODE1 -> bitmap_nodes(2)
NODE2 -> bitmap_nodes(1)
NODE3 -> bitmap_nodes(0)

I am wondering if it is possible to use a variable inside a generate statement.

signal bitmap_nodes : std_logic_vector(0 to NB_NODES-1) := (others => '0');

CIRCULAR: if (CLOCKWISE = 0) generate
    variable index : integer := 0;
    begin
    GENERATE_NODE : for i in NB_NODES-1 to 0 generate
    begin        
        node_inst: node
        port map (                    
            rx_bitmap => bitmap_nodes(index)
        );

        -- Increment index
        index := index + 1;

    end generate GENERATE_NODE;

end generate CIRCULAR;

Here, the variable is only used for the vector slicing. What it will do is assign the following (assume NB_NODES equals 4):

NODE0 -> bitmap_nodes(3)
NODE1 -> bitmap_nodes(2)
NODE2 -> bitmap_nodes(1)
NODE3 -> bitmap_nodes(0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时常饿 2024-10-29 22:29:37

这似乎与:

   LAST: if (i = 0) generate
            firstnode : node
            port map (
                rx_bitmap => bitmap_nodes(NB_NODES-1)
            );
        end generate LAST;

不是吗?

编辑:

我仍然不清楚为什么你想这样做,但是你可以(VHDL87后)放置一个共享变量在这个区域中(您可以将其视为architecturebegin之间的部分)。请记住,如果您不想遇到各种竞争条件问题,则共享变量必须是受保护的类型。

但是,您不能像现在这样增加变量,因为生成语句必须填充并发语句(而变量赋值则不然)。

再说一次,我真的很想看到一个例子,其中这个功能是必要的(或者它更像是一个学术问题?)

That seems to be the same as:

   LAST: if (i = 0) generate
            firstnode : node
            port map (
                rx_bitmap => bitmap_nodes(NB_NODES-1)
            );
        end generate LAST;

isn't it?

EDIT:

I'm still not clear why you'd like to do this, but you can (post-VHDL87) put a shared variable in this area (you can treat it much like the part between architecture and begin). Remember that shared variables have to be of a protected type if you're not going to have all sorts of problems with race conditions.

However, you can't increment a variable like you are doing as the generate statement has to be populated with concurrent statements (and variable assignments aren't).

Again, I'd be really interested to see an example where this functionality is necessary (or is it more of an academic question?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文