User`s manual

Copyright © Quantum Leaps, LLC. All Rights Reserved.
QDK™
Renesas RX with HEW
state-machine.com/rx
6.3 QS Time Stamp Callback QS_onGetTime()
The platform-specific QS port must provide function
QS_onGetTime()
(Listing 9(12)) that returns the
current time stamp in 32-bit resolution. To provide such a fine-granularity time stamp, the RX port uses
the CMT0 facility, which is the same timer already used for generation of the system clock-tick interrupt.
NOTE: The
QS_onGetTime()
callback is always called with interrupts disabled.
Listing 16: QS initialization in bsp.c
(1) QSTimeCtr QS_onGetTime(void) { /* invoked with interrupts locked */
(2) if (IR(CMT0, CMI0)) { /* is tick ISR pending? */
(3) return QS_tickTime_ + CMT0.CMCNT + QS_tickPeriod_;
}
else { /* no rollover occured */
(4) return QS_tickTime_ + CMT0.CMCNT;
}
}
(1)
QS_onGetTime()
is a very important function. It provides a high-resolution time-stamp for outgoing
trace records. It is invoked at the time a trace record is appended to the trace record by the
application (as opposed to when the record is transmitted). This routine is called with interrupts
disabled.
(3) We check to see if the tick timer interrupt on timer peripheral CMT0 is already pending. (it could be
pending, because interrupts are disabled inside the
QS_onGetTime()
callback).
(4) If timer peripheral CMT0 has a pending interrupt, this indicates that the free-running counter CMCNT
has already counted up to its target match value and has been re-loaded with 0 again. Thus, in
order to get an accurate timestamp, the overflow must be accounted for by adding an extra number
of ticks (stored in
QS_tickPeriod_
) in addition to the step described in item
NOTE: The CMT0 interrupt (the system clock tick) could be pending at this time, because interrupts
are disabled. Once interrupts are re-enabled, the timer interrupt will fire,
QS_timeTick_
will
be incremented by
QS_tickPeriod_
in the tick ISR as we have seen, and the timer
interrupt pending flag will be cleared.)
(5) If the timer interrupt is not pending, the current timestamp is the sum of the long-term value in
QS_timeTick_
, which is updated in fairly large increments, and the instantaneous value in the free
running timer counter register CMCNT in peripheral CMT0. The counter is an up-counter, so this is a
simple addition.
6.4 Running the QSpy host application
The QSPY host application receives the QS trace data from the target, parses it and displays on the host
workstation (currently Windows, Linux, or Mac OS X). For the configuration options chosen in this port,
you invoke the QSPY host application as follows (please refer to “QSP Reference Manual” section in the
“QP/C Reference Manual” and also to Chapter 11 in [PsiCC2]):
qspy –cCOMx
NOTE: COMx will be something like COM1, COM2, etc. depending on your machine's serial port
availability and configuration.
30 of 32