Jump to content
Sign in to follow this  
Carmichael

Syntax questions on systemC

Recommended Posts

Hi,

 

I have some questions on systemC syntax. 

 

1. sc_event_queue. I found a lot of examples for sc_event_queue on some systemC coursewares (even threads on this forum), like below,

 
SC_MODULE(somemod){
     sc_event_queue eq;
     ...
     void process1(){
          while(true){
          ...
          wait(eq);                       // here got a message: cannot convert from 'sc_core::sc_event_queue' to 'const sc_core::sc_event' ,
          ...
          }
     }
     void process2(){
          while(true){
         ...
         eq.notify(5,SC_NS);
         eq.notify(8,SC_NS);
         ...
          }
     }
     SC_CTOR(somemod){
     ...
     }
};
    If I change "wait(eq)" into "wait(eq.default_event())" or just use "wait()" meanwhile add eq into the sensitive list, it will work. Is it correct?
 
2. sc_semaphore channel. I see an example from the book systemc from the ground up like this,
 
SC_MODULE(gas_station) {
     sc_semaphore pump(12);      // here seems define a function which will return a sc_semaphore instance
     void customer1_thread {
          for(;; ) {
          // wait till tank empty 
          …
          // find an available gas pump
          pump.wait();
          // fill tank & pay
     }
};
    But this seems that it cannot work at all. Then if I use a new form like below it will work,
 
SC_MODULE(gas_station) {
     sc_semaphore pump;      
     void customer1_thread {
          for(;; ) {
          // wait till tank empty 
          …
          // find an available gas pump
          pump.wait();
          // fill tank & pay
     }
     SC_CTOR: pump(12){
     ...
     }
};
    So if I want to use the form of sc_semaphore pump(12) to the module, what should I do on the constructor?
 
Another question for the semaphore channel: does the sc_semaphore value have a upper limit or what is the size of this channel?
 
Thanks a lot!
 
Wayne

Share this post


Link to post
Share on other sites

For question 1, please see Note 1 in the 1666-2011 LRM section 6.30.3.

 

For question 2 - that looks like an error in SystemC from the Ground Up. In c++ before c++11 you can't do any initialisation of class members at declaration, so you must initialise on the constructor initialiser list (I think from memory that's been relaxed in c++ 11).

 

When you say "So if I want to use the form of sc_semaphore pump(12) to the module, what should I do on the constructor?" the answer is you can't (pre C++11). Your second example is correct. Of course you can use a pointer to an sc_semaphore and call new in the constructor if you prefer.

 

For your last question, please see the LRM section 6.29.3,

 

regards

Alan

 

P.S. The LRM is free, and can be downloaded via the main Accellera website.

Share this post


Link to post
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.

Sign in to follow this  

×
×
  • Create New...