Low Power RTOS Demo - Renesas RX100
Including ports for IAR, e2studio with GCC & e2studio with Renesas tools
[RTOS Ports]



RX100 RSK (available June 2013)



Introduction

The application documented on this page demonstrates how the FreeRTOS tick suppression features can be used to minimise the power consumption of an application running on an RX100 microcontroller from Renesas. The RX100 is designed specifically for use in applications that require low power consumption.

The demo is provided with the following three build options:

  1. IAR Embedded Workbench for RX
  2. The Renesas e2studio Eclipse based IDE using the Renesas RX compiler
  3. The Renesas e2studio Eclipse based IDE using the GNU GCC compiler

The projects are pre-configured to run on the official Renesas Starter Kit (RSK) for the RX100.


IMPORTANT! Notes on using the FreeRTOS RX100 low power demo project

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

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

Source Code Organisation

The FreeRTOS zip file contains the source files for all the FreeRTOS ports, and all the demo applications. Only a small subset of the files are needed by this project. See the Source Code Organization section for a description of the downloaded files and information on creating a new project.

The IAR Embedded Workbench project is called RTOSDemo_IAR.eww and is located in the FreeRTOS/Demo/RX100-RSK_IAR directory.

The e2studio project that is configured to use the Renesas compiler is located in the FreeRTOS/Demo/RX100-RSK_Renesas directory. The build instructions section of this page contains important information on preparing the Eclipse project directory.

The e2studio project that is configured to use the GCC compiler is located in the FreeRTOS/Demo/RX100-RSK_GCC directory. The build instructions section of this page contains important information on preparing the Eclipse project directory.



The Renesas RX100 Demo Application


Hardware set up

The demo uses the LEDs, buttons and the potentiometer built onto the RX100 RSK and no hardware setup is required.


Functionality

configCREATE_LOW_POWER_DEMO is a constant that is defined at the top of FreeRTOSConfig.h. The low power demo is created when the project is built with configCREATE_LOW_POWER_DEMO set to 1. A standard kernel only demo (without tick suppression) is created when the project is built with configCREATE_LOW_POWER_DEMO set to 0.


Functionality with configCREATE_LOW_POWER_DEMO set to 1

When configCREATE_LOW_POWER_DEMO is set to 1 main() calls main_low_power(). main_low_power() creates a very simple demo as follows:


Using the demo when configCREATE_LOW_POWER_DEMO is set to 1

For optimum low power results the RX100 must be disconnected from the debugger (the application must be executed 'stand alone').

  1. Turn the potentiometer on the RX100 completely counter clockwise.

  2. Program the RX100 with the application, then disconnect the programming/debugging hardware to ensure power readings are not affected by any connected interfaces.

  3. Start the application running. LED 0 will toggle quickly because the potentiometer is turned to its lowest value.

    LED 1 is on only when the RX100 is not in a power saving mode. It will appear (to the human eye) to be off because most execution time is spent in a low power mode, and the low power mode is only ever exited very briefly.

    Led 2 is on only when the RX100 is in deep sleep mode. It will appear (to the human eye) to be always on, again because most execution time is spent in the deep sleep mode.

    NOTE: The power consumption measured when in the deep sleep mode is affected by having LED 2 on.

  4. Slowly turn the potentiometer in the clockwise direction. This will increase the value read from the potentiometer, which will increase the time the Tx task spends in the Blocked state, which will therefore also decrease the frequency at which the Tx task sends data to the queue (and the rate at which LED 0 is toggled).

  5. Keep turning the potentiometer in the clockwise direction. Eventually the value read from the potentiometer will go above mainSOFTWARE_STANDBY_DELAY, causing the Tx task to block on the semaphore with an infinite timeout. The RTOS will place the RX100 microcontroller into its software standby mode.

    LED 0 will stop toggling because the Tx task is no longer sending to the queue. LED 1 and LED 2 will both be off because the RX100 is neither running or in deep sleep mode (it is in software standby mode).

    NOTE: Unlike when in deep sleep mode, when the RX100 is in software standby mode all the LEDs are turned off. This is done to ensure the measured power consumption is not adversely affected by the LEDs.

  6. Turn the potentiometer counter clockwise again to ensure its value goes back below mainSOFTWARE_STANDBY_DELAY.

  7. Press any of the three buttons to generate an interrupt. The interrupt will take the RX100 out of software standby mode, and the interrupt service routine will unblock the Tx task by 'giving' the semaphore. LED 0 will start to toggle again.


RTOS implementation when configCREATE_LOW_POWER_DEMO is set to 1

Turning the tick interrupt off allows the microcontroller to remain in a low power mode until such time that a task has to leave the Blocked state and execute. If the RTOS tick interrupt was not suppressed in this way the microcontroller would have to periodically exit the low power mode to process the RTOS ticks.


Functionality with configCREATE_LOW_POWER_DEMO set to 0

When configCREATE_LOW_POWER_DEMO is set to 0 main() calls main_full(). main_full() creates a comprehensive test and demo application that demonstrates: The created tasks are from the set of standard demo tasks. Standard demo tasks are used by all FreeRTOS port demo applications. They have no specific functionality, and are created just to demonstrate how to use the FreeRTOS API, and test the RTOS port. The following tasks and timers are created in addition to the standard demo tasks:


