User`s manual
Copyright © Quantum Leaps, LLC. All Rights Reserved.
QDK™
Renesas RX with HEW
state-machine.com/rx
5.4.3 Idle loop customization in the QK port
As described in Chapter 10 of [PSiCC2], the QK idle loop executes only when there are no events to 
process. The QK allows you to customize the idle loop processing by means of the callback 
QK_onIdle()
, which is invoked by every pass through the QK idle loop. You can define the platform-
specific callback function 
QK_onIdle()
 to save CPU power, or perform any other “idle” processing.
NOTE: The idle callback 
QK_onIdle()
 is invoked with interrupts unlocked (which is in contrast to 
QF_onIdle()
 that is invoked with interrupts locked, see Section 6).
Listing 13: Idle callback QK_onIdle() for the QK kernel in bsp.c
 (1) void QK::onIdle(void) {
 (2) QF_INT_DISABLE();
 (3) BSP_LED_IDLE_ON(); // toggle the User LED on and then off, see NOTE02
 (4) BSP_LED_IDLE_OFF();
 (5) QF_INT_ENABLE();
 (6) #ifdef Q_SPY
 . . .
 (7) #elif defined NDEBUG
 (8) _wait();
 #endif
 }
(1) The idle callback for the QK kernel is always entered with interrupts enabled.
(2) Interrupts are disabled to toggle the idle LED.
(3-4) The idle LED (LED12 of the YRDKRX62N board) is toggled on and off each time through the idle 
callback. Thus, a brighter LED indicates more idle time. A heavily loaded CPU will spend little or no 
time in the idle loop and thus the idle LED would be dim. Note that in a release build, the CPU will 
sleep most of the time, and the LED will be toggled only at the rate of the interrupts that wake up the 
CPU. In a debug build variant, the CPU never sleeps, and the LED's intensity gives a good 
indication of the idle task activity.
(5) Interrupts are re-enabled after toggling the idle LED.
(6) The software-tracing code is conditionally compiled into the build when enabled at compile time. 
When using QS, the trace data is sent out during idle loop processing. If the UART's Transmit Data 
Register (TDR) is empty, this code calls a QSPY API to see if there is another byte of data to send 
out the serial port.
(7) In release mode (no debugger) the CPU can be put to low-power sleep.
(8) The intrinsic function 
wait()
 provided by the Renesas compiler simply inserts a 
WAIT
 instruction to 
the RX CPU. (More advanced power management could be performed here; this port only sleeps 
the CPU, and does not put any other peripheral in low-power mode).
27 of 32










