Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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


This page presents the FreeRTOS demo for the NEC 78K0R 16bit microcontroller. Note - since this page was written, NEC have merged with Renesas, and the links on this page have been updated accordingly.

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.

Note: If this project fails to build then it is likely the version of IAR Embedded Workbench being used is too old. If this is the case, then it is also likely that the project file has been (silently) corrupted and will need to be restored to its original state before it can be built even with an updated IAR version.


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 than 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 RTOS 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:

  • Register Test Tasks

    Two register test tasks are created. These fill the microcontroller registers with known values, then continuously check that each register still contains its expected value - each task using different values. As the tasks run with very low priority they will get pre-empted regularly. A register test task finding an unexpected value in one of its registers is indicative of an error in the pre-emption context switching mechanism.

  • Button Push Task and ISR

    Most FreeRTOS demos demonstrate context switching from within an interrupt using a serial port loopback 'com test'. The 78K0R target board does not include an RS232 port so context switching from within interrupts is instead demonstrated using the interrupts generated by the button that is mounted directly onto the target board.

    Both the button push ISR and corresponding task are very basic. The ISR simply 'gives' a semaphore each time the button is pushed. The task simply blocks on the semaphore, then toggles an LED each time the semaphore is given by the ISR - effectively synchronising the task with the interrupt.

  • Check Task

    The check task is used to give visible feedback of the system status. It only executes every three seconds but has a high priority so is guaranteed to get processing time. Each time it executes it inspects the status of all the other tasks in the system to see if any of them are reporting an error. The check task will toggle an LED every 3 seconds provided all the other tasks are running as expected. The toggle rate will change to 500ms if an error is discovered in any task.

When executing correctly the demo will behave as follows:

  • LED1 (P76) will toggle every 3 seconds.
  • LED2 (P77) will toggle each time the button (SW1, INTP0) is pushed.
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:

  • configMEMORY_MODE

    This must be set to match the selected compiler 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.

  • configCLOCK_SOURCE

    Set configCLOCK_SOURCE to 0 to use an external clock source, or 1 to use the high speed internal clock source (typically 8MHz). Ensure configCPU_CLOCK_HZ is also set correctly when altering any clock configuration.

Each port #defines 'BaseType_t' to equal the most efficient data type for that processor. This port defines BaseType_t 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 RTOS kernel

The RTOS 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 RTOS 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 RTOS kernel. Please refer to the Memory Management section of the API documentation for full information.




[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM 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.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists