User`s manual

Copyright © Quantum Leaps, LLC. All Rights Reserved.
QDK™
Renesas RX with HEW
state-machine.com/rx
5 Preemptive QK Port
This section describes how to use QP with the preemptive QK real-time kernel described in Chapter 10 of
[PSiCC2]. The benefit is very fast, fully deterministic task-level response and that execution timing of the
high-priority tasks (active objects) will be virtually insensitive to any changes in the lower-priority tasks.
The downside is bigger RAM requirement for the stack. Additionally, as with any preemptive kernel, you
must be very careful to avoid any sharing of resources among concurrently executing active objects, or if
you do need to share resources, you need to protect them with the QK priority-ceiling mutex (again see
Chapter 10 of [PSiCC2]).
NOTE: The preemptive configuration with QK uses more stack than the non-preemptive Vanilla
configuration. You may need to adjust the Supervisor mode stack size to be large enough for your
application.
As mentioned earlier, the RX family's interrupt control and handling is a perfect match for a single-stack
run-to-completion kernel. As in the Vanilla kernel, also under the QK kernel the CPU executes in
Supervisor Mode using the Interrupt Stack Pointer. User Mode, and the User Stack Pointer, are unused.
As with the Vanilla port, the QK allows nested interrupts by (re-)enabling interrupts inside ISRs once it is
safe. It is the application developer's responsibility to assign interrupt priorities correctly in order to
achieve the desired behavior. Interrupts of the same level or lower cannot preempt each other. By setting
all interrupts to the same priority (e.g., 1), interrupt nesting is effectively disabled.
5.1 The qep_port.h Header File
The QEP header file for the QK port is located in
qpc\ports\rx\qk\renesas\qep_port.h
. It is identical
to the non-preemptive calse shown in Listing 4.
5.2 The qf_port.h Header File
The QEP header file for the QK port is located in
qpc\ports\rx\qk\renesas\qf_port.h
. It is almost
identical to the non-preemptive calse shown in Listing 5, except the functions for saving and restoring the
RX Accumulator are moved to the QK port
qk_port.h
.
5.3 The qk_port.h Header File
As with any preemptive kernel, the QK needs to be notified about entering an interrupt context and about
exiting an interrupt context in order to perform a context switch, if necessary. Additionally, in case of the
RX CPU and the specific interrupt functions generated by the Renesas compiler, the QK kernel must
perform an extended context switch to preserve the state of the FPSW (Floating Point Status Word)
register. The coprocessor support via the extended context switch of the QK kernel is described in
Section 10.4 of [PsiCC2].
Listing 11: ISR entry and exit in qk_port.h
/* QK interrupt entry and exit */
(1) #define QK_ISR_ENTRY() do { \
(2) RxAcc acc_; \
(3) save_acc(&acc); \
(4) ++QK_intNest_; \
(5) set_psw_i()
(6) #define QK_ISR_EXIT() \
(7) clr_psw_i(); \
23 of 32