本页所记录的应用程序演示了如何将 FreeRTOS 用于 Renesas RL78 16 位微控制器。 根据配置,此演示项目在 RL78/G13 Promotion Board (YRPBRL78G13) 上运行, 该评估板配备了 R5F100LEA 微控制器。 R5F100LEA 为软件 应用程序提供了略低于 4K 字节的可用 RAM, 不足以在单一应用程序中充分演示所有 FreeRTOS 功能。 然而,RL78 系列内确实有多达 32K 字节的 RAM, 几乎是 R5F100LEA 的 RAM 的八倍之多。 R5F100LEA 演示创建了 13 个任务、4 个队列和 2 个定时器。 注意:如果项目构建失败,可能是使用的 IAR 嵌入式工作台版本过低。 如果构建失败, 那么也可能是项目文件(在无提示的情况下)已经损坏,因此需要 将其恢复至初始状态,然后才能使用新版本的 IAR 构建项目。
重要!Renesas RL78 RTOS 移植使用说明使用此 RTOS 移植之前,请阅读以下所有要点。另请参阅常见问题:我的应用程序未运行,问题可能出在哪里? 源代码组织FreeRTOS 下载文件中包含所有 FreeRTOS 移植的源代码, 因此包含的文件远多于此演示所使用的文件。 请参阅源代码组织部分,查看 详细了解下载文件的描述和创建新项目的信息。适用于 Renesas RL78 Promo Board 演示的 IAR Embedded Workbench 工作区被称为 RTOSDemo.eww,位于 FreeRTOS/Demo/RL78_RL78G13_Promo_Board_IAR 目录下。
演示应用程序演示应用程序硬件设置演示应用程序使用直接安装在 promo board 板硬件上的 LED, 因此无需额外的硬件设置。
功能本部分介绍了 RL78G13 演示的功能。 总共使用了 13 个任务、 4 个队列和 2 个定时器。 一些任务来自 “标准演示”任务集。 这些是所有 FreeRTOS 演示的常见内容, 并非 RL78 所特有。 它们仅用于演示 FreeRTOS API 的使用, 及测试核心 FreeRTOS 功能。除了标准演示任务外,还创建了以下特定演示任务:
main.c 还包括堆栈溢出、空闲和 malloc 文件挂钩函数的示例。 当正确执行时,演示应用程序将每 3 秒切换用户 LED。
构建演示应用程序
对微控制器进行编程和调试
配置和使用详情RTOS 移植专用配置此演示的特定配置项目位于 FreeRTOS/DemoRL78_RL78G13_Promo_Board_IAR/FreeRTOSConfig.h。 可对此文件中 定义的常量进行编辑以适应您的应用程序。还有一个专门针对 Renesas RL78 移植和演示的常量:
每个移植 #defines 'BaseType_t 等于该处理器的最有效数据类型。 本端口将 BaseType_t 定义为短整型。 请注意,vPortEndScheduler() 尚未实现。 内存模型FreeRTOS 移植将在近端和远端内存模型之间自动切换, 具体取决于 IAR 项目选项中的设置。 我们已使用两种内存模型组合对该移植进行了测试, 分别是:
编写中断服务程序不会引起上下文切换的中断服务程序没有特殊要求,可以按照 IAR 编译器文档中的描述编写。通常,上下文切换需要中断服务程序。 例如,正在接收的串行端口字符可以解除对高优先级任务(在阻塞状态下等待该字符到达)的阻塞 。如果已解除阻塞任务的 优先级高于当前任务优先级,则 ISR 应直接返回 至已解除阻塞的任务。由于 IAR 内联汇编器的限制, 该中断服务程序必须使用汇编文件包装器来输入。 请参阅 以下示例。 首先是汇编文件包装器。 ; ISR_Support.h defines the portSAVE_CONTEXT and portRESTORE_CONTEXT ; macros. #include "ISR_Support.h" ; The wrapped implemented in the assembly file. PUBLIC vISRWrapper ; The portion of the handler that is implemented in an external C file. EXTERN vISRHandler ; Ensure the code segment is used. RSEG CODE:CODE ; The wrapper is the interrupt entry point. vISRWrapper: ; 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 vISRHandler ; 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 ; The interrupt handler can be installed into the vector table in the same ;assembly file. ; Ensure the vector table segement is used. COMMON INTVEC:CODE:ROOT(1) ; Place a pointer to the asm wrapper at the correct index into the vector ; table. Note 56 is used is purely as an example. The correct vector ; number for the interrupt being installed must be used. ORG 56 DW vISRWrapper 用于中断处理程序的示例汇编文件包装器。
中断处理程序的 C 部分只是一个标准 C 函数。 /* 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 ); } 示例中断处理程序的 C 部分。
RTOS 内核使用的资源RTOS 内核使用间隔定时器生成 RTOS tick。 函数 prvSetupTimerInterrupts() 在 FreeRTOSSourceportableIARRL78port.c 中可被更改为使用任何方便的定时器源。RTOS 内核还需要独占使用 BRK 软件中断指令。 编译器选项与所有的端口一样,使用正确的编译器选项至关重要。 若要确保这一点, 最佳方法是基于提供的演示应用程序文件构建您的应用程序。内存分配演示应用程序项目中包含 SourcePortableMemMangheap_1.c, 用于提供 RTOS 内核所需的内存分配。 请参阅 API 文档的内存管理部分, 获取完整信息。Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|