Jump to content

SC_THREAD and sensitivity


Recommended Posts

Hey Everyone,

I'm very new to SystemC so this might sound like a pretty trivial question, but I'm not really sure what specifically to look for in order to resolve this issue.

I have a simple module with 2 input ports and an SC_THREAD method which is sensitive to these inputs. The function assigned to this SC_THREAD is :

void test()

In sc_main where I instantiate this module, I attach 2 signals (laneA and laneB) to its 2 input ports and execute the following :


My assumption was that the output printed in test() would be called twice (once for each of the writes). Unfortunately, it is only printed once. I'm sure there must be some underlying misunderstanding here, but hopefully it is something trivial.

Another clue that I've misunderstood something is that if I print the contents of both the ports within the while(true){} block, both of the values written in sc_main appear.

So, what exactly am I missing about the overall flow of execution? Any help would be greatly apprecaited. Thanks in advance!


Link to comment
Share on other sites

I'm a bit confused by your code - if you do the calls to write *after* returning from sc_start(), I wouldn't expect either write to work as once the simulation has returned from sc_start(), it is either finished or paused.

Regarding your main question - the two events created by assigning signals in the same delta will only result in the process running once.

Have a look at our (Doulos's - I work for Doulos) little tutorial here: http://www.doulos.com/knowhow/systemc/tutorial/ and see if that helps,



P.S. An interesting experiment would be to put

dont_initialize() ;

after the sensitivity of your SC_THREAD and see what happens. All SystemC processes run at time zero without being triggered - by adding dont_initialize(), you will be able to see if your writes are really what is causing the process to run.

Link to comment
Share on other sites

Thanks everyone for the quick responses. I believe my confusion arises from what should be done in sc_main() in regards to providing stimulus for a module. Currently my sc_main() simply consists of instantiating a module and attacing sc_signals to each of its ports. My hope was that I could write to these ports to see how the module reacts. How I (incorrectly) did this was shown in my initial post.

Is it a requirement to create a separate module which creates and issues stimulus to the my module being tested as shown in the tutorial that Alan posted, or is there a way to provide stimulus to my module directly within sc_main()?

Again, very sorry for these uninformed questions. Moving from C++ to SystemC has been a rather large paradigm shift :( Thanks for everyone's help.

Link to comment
Share on other sites

Hi : ElliottCB :

You can refer and modify the following example as your template, actually it was modified by using SystemC example

(pipe project as i remember). Due to the version of SystemC, some descriptions indicated in old documents can not work properly at

this moment. That will be a major problem for you as a beginner.

It works after referring many documents and examples about SystemC. :blink:

Good Luck to make it happen ^_^

#define DISPLAY_H

// display.h

#include "systemc.h"

class display : public sc_module {


sc_in<bool> inPort0;

sc_in<bool> inPort1;

sc_in<bool> cin; // input port 1

sc_in<bool> sum;

sc_in<bool> clk; // clock

void print_result(); // method to display input port values


SC_CTOR( display ) {

SC_METHOD( print_result ); // declare print_result as SC_METHOD and


sensitive << clk.pos(); // make it sensitive to positive clock edge




#include "systemc.h"

class driver : public sc_module{


sc_out<bool> outPort_a;

sc_out<bool> outPort_b; // output port

sc_in<bool> clk;

void prc_driver();

// Constructor

SC_CTOR(driver) {

SC_METHOD(prc_driver); // Method process to print data


sensitive << clk.pos(); //make it sensitive to positive clock edge





#include "systemc.h"

class halfadder : public sc_module{


sc_in<bool> inPort_0,inPort_1; //input 1

sc_out<bool> sum,carry; //output 1

sc_in<bool> clk;


void prc_half_adder(); //method implementing functionality


SC_CTOR(halfadder) {

SC_METHOD(prc_half_adder); //Declare addsub as SC_METHOD and

//sensitive << a<<b ; //make it sensitive to positive clock edge


sensitive << clk.pos(); //make it sensitive to positive clock edge




#include "waveform.h"

#include "halfadder.h"

#include "monitor.h"

int sc_main(int argc, char* argv[])


sc_signal<bool> in1; // initial signals for the system

sc_signal<bool> in2;

sc_signal<bool> t_cin;

sc_signal<bool> t_sum;

sc_signal<bool> clk;

WaveForm wave("waveforms"); //instance of `waveform' module


HalfAdder h1("halfadder"); //instance of `halfadder' module






Monitor m("monitor"); //instance of `monitor' module

m(in1,in2,t_cin,t_sum,clk); //Positional port binding

cout<<"start waveform :"<<endl;

sc_start(0, SC_NS); //Initialize simulation

for(int i = 0; i < 50; i++){


sc_start( 10, SC_NS );


sc_start( 10, SC_NS );



return 0;


Diagram of Example

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