QP state machine frameworks for M16C QDK™ Renesas R8C/Tau-NC30 Document Revision A August 2008 Copyright © Quantum Leaps, LLC www.quantum-leaps.com www.state-machine.
Table of Contents 1 1.1 1.2 Introduction.................................................................................................... 1 What’s Included in the QDK? .............................................................................. 2 Licensing QP .................................................................................................... 2 2 Getting Started ............................................................................................... 3 2.1 Installation .......
1 Introduction This QP™ Development Kit (QDK) describes how to use QP™ event-driven platform with the Renesas R8C processors, the Renesas NC30 compiler, and the High Performance Embedded Workshop 4 (HEW4). Q_SPY trace data to host USB cable To Host PC E8 In-Circuit Debugger TTL-RS-232 transceiver board 4 User LEDs R8C Tiny R5F2125 target device Switch 1 Figure 1 Renesas R8C/Tau board with built-in E8 In-Circuit Debugger and RS232-TTL transceiver board. Copyright © Quantum Leaps, LLC.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c The actual hardware/software used to validate this QDK is described below (see Figure 1): 1. Renesas R8C/Tau evaluation board with built-in E8 In-Circuit Debugger. 2. High Performance Embedded Workshop 4.04 (HEW4) 3. Renesas NC30 compiler v5.44. 4. QP/C v4.0.01 or higher. As shown in Figure 1, the Renesas TAU Starter Kit Plus contains the TAU board and the E8 InCircuit Debugger that connects directly to the host development workstation via the provided USB cable.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 2 Getting Started This section describes how to install, build, and use the QDK-R8C-NC30_TAU based two examples. This information is intentionally included early in this document, so that you could start using the QDK as soon as possible. The main focus of this section is to walk you quickly through the main points without slowing you down with full-blown detail.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c | | | | +-make_r8c.bat - make script for building the QP libraries for R8C target | | | | +-qep_port.h - QEP port | | | | +-qf_port.h - QF port | | | | +-qk_port.h - QK port | | | | +-qs_port.h - QS port | | | | +-qp_port.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 2.2 Building the QP Libraries All QP components are deployed as libraries that you statically link to your application. The pre-All QP components are deployed as libraries that you statically link to your application. The pre-built libraries for QEP, QF, QS, and QK are provided inside the \ports\m16c\ directory (see Listing 1). This section describes steps you need to take to rebuild the libraries yourself.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 2.3 Building the Examples The examples included in this QDK are based on the standard Dining Philosopher Problem application implemented with active objects (see Quantum Leaps Application Note: “Dining Philosopher Problem Application” [QL AN-DPP 08] includes in this QDK). The example directory contains the HEW workspace file dpp_tau.hws that you can load into the HEW IDE.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 1. Connect the E8 debugger to the TAU board with the provided ribbon cable as described in the Quick Start Guide. 2. Connect the E8 debugger to the PC with the provided USB cable as described in the Quick Start Guide. 3. Launch HEW IDE and open the project pelican-tau.hws (located in \examples\m16c\vanilla\nc30\dpp_tau\). Figure 2 shows the screen shot of the HEW IDE after opening the project. 4.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c An example run of the DPP application is shown in Figure 1. The three user LEDs should start blinking. The LEDs represent Philosophers 0-2. An LED-on represents an “eating” philosopher. Extinguished LED represents philosopher “thinking” or “hungry”. For the QS (Q-SPY) software tracing output, you need to connect a TTL to RS-232 transceiver to the TAU board, as shown in Figure 4. The figure shows the RS232 to TTL converter board 3.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c command-line options used timestamp data lost due to insufficient bandwidth or too little filtering QS trace record Figure 5 Screen shot from the QSPY output. Copyright © Quantum Leaps, LLC. All Rights Reserved.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 3 The Vanilla QP Port The “vanilla” port shows how to use QP on a “bare metal” M16C/R8C-based system without any underlying multitasking kernel. In the “vanilla” version of the QP, the only component requiring platform-specific porting is the QF. The other two components: QEP and QS require merely recompilation and will not be discussed here. Obviously, with the vanilla port you’re not using the QK component.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c #include "qep_port.h" #include "qvanilla.h" #include "qf.h" /* QEP port */ /* "Vanilla" cooperative kernel */ /* QF platform-independent public interface */ Listing 3 The qf_port.h header file. 3.2.1 The QF Object Size Configuration The first part of the qf_port.h header file defines limits and sizes of various internal data structures used in the QF and the applications.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 3.3 ISRs in the Non-preemptive “Vanilla” Configuration The NC30 compiler supports writing interrupts in C. In the “vanilla” port, the ISRs are identical as in the simplest of all “superloop” (main+ISRs), and there is nothing QP-specific in the structure of the ISRs.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 3.4 QP Idle Loop Customization in QF_onIdle() The cooperative “vanilla” kernel can very easily detect the situation when no events are available, in which case QF_run() calls the QF_onIdle() callback. You can use QF_onIdle() to suspended the CPU to save power, if your CPU supports such a power-saving mode.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 4 The QK Port The QP port with the preemptive kernel (QK) is remarkably simple and very similar to the “vanilla” port. In particular, the interrupt locking/unlocking policy is the same, and the BSP is identical, except some small additions to the ISRs. The DPP example for the QK port is provided in the directory \examples\m16c\qk\nc30\dpp_qk_tau.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c (4) The macro QK_ISR_EXIT() is designed to be called upon the exit from an ISR programmed in C. The macro informs the QK preemptive kernel about exiting an interrupt. (5) The flags register is set to zero, which accomplishes two things at the same time. First, the interrupts are locked again (the I flag is cleared). Second, the current interrupt priority level (IPL) of the M16C/R8C processor is forced to zero, which corresponds to the task-level priority.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c } Listing 8 QK_onIdle() callback for R8C Copyright © Quantum Leaps, LLC. All Rights Reserved.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 5 Board Support Package The Board Support Package (BSP) for R8with the non-preemptive Vanilla kernel is located in the directory: \examples\m16c\vanilla\nc30\dpp_tau\ and consists of the following files: 1. bsp.h contains the Board Support Package interface (BSP) 2. bsp.c contains the implementation of the BSP, which includes all ISRs and all platform-specific QP callbacks. NOTE: This QDK uses the recommended by Renesas C-startup for M16C/R8C.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 5.2 Linker Options Used 5.2.1 Specifying Program Sections The HEW IDE allows to specify very precisely all the program sections, as shown in the screen shot in Figure 6. For the TAU board, the sections are configured according to the memory map included in Section 6.3 of the “TAU User’s Manual” [Renesas TAU]. 4. Specify sections according to the memory map in the RSKM16C26A User’s Manual 1. Select Link Tab 2. Select Section Order category 3.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 5.2.2 Specifying Stack and Heap Sizes This QDK-M16C/R8C does not use the heap 1 uses only the Interrupt Stack and no User Stack. Therefore, you disable the heap and set the User Stack size to zero. You need to declare adequate stack size for the Interrupt Stack, which is the only stack used in this QDK-nano. In the C-startup code, you specify the heap and stack sizes in the file cstartdef.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c cm13 = 1; cm15 = 1; cm05 = 0; cm16 = 0; cm17 = 0; cm06 = 0; asm("nop"); asm("nop"); asm("nop"); asm("nop"); ocd2 = 0; prcr = 0; /* Xin Xout /* XCIN-XCOUT drive capacity select bit : HIGH /* Xin on /* main clock = No division mode /* main clock = No division mode /* CM16 and CM17 enable /* Wait for stable of oscillation... */ */ */ */ */ */ */ /* main clock change */ /* protect on */ /* configure 32kHz clock...
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 5.6 Assertion Handling Policy in Q_onAssert() As described in Chapter 6 of [PSiCC2], all QP components use internally assertions to detect errors in the way application is using the QP services. You need to define how the application reacts in case of assertion failure by providing the callback function Q_onAssert(). Typically, you would put the system in fail-safe state and try to reset.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 6 The Quantum Spy (QS) Instrumentation This QDK demonstrates how to use the QS software tracing instrumentation to generate real-time trace of a running QP application. Normally, the QS instrumentation is inactive and does not add any overhead to your application, but you can turn the instrumentation on by defining the Q_SPY macro and recompiling the code. QS is a software tracing facility built into all QP components and also available to the Application code.
QDK™ R8C/Tau-NC30 www.state-machine.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c (4) The l_nTimerA1Underflows variable is used to count the number of underflows (transitions 0x0000 -> 0xFFFF) of the 16-bit TimerA1. This variable is used to generate 32-bit timestamp. (5) The QS_onStartup() callback performs the initialization of QS (6) The QS trace buffer is statically allocated to the specified size (7) You always need to call QS_initBuf() from QS_onStartup() to initialize the trace buffer.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 7 Related Documents and References Document Location [PSiCC2] “Practical UML Statecharts in C/C++, Second Edition”, Miro Samek, Newnes, 2008 Available from most online book retailers, such as amazon.com. See also: http://www.quantumleaps.com/psicc2.htm [QP 08] “QP/C/C++ Reference Manuals”, Quantum Leaps, LLC, 2008 http://www.quantum-leaps.com/doxygen/qpc/ [QL AN-Directory 07] “Application Note: QP Directory Structure”, Quantum Leaps, LLC, 2007 http://www.
QDK™ R8C/Tau-NC30 www.state-machine.com/m16c 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) e-mail: info@quantum-leaps.com WEB : http://www.quantum-leaps.com http://www.state-machine.com “Practical UML Statecharts in C/C++, Second Edition: Event Driven Programming for Embedded Systems”, by Miro Samek, Newnes, 2008 Renesas Technology Corp. 2-6-2, Ote-machi Chiyoda-ku, Tokyo,100-0004 Japan WEB: www.