Jump to content

SC_THREAD and sensitivity


ElliottCB

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()
{
 while(true)
{
  wait();
  cout<<"received"<<endl;
}
}

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

sc_start();
laneA.write(testA);
laneB.write(testB);

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!

Elliott

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,

regards

Alan

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 {

public:

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

//Constructor

SC_CTOR( display ) {

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

dont_initialize();

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

}

};

#endif

#include "systemc.h"

class driver : public sc_module{

public:

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

dont_initialize();

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

}

};

#ifndef HALFADDER_H

#define HALFADDER_H

#include "systemc.h"

class halfadder : public sc_module{

public:

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

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

sc_in<bool> clk;

//halfadder():sc

void prc_half_adder(); //method implementing functionality

//Counstructor

SC_CTOR(halfadder) {

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

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

dont_initialize();

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

}

};

#endif

#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

wave(in1,in2,clk);

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

h1.inPort_0(in1);

h1.inPort_1(in2);

h1.carry(t_cin);

h1.sum(t_sum);

h1.clk(clk);

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++){

clk.write(1);

sc_start( 10, SC_NS );

clk.write(0);

sc_start( 10, SC_NS );

}

system("Pause");

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.

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.

×
×
  • Create New...