User`s manual
Copyright © Quantum Leaps, LLC. All Rights Reserved.
QDK™
Renesas RX with HEW
state-machine.com/rx
(4) This omitted piece of code performs the hardware-specific initialization of the UART used by QSPY.  
QSPY uses the YRDKRX62N's single serial comm port, which is connected to Serial 
Communications Interface #2 (SCI2) on the RX62N. Chip-specific details of the UART initialization 
are not shown here, but they are heavily commented in the source code and reference sections in 
the chip's manual.
(5-6)
QS_tickPeriod_
 is initialized and never changes. This is the value that timer peripheral CMT0 
(used for the OS tick timer) counts up to before matching & resetting to zero before counting up 
again. 
QS_tickTime_
 increments by an amount of 
QS_tickPeriod_
 each time a kernel tick timer 
interrupt is handled. The description of 
QS_onGetTime()
 later describes use of these values.
(8) Here we enable all QS trace records, and then selectively disable some of them. Deciding which 
data to trace is a subject covered in depth in Chapter 11 of [PSiCC2] and is not specific to this port.
(9) We return 1 to indicate initialization was successful.
6.2 QS Trace Output in QF_onIdle()/QK_onIdle()
To be minimally intrusive, the actual output of the QS trace data happens when the system has nothing 
else to do, that is, during the idle processing. The following listing shows the code placed either in the 
QF_onIdle()
 callback (“Vanilla” port), or 
QK_onIdle()
 callback (in the QK port): 
Listing 15: QS trace output in bsp.c
 void QF_onIdle(void) {
 . . .
 (1) #ifdef Q_SPY
 /* RX62N has no TX FIFO, just a Transmit Data Register (TDR) */
 (2) if (SMCI2.SSR.BIT.TDRE) {  /* Is SMC's TDR Empty? */
 (3) uint16_t b;
 (3) QF_INT_DISABLE();
 (4) b = QS_getByte();
 (5) QF_INT_ENABLE();
 (6) if (b != QS_EOD) {
 (7) SMCI2.TDR = (uint8_t)b; /* send byte to UART TDR */
 }
 }
 . . .
(1) The code is only compiled into the Q_SPY build configuration.
(2) The UART's TDRE status flag is checked to see if the Transmit Data Register is Empty.
(3) Interrupts are disabled to protect the QS output trace buffer while it is being accessed from non-
interrupt code. Otherwise, this idle loop processing could be interrupted by an ISR which could try to 
access the trace buffer and corrupt it (shared resource problem).
(4) The temporary variable for storing the return from the 
QS_getByte()
 API call must be 16-bit wide.
(4) The 
QS_getByte()
 returns the next byte of trace data or 
QS_EOD
 if no data is available.
(5) Once access to the trace buffer is complete, interrupts can safely be re-enabled.
(6) If the returned data is not 
QS_EOD
 (end of data), the data needs to be sent out
(7) A byte of trace data is written into the Transmit Data Register and sent out the UART.
29 of 32










