程序如下
main.c
#include "FreeRTOS.h"
#include "task.h"
#include "bsp_led.h"
#include "bsp_usart.h"
static TaskHandle_t AppTaskCreate_Handle = NULL;
static TaskHandle_t LED1_Task_Handle = NULL;
static TaskHandle_t LED2_Task_Handle = NULL;
static void AppTaskCreate(void);
static void LED1_Task(void* pvParameters);
static void LED2_Task(void* pvParameters);
static void BSP_Init(void);
int main(void)
{
BaseType_t xReturn = pdPASS;
BSP_Init();
xReturn = xTaskCreate((TaskFunction_t )AppTaskCreate,
(const char* )"AppTaskCreate",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )1,
(TaskHandle_t* )&AppTaskCreate_Handle);
if(pdPASS == xReturn)
vTaskStartScheduler();
else
return -1;
while(1);
}
static void AppTaskCreate(void)
{
BaseType_t xReturn = pdPASS;
taskENTER_CRITICAL();
xReturn = xTaskCreate((TaskFunction_t )LED1_Task,
(const char* )"LED1_Task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )2,
(TaskHandle_t* )&LED1_Task_Handle);
if(pdPASS == xReturn)
printf("´´½¨LED1_TaskÈÎÎñ³É¹¦!\r\n");
xReturn = xTaskCreate((TaskFunction_t )LED2_Task,
(const char* )"LED2_Task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )3,
(TaskHandle_t* )&LED2_Task_Handle);
if(pdPASS == xReturn)
printf("´´½¨LED2_TaskÈÎÎñ³É¹¦!\r\n");
vTaskDelete(AppTaskCreate_Handle);
taskEXIT_CRITICAL();
}
static void LED1_Task(void* parameter)
{
while (1)
{
LED1_ON;
vTaskDelay(500);
printf("LED1_Task Running,LED1_ON\r\n");
LED1_OFF;
vTaskDelay(500);
printf("LED1_Task Running,LED1_OFF\r\n");
}
}
static void LED2_Task(void* parameter)
{
while (1)
{
vTaskDelay(2000);
printf("hello windows !! \r\n");
}
}
static void BSP_Init(void)
{
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
LED_GPIO_Config();
USART_Config();
}
|
———————————————— 版权声明:本文为CSDN博主「秋雯」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_51109735/article/details/110501560