330 likes | 355 Views
SystemC (Week 3). Tsao, Lin-wei Li, Han-lin Hu, Sun-Bo. Today’s Articles. Chap. 2 Execution Semantics Chap. 4 Events Chap. 9 Processes. Chap. 2 Execution Semantics. Execution Semantics. Start at time = 0 Move forward only
E N D
SystemC (Week 3) Tsao, Lin-wei Li, Han-lin Hu, Sun-Bo Embedded Computing Lab
Today’s Articles • Chap. 2 Execution Semantics • Chap. 4 Events • Chap. 9 Processes Embedded Computing Lab
Chap. 2 Execution Semantics Embedded Computing Lab
Execution Semantics • Start at time = 0 • Move forward only • Time increment are base on the default time unit and time resolution. Embedded Computing Lab
main() and sc_main() • main() • It is a part of SystemC library. • It calls the function sc_main(). Embedded Computing Lab
Elaboration • Elaboration is defined as the execution of sc_main() function from the start if sc_main() to the first invocation of sc_start(). • Includes the construction of instances of modules and channels to connect them, sc_object and sc_time variables. Embedded Computing Lab
Elaboration • sc_set_default_time_unit() • Changing default time unit. • sc_set_time_resolution() • Changing time resolution. • If the 2 functions are called, must called during elaboration. • The 2 functions must also be called before any sc_time objects are constructed. Embedded Computing Lab
Elaboration • During elaboration, the structural elements of the system are created and connected throughout the system hierarchy. • Facilitated by C++ class object constructor behavior. • There are no constraints on the order in which port to channel binding occurs during elaboration. • a port must be bound to some channel, then the port must be bound by the time elaboration completes Embedded Computing Lab
Elaboration • Finally, the top level modules are connected via channels in the sc_main() function. • SystemC does not support the dynamic creation of modules. • The structure of the system is created during elaboration time and does not change during simulation. Embedded Computing Lab
Initialization • Initialization is the first step in the SystemC scheduler. • dont_initialize() • To turn off the initialization of a process, this function can be called after SC_METHOD or SC_THREAD process declaration inside the module constructor Macro (ref chap. 9) Embedded Computing Lab
Initialization • Different versions or a different simulator may yield a different result if care is not taken when writing models. Embedded Computing Lab
Simulation Semantics • The SystemC scheduler: • Controls the timing of process execution • supports the notion of delta-cycles • A delta-cycle consists of the execution of an evaluate and update phase. • There may be a variable number of delta-cycles for every simulation time Embedded Computing Lab
Simulation Semantics • SystemC processes are non-preemptive. • The scheduler is invoked by sc_start(). • Once scheduler is returned, simulation may continue from the time the scheduler last stopped by invoking the sc_start() function. Embedded Computing Lab
Simulation Semantics • Once started the scheduler continues until • there are no more events • a process explicitly stops it (by calling the sc_stop() function) • an exception condition occurs. Embedded Computing Lab
Scheduler Steps • Initialize phase (chap. 2.3) • Evaluate phase • From the set of processes that are ready to run, select a process and resume its execution. • The order is unspecified • The execution of a process may include calls to the request_update() function which schedules pending calls to update()function in the update phase. • The request_update() function may only be called inside member functions of a primitive channel. Embedded Computing Lab
Scheduler Steps • Repeat step2 for any other process ready to run. • Update phase • Execute any pending calls to update() from calls to the request_update() function executed in the evaluate phase. • If there are pending delta-delay notifications, determine which processes are ready to run and go to step 2. Embedded Computing Lab
Scheduler Steps • If there are no more timed event notifications, the simulation is finished. • Else, advance the current simulation time to the time of the earliest (next) pending timed event notification. • Determine which processes become ready to run due to the events that have pending notifications at the current time. Go to step 2. Embedded Computing Lab
Simulation functions • sc_start() • Called in sc_main() to start the scheduler. • sc_stop() • Called in sc_main() to stop the scheduler. • Process can not be continued anymore • Two functions are provided for the user to obtain the current simulation time. • sc_time_stamp() (Chapter 12.20 ) • sc_simulation_time() (Chapter 12.16 ). Embedded Computing Lab
Event Embedded Computing Lab
Event Occurrence Embedded Computing Lab
Notification • Immediate notification. • Event occurs in the same evaluate phase within a delta-cycle • Delta-delay notification. • Event occurs in the evaluate phase within the next delta-cycle • Non-zero delay notification (timed notification). • Event occurs delayed by the time value Embedded Computing Lab
Example • Process C will be triggered only in this delta cycle. • Example Code • sc_event my_event ; // event declaration • sc_time t (10, SC_NS) // declaration of a 10 ns time interval • my_event.notify(); // immediate notification • my_event.notify (SC_ZERO_TIME); // delta-delay notification • my_event.notify (t); // notification in 10 ns Embedded Computing Lab
Canceling event notifications • Define event and const value • sc_event a, b, c; • sc_time t(10, SC_MS); • Notify an event • a.notify(); // current delta-cycle • notify(SC_ZERO_TIME, b); // next delta-cycle • notify(t, c); // 10 ms delay • Cancel an event notification • a.cancel(); // Error! Can't cancel immediate notification • b.cancel(); // cancel notification on event b • c.cancel(); // cancel notification on event c Embedded Computing Lab
Process Embedded Computing Lab
Basic Concept • Target • A member function of a module class. • Be invoked by events (sensitivity list). • Static Sensitivity , Dynamic Sensitivity • Not hierarchical. • Type • Method , Thread , Clocked Thread. Embedded Computing Lab
Method Process • When completion, it returns control to the SystemC kernel (simulator scheduler). • Never write infinite loop. • Never call wait() to suspend process. • Has no internal state. • Code example 1. Embedded Computing Lab
Thread Process • Be invoked only once (during simulation initialization). • Be implemented with an infinite loop. • When calling wait(), the process is suspended and internal state (local variables) is saved. • The process is resumed by sensitivity list (state is restored). Embedded Computing Lab
Static Sensitivity • Be declared in the module constructor for that process. • Both the () and the << operators are overloaded in sc_sensitive class. • Code example 2. Embedded Computing Lab
Dynamic Sensitivity • Set the sensitivity list in runtime for next trigger condition. • Method process => next_trigger() • Thread process => wait() Embedded Computing Lab
Dynamic Sensitivity - next_trigger • Execution of a next_trigger() statement sets the sensitivity for the next trigger for the method process. • If multiple next_trigger() statements are executed, the last one wins. Embedded Computing Lab
Dynamic Sensitivity - wait • wait() specifies the condition for resuming the thread process. Embedded Computing Lab
Dynamic Sensitivity - Argument • There are several different function prototypes for dynamic sensitivity. • Code example 3. Embedded Computing Lab