Jump to content

generate block


Recommended Posts

Hi experts,

I want to write several forever blocks dynamically.

Just like:

fork
   forever begin
       e[0].wait_on();
       seq[0].start(agents[0].sequencer);
       e[0].reset();
   end

   forever begin
       e[1].wait_on();
       seq[1].start(agents[1].sequencer);
       e[1].reset();
   end

   ...
join
Then I want to use generate block to replace mass codes above and make it configurable.

for(genvar i=0 ;i< NUM; i++)
  forever begin
       e[i].wait_on();
       seq[i].start(agents[i].sequencer);
       e[i].reset();
  end

But compile error:

Verilog keyword 'genvar' is not expected to be used in this context.

How can i use generate block in a class context??

Thanks

Link to comment
Share on other sites

You don't need to use generate block to do what you want:

for(int i=0 ;i< NUM; i++)
   fork
     int j=i; // each process needs a separate copy of 'i'
     forever begin
        e[i].wait_on();
        seq[i].start(agents[i].sequencer);
        e[i].reset();
     end
  join_none
wait fork; // waits forever
Edited by dave_59
Link to comment
Share on other sites

I ain't an expert, but here's how you can spawn multiple threads from within a class:

class whatever;
  // -- Stuff omitted for brevity of example.
  task sometask;
    foreach(e[i]) begin  // Can be a standard for loop as well.
      fork
        automatic int j = i;  // Put this in the fork declarative region to ensure each thread gets iteration value.
        forever begin
          e[j].wait_on();
          seq[j].start(agents[j].sequencer);
          e[j].reset();
        end
      join_none
    end
  endtask : sometask
endclass : whatever

Hi experts,

I want to write several forever blocks dynamically.

Just like:

fork
   forever begin
       e[0].wait_on();
       seq[0].start(agents[0].sequencer);
       e[0].reset();
   end

   forever begin
       e[1].wait_on();
       seq[1].start(agents[1].sequencer);
       e[1].reset();
   end

   ...
join
Then I want to use generate block to replace mass codes above and make it configurable.

for(genvar i=0 ;i< NUM; i++)
  forever begin
       e[i].wait_on();
       seq[i].start(agents[i].sequencer);
       e[i].reset();
  end

But compile error:

Verilog keyword 'genvar' is not expected to be used in this context.

How can i use generate block in a class context??

Thanks

Link to comment
Share on other sites

Thanks, Dave & mea1201.

It works for me.

for(int n = 0; n<CLIENT_LEVEL_NUM; n++)
        fork
            automatic int j = n;
            forever begin
            ......
            end
        join_none

I have another workaround and maybe non-standard.

class A extends uvm_component;
 int i;

task run_phase(uvm_phase phase);
       forever begin
           e[i].wait_on();
           seq.start(agents[i].sequencer);
           e[i].reset();
       end
endtask
endclass : a

A x_agents = new[NUM];
Link to comment
Share on other sites

Few quick notes:

1. I believe generate is NOT allowed inside a class as generate is elab time and class objects are run-time

2. IChip - your work-around code doesn't seem to be fully shown (how is value of "i" fixed/assigned?). Note that it is important to have automatic variable inside the for loop inorder to get it correctly working - else all threads may use the last iteration value (or the one beyond, dpeending on your looping).

Regards

Ajeetha, CVC

www.cvcblr.com/blog

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...