NEC 78K0R RTOS Port
Using the IAR compiler
[RTOS Ports]


This page presents the FreeRTOS demo for the NEC 78K0R 16bit microcontroller.

The demo project contains configurations for both the 78K0R/KG3 and 78K0R/KE3L target boards. A MINICUBE2 is used to interface between the IAR Embedded Workbench and the target boards. The MINICUBE2 is used for both flash programming and debugging.

The 78K0R target boards allow for easy evaluation of the microcontroller by including the microcontroller itself along with the necessary reset, clock, power and debug circuitry on a board that routes all the microcontroller pins to connector mounting points along the edge of the PCB.


IMPORTANT! Notes on using the NEC 78K0R RTOS port

Please read all the following points before using this RTOS port.

  1. Source Code Organization
  2. The Demo Application
  3. Configuration and Usage Details
See also the FAQ My application does not run, what could be wrong?

Source Code Organization

The FreeRTOS download contains the source code for all the FreeRTOS ports so contains many more files that used by this demo. See the Source Code Organization section for a description of the downloaded files and information on creating a new project.

The IAR Embedded Workbench workspace for the NEC 78K0R demo is called RTOSDemo.eww and can be located within the FreeRTOS\Demo\NEC_78K0R_IAR directory.


The Demo Application


Demo application hardware setup

The demo application makes use of the two LEDs and button that are mounted directly onto the target board, so no additional hardware setup is required.

The button is used to generate interrupts on INTP0.


Functionality

This section describes the functionality of the 78K0R/KG3 demo. The 78K0R/KE3L demo creates fewer tasks because it has less RAM.

The demo project creates 22 tasks before starting the scheduler. Most of these tasks consist of the 'standard demo' tasks - the purpose of these tasks is to both demonstrate the RTOS API and test the RTOS port. They do not in themselves perform any other useful function.

The following demo specific tasks are created in addition to the standard demo tasks:

When executing correctly the demo will behave as follows:

More information is provided within the comments of the source code.


Building the demo application

  1. Open the FreeRTOS\Demo\NEC_78K0R_IAR\RTOSDemo.eww workspace from within the IAR Embedded Workbench IDE.
  2. Select the configuration that is correct for the target board being used, as demonstrated in the image below.


    Selecting the configuration for the target board being used.

  3. Important! Ensure the setting of configMEMORY_MODE within FreeRTOSConfig.h matches the settings in the IAR project options. If the compiler options are set to use the 'near' code model and the 'near' data model then configMEMORY_MODE must be set to 0. If the compiler options are set to use the 'far' code model and the 'far' data model then configMEMORY_MODE must be set to 1. These are the only tested combinations of settings.
  4. Press F7 - the project should build with no errors or warnings.


Programming the microcontroller and debugging

  1. Ensure the MINICUBE2 switches are correctly set to the "M1" and "3" positions.
  2. Connect the MINICUBE2 between the target board and the host computer.
  3. Select "Download and Debug" from the Embedded Workbench "Project" menu. There will be a short delay while the flash memory is programmed before the debugger breaks on entry to the main() function.

Configuration and Usage Details


RTOS Port specific configuration

Configuration items specific to this demo are contained in FreeRTOS\Demo\NEC_78K0R_IAR\FreeRTOSConfig.h. The constants defined in this file can be edited to suit your application.

There are also two constants that are specific to the NEC 78K0R port and demo:

Each port #defines 'portBASE_TYPE' to equal the most efficient data type for that processor. This port defines portBASE_TYPE to be of type short.

Note that vPortEndScheduler() has not been implemented.


Writing interrupt service routines

Interrupt service routines that cannot cause a context switch have no special requirements and can be written as described by the IAR compiler documentation.

Often you will require an interrupt service routine to cause a context switch. For example a serial port character being received may unblock a high priority task that was blocked waiting for the character to arrive. If the unblocked task has a higher priority than the current task then the ISR should return directly to the unblocked task. Limitations in the IAR inline assembler necessitate such interrupt service routines include an assembly file wrapper. The simple button push interrupt is included in this demo to demonstrate the mechanism. The example is replicated below.

First the assembly file wrapper.



; ISR_Support.h defines the portSAVE_CONTEXT and portRESTORE_CONTEXT 
; macros.
#include "ISR_Support.h"

    PUBLIC    vButtonISRWrapper
    EXTERN    vButtonISRHandler

    RSEG CODE:CODE
	
; The wrapper is the interrupt entry point.
vButtonISRWrapper:

    ; The ISR must start with a call to the portSAVE_CONTEXT() macro to save 
    ; the context of the currently running task.
    portSAVE_CONTEXT

    ; Once the context is saved the C portion of the handler can be called.
    ; This is where the interrupting peripheral is actually serviced.
    call vButtonISRHandler

    ; Finally the ISR must end with a call to portRESTORE_CONTEXT() followed by
    ; a reti instruction to return from the interrupt to whichever task is 
    ; now the task selected to run (which may be different to the task that 
    ; was running before the interrupt started).
    portRESTORE_CONTEXT
    reti

An example assembly file wrapper for an interrupt handler.

The C portion of the interrupt handler is just a standard C function.



/* This standard C function is called from the assembly wrapper above. */
void vButtonISRHandler( void )
{
short sHigherPriorityTaskWoken = pdFALSE;

    /* The code in this handler is just a copy of the button push interrupt code
    for demonstration only. */


    /* 'Give' the semaphore to unblock the button task. */
    xSemaphoreGiveFromISR( xButtonSemaphore, &sHigherPriorityTaskWoken );

    /* If giving the semaphore unblocked a task, and the unblocked task has a
    priority that is higher than the currently running task, then
    sHigherPriorityTaskWoken will have been set to pdTRUE.  Passing a pdTRUE
    value to portYIELD_FROM_ISR() will cause this interrupt to return directly
    to the higher priority unblocked task. */
    portYIELD_FROM_ISR( sHigherPriorityTaskWoken );
}

The C portion of the example interrupt handler.


Resources used by the kernel

The kernel uses channel 5 of the TAU to generate the RTOS tick. The function prvSetupTimerInterrupts() in FreeRTOS\Source\portable\IAR\78K0R\port.c can be altered to use any convenient timer source.

The kernel also requires exclusive use of the BRK software interrupt instruction.


Compiler options

As with all the ports, it is essential that the correct compiler options are used. The best way to ensure this is to base your application on the provided demo application files.


Memory allocation

Source\Portable\MemMang\heap_1.c is included in the demo application project to provide the memory allocation required by the real time kernel. Please refer to the Memory Management section of the API documentation for full information.



Copyright (C) 2010 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOS distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd..