Time Resolution

advertisement
A Class Presentation on
Time & Events in
SystemC
Professor: Dr. S. Mohammadi
Shohreh Sharif Mansouri
Anahita Naghilou
1
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
2
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
};
3
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_time sc_get_time_resolution();
4
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_time sc_get_time_resolution();
5
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();
6
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
7
Structure of a SC program
Module
ports
in
out
inout
processes
channels
methods
threads
constructor
events
Sensitivity list
8
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.
9
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()
10
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
11
Examples
sc_event
sc_time
a, b, c ;
t (10, SC_NS)
a.notify();
notify(SC_ZERO_TIME, b);
notify(t, c);
// event declaration
// declaration of a 10ns time interval
// immediate notification, current delta-cycle
// delta-delay notification, next delta-cycle
// 10 ns delay
//Cancel an event notification
a.cancel();
b.cancel();
c.cancel();
// Error! Can't cancel immediate notification
// cancel notification on event b
// cancel notification on event c
12
Sesitivity
• A member variable of sc_module,
• Operator “sensitive << port;”
• Each process in a module has its own
sensitivity declaration
• Two kind:
– Static
– Dynamic
13
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;
}
}
14
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
15
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
16
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
17
Refrences
• SystemC 2.0.1 Language Reference Manual,
www.systemC.org
• SystemC Overview, www.mes.tudarmstadt.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/LangDo
cs/LRM_version2.1.pdf
18
Download