QP Development Kit for Renesas RX with HEW Compiler QP™ Development Kit (QDK) Renesas RX with HEW Document Revision F October 2012 Copyright © Quantum Leaps, LLC info@quantum-leaps.com www.state-machine.
Table of Contents 1 Introduction..................................................................................................................................................... 1 1.1 About QP™.................................................................................................................................................... 2 1.2 About QM™...................................................................................................................................................
1 Introduction This QP Development Kit™ (QDK) describes how to use the QP/C™ and QP™/C++ state machine frameworks and the QM™ modeling tool for projects based on the Renesas RX family of 32-bit processors with the Renesas High-performance Embedded Workshop (HEW). This QDK applies to the YRDKRX63N and YRDKRX62N Development Kits from Renesas shown in Figure 1(a) and Figure 1(b), respectively.
QDK™ Renesas RX with HEW state-machine.com/rx Reset User LEDs Monochrome graphics LCD (b) RS-232 port J-Link debugger Ethernet port USB port Headphones Speaker User switches Renesas RX62N The actual hardware/software used to test this QDK is described below: Renesas YRDKRX63N or YRDKRX62N Development Kits (Figure 1(a) and Figure 1(b), respectively). Renesas HEW (High-performance Embedded Workshop) 4.x Renesas RX C/C++ Compiler 1.2.1 or GNU-RX (developed by KPIT Cummings) 12.
QDK™ Renesas RX with HEW state-machine.com/rx As shown in Figure 2, QP consists of a universal UM-compliant event processor (QEP), a portable realtime framework (QF), a tiny run-to-completion kernel (QK) as well as simple cooperative kernel (Vanilla), and software tracing instrumentation (QS). Current versions of QP include: QP/C™ and QP/C++™, which require about 4KB of code and a few hundred bytes of RAM, and the ultra-lightweight QP-nano, which requires only 1-2KB of code and just several bytes of RAM.
QDK™ Renesas RX with HEW state-machine.com/rx Figure 3: The example model opened in the QM™ modeling tool The QDK-RX example code includes the following components: Board support package (BSP) which provides interrupt service routines (ISRs), all QP callbacks, and an interface to the board's LEDs, push buttons, system clock tick timer, and serial port.
QDK™ Renesas RX with HEW state-machine.com/rx The GNU General Public License version 2 (GPL) as published by the Free Software Foundation and appearing in the file GPL.TXT included in the packaging of every Quantum Leaps software distribution.
QDK™ Renesas RX with HEW state-machine.com/rx 2 Getting Started This section describes how to install, build, and use the QDK-RX-Renesas. This section assumes that you have the YRDKRX62N board, and have downloaded and installed the Renesas HEW IDE and Renesas RX Toolset on your machine. Also this section assumes that you have downloaded and installed the QP™ Baseline Code, available for a separate download from www.state-machine.com/downloads.
QDK™ Renesas RX with HEW state-machine.com/rx | | | | | +-bsp.c - BSP for the YRDKRX62N (non-preemptive) | | | | | +-bsp.h - BSP header file | | | | | +-main.c - the main function | | | | | +-dpp.h - the DPP application header file (auto-generated by QM) | | | | | +-dpp.qm - QM model for the DPP application | | | | | +-dpp_qk_yrdkrx62n.hwp - HEW project for the DPP application | | | | | +-dpp_qk_yrdkrx62n.hws - HEW workspace for the DPP application | | | | | +-philo.
QDK™ Renesas RX with HEW state-machine.com/rx 2.2 Setting up HEW Placeholders The HEW project files included in this QDK assume that custom HEW “Placeholders” are set up to point to the location of the QP frameworks in your file system. Therefore it is strongly recommended that you define the custom placeholders for QP globally for all applications. To define HEW placeholders, you launch HEW and select the menu Setup | Customize... menu (see Figure 4).
QDK™ Renesas RX with HEW state-machine.com/rx Debug - this configuration is built with full debugging information and minimal optimization. When the QP framework finds no events to process, the framework busy-idles until there are new events to process. Release - this configuration is built with no debugging information and high optimization.
QDK™ Renesas RX with HEW state-machine.com/rx 2.4 Building the Examples The examples accompanying this QDK-RX-Renesas are based on the DPP application (see Quantum Leaps Application Note: “Dining Philosophers Problem Application” [QL AN-DPP 08] included in this QDK). The example directory qpc\examples\rx\ contains the HEW workspaces and project that you can load into the HEW IDE, as shown in Figure 6.
QDK™ Renesas RX with HEW state-machine.com/rx 2.5 Running the Examples You program the code into the flash memory of the MCU through the HEW Session. First, you must select the debugger session SesstionRX600_Segger_JLink (see Figure 6) and you need to connect to the target by selecting the Debug | Connect menu. Next, in HEW you must always make sure that the image is actually loaded into the target. You download the code into the target by selecting the Debug | Download Modules menu.
QDK™ Renesas RX with HEW state-machine.com/rx Figure 7: Screen shot from the QSPY run Copyright © Quantum Leaps, LLC. All Rights Reserved.
QDK™ Renesas RX with HEW state-machine.com/rx 3 The Renesas RX CPU This section provides a very quick overview of the Renesas RX CPU and its features relevant to the QP framework. 3.1 RX CPU Register Set The RX CPU has sixteen general-purpose 32-bit registers, nine 32-bit control registers, and one 64-bit accumulator used for DSP instructions. Figure 8: RX CPU register set 3.1.
QDK™ Renesas RX with HEW state-machine.com/rx The PSW has an interrupt control bit (PSW[I], bit 16) that globally enables (PSW[I] = 1) or disables (PSW[I] = 0) interrupts. Furthermore, a 4-bit field called Interrupt Priority Level (PSW[IPL], bits 24-27) reflects the current interrupt priority level. All interrupts to the CPU are assigned a priority of 0-15, with 0 being the lowest priority, and 15 being the highest priority.
QDK™ Renesas RX with HEW state-machine.com/rx Figure 10: RX exception processing After vectoring to the Interrupt Service Routine (ISR), the software takes over (see the next section). The software returns from the ISR by executing the RTE instruction (or RTFI for the fast interrupt), at which point the hardware takes over and executes the hardware post processing. This atomic sequence consists of restoring the PSW and PC from the stack and resuming the interrupted program. Copyright © Quantum Leaps, LLC.
QDK™ Renesas RX with HEW state-machine.com/rx 3.5 RX CPU Interrupt Processing (Software) The Renesas RX compiler, as most embedded cross-compilers, can generate interrupt service routines (ISRs), which are designated with the special #pragma interrupt (see Listing 2). The Renesas compiler can also automatically populate the RX vector table with the address of the ISR, when you provide the vector number by means of the #pragma vect=... attribute.
QDK™ Renesas RX with HEW state-machine.com/rx 4 Non-Preemptive “Vanilla” Port The “Vanilla” port shows how to use the QP frameworks on an RX-based system with the non-preemptive “Vanilla” kernel. In this version you’re using the cooperative kernel built-into the QF framework and you're not using the QK component. NOTE: The source code for the QP port to the cooperative “Vanilla” kernel is generic and should not need to change for different members of the Renesas 32-Bit MCU RX Family (RX200, RX600, etc.).
QDK™ Renesas RX with HEW state-machine.com/rx (10) #pragma inline_asm clr_psw_i (11) static void clr_psw_i(void) { CLRPSW I } /* inline definitions */ (12) #pragma inline_asm set_psw_i (13) static void set_psw_i(void) { SETPSW I } #include "qep_port.h" #include "qvanilla.h" #include "qf.h" /* QEP port */ /* "Vanilla" cooperative kernel */ /* QF platform-independent public interface */ (1) The QF_MAX_ACTIVE macro specifies the maximum number of active object priorities in the application.
QDK™ Renesas RX with HEW state-machine.com/rx (12-13) The Renesas RX compiler requires this unusual syntax to define the inline assembly function set_psw_i(). 4.3 The Board Support Package for the “Vanilla” Port The Board Support Package (BSP) for a QP application implements the board initialization, ISRs, QP callback functions, and application-specific board-specific functions. The whole BSP is located in the file bsp.c in the directory qpc\examples\rx\vanilla\renesas\dpp-yrdkrx62n\. 4.3.
QDK™ Renesas RX with HEW state-machine.com/rx 4.3.2 Saving and Restoring the Accumulator in the ISRs The interrupt functions generated by the RX compiler with #pragma vector do not preserve the RX accumulator register, unless the compiler option -save_acc is activated. This can be achieved in the HEW IDE by selecting the menu Build | RX Standard Toolchain, the CPU tab, Details... button (see Figure 11).
QDK™ Renesas RX with HEW state-machine.com/rx (2-3) 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.
QDK™ Renesas RX with HEW state-machine.com/rx Listing 10: Startup code in resetprg.
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.
QDK™ Renesas RX with HEW state-machine.com/rx (8) (9) (10) (11) (12) (13) --QK_intNest_; \ if (QK_intNest_ == (uint8_t)0) { \ uint8_t p = QK_schedPrio_(); \ if (p != (uint8_t)0) { \ set_psw((unsigned long)0); \ QK_schedExt_(p); \ } \ } \ (14) restore_acc(&acc_); \ } while (0) (15) #define QK_EXT_SAVE(act_) \ (16) ((act_)->thread = (void *)get_fpsw()) (17) #define QK_EXT_RESTORE(act_) \ (18) set_fpsw((unsigned long)(act_)->thread) #include #include "qk.
QDK™ Renesas RX with HEW state-machine.com/rx NOTE: The extended QK scheduler is used, instead of the regular scheduler, to save and restore the FPSW register. The following macros QK_EXT_SAVE()/QK_EXT_RESTORE() specify how to save and restore the extended context of the FPSW. (14) The RX Accumulator register is restored. (15) The QK_EXT_SAVE() macro specifies the process of saving the extended context, which in the case of the RX processor is the FPSW register.
QDK™ Renesas RX with HEW state-machine.com/rx 5.4.2 Saving and Restoring the Accumulator in the ISRs The interrupt functions generated by the RX compiler with #pragma vector do not preserve the RX accumulator register, unless the compiler option -save_acc is activated. This can be achieved in the HEW IDE by selecting the menu Build | RX Standard Toolchain, the CPU tab, Details... button (see Figure 11).
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 platformspecific callback function QK_onIdle() to save CPU power, or perform any other “idle” processing.
QDK™ Renesas RX with HEW state-machine.com/rx 6 QS Software Tracing Instrumentation Quantum Spy (QS) is a software tracing facility built into all QP components and also available to your application code. QS allows you to gain unprecedented visibility into your application by selectively logging almost all interesting events occurring within state machines, the framework, the kernel, and your application code.
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.
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.
QDK™ Renesas RX with HEW state-machine.com/rx 7 Related Documents and References Document [PSiCC2] “Practical UML Statecharts in C/C++, Second Edition”, Miro Samek, Newnes, 2008 Location Available from most online book retailers, such as Amazon.com. See also: http://www.statemachine.com/psicc2.htm [QP/C 08] “QP/C Reference Manual”, Quantum Leaps, LLC, 2010 http://www.state-machine.com/doxygen/qpc/ [QP/C++ 08] “QP/C++ Reference Manual”, Quantum Leaps, LLC, 2010 http://www.state-machine.
QDK™ Renesas RX with HEW state-machine.com/rx 8 Contact Information Quantum Leaps, LLC 103 Cobble Ridge Drive Chapel Hill, NC 27516 USA +1 866 450 LEAP (toll free, USA only) +1 919 869-2998 (FAX) “Practical UML Statecharts in C/C++, Second Edition: Event Driven Programming for Embedded Systems”, by Miro Samek, Newnes, 2008 e-mail: info@quantum-leaps.com WEB : http://www.quantum-leaps.com http://www.state-machine.com Copyright © Quantum Leaps, LLC. All Rights Reserved.