Download presentation
Presentation is loading. Please wait.
1
Design & Co-design of Embedded Systems Processes in SystemC Maziar Goudarzi
2
2005 Design & Co-design of Embedded Systems2 Today Program zProcesses in SystemC zElements in defining processes in SystemC zSome examples
3
2005 Design & Co-design of Embedded Systems3 Process zModule yBasic unit of hierarchy (basic building block) in SystemC zProcess yBasic unit of execution in SystemC zProcesses are called to emulate the behavior of a target device or system
4
2005 Design & Co-design of Embedded Systems4 Process zBasics yBasic unit of execution within SystemC yEmulate the behavior of target device yAre triggered by clock edges and/or signal expressions yProcesses are not hierarchical xA process does not call another process C++ allows this. Avoid using that. yProcesses communicate through signals
5
2005 Design & Co-design of Embedded Systems5 Process (cont’d) Module Process 1 Process 2 Internal signal Input ports IO port Output ports
6
2005 Design & Co-design of Embedded Systems6 Process (cont’d) zEach process has ySensitivity list yExecution type yA series of statements zA process is specified in two parts yProcess declaration xRegisters the process with the SystemC simulation kernel yProcess definition xSpecifies the C++/SystemC statements that the process executes
7
2005 Design & Co-design of Embedded Systems7 Process (cont’d) zProcess declaration ySensitivity list + execution type yMust be given to SystemC simulation kernel to enable simulation xSystemC uses SC_MODULE constructor for this xExample: SC_CTOR(a_module) { SC_METHOD(a_process); sensitive<<a_port; }
8
2005 Design & Co-design of Embedded Systems8 Process (cont’d) zProcess definition yThe series of statements (operations) to be executed xIncludes reading/writing ports, signals, and variables Any valid C++ statement (display messages, calculations, etc.) SystemC uses SC_MODULE member functions for this xSystemC simulation kernel calls this member function when a corresponding event happens xExample: SC_MODULE(a_module) { void a_process(void) {... } SC_CTOR(a_module) { SC_METHOD(a_process); } };
9
2005 Design & Co-design of Embedded Systems9 Process (cont’d) zCommunication between processes SystemC (actually C++) allows to use SC_MODULE data members for this xShould we use that? Why? Use signals ( sc_signal<> type) to synchronize processes
10
2005 Design & Co-design of Embedded Systems10 Declaring a Process zProcess sensitivity list yList of events that trigger this process yThree types of sensitivity xsensitive Any change of value on the port/signal triggers the process xsensitive_pos A positive edge on the port/signal triggers the process xsensitive_neg A negative edge on the port/signal triggers the process yGeneral syntax xsensitive << port_1 << signal_1 <<... << port_n xsensitive_pos << port_1 << signal_1; xsensitive_neg << port_1 << signal_1;
11
2005 Design & Co-design of Embedded Systems11 Declaring a Process (cont’d) zProcess sensitivity list (cont’d) yThe other syntax: xsensitive( port1 ); sensitive( signal1 ); xsensitive_pos( port1 ); sensitive_pos( sig1 ); xSensitive_neg( port1 ); sensitive_neg( sig1 );
12
2005 Design & Co-design of Embedded Systems12 Declaring a Process (cont’d) zProcess execution types in SystemC yDefines the way that the process is executed yProcess types xMethod xThread xClocked Thread
13
2005 Design & Co-design of Embedded Systems13 Execution Types of Processes in SystemC zThree types of Process in SystemC yMethods SC_METHOD process yThreads SC_THREAD process yClocked threads SC_CTHREAD process
14
2005 Design & Co-design of Embedded Systems14 SC_METHOD Process zIs called once, when events occur on its sensitivity list Cannot suspend execution (i.e. cannot wait() ) wait() is a function in SystemC kernel. What happens if you put a wait() in a SC_METHOD process? zReturns control to the caller (SystemC Kernel)
15
2005 Design & Co-design of Embedded Systems15 Method Example: Packet Receiver #include “frame.h” SC_MODULE(rcv) { sc_in xin; sc_out id; void extract_id(); SC_CTOR(rcv){ SC_METHOD(extract_id); sensitive(xin); }}; void rcv::extract_id() { frame_type frame; frame = xin; if(frame.type==1) id = frame.ida; else id = frame.idb; } rcv frame id xinid
16
2005 Design & Co-design of Embedded Systems16 SC_THREAD Process Declaration to SystemC kernel is the same as SC_METHOD process zCan be suspended and re-activated wait() system call xProcess is re-activated when an event occurs on process sensitivity list zGeneral syntax: void a_thread_process() { // some statements (initialization) while ( 1) { // some other statements wait(); }
17
2005 Design & Co-design of Embedded Systems17 SC_THREAD Example: Traffic Light Controller SC_MODULE(traff) { sc_in roadsensor; sc_in clock; sc_out NSred; sc_out NSyellow; sc_out NSgreen; sc_out EWred; sc_out EWyellow; sc_out EWgreen; void control_lights(); SC_CTOR(traff){ SC_THREAD(control_lights); sensitive << roadsensor; sensitive_pos << clock; } }; Road Sensor
18
2005 Design & Co-design of Embedded Systems18 SC_THREAD Example: Traffic Light Controller (cont’d) void traff::control_lights() { NSred = NSyellow = false; NSgreen = true; EWred = true; EWyellow = EWgreen = false; while (true) { while (roadsensor == false) wait(); NSgreen = false; NSyellow = true; NSred = false; for (i=0; i<5; i++) wait(); NSgreen = NSyellow = false; NSred = true; EWgreen = true; EWyellow = EWred = false; for (i= 0; i<50; i++) wait(); NSgreen = NSyellow = false; NSred = true; EWgreen = false; EWyellow = true; EWred = false; for (i=0; i<5; i++) wait();
19
2005 Design & Co-design of Embedded Systems19 SC_THREAD Example: Traffic Light Controller (cont’d) NSgreen = true; NSyellow = NSred = false; EWgreen = EWyellow = false; EWred = true; for (i=0; i<50; i++) wait(); } // while (true) }
20
2005 Design & Co-design of Embedded Systems20 SC_THREAD Process (cont’d) The SC_THREAD process is the most general one Implementing traff module with SC_METHOD process requires defining several states zPerformance issue ySC_THREAD simulation is slower than SC_METHOD
21
2005 Design & Co-design of Embedded Systems21 SC_CTHREAD Process The same as SC_THREAD, but is merely sensitive to edge of one clock zResults in better descriptions for synthesis zOne major use: Implicit state machine zImplicit state machine vs. Explicit state machine zAdditional waiting mechanisms wait_until( ) system call xProcess is re-activated when the condition on the signals hold ytimed wait, wait until condition with timeout (SystemC 2.0)
22
2005 Design & Co-design of Embedded Systems22 SC_CTHREAD Example: Bus Controller SC_MODULE(bus) { sc_in_clk clock; sc_in newaddr; sc_in > addr; sc_in ready; sc_out > data; sc_out start; sc_out datardy; sc_inout > data8; sc_uint tdata; sc_uint taddr; void xfer(); SC_CTOR(bus) { SC_CTHREAD(xfer, clock.pos()); datardy.initialize(true); } }; Bus Cntrlr Mem Cntrlr addr 32 newaddrstart data8 ready data 32 datardy
23
2005 Design & Co-design of Embedded Systems23 SC_CTHREAD Example: Bus Controller (cont’d) void bus::xfer() { while (true) { wait_until( newaddr.delayed() == true); taddr = addr.read(); datardy = false; data8 = taddr.range(7,0); start = true; wait(); data8 = taddr.range(15,8); start = false; wait(); data8 = taddr.range(23,16); wait(); data8 = taddr.range(31,24); wait(); wait_until(ready.delayed() == true); tdata.range(7,0)=data8; wait(); tdata.range(15,8)=data8; wait(); tdata.range(23,16)=data8; wait(); tdata.range(31,24)=data8; data = tdata; datardy = true; }
24
2005 Design & Co-design of Embedded Systems24 What we learned today zProcesses in SystemC yVarious sensitivity styles yVarious execution styles zSystemC ver. 2.0 User’s Guide yMost of Chapter 4
25
2005 Design & Co-design of Embedded Systems25 Assignments zToday: Due date for Assignment 1 zAssignment 2: yIs put on the course web-page 1.Implement the traffic-light controller using only SC_METHOD 2.Model a file-server and its clients yDue date: xOne week from now: Tuesday, Aban 3rd
26
2005 Design & Co-design of Embedded Systems26 Complementary Notes: SystemC_Win zhttp://www.geocities.com/systemc_win/http://www.geocities.com/systemc_win/
27
2005 Design & Co-design of Embedded Systems27 Complementary Notes: SystemC_Win zhttp://www.geocities.com/systemc_win/http://www.geocities.com/systemc_win/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.