记录一段FreeRTOS程序,该程序演示了任务状态怎么判断。
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 131 132 133 134 135 136 137 138 139 140
|
#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);
uint32_t ui32Count = 0; uint32_t u32_nums[5] = {1, 2, 3, 4, 5};
static const char *pv_string = "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*)pv_string, \ (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) { static uint32_t count = 0; while(1) { UBaseType_t current_p = uxTaskPriorityGet(LED2Task_Handler); printf("任务2的优先级为:%ld\n", current_p); if (current_p == 0) vTaskPrioritySet(LED2Task_Handler, 1); gd_eval_led_toggle(LED1); vTaskDelay(1000); count++; if(count >= 10) { count = 0; vTaskResume(LED2Task_Handler); } if (eTaskGetState(LED2Task_Handler) != eSuspended) vTaskSuspend(LED2Task_Handler); } }
void led2_task(void *pvParameters) { while(1) { printf("led2_task...\n"); 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); }
|