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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
| #include "main.h" #include "driver_led.h" #include "driver_key.h"
#define START_TASK_STACK 128 #define START_TASK_PRIORITY 1 TaskHandle_t start_task_handle; StackType_t start_task_stack[START_TASK_STACK]; StaticTask_t start_task_tcb; void start_task(void);
#define TASK1_STACK 128 #define TASK1_PRIORITY 2 TaskHandle_t task1_handle; StackType_t task1_stack[TASK1_STACK]; StaticTask_t task1_tcb; void task1(void);
#define TASK2_STACK 128 #define TASK2_PRIORITY 3 TaskHandle_t task2_handle; StackType_t task2_stack[TASK2_STACK]; StaticTask_t task2_tcb; void task2(void);
#define TASK3_STACK 128 #define TASK3_PRIORITY 4 TaskHandle_t task3_handle; StackType_t task3_stack[TASK3_STACK]; StaticTask_t task3_tcb; void task3(void);
StackType_t idle_task_stack[configMINIMAL_STACK_SIZE]; StaticTask_t idle_task_tcb;
StackType_t timer_task_stack[configTIMER_TASK_STACK_DEPTH]; StaticTask_t timer_task_tcb;
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) { *ppxIdleTaskTCBBuffer = &idle_task_tcb; *ppxIdleTaskStackBuffer = idle_task_stack; *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; }
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize) { *ppxTimerTaskTCBBuffer = &timer_task_tcb; *ppxTimerTaskStackBuffer = timer_task_stack; *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; }
void FreeRTOS_Start(void) { start_task_handle = xTaskCreateStatic( (TaskFunction_t)start_task, (char *)"start_task", (uint32_t)START_TASK_STACK, (void *)NULL, (UBaseType_t)START_TASK_PRIORITY, (StackType_t *)start_task_stack, (StaticTask_t *)&start_task_tcb );
vTaskStartScheduler(); }
int main(void) { HAL_Init(); SystemClock_Config();
LedGpioInit(); KeyInit(); FreeRTOS_Start(); }
void start_task(void) { taskENTER_CRITICAL();
task1_handle = xTaskCreateStatic( (TaskFunction_t)task1, (char *)"task1", (configSTACK_DEPTH_TYPE)TASK1_STACK, (void *)NULL, (UBaseType_t)TASK1_PRIORITY, (StackType_t *)task1_stack, (StaticTask_t *)&task1_tcb );
task2_handle = xTaskCreateStatic( (TaskFunction_t)task2, (char *)"task2", (configSTACK_DEPTH_TYPE)TASK2_STACK, (void *)NULL, (UBaseType_t)TASK2_PRIORITY, (StackType_t *)task2_stack, (StaticTask_t *)&task2_tcb );
task3_handle = xTaskCreateStatic( (TaskFunction_t)task3, (char *)"task3", (configSTACK_DEPTH_TYPE)TASK3_STACK, (void *)NULL, (UBaseType_t)TASK3_PRIORITY, (StackType_t *)task3_stack, (StaticTask_t *)&task3_tcb );
vTaskDelete(NULL);
taskEXIT_CRITICAL(); }
void task1(void) { while(1) { LED_TOGGLE(LED0_GPIO_PORT,LED0_GPIO_PIN); vTaskDelay(500); } } void task2(void) { while(1) { LED_TOGGLE(LED1_GPIO_PORT,LED1_GPIO_PIN); vTaskDelay(500); } } void task3(void) { while(1) { if(KeyScan() == 0) { if(task1_handle != NULL) vTaskDelete(task1_handle); task1_handle = NULL; } vTaskDelay(500); } }
|