テストタスク
task1:LEDが500ms間隔で1回点滅(変化)
task2:2000msごと、コマンドデータ「helloworld!」をシリアルポートに1回
送信task3:5000msごと、AHT20から温度と湿度のデータを収集
実験手順
1.キール書き込みプログラムを開きます(Wildfireが提供するプログラムを使用し
ます)1。プロジェクトを開き
ます
2.構成するチップを見つけます2.コードをコンパイルした後、ダウンロードをクリックして
書き込みます3.書き込み後、コアボードのステータス
2。変調アシスタントを開くシリアル通信用
関連コード
#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 hello_Task_Handle = NULL;
static TaskHandle_t AHT_Task_Handle = NULL;
static void AppTaskCreate(void);
static void LED1_Task(void* pvParameters);
static void hello_Task(void* pvParameters);
static void AHT_Task(void* pvParameters);
static void BSP_Init(void);
int main(void)
{
BaseType_t xReturn = pdPASS;
BSP_Init();
printf("这是一个多任务程序实验!\r\n");
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 )hello_Task,
(const char* )"hello_Task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )3,
(TaskHandle_t* )&hello_Task_Handle);
if(pdPASS == xReturn)
printf("创建hello_Task任务成功!\r\n");
xReturn = xTaskCreate((TaskFunction_t )AHT_Task,
(const char* )"AHT_Task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )3,
(TaskHandle_t* )&AHT_Task_Handle);
if(pdPASS == xReturn)
printf("创建AHT_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 hello_Task(void* parameter)
{
while (1)
{
vTaskDelay(2000);
printf("hello World!\n");
}
}
static void AHT_Task(void* parameter)
{
/*无硬件,之后实现*/
}
static void BSP_Init(void)
{
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
LED_GPIO_Config();
USART_Config();
}