Building and executing the demo application - e2studio

  1. Create the directory structure required by the Eclipse managed make system by executing the appropriate CreateProjectDirectoryStructure.bat batch file.

    If you are using e2studio with the Renesas compiler then execute FreeRTOS/Demo/RX100-RSK_Renesas/CreateProjectDirectoryStructure.bat.

    If you are using e2studio with the GCC compiler then execute FreeRTOS/Demo/RX100-RSK_GCC/CreateProjectDirectoryStructure.bat.

  2. Open e2studio and either create a new or select an existing workspace.

  3. Select "Import" from e2studio's "File" menu, then in the Import dialog box select "General | Existing Projects Into Workspace" then click "Next".

    Selecting to import an existing RTOS project into the Eclipse IDE
    Select "Existing Project Into Workspace"

  4. In the import dialog box browse to the FreeRTOS/Demo/RX100-RSK_Renesas directory to use the Renesas compiler, or the FreeRTOS/Demo/RX100-RSK_GCC directory to use the GCC compiler, ensure the project is selected in the "Projects" window, and click Finish to complete the import process.

    Importing an embedded RTOS project into the E2Studio IDE
    Browsing to the project to import (GCC project depicted)

  5. Open FreeRTOSConfig.h, and set configCREATE_LOW_POWER_DEMO to generate either the tickless low power demo, or the full test and demo application, as required.

  6. Select "Build All" from e2studio's "Project" menu.

  7. Ensure the target hardware is connected to the host computer through the E1 USB interface (which may come as part of the RSK, or may need to be purchased separately).

  8. Click the "Debug" speed button to start a debug session.

    Start debugging in Eclipse using the CDT
    The speed button used to start a
    debug session from within Eclipse


Building and executing the demo application - IAR

  1. Open /FreeRTOS/Demo/RX100-RSK_IAR/RTOSDemo_IAR.eww from within the IAR Embedded Workbench IDE.

  2. Open FreeRTOSConfig.h, and set configCREATE_LOW_POWER_DEMO to generate either the tickless low power demo, or the full test and demo application, as required.

  3. Select "Build All" from the IDE's "Project" menu.

  4. Ensure the target hardware is connected to the host computer through the E1 USB interface (which may come as part of the RSK, or may need to be purchased separately).

  5. Select "Download and Debug" from the IDE's "Project" menu to start a debug session.



RTOS Configuration and Usage Details


RX100 RTOS port specific configuration

Configuration items specific to this demo are contained in FreeRTOSConfig.h located in the project directory. The constants defined in these file can be edited to suit your application. In particular -

The RX100 port layer #defines 'BaseType_t' to 'long'.


Writing interrupt service routines (ISRs)

Interrupts can be written using the standard compiler syntax. See the function vButtonInterrupt1() in main_low_power.c for an example specific to the compiler being used.

Often an ISR wants to cause a context switch so the task that is returned to when the ISR completes is different to the task that the ISR interrupted. This would be the case if the ISR caused a task to unblock, and the unblocked task had a priority above that of the task that was already in the Running state. This can be achieved by calling portYIELD_FROM_ISR(), which takes a single parameter. The parameter should be 0 if a context switch is not required, or non-zero if a context switch is required. This is demonstrated in the code below:

void Dummy_IRQHandler(void)
{
long lHigherPriorityTaskWoken = pdFALSE;

    /* Clear the interrupt if necessary. */
    Dummy_ClearInterruptPendingBit();

    /* This interrupt does nothing more than demonstrate how to synchronise a
    task with an interrupt.  A semaphore is used for this purpose.  Note
    lHigherPriorityTaskWoken is initialised to zero. */
    xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );

    /* If there was a task that was blocked on the semaphore, and giving the
    semaphore caused the task to unblock, and the unblocked task has a priority
    higher than the current Running state task (the task that this interrupt
    interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE
    internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the
    portYIELD_FROM_ISR() macro will result in a context switch being pended to
    ensure this interrupt returns directly to the unblocked, higher priority,
    task.  Passing pdFALSE into portYIELD_FROM_ISR() has no effect. */
    portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
}


Resources used by FreeRTOS

FreeRTOS requires exclusive use of the software interrupt.

By default the RTOS kernel uses the compare match timer (CMT) to generate the RTOS tick. The application writer can define configSETUP_TICK_INTERRUPT() (in FreeRTOSConfig.h) such that their own tick interrupt configuration is used in place of the default. For example, if the application writer creates a function called MyTimerSetup() that configures an alternative timer to generate an interrupt at the required frequency, then adding the following code to FreeRTOSConfig.h will cause MyTimerSetup() to be called in place of the default timer configuration:

#define configSETUP_TICK_INTERRUPT() MyTimerSetup()
NOTE 1: The default tick suppression implementation assumes the use of the CMT timer.

NOTE 2: The way the tick interrupt is installed is dependent on the compiler used:


Switching between the pre-emptive and co-operative RTOS kernels

Set the definition configUSE_PREEMPTION within RTOSDemo/FreeRTOSConfig.h to 1 to use pre-emption or 0 to use co-operative. The full demo application may not execute correctly when the co-operative RTOS scheduler is selected.


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_4.c is included in the RX100 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.


Miscellaneous

Note that vPortEndScheduler() has not been implemented.