Design Codesign of Embedded Systems Processes in System
Design & Co-design of Embedded Systems Processes in System. C Maziar Goudarzi 2005 Design & Co-design of Embedded Systems
Today Program z Processes in System. C z Elements in defining processes in System. C z Some examples 2005 Design & Co-design of Embedded Systems 2
Process z. Module y. Basic unit of hierarchy (basic building block) in System. C z. Process y. Basic unit of execution in System. C z. Processes are called to emulate the behavior of a target device or system 2005 Design & Co-design of Embedded Systems 3
Process z. Basics y. Basic unit of execution within System. C y. Emulate the behavior of target device y. Are triggered by clock edges and/or signal expressions y. Processes are not hierarchical x. A process does not call another process • C++ allows this. Avoid using that. y. Processes communicate through signals 2005 Design & Co-design of Embedded Systems 4
Process (cont’d) Module Input ports IO port Process 1 Output ports Process 2 Internal signal 2005 Design & Co-design of Embedded Systems 5
Process (cont’d) z Each process has y. Sensitivity list y. Execution type y. A series of statements z A process is specified in two parts y. Process declaration x. Registers the process with the System. C simulation kernel y. Process definition x. Specifies the C++/System. C statements that the process executes 2005 Design & Co-design of Embedded Systems 6
Process (cont’d) z Process declaration y. Sensitivity list + execution type y. Must be given to System. C simulation kernel to enable simulation x. System. C uses SC_MODULE constructor for this x. Example: SC_CTOR(a_module) { SC_METHOD(a_process); sensitive<<a_port; } 2005 Design & Co-design of Embedded Systems 7
Process (cont’d) z Process definition y The series of statements (operations) to be executed x. Includes • reading/writing ports, signals, and variables • Any valid C++ statement (display messages, calculations, etc. ) y System. C uses SC_MODULE member functions for this x. System. C simulation kernel calls this member function when a corresponding event happens x. Example: SC_MODULE(a_module) { void a_process(void) {. . . } SC_CTOR(a_module) { SC_METHOD(a_process); } }; 2005 Design & Co-design of Embedded Systems 8
Process (cont’d) z. Communication between processes y. System. C (actually C++) allows to use SC_MODULE data members for this x. Should we use that? Why? x. Use signals (sc_signal<> type) to synchronize processes 2005 Design & Co-design of Embedded Systems 9
Declaring a Process z Process sensitivity list y. List of events that trigger this process y. Three 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 y. General syntax xsensitive << port_1 << signal_1 <<. . . << port_n xsensitive_pos << port_1 << signal_1; xsensitive_neg << port_1 << signal_1; 2005 Design & Co-design of Embedded Systems 10
Declaring a Process (cont’d) z. Process sensitivity list (cont’d) y. The other syntax: xsensitive( port 1 ); sensitive( signal 1 ); xsensitive_pos( port 1 ); sensitive_pos( sig 1 ); x. Sensitive_neg( port 1 ); sensitive_neg( sig 1 ); 2005 Design & Co-design of Embedded Systems 11
Declaring a Process (cont’d) z. Process execution types in System. C y. Defines the way that the process is executed y. Process types x. Method x. Thread x. Clocked Thread 2005 Design & Co-design of Embedded Systems 12
Execution Types of Processes in System. C z. Three types of Process in System. C y. Methods x. SC_METHOD process y. Threads x. SC_THREAD process y. Clocked threads x. SC_CTHREAD process 2005 Design & Co-design of Embedded Systems 13
SC_METHOD Process z Is called once, when events occur on its sensitivity list z Cannot suspend execution (i. e. cannot wait()) ywait() is a function in System. C kernel. y. What happens if you put a wait() in a SC_METHOD process? z Returns control to the caller (System. C Kernel) 2005 Design & Co-design of Embedded Systems 14
Method Example: Packet Receiver frame xin rcv id id void rcv: : extract_id() { frame_type frame; frame = xin; if(frame. type==1) id = frame. ida; else id = frame. idb; #include “frame. h” SC_MODULE(rcv) { sc_in<frame_type> xin; sc_out<int> id; } void extract_id(); SC_CTOR(rcv){ SC_METHOD(extract_id); sensitive(xin); }}; Design & Co-design of Embedded 2005 Systems 15
SC_THREAD Process z Declaration to System. C kernel is the same as SC_METHOD process z Can be suspended and re-activated y wait() system call x Process is re-activated when an event occurs on process sensitivity list z General syntax: void a_thread_process() { // some statements (initialization) while ( 1) { // some other statements wait(); } } 2005 Design & Co-design of Embedded Systems 16
SC_THREAD Example: Traffic Light Controller SC_MODULE(traff) { sc_in<bool> roadsensor; sc_in<bool> clock; sc_out<bool> sc_out<bool> NSred; NSyellow; NSgreen; EWred; EWyellow; EWgreen; void control_lights(); 2005 Road Sensor SC_CTOR(traff){ SC_THREAD(control_lights); sensitive << roadsensor; sensitive_pos << clock; } }; Design & Co-design of Embedded Systems 17
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(); 2005 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(); Design & Co-design of Embedded Systems 18
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) } 2005 Design & Co-design of Embedded Systems 19
SC_THREAD Process (cont’d) z. The SC_THREAD process is the most general one z. Implementing traff module with SC_METHOD process requires defining several states z. Performance issue y. SC_THREAD simulation is slower than SC_METHOD 2005 Design & Co-design of Embedded Systems 20
SC_CTHREAD Process z The same as SC_THREAD, but is merely sensitive to edge of one clock z Results in better descriptions for synthesis z One major use: Implicit state machine z Implicit state machine vs. Explicit state machine z Additional waiting mechanisms ywait_until(<signal condition>) system call x. Process is re-activated when the condition on the signals hold ytimed wait, wait until condition with timeout (System. C 2. 0) Design & Co-design of Embedded 2005 Systems 21
SC_CTHREAD Example: Bus Controller SC_MODULE(bus) { sc_in_clk clock; sc_in<bool> newaddr; sc_in<sc_uint<32> > addr; sc_in<bool> ready; sc_out<sc_uint<32> > data; sc_out<bool> start; sc_out<bool> datardy; sc_inout<sc_uint<8> > data 8; sc_uint<32> tdata; sc_uint<32> taddr; void xfer(); 2005 addr 32 newaddr data 32 start Bus Cntrlr datardy data 8 ready Mem Cntrlr SC_CTOR(bus) { SC_CTHREAD(xfer, clock. pos()); datardy. initialize(true); } Design & Co-design of }; Embedded Systems 22
SC_CTHREAD Example: Bus Controller (cont’d) void bus: : xfer() { while (true) { wait_until( newaddr. delayed() == true); taddr = addr. read(); datardy = false; data 8 = taddr. range(7, 0); start = true; wait(); data 8 = taddr. range(15, 8); start = false; wait(); data 8 = taddr. range(23, 16); wait(); 2005 data 8 = taddr. range(31, 24); wait(); wait_until(ready. delayed() == true); tdata. range(7, 0)=data 8; wait(); tdata. range(15, 8)=data 8; wait(); tdata. range(23, 16)=data 8; wait(); tdata. range(31, 24)=data 8; data = tdata; datardy = true; } } Design & Co-design of Embedded Systems 23
What we learned today z. Processes in System. C y. Various sensitivity styles y. Various execution styles z. System. C ver. 2. 0 User’s Guide y. Most of Chapter 4 2005 Design & Co-design of Embedded Systems 24
Assignments z Today: Due date for Assignment 1 z Assignment 2: y Is put on the course web-page 1. Implement the traffic-light controller using only SC_METHOD 2. Model a file-server and its clients y Due date: x One week from now: Tuesday, Aban 3 rd 2005 Design & Co-design of Embedded Systems 25
Complementary Notes: System. C_Win z http: //www. geocities. com/systemc_win/ Design & Co-design of Embedded 2005 Systems 26
Complementary Notes: System. C_Win z http: //www. geocities. com/systemc_win/ Design & Co-design of Embedded 2005 Systems 27
- Slides: 27