190 likes | 428 Views
A Class Presentation on Time & Events in SystemC. Professor: Dr. S. Mohammadi Shohreh Sharif Mansouri Anahita Naghilou. Time. Time a type: internally represented by an unsigned integer of at least 64-bits, starts at 0, moves forward only. Three important time type in systemC:
E N D
A Class Presentation onTime & Events in SystemC Professor: Dr. S. Mohammadi Shohreh Sharif Mansouri Anahita Naghilou
Time • Time a type: • internally represented by an unsigned integer of at least 64-bits, • starts at 0, • moves forward only. • Three important time type in systemC: 1) sc_time 2)Time Resolution 3) Default Time Unit
sc_time • Represent time or time intervals in SystemC, • Constructed from a numeric value (type double) and a time unit (type sc_time_unit): enum sc_time_unit { SC_FS = 0, // femtosecond SC_PS, // picosecond SC_NS, // nanosecond SC_US, // microsecond SC_MS, // millisecond SC_SEC // second };
Time Resolution • The smallest amount of time, represented by all sc_time objects in a SystemC simulation. • Default value : 1 picosecond • Setter: sc_set_time_resolution( double val, sc_time_unit tu ); • Val: • must be positive and a power of ten, • must be greater than or equal to 1 femtosecond. • Getter: sc_timesc_get_time_resolution();
Default Time • Used to specify the unit of time for the values without time unit, • Default value: 1 nanosecond, • Setter: sc_set_default_time_unit( double val, sc_time_unit tu ); • val must be: • positive and a power of ten, • greater than or equal to the current time resolution. • Getter: sc_timesc_get_time_resolution();
Time Related Functions • sc_time sc_get_default_time_unit(); • sc_time sc_get_time_resolution(); • double sc_simulation_time(); • void sc_set_default_time_unit( double val, sc_time_unit tu ); • void sc_set_time_resolution( double val, sc_time_unit tu ); • void sc_start( const sc_time& duration ) • void sc_start( double d_val, sc_time_unit d_tu ); • void sc_start( double d_val = -1 ); • void sc_stop(); • const sc_time& sc_time_stamp();
Example //Given sc_time r_time( 1000, SC_NS); // Then sc_start(r_time); // run 1000 nSec sc_start(1000, SC_NS); // run 1000 nSec sc_start( 1000 ); // run 1000 default time units sc_start(); // run forever sc_start(-1); // run forever
Structure of a SC program Module ports processes channels in methods out inout threads constructor events Sensitivity list
Events • Event an object: • Represented by class sc_event • Determinnig whether and when a process’ execution should be triggered or resumed • provides basic synchronization for processes.
sc_event type • Processes can be made “sensitive” to events, • Processes are activated automatically when events occur that the process are sensitive to, • Events are implemented in channels and bounded to processes through ports, • An event executes on time by notify()
Events’ Notification • Immidiate • event is triggered in the current evaluation phase of the current delta-cycle. • Delta-cycle delayed • the event will be triggered during the evaluate phase of the next delta-cycle. • Timed • event will be triggered at the specified time in the future
Examples sc_event a, b, c ; // event declaration sc_time t (10, SC_NS) // declaration of a 10ns time interval a.notify(); // immediate notification, current delta-cycle notify(SC_ZERO_TIME, b); // delta-delay notification, next delta-cycle notify(t, c); // 10 ns delay //Cancel an event notification a.cancel(); // Error! Can't cancel immediatenotification b.cancel(); // cancel notification on event b c.cancel(); // cancel notification on event c
Sesitivity • A member variable of sc_module, • Operator “sensitive << port;” • Each process in a module has its own sensitivity declaration • Two kind: • Static • Dynamic
Example of Static Sensitivity SC_MODULE(Adder){ sc_int<int> a; sc_int<int> b; sc_out<int> c; void compute{ c = a + b; } SC_CTOR(Adder){ SC_METHOD(compute); sensitive << a << b; } }
Example of Dynamic Sensitivity • Suspends and resumes processes • wait(); // wait for the next event been notified • wait( e1 ); // wait for “e1” been notified • wait( e1 & e2 ) //wait for both e1 and e2 • wait( e1 | e2 ) //wait for either e1 or e2 • wait( 200, SC_NS ) // trigger 200 ns later • wait( 200, SC_NS, e1 ); // e1, timeout 200 ns
sc_event_finder and sc_event_finder_t* • sc_event_finder: • Member function of a port • Return type: sc_event_finder&. • sc_event_finder_t: • Templated wrapper for class sc_event_finder • interface type of the port : template parameter • An application use class sc_event_finder_t in constructing the object returned from an event
Example namespace sc_core { class sc_event_finder implementation-defined ; template <class IF> class sc_event_finder_t: public sc_event_finder { public: sc_event_finder_t(const sc_port_base& port_, const sc_event& (IF::*event_method_) () const ); // Other members implementation-defined }; } // namespace sc_core
Refrences • SystemC 2.0.1 Language Reference Manual, www.systemC.org • SystemC Overview, www.mes.tu-darmstadt.de/staff/lsi/lectures/systemc • System Design with SystemC, T. Grotker, S. Liao, G. Martin, and S. Swan. • Draft Standard SystemC Language Reference Manual, www.cse.iitd.ernet.in/~panda/SYSTEMC/LangDocs/LRM_version2.1.pdf