开始任务创建三个任务
xReturn = xTaskCreate((TaskFunction_t )Start_task,
(const char* )"start_task",
(uint16_t )START_STK_SIZE,
(void* )NULL,
(UBaseType_t )START_TASK_PRIO,
(TaskHandle_t* )&StartTask_Handler);
if(xReturn == pdPASS)
{
printf("开始任务创建成功!\r\n");
}
第1个任务LED1进行闪烁1000毫秒1次
xReturn = xTaskCreate((TaskFunction_t )Led1_task,
(const char* )"Led1_task",
(uint16_t )LED1_STK_SIZE,
(void* )NULL,
(UBaseType_t )LED1_TASK_PRIO,
(TaskHandle_t* )&LED1Task_Handler);
if(xReturn == pdPASS)
{
printf("LED1任务创建成功!\r\n");
}
第2个任务LED2进行闪烁500毫秒1次
xReturn = xTaskCreate((TaskFunction_t )Led2_task,
(const char* )"Led2_task",
(uint16_t )LED2_STK_SIZE,
(void* )NULL,
(UBaseType_t )LED1_TASK_PRIO,
(TaskHandle_t* )&LED2Task_Handler);
if(xReturn == pdPASS)
{
printf("LED2任务创建成功!\r\n");
}
第3个任务进行浮点运算
xReturn = xTaskCreate((TaskFunction_t )Float_task,
(const char* )"float_task",
(uint16_t )FLOAT_STK_SIZE,
(void* )NULL,
(UBaseType_t )FLOAT_TASK_PRIO,
(TaskHandle_t* )&FLOATTask_Handler);
if(xReturn == pdPASS)
{
printf("浮点运算任务创建成功!\r\n");
}
开始任务创建三个任务后删除开始任务,开始任务创建的三个任务进行调度
int main(void)
{
LED1_Init();
LED2_Init();
BEEP_Init();
USART1_Init(9600);
BaseType_t xReturn = 0;
xReturn = xTaskCreate((TaskFunction_t )Start_task,
(const char* )"start_task",
(uint16_t )START_STK_SIZE,
(void* )NULL,
(UBaseType_t )START_TASK_PRIO,
(TaskHandle_t* )&StartTask_Handler);
if(xReturn == pdPASS)
{
printf("开始任务创建成功!\r\n");
}
vTaskStartScheduler();
}
void Start_task(void *pvParameters)
{
BaseType_t xReturn = 0;
taskENTER_CRITICAL();
xReturn = xTaskCreate((TaskFunction_t )Led1_task,
(const char* )"Led1_task",
(uint16_t )LED1_STK_SIZE,
(void* )NULL,
(UBaseType_t )LED1_TASK_PRIO,
(TaskHandle_t* )&LED1Task_Handler);
if(xReturn == pdPASS)
{
printf("LED1任务创建成功!\r\n");
}
xReturn = xTaskCreate((TaskFunction_t )Led2_task,
(const char* )"Led2_task",
(uint16_t )LED2_STK_SIZE,
(void* )NULL,
(UBaseType_t )LED1_TASK_PRIO,
(TaskHandle_t* )&LED2Task_Handler);
if(xReturn == pdPASS)
{
printf("LED2任务创建成功!\r\n");
}
xReturn = xTaskCreate((TaskFunction_t )Float_task,
(const char* )"float_task",
(uint16_t )FLOAT_STK_SIZE,
(void* )NULL,
(UBaseType_t )FLOAT_TASK_PRIO,
(TaskHandle_t* )&FLOATTask_Handler);
if(xReturn == pdPASS)
{
printf("浮点运算任务创建成功!\r\n");
}
vTaskDelete(StartTask_Handler);
taskEXIT_CRITICAL();
}
实验现象