使用 vTaskList()
函数可以获取各个任务的信息保存到函数的参数中。
要使用 vTaskList()
函数需要先定义必要的宏定义为1,具体看一下代码:
1 2 3 4 5 6 7
| #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
void vTaskList( char * pcWriteBuffer ) { TaskStatus_t * pxTaskStatusArray; UBaseType_t uxArraySize, x; char cStatus;
|
共需要定义3个宏定义:
- configUSE_TRACE_FACILITY
- configUSE_STATS_FORMATTING_FUNCTIONS
- configSUPPORT_DYNAMIC_ALLOCATION
例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include "main.h" #include "FreeRTOS.h" #include "semphr.h" #include "task.h" #include "debug_printf.h"
#include "gd32f1x0.h" #include "gd32f1x0r_eval.h" #include <stdio.h> #include "key.h"
#define LED1_TASK_PRIO 0 #define LED1_STK_SIZE 50 TaskHandle_t LED1Task_Handler; void led1_task(void *pvParameters);
#define LED2_TASK_PRIO 0 #define LED2_STK_SIZE 50 TaskHandle_t LED2Task_Handler; void led2_task(void *pvParameters);
static char pcWriteBuffer[256] = {0};
int main(void) { key_init(); debug_printf_init(EVAL_COM0); gd_eval_led_init(LED1); gd_eval_led_init(LED2); gd_eval_led_init(LED3);
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); xTaskCreate((TaskFunction_t)led2_task, \ (const char*)"led2_task", \ (uint16_t)LED2_STK_SIZE, \ (void*)NULL, \ (UBaseType_t)LED2_TASK_PRIO, \ (TaskHandle_t*)&LED2Task_Handler); app_main(); vTaskStartScheduler();
while (1) {
} }
void led1_task(void *pvParameters) { uint32_t count = 1; while(1) { gd_eval_led_toggle(LED1); vTaskDelay(1000); printf("led1_task(%d)...\n", count); count++; if (count > 10) { count = 1; xTaskNotifyGive(LED2Task_Handler); } } }
void led2_task(void *pvParameters) { while(1) { printf("led2_task...\n"); ulTaskNotifyTake(pdTRUE, portMAX_DELAY); gd_eval_led_toggle(LED2); vTaskDelay(500); } }
void app_main(void) { vTaskList(pcWriteBuffer); printf("--------------------------------------------------\n"); printf("Name|State|riority|Stack|Num\n"); printf("%s\n", pcWriteBuffer); }
|
串口打印结果