SystemC hangs abruptly

ello guys. I am trying to learn systemC in school. If anyone is not familiar with it please check out the link.

Its an extension to the C++ library which helps to model concurrency in hardware. Im tryin to model a traffic light controller with 4 directions and since the whole idea is to come up with a code which correctly models event driven simulation, ive tried to use threads which respond to certain events (similar to the sensitivity list in VHDL in case u know VHDL).

And for some reason my output seems to be stuck somewhere..it hangs and i have to manually kill the terminal by force closing it. Heres the description of the problem: I have four light controllers for traffic light in each direction (North South(NS), South North(SN),West East(WE) and East West(EW).Each of these controllers has 2 inputs and 1 output.Each light controller receives input from a sensor(which magically senses cars) and the light controller responds to this 'event' by sending a request to the main controller thru the out port. The main controller processes its request and send it its decision(decribed below) which it receives on the 2nd in port. As u might have guessed, the main controller's job is to issue decisions to these local controllers( they shud have been called light controllers i know :|) taking care of conflicting requests if there are any. The main controller gives preference to the NS-SN direction over the WE-EW direction in case of a conflict. I have tried to introduce modularity in the code and hence I seperated the sensor from the light controller(controller). When I build the file and then run the executable, the whole terminal hangs and shows nothing ... Heres the code: include //main controller source file #include

main_controller::main_controller(sc_module_name name):sc_module(name) {

SC_THREAD(check_requests); result1.initialize(false); result2.initialize(false); result3.initialize(false); result4.initialize(false);

SC_METHOD(issue_results); dont_initialize(); sensitive read(); req1 = request1->read(); req3 = request3->read(); req4 = request4->read();

cout

Reply to
Guy_Sweden
Loading thread data ...

Someone wrote: "[..]

And for some reason my output seems to be stuck somewhere..it hangs and i have to manually kill the terminal by force closing it. Heres the description of the problem: [..] [..] When I build the file and then run the executable, the whole terminal hangs and shows nothing ... Heres the code: [.. Over two hundred lines of C++ edited. That is a lot of code to bother reading if we have not even narrowed down the possible problems, which might not even be in your C++ code.]

int sc_main(int argc, char **argv) { srand(time(NULL));

// create instances of sensor generator modules for each direction Generator gen_NS("Generator_NS"); Generator gen_SN("Generator_SN"); Generator gen_WE("Generator_WE"); Generator gen_EW("Generator_EW");

// create intances of controller modules Controller c_NS("Controller_NS"); //name and pointer to sensor_values Controller c_SN("Controller_SN"); Controller c_WE("Controller_WE"); Controller c_EW("Controller_EW"); main_controller M("main_controller");

// create channels between the controller instances and main controller

sc_signal NS_main; sc_signal SN_main; sc_signal WE_main; sc_signal EW_main; sc_signal main_NS; sc_signal main_SN; sc_signal main_EW; sc_signal main_WE;

// create channels between the sensor generator modules and the corresponding controllers sc_signal sen_NS; sc_signal sen_SN; sc_signal sen_WE; sc_signal sen_EW;

// connect channels to ports of the modules instances gen_NS(sen_NS); gen_SN(sen_SN); gen_WE(sen_WE); gen_EW(sen_EW);

c_NS(sen_NS, main_NS, NS_main); c_SN(sen_SN, main_SN, SN_main); c_WE(sen_WE, main_WE, WE_main); c_EW(sen_EW, main_EW, EW_main);

M(NS_main,WE_main,SN_main,EW_main,main_NS,main_WE,main_SN,main_EW);

// start simulation sc_start(50, SC_SEC); //simulation time?

return 0; }

-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

------ Heres the make file which i use: [..] OPT = -O3 DEBUGFLAG = #-g #OTHER = -Wall [..] OTHER = -Wno-deprecated

[..]

# List all directories from where you include .h-files INCDIR= -I. -I.. -I$(SYSTEMC)/include

[..]

## Variable that points to SystemC installation path ## version 2.1 SYSTEMC = /usr/include

[..]

Would be glad if anyone would point out something in the system which will atleast make it run..[..] or maybe theres a problem with the make file i dont really know. I used the same make file which is used in our school lab where we work with sun ray machines and modified it to reflect the x86 machine im working with. May be i didnt do it correctly in the make file.

Any help wud be sincerely appreciated."

You have written code which calls many functions and constructors but you do not know whether main() or sc_main() or any other part of the program is ever reached. I suggest a debugging technique which may or may not help you in your current situation but which is occassionally very useful with almost any language: add debugging print statements in your code to trace the control flow. I would start by e.g. adding std::cerr

Reply to
Colin Paul Gloster

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.