概述
sdk版本: telink_b91m_driver_sdk V2.3.0
sdk本身带Freertos_demo
,如果是新项目,建议直接在Freertos_demo
基础上开发。
本文适用场景:项目开发一部分后,想添加Freertos。
步骤
泰凌微官方已经完成了移植,只需要做简单配置即可使用Freertos
添加Freertos源码参与编译
在IDE中找到Freertos源码文件夹,右键 - Resource Configurations
- Exclude from Build
- 将自己的demo取消勾选(怎么新建自己的demo见泰凌微B91开发环境搭建_telinkiotstudio安装-CSDN博客)
将vendor/common/exception.c
排除编译(右键 - Resource Configurations
- Exclude from Build
- 将自己的demo勾选)
不排除vendor/common/exception.c
编译时会提示trap_entry
重定义,该函数已经在./3rd-party/freertos-V5/portable/GCC/RISC-V/portASM.S
中定义了
添加头文件路径
打开项目的属性,分别在
C/C++ Build
-Settings
-Tool Settings
-GNU RISC-V Cross Assembler
-Includes
- 右侧Include path (-l)窗口C/C++ Build
-Settings
-Tool Settings
-GNU RISC-V Cross C Compiler
-Includes
- 右侧Include path (-l)窗口
添加"${workspace_loc:/${ProjName}/3rd-party/freertos-V5/include}"
,如下图所示
开始使用
配置完成,接下来只需要添加Freertos对应的头文件即可使用
#include "app_config.h"
#include <FreeRTOS.h>
#include <task.h>
static void led_task(void *pvParameters)
{
const TickType_t xFrequency = pdMS_TO_TICKS(500); // 500ms
while (1) {
///
vTaskDelay(xFrequency);
}
(void)(pvParameters);
}
static void led_task1(void *pvParameters)
{
const TickType_t xFrequency = pdMS_TO_TICKS(1000); // 500ms
while (1) {
///
vTaskDelay(xFrequency);
}
(void)(pvParameters);
}
extern void vPortRestoreTask();
int main(void)
{
PLATFORM_INIT;
CLOCK_INIT;
if (0) { // deepRetWakeUp
vPortRestoreTask();
} else {
xTaskCreate(led_task, "tLed", configMINIMAL_STACK_SIZE, (void *)0, (tskIDLE_PRIORITY + 1), 0);
xTaskCreate(led_task1, "tLed1", configMINIMAL_STACK_SIZE, (void *)0, (tskIDLE_PRIORITY + 1), 0);
vTaskStartScheduler();
}
return 0;
}