The custom constructor passes its arguments directly to the base class
constructor. It then uses the Or1ksim library function,
or1ksim_set_time_point
to set an initial time
point at the start of simulation. The first call to
or1ksim_get_time_period
will return the time
since the ISS started.
The doTrans
function (which is used for both
read and write) is extended from the version used with
Or1ksimExtSC
to synchronize with the SystemC
clock.
There are two components to the time taken in this model, the time
taken by the Or1ksim ISS and the time taken in any
peripherals. At the time of an upcall, the SystemC wrapper thread
will not have yielded control since either initialization or the
last upcall, when a time point was set in the ISS using
or1ksim_set_time_point
.
A call to or1ksim_get_time_period
gives the
time used by the ISS in this period. This is used as the argument
to wait
, allowing any other threads in the
SystemC world to run until the calculated simulation time is
reached.
wait( sc_core::sc_time( or1ksim_get_time_period(), sc_core::SC_SEC ));
At this time the blocking transport function of the simple initiator
socket is called with the payload and specifying a zero time offset
(since the call to wait
means the thread is
synchronized with the SystemC clock).
sc_core::sc_time delay = sc_core::SC_ZERO_TIME; dataBus->b_transport( trans, delay );
On return, the delay
parameter will have been
updated with any additional delay due to the transaction—in
this case an estimate of the number of cycles to read or write the
relevant UART register. This delay represents the additional time
modeled since this thread last called
wait
. The thread should
wait
for this time, to allow other threads to
catch up.
However, since this is a synchronized model, the target (which is
still part of this thread of control, just in a different object)
will have already called wait
to model the time
taken to read or write. So in this case, delay
will still be zero on return.
The read or write is now complete. A new time point is set with
set_time_point
before control is returned to
the ISS. The ISS will start measuring time from this start
point, ready for use in the next upcall.
or1ksim_set_time_point();
The utility getClockRate
is a simple wrapper
for the underlying Or1ksim library function (see Section 8.3.1). It will be used in the main
program (see Section 8.6).
unsigned long int Or1ksimSyncSC::getClockRate() { return or1ksim_clock_rate(); } // getClockRate()
The definition of the Or1ksim ISS wrapper module class with
synchronized timing, Or1ksimSyncSC
may be
found in sys-models/sync-soc/Or1ksimSyncSC.cpp
in the distribution.