QP state machine frameworks for M16C QDK™ Renesas M16C/Neutrino-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 M16C 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 M16C Tiny M3026FA8 target device 4 User LEDs Switch 1 Figure 1 Renesas M16C/Neutrino board with built-in E8 In-Circuit Debugger and RS232-TTL transceiver board. Copyright © Quantum Leaps, LLC.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c The actual hardware/software used to validate this QDK is described below (see Figure 1): 1. Renesas M16C/NEUTRINO development 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. NOTE: For the QS (Q-SPY) software tracing output, you also need a TTL to RS-232 transceiver board. Such boards are available from a number of vendors.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c 2 Getting Started This section describes how to install, build, and use the QDK-M16C-NC30_NEUTRINO 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™ M16C/Neutrino-NC30 www.state-machine.com/m16c | | | | +-make_m16c.bat - make script for building the QP libraries for M16C target | | | | +-qep_port.h - QEP port | | | | +-qf_port.h - QF port | | | | +-qk_port.h - QK port | | | | +-qs_port.h - QS port | | | | +-qp_port.
QDK™ M16C/Neutrino-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™ M16C/Neutrino-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_neutrino.hws that you can load into the HEW IDE.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c 1. Connect the E8 debugger to the NEUTRINO 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-neutrino.hws (located in \examples\m16c\vanilla\nc30\dpp_neutrino\). Figure 2 shows the screen shot of the HEW IDE after opening the project. 4.
QDK™ M16C/Neutrino-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 2 and 3 represent Philosophers 2-3. An LED-on represents an “eating” philosopher. Extinguished LED represents philosopher “thinking” or “hungry”.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c This will start the QSPY host application to listen on COM2 serial port with baud rate 115200. (Please use the actual virtual COM port number on your PC.) The screen shot in Figure 5 shows the QSPY output from the DPP run: 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™ M16C/Neutrino-NC30 www.state-machine.com/m16c 3 The Vanilla QP Port The “vanilla” port shows how to use QP on a “bare metal” M16C-based system without any underlying multitasking kernel. In the “vanilla” version of the QP, the only component requiring platformspecific 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™ M16C/Neutrino-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™ M16C/Neutrino-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. (1) #pragma INTERRUPT ta0_isr (vect = 21) (2) void ta0_isr(void) { (3) QF_INT_UNLOCK(); /* Timer A0 ISR */ /* see NOTE01 */ (4) /* clear any level-sensitive interrupt sources, if necessary .
QDK™ M16C/Neutrino-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™ M16C/Neutrino-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_neutrino.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c (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 processor is forced to zero, which corresponds to the task-level priority. Setting the IPL to zero enables all interrupts and is effectively the End-Of-Interrupt instruction for the M16C architecture.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c 5 Board Support Package The Board Support Package (BSP) for M16C with the non-preemptive Vanilla kernel is located in the directory: \examples\m16c\vanilla\nc30\dpp_neutrino\ 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-nano callbacks. NOTE: This QDK uses the recommended by Renesas C-startup for M16C.
QDK™ M16C/Neutrino-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 NEUTRINO board, the sections are configured according to the memory map included in Section 6.3 of the “NEUTRINO User’s Manual” [Renesas NEUTRINO]. 4. Specify sections according to the memory map in the NEUTRINO User’s Manual 1. Select Link Tab 2. Select Section Order category 3.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c 5.2.2 Specifying Stack and Heap Sizes This QDK-nano-M16C 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™ M16C/Neutrino-NC30 www.state-machine.com/m16c /* initialize the clock... /* enable access to processor mode registers /* 2 wait states for SFR access for >16MHz operation...
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c 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. It is also a good idea to log some information as to where the assertion failed. The following code fragment shows the Q_onAssert() callback for M16C. The function simply locks all interrupts and enters a for-ever loop.
QDK™ M16C/Neutrino-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.
QDK™ M16C/Neutrino-NC30 www.state-machine.
QDK™ M16C/Neutrino-NC30 www.state-machine.com/m16c (2) You should adjust the QS buffer size (in bytes) to your particular application (3) You might want to adjust the UART baud rate to your particular system (the 115200 baud rate works well with the 20MHz f1 clock) (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.
QDK™ M16C/Neutrino-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.
QDK™ M16C/Neutrino-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.