Jump to content

Drive SCModel from a C-Shell

Elvis Shera

Recommended Posts

Hello, I am trying to drive an SC model via a C-shell. 

My C-Shell program:


the SC model is exposed to the c-shell via an API declared as:



the main.cpp of my SC model is:



the DUT is modeled as a short... where the output = input every time the input is changing. The main program is compiled and I am generating a shared library out of it. Such library is then linked while creating an executable for the c-shell program.

By playing around... I either get a core-dump or an error message telling me that it could not insret primitive channel.  Does anyone see something wrong in my code ?

Thanks Elvis

Link to comment
Share on other sites

Actually you don't assign anything to adata->sdata in sc_main In your if branch testing the pointer for NULL and create the design but then you throw away the pointer. So it is called a second time after calling sc_start() and it is not allowed to instantiate primitive channels after the elaboration phase.

But in genereral your approach is quite a mess and prone to errors (as you encountered already). Why don't you put your outer for-loop in sc_main and just load the model from the shared librar? This way you have proper initialization, do not abuse any parameters and have a similar flexibility (as I  can judge). Moreover you have some compatibility with other (commercial) SystemC simulators. Another aspect: repeatedly calling sc_elab_and_sim() has quite some perfomance impact as there are memory allocations to hold copies the argc[] strings and some more.

Best regards

Link to comment
Share on other sites

I would suggest that putting anything other than instantiation of a top level module is inappropriate. You should create a top level module with a thread to contain your behavior. As you are interested in communicating with SystemC from outside the simulator (i.e. from the shell), then you need to use thread-safe techniques. SystemC is not thread-safe without special precautions. You have two choices in this regard:

  1. Use polling inside your thread and use appropriate interprocess communications mechanisms (don't forget to use a mutex).
  2. Create a primitive channel using async_request_update and appropriate interprocess communications mechanisms to capture the data from outside.

Neither approach is trivial.

Link to comment
Share on other sites


"you don't assign anything to adata->sdata in sc_main In your if branch testing the pointer for NULL and create the design but then you throw away the pointer". I missed this. Thanks for pointing out. 

The issue I have in putting the loop inside sc_main is that I would be assuming how the external application will want to use the mode.?  Think about the schenariou where you want to ship this model to a costumer. The only think they should care is the API interface exposed to them... data and methods eventually.  

In general I am not proud of this approach but I seem comming regularly into problems. A guideline on how to do this is missing. Maybe the folks in the working group can write a documetn/guideline to this. 

How would you approach this kind of problem if what you want is to pass an input vector to SC + timing and read yn output vector? the data can be from logic, int, string and reals.

Yes. sc_elab_and_sim()  will create peprfomance issues but cannot call sc_start() outside sc_main  (like sc_stop) and i do not know anyother way of doing it. 


Thanks for your inputs. Is clear but as you said... would need to play around on how to do this seems not trivial.

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.

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...