FreeRTOS-Kernel/FreeRTOS/Demo/RL78_multiple_IAR
Aniruddha Kanhere 1277ba1661
Revert "Remove coroutines (#874)" (#1019)
* Revert "Remove coroutines (#874)"

This reverts commit 569c78fd8c.

* Update freertos Kernel submodule to latest head

* Remove temporary files

* Fix MingW demos and spell check

* Fix manifest version; fix headers

* Add ignore files and paths to core-checker.py

* Fix copyright in remaining files

* Fix PR check build failure

1. Remove defining `inline` in Makefile. This was causing build
   warnings.
2. Ensure that the linker removed unused functions from various
   compilation units.
3. Update the linker script so that all the functions are correctly
   placed in FLASH section.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
2023-06-09 15:25:48 -07:00
..
.gitignore Migrated RL78/IAR port to EWRL78v3+ (#799) 2022-03-24 09:59:45 -07:00
demo_specific_io.h [AUTO][RELEASE]: Bump file header version to "202212.00" 2022-12-10 01:17:30 +00:00
FreeRTOSConfig.h Revert "Remove coroutines (#874)" (#1019) 2023-06-09 15:25:48 -07:00
interrupt_vector.s Migrated RL78/IAR port to EWRL78v3+ (#799) 2022-03-24 09:59:45 -07:00
main.c [AUTO][RELEASE]: Bump file header version to "202212.00" 2022-12-10 01:17:30 +00:00
main_blinky.c [AUTO][RELEASE]: Bump file header version to "202212.00" 2022-12-10 01:17:30 +00:00
main_full.c [AUTO][RELEASE]: Bump file header version to "202212.00" 2022-12-10 01:17:30 +00:00
README.md Migrated RL78/IAR port to EWRL78v3+ (#799) 2022-03-24 09:59:45 -07:00
RegTest.s [AUTO][RELEASE]: Bump file header version to "202212.00" 2022-12-10 01:17:30 +00:00
RTOSDemo.ewd Migrated RL78/IAR port to EWRL78v3+ (#799) 2022-03-24 09:59:45 -07:00
RTOSDemo.ewp Migrated RL78/IAR port to EWRL78v3+ (#799) 2022-03-24 09:59:45 -07:00
RTOSDemo.eww Migrated RL78/IAR port to EWRL78v3+ (#799) 2022-03-24 09:59:45 -07:00

FreeRTOS for the Renesas RL78 microcontrollers

This directory contains an application that demonstrates the use of FreeRTOS on a Renesas RL78 16-bit microcontroller using the IAR compiler.

Overview

The demo project includes multiple build configurations. Each build configuration is set for an evaluation board.

Build Configuration Description
YRPBRL78G13 Renesas Promotion Board RL78/G13
YRPBRL78G14 Renesas Promotion Board RL78/G14
YRDKRL78G14 Renesas Development Kit RL78/G14
RSKRL78G1C Renesas Starter Kit RL78/G1C
RSKRL78L13 Renesas Starter Kit RL78/L13
RSKRL78L1C Renesas Starter Kit RL78/L1C
QB_R5F10ELE_TB Renesas Target Board RL78/G1A

⚠️ This demo project requires IAR Embedded Workbench for Renesas RL78 (EWRL78) version 3.10.1 or later.

Important notes

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

💡 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 Demo Application

Demo application hardware setup

The demo application makes use of an LED that is mounted directly onto each of the supported hardware platforms. No hardware setup is required.

Functionality

mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is defined in main.c. If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 then main() will call main_blinky(), which creates a simple 'blinky' style demo. If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0 then main() will call main_full() which creates a more comprehensive demo.

Functionality when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1

main_blinky() creates one queue, and two tasks before starting the RTOS scheduler.

  • The "Queue Send" Task: The queue send task is implemented by the prvQueueSendTask() function in main_blinky.c. prvQueueSendTask() sits in a loop that causes it to repeatedly block for 200 ms, before sending the value 100 to the queue that was created within main_blinky(). Once the value is sent, the task loops back around to block for another 200 ms, and so on.

  • The "Queue Receive" Task: The queue receive task is implemented by the prvQueueReceiveTask() function in main_blinky.c. prvQueueReceiveTask() sits in a loop where it repeatedly blocks on attempts to read data from the queue that was created within main_blinky(), toggling an LED each time the value 100 is received.

The queue receive task will only leave the Blocked state when the queue send task writes to the queue. As the queue send task writes to the queue every 200 ms, the queue receive task leaves the Blocked state and toggles the LED every 200 ms.

Functionality when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0

main_full() creates 13 tasks, 4 queues, and 2 software timers. Many of the tasks are from the set of standard demo tasks that are used with all the RTOS demos, and are documented on the FreeRTOS.org website.

The following tasks and timers are created in addition to the standard demo tasks.

  • The "Reg test" tasks: These fill the registers with known values, then check that each register still contains its expected value. Each task uses a different set of values. The reg test tasks execute with a very low priority, so get preempted very frequently. A register containing an unexpected value is indicative of an error in the context switching mechanism.

  • The "Demo" Software Timer and Callback Function: The demo software timer callback function does nothing more than increment a variable. The period of the demo timer is set relative to the period of the check timer (described below). This allows the check timer to know how many times the demo timer callback function should execute between each execution of the check timer callback function. The variable incremented in the demo timer callback function is used to determine how many times the callback function has executed.

  • The "Check" Software Timer and Callback Function: The check software timer period is initially set to 3 seconds. The check timer callback function checks that all the standard demo tasks, the reg test tasks, and the demo timer are not only still executing, but are executing without reporting any errors. If the check timer discovers that a task or timer has stalled, or reported an error, then it changes its own period from the initial 3 seconds, to just 200 ms.

The check timer callback function also toggles an LED each time it is called. This provides a visual indication of the system status: If the LED toggles every 3 seconds, then no issues have been discovered. If the LED toggles every 200 ms, then an issue has been discovered with at least one task.

Building the demo application

  1. Launch the IAR Embedded Workbench for Renesas RL78.
  2. In the menu, select FileOpen Workspace and choose the RTOSDemo.eww workspace.
  3. Use the drop-down list at the top of the Workspace window to select the build configuration that is correct for the target hardware being used.
  4. Press F7 to build the project. The project should build without any errors or warnings.

Programming the microcontroller and debugging

  1. Ensure the target board is connected to the host computer as appropriate. Some development boards include a built in TK interface and only require a USB cable. Other boards require a Renesas E1 Emulator (or later) debug interface.
  2. In the menu, select ProjectDownload and Debug. When a debug session is launched for the first time in the EWRL78, a message will show up saying that the emulator has to be configured before downloading a new application. Click the OK button to open the "Emulator Hardware Setup" window for the debug probe. The configuration window provides several options such as "Power supply" for when powering the evaluation board directly from the probe. Once the configuration is complete, the flash memory will be programmed and the program initialization will execute until the debugger breaks on the main() function entry point.

Configuration and Usage Details

RTOS port specific configuration

Configuration items specific to this demo are contained in FreeRTOSConfig.h. The constants defined in this file can be edited to suit your application. 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.

⚠️ vPortEndScheduler() has not been implemented.

Memory models

The FreeRTOS port will automatically switch between the near and far memory models, depending on the settings in the IAR project options.

This port has been tested with 2 memory model combinations, which are:

Combination Code Model Data Model
Combination 1 NEAR NEAR
Combination 2 FAR FAR

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 (the task that was interrupted by the ISR), then the ISR should return directly to the unblocked task. The use of the IAR tools necessitates such interrupt service routines are entered using an assembly file wrapper as it can be seen in the interrupt_vector.s file. An example is provided below, and another example is provided in main.c.

Assembly wrapper in interrupt_vector.s:

;   The portmacro.h header provides the portSAVE_CONTEXT() and
;   portRESTORE_context() macros.
#include "portmacro.h"
...
    PUBLIC _vAnExampleISR_ASM_Wrapper
    EXTERN _vAnExampleISR_C_Handler

    SECTION `.text`:CODE
_vAnExampleISR_ASM_Wrapper:
    portSAVE_CONTEXT                    ; The wrapped ISR must start with the portSAVE_CONTEXT() macro.

    CALL    _vAnExampleISR_C_Handler    ; Once the context has been saved the C handler can be called.

    portRESTORE_CONTEXT                 ; The wrapped ISR must end with the to portRESTORE_CONTEXT() macro.

    RETI                                ; Returns from the interrupt to whichever task task is now the task selected
                                        ; to run (which might differ from the task that was running before the ISR.
...
;-------------------------------------------------------------------------------
;   Place a pointer to the _vAnExampleISR_ASM_Wrapper at the correct index into
;   the interrupt vector table. This is an example for a ISR which needs context
;   switch.
;
;   NOTE: 0x3A is used is purely as an example.  The correct vector index for
;   the interrupt being installed must be used.
;-------------------------------------------------------------------------------
___interrupt_tab_0x3A:
    DATA16
    DC16      _vAnExampleISR_ASM_Wrapper
;-------------------------------------------------------------------------------

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 vISRHandler( void )
{
short sHigherPriorityTaskWoken = pdFALSE;

    /* Handler code goes here, for purposes of demonstration, assume
    at some point the hander calls xSemaphoreGiveFromISR().*/
    xSemaphoreGiveFromISR( xSemaphore, &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

By default the RTOS kernel uses the RL78 Interval Timer peripheral to generate the RTOS tick. The application writer can modify the vApplicationSetupTimerInterrupt() in the main.c such that their own tick interrupt configuration is used in place of the default.

⚠️ vPortTickISR() must be installed as the handler for which ever interrupt is used to generate the RTOS tick.

⚠️ 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

The 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.