使用stm32 cubemx 自带生成的代码中,如何使用freertos 系统实现cmsis rtos api2 接口 - 1
两个静态task idle_TCB Timer_TCB
FreeRTOSConfig.h 配置文件
#define configUSE_PREEMPTION 1
支持抢占,即的中断中切换任务(不用等其他任务调用taskYIELD 函数)
#define configSUPPORT_STATIC_ALLOCATION 1
支持静态分配,根据 https://www.freertos.org/a00110.html ,需要提供两个函数vApplicationGetIdleTaskMemory 和vApplicationGetTimerTaskMemory,在下面提供
#define configSUPPORT_DYNAMIC_ALLOCATION 1
使用 自带的 heap 内存管理器,使用 pvPortMalloc 和 vPortFree 函数。
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
cmsis_os2.c 中提供实现
/* Idle task control block and stack */
static StaticTask_t Idle_TCB;
static StackType_t Idle_Stack[configMINIMAL_STACK_SIZE];
/* Timer task control block and stack */
static StaticTask_t Timer_TCB;
static StackType_t Timer_Stack[configTIMER_TASK_STACK_DEPTH];
/*
vApplicationGetIdleTaskMemory gets called when configSUPPORT_STATIC_ALLOCATION
equals to 1 and is required for static memory allocation support.
*/
void vApplicationGetIdleTaskMemory (StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
*ppxIdleTaskTCBBuffer = &Idle_TCB;
*ppxIdleTaskStackBuffer = &Idle_Stack[0];
*pulIdleTaskStackSize = (uint32_t)configMINIMAL_STACK_SIZE;
}
/*
vApplicationGetTimerTaskMemory gets called when configSUPPORT_STATIC_ALLOCATION
equals to 1 and is required for static memory allocation support.
*/
void vApplicationGetTimerTaskMemory (StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize) {
*ppxTimerTaskTCBBuffer = &Timer_TCB;
*ppxTimerTaskStackBuffer = &Timer_Stack[0];
*pulTimerTaskStackSize = (uint32_t)configTIMER_TASK_STACK_DEPTH;
}
next: 使用stm32 cubemx 自带生成的代码中,如何使用freertos 系统实现cmsis rtos api2 接口 - 2