Jump to content
Elvis Shera

Drive SCModel from a C-Shell

Recommended Posts

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

My C-Shell program:

image.png.35a5b8d0efb8a7d896320f99b4bfdf01.png

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

image.thumb.png.eefe70c72f5e88117790f55b8a7791d3.png

 

the main.cpp of my SC model is:

image.thumb.png.2b59bd7ca188c3ea23af7f378ddced21.png

 

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

@Eyck, 

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

@David,

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×