IChip Posted March 27, 2012 Report Share Posted March 27, 2012 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 ... joinThen 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 Quote Link to comment Share on other sites More sharing options...
dave_59 Posted March 27, 2012 Report Share Posted March 27, 2012 (edited) 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 March 27, 2012 by dave_59 Quote Link to comment Share on other sites More sharing options...
mea1201 Posted March 27, 2012 Report Share Posted March 27, 2012 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 ... joinThen 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 Quote Link to comment Share on other sites More sharing options...
IChip Posted March 28, 2012 Author Report Share Posted March 28, 2012 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]; Quote Link to comment Share on other sites More sharing options...
aji.cvc Posted March 28, 2012 Report Share Posted March 28, 2012 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 Quote Link to comment Share on other sites More sharing options...
IChip Posted March 28, 2012 Author Report Share Posted March 28, 2012 Thanks aji.cvc for your useful notes. And I should add the line below in my workaround. foreach(x_agents) x_agents.set_i(xxx); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.