FreeRtos的静态方法创建任务和删除示例

需要使用静态方法需要将宏configSUPPORT_STATIC_ALLOCATION=1

步骤

1.修改宏configSUPPORT_STATIC_ALLOCATION=1运行时候会显示两个函数未定义

vApplicationGetIdleTaskMemory()vApplicationGetTimerTaskMemory()

#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "FreeRTOS.h"
#include "task.h"

//开始任务
#define START_TASK_SIZE  120;
#define START_TASK_PRIO 1;
StackType_t StackTaskBuffer[START_TASK_SIZE];
StaticTask_t StackTaskTcb;
TaskHandle_t StartTask_Handle;
void start_task( void * pvParameters ); //定义
//任务1
#define START_TASK1_SIZE  120;
#define START_TASK1_PRIO 1;
StackType_t StackTaskBuffer[START_TASK1_SIZE];
StaticTask_t StackTask1Tcb;
TaskHandle_t StartTask1_Handle;
void start1_task( void * pvParameters ); //定义
//任务2
#define START_TASK2_SIZE  120;
#define START_TASK2_PRIO 1;
StackType_t StackTask2Buffer[START_TASK2_SIZE];
StaticTask_t StackTask2Tcb;
TaskHandle_t StartTask2_Handle;
void start2_task( void * pvParameters ); //定义


static StaticTask_t IdleTaskStackTcb;
static StackType_t IdleTaskStackBuf[configMINIMAL_STACK_SIZE];

static StaticTask_t TimerTaskTcb;
static StackType_t TimeTaskStackBuf[configTIMER_TASK_STACK_DEPTH];
//空闲任务
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,  //空闲任务的任务控制块
																		StackType_t **ppxIdleTaskStackBuffer, //空闲任务的堆栈
																		uint32_t *pulIdleTaskStackSize )			//空闲任务的堆栈的大小
{
		*ppxIdleTaskTCBBuffer	= &IdleTaskStackTcb;
		*ppxIdleTaskStackBuffer =	IdleTaskStackBuf;
			*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;															
}
//定时器任务
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, 
																		 StackType_t **ppxTimerTaskStackBuffer, 
																		 uint32_t *pulTimerTaskStackSize )
{
		*ppxTimerTaskTCBBuffer = &TimerTaskTcb;
		*ppxTimerTaskStackBuffer = TimeTaskStackBuf;
		*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}

int main(void)
{
	
	   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//设置系统中断优先级分组4	 
	   delay_init();	    				//延时函数初始化	  
	   uart_init(115200);					//初始化串口
	   LED_Init();		  					//初始化LED
	//任务一
	   StartTask_Handle	= xTaskCreateStatic(	(TaskFunction_t) 		start_task,
												 (char *)  				  "start_task",
												 (uint32_t) 				START_TASK_SIZE,
												(void *) 					  NULL,
												(UBaseType_t) 			START_TASK_PRIO,
												(StackType_t *)  		StackTaskBuffer,
												(StaticTask_t *)  	&StackTaskTcb );											
	
		vTaskStartScheduler();
}
void start_task( void * pvParameters ) //定义
{
      StartTask1_Handle	= xTaskCreateStatic(	(TaskFunction_t) 		start1_task,
												 (char *)  				  "start1_task",
												 (uint32_t) 				START_TASK1_SIZE,
												(void *) 					  NULL,
												(UBaseType_t) 			START_TASK_PRIO,
												(StackType_t *)  		StackTaskBuffer,
												(StaticTask_t *)  	&StackTask1Tcb );
												
		 StartTask2_Handle	= xTaskCreateStatic(	(TaskFunction_t) 		start2_task,
												 (char *)  				  "start2_task",
												 (uint32_t) 				START_TASK2_SIZE,
												(void *) 					  NULL,
												(UBaseType_t) 			START_TASK2_PRIO,
												(StackType_t *)  		StackTask2Buffer,
												(StaticTask_t *)  	&StackTask2Tcb );
	
		vTaskStartScheduler();
}

void start1_task( void * pvParameters ) //定义
{
      while(1){
			}
 
}
void start2_task( void * pvParameters ) //定义
{
      while(1){
			}
 
} 
 

你可能感兴趣的:(单片机,stm32)