System C Week 3 Tsao Linwei Li Hanlin

  • Slides: 32
Download presentation
System. C (Week 3) Tsao, Lin-wei Li, Han-lin Hu, Sun-Bo 11/3/2020 Embedded Computing Lab

System. C (Week 3) Tsao, Lin-wei Li, Han-lin Hu, Sun-Bo 11/3/2020 Embedded Computing Lab 1

Today’s Articles n n n Chap. 2 Execution Semantics Chap. 4 Events Chap. 9

Today’s Articles n n n Chap. 2 Execution Semantics Chap. 4 Events Chap. 9 Processes 11/3/2020 Embedded Computing Lab 2

Chap. 2 Execution Semantics 11/3/2020 Embedded Computing Lab 3

Chap. 2 Execution Semantics 11/3/2020 Embedded Computing Lab 3

Execution Semantics n n n Start at time = 0 Move forward only Time

Execution Semantics n n n Start at time = 0 Move forward only Time increment are base on the default time unit and time resolution. 11/3/2020 Embedded Computing Lab 4

main() and sc_main() n main() ¡ ¡ 11/3/2020 It is a part of System.

main() and sc_main() n main() ¡ ¡ 11/3/2020 It is a part of System. C library. It calls the function sc_main(). Embedded Computing Lab 5

Elaboration n Elaboration is defined as the execution of sc_main() function from the start

Elaboration n Elaboration is defined as the execution of sc_main() function from the start if sc_main() to the first invocation of sc_start(). n Includes the construction of instances of modules and channels to connect them, sc_object and sc_time variables. 11/3/2020 Embedded Computing Lab 6

Elaboration n sc_set_default_time_unit() ¡ n sc_set_time_resolution() ¡ n n Changing default time unit. Changing

Elaboration n sc_set_default_time_unit() ¡ n sc_set_time_resolution() ¡ n n Changing default time unit. 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. 11/3/2020 Embedded Computing Lab 7

Elaboration n During elaboration, the structural elements of the system are created and connected

Elaboration n During elaboration, the structural elements of the system are created and connected throughout the system hierarchy. ¡ n Facilitated by C++ class object constructor behavior. There are no constraints on the order in which port to channel binding occurs during elaboration. ¡ 11/3/2020 a port must be bound to some channel, then the port must be bound by the time elaboration completes Embedded Computing Lab 8

Elaboration n Finally, the top level modules are connected via channels in the sc_main()

Elaboration n Finally, the top level modules are connected via channels in the sc_main() function. System. C does not support the dynamic creation of modules. The structure of the system is created during elaboration time and does not change during simulation. 11/3/2020 Embedded Computing Lab 9

Initialization n n Initialization is the first step in the System. C scheduler. dont_initialize()

Initialization n n Initialization is the first step in the System. C 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) 11/3/2020 Embedded Computing Lab 10

Initialization n Different versions or a different simulator may yield a different result if

Initialization n Different versions or a different simulator may yield a different result if care is not taken when writing models. 11/3/2020 Embedded Computing Lab 11

Simulation Semantics n The System. C scheduler: ¡ ¡ Controls the timing of process

Simulation Semantics n The System. C scheduler: ¡ ¡ Controls the timing of process execution supports the notion of delta-cycles n n 11/3/2020 A delta-cycle consists of the execution of an evaluate and update phase. There may be a variable number of deltacycles for every simulation time Embedded Computing Lab 12

Simulation Semantics n n n System. C processes are nonpreemptive. The scheduler is invoked

Simulation Semantics n n n System. C processes are nonpreemptive. 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. 11/3/2020 Embedded Computing Lab 13

Simulation Semantics n Once started the scheduler continues until ¡ there are no more

Simulation Semantics n 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. ¡ 11/3/2020 Embedded Computing Lab 14

Scheduler Steps Initialize phase (chap. 2. 3) Evaluate phase 1. 2. ¡ ¡ ¡

Scheduler Steps Initialize phase (chap. 2. 3) Evaluate phase 1. 2. ¡ ¡ ¡ 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. n 11/3/2020 The request_update() function may only be called inside member functions of a primitive channel. Embedded Computing Lab 15

Scheduler Steps Repeat step 2 for any other process ready to run. Update phase

Scheduler Steps Repeat step 2 for any other process ready to run. Update phase 3. 4. ¡ 5. 11/3/2020 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 16

Scheduler Steps 5. 6. 7. 11/3/2020 If there are no more timed event notifications,

Scheduler Steps 5. 6. 7. 11/3/2020 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 17

Simulation functions n sc_start() ¡ n sc_stop() ¡ ¡ n Called in sc_main() to

Simulation functions n sc_start() ¡ n sc_stop() ¡ ¡ n Called in sc_main() to start the scheduler. 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. ¡ ¡ 11/3/2020 sc_time_stamp() (Chapter 12. 20 ) sc_simulation_time() (Chapter 12. 16 ). Embedded Computing Lab 18

Event 11/3/2020 Embedded Computing Lab 19

Event 11/3/2020 Embedded Computing Lab 19

Event Occurrence 11/3/2020 Embedded Computing Lab 20

Event Occurrence 11/3/2020 Embedded Computing Lab 20

Notification n Immediate notification. ¡ Event occurs in the same evaluate phase within a

Notification n 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 11/3/2020 Embedded Computing Lab 21

Example n n Process C will be triggered only in this delta cycle. Example

Example n n 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 11/3/2020 Embedded Computing Lab 22

Canceling event notifications n n n Define event and const value ¡ sc_event a,

Canceling event notifications n n n 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 11/3/2020 Embedded Computing Lab 23

Process 11/3/2020 Embedded Computing Lab 24

Process 11/3/2020 Embedded Computing Lab 24

Basic Concept n n n Target A member function of a module class. Be

Basic Concept n n n 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. 11/3/2020 Embedded Computing Lab 25

Method Process n n n When completion, it returns control to the System. C

Method Process n n n When completion, it returns control to the System. C kernel (simulator scheduler). Never write infinite loop. Never call wait() to suspend process. Has no internal state. Code example 1. 11/3/2020 Embedded Computing Lab 26

Thread Process n n Be invoked only once (during simulation initialization). Be implemented with

Thread Process n n 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). 11/3/2020 Embedded Computing Lab 27

Static Sensitivity n n n Be declared in the module constructor for that process.

Static Sensitivity n n n Be declared in the module constructor for that process. Both the () and the << operators are overloaded in sc_sensitive class. Code example 2. 11/3/2020 Embedded Computing Lab 28

Dynamic Sensitivity n n n Set the sensitivity list in runtime for next trigger

Dynamic Sensitivity n n n Set the sensitivity list in runtime for next trigger condition. Method process => next_trigger() Thread process => wait() 11/3/2020 Embedded Computing Lab 29

Dynamic Sensitivity - next_trigger n n Execution of a next_trigger() statement sets the sensitivity

Dynamic Sensitivity - next_trigger n n 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. 11/3/2020 Embedded Computing Lab 30

Dynamic Sensitivity - wait n wait() specifies the condition for resuming the thread process.

Dynamic Sensitivity - wait n wait() specifies the condition for resuming the thread process. 11/3/2020 Embedded Computing Lab 31

Dynamic Sensitivity - Argument n n There are several different function prototypes for dynamic

Dynamic Sensitivity - Argument n n There are several different function prototypes for dynamic sensitivity. Code example 3. 11/3/2020 Embedded Computing Lab 32