【AG32VH407开发板】创建FreeRTOS系统
[复制链接]
在项目中创建FreeRTOS系统。
一、复制文件
将AgRV_pio\platforms\AgRV\examples\freeRTOS\src\FreeRTOSConfig.h 文件复制到AgRV_pio\platforms\AgRV\examples\example目录下。
测试的工程在AgRV_pio\platforms\AgRV\examples\example目录
二、程序部分
2.1、修改paltform.ini
在此此处增加支持的FreeRTOS 系统
2.2、fun_task.c
测试FreeRTOS任务程序
- #include "example.h"
- #include "led/led.h"
- #include "key/key.h"
- #include "timer/mtimer.h"
- #include "lcd/jlx12864g.h"
- #include "oled/oled.h"
-
- #include "FreeRTOS.h"
- #include "task.h"
- #include "queue.h"
- #include "timers.h"
- #include "semphr.h"
-
- #define START_TASK_PRO 1
- #define START_STK_SIZE 128
- TaskHandle_t StartTask_Handler;
-
- #define TASK1_PRIO 4
- #define TASK1_STK_SIZE 128
- static TaskHandle_t Task1Task_Handler = NULL;
-
- #define TASK2_PRIO 3
- #define TASK2_STK_SIZE 128
- static TaskHandle_t Task2Task_Handler = NULL;
-
-
- void start_task(void *pvParameters);
-
- void task1(void *pvParameters);
- void task2(void *pvParameters);
-
- void task_create(void)
- {
-
-
- xTaskCreate((TaskFunction_t )start_task,
- (const char* )"start_task",
- (uint16_t )START_STK_SIZE,
- (void* )NULL,
- (UBaseType_t )START_TASK_PRO,
- (TaskHandle_t* )&StartTask_Handler);
-
- vTaskStartScheduler();
- }
-
- void start_task(void *pvParameters)
- {
- taskENTER_CRITICAL();
-
- xTaskCreate((TaskFunction_t )task1,
- (const char* )"task1",
- (uint16_t )TASK1_STK_SIZE,
- (void* )NULL,
- (UBaseType_t )TASK1_PRIO,
- (TaskHandle_t* )&Task1Task_Handler);
-
- xTaskCreate((TaskFunction_t )task2,
- (const char* )"task2",
- (uint16_t )TASK2_STK_SIZE,
- (void* )NULL,
- (UBaseType_t )TASK2_PRIO,
- (TaskHandle_t* )&Task2Task_Handler);
- taskEXIT_CRITICAL();
- vTaskDelete(StartTask_Handler);
- }
-
-
-
- void task1(void *pvParameters)
- {
- while (1)
- {
- printf("task1 run ...\r\n");
- vTaskDelay(200);
- }
- }
-
-
- void task2(void *pvParameters)
- {
- while (1)
- {
- printf("task2 run ...\r\n");
- vTaskDelay(100);
- }
- }
-
- void vApplicationTickHook(void)
- {
- return;
- }
-
-
- void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
- StackType_t **ppxIdleTaskStackBuffer,
- uint32_t *pulIdleTaskStackSize)
- {
- static StaticTask_t xIdleTaskTCB;
- static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
-
- *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
- *ppxIdleTaskStackBuffer = uxIdleTaskStack;
- *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
- }
-
- void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
- StackType_t **ppxTimerTaskStackBuffer,
- uint32_t *pulTimerTaskStackSize)
- {
- static StaticTask_t xTimerTaskTCB;
- static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];
-
- *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
- *ppxTimerTaskStackBuffer = uxTimerTaskStack;
- *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
- }
2.3、fun_task.h
- #ifndef __FUN_TASK_H
- #define __FUN_TASK_H
-
- void task_create(void);
-
- #endif
-
-
-
2.4、example.c
- #include "example.h"
- #include "led/led.h"
- #include "key/key.h"
- #include "timer/mtimer.h"
- #include "lcd/jlx12864g.h"
- #include "oled/oled.h"
- #include "task/fun_task.h"
-
- int main(void)
- {
- board_init();
- init_led();
- init_key();
- init_mtimer(1);
- init_lcd_jlx12864g();
- init_oled();
-
- task_create();
-
- while(1)
- {
-
- }
- }
-
三、运行结果
编译后,下载ve和code代码后,串口输出如下
使用官方的SDK包中的FreeRTOS系统还是比较方便的,官方已经把底层都移植好了,只需要编写应用程序。
|