diff --git a/app/FreeRTOSConfig.h b/app/FreeRTOSConfig.h index ad0363b..df2fe48 100644 --- a/app/FreeRTOSConfig.h +++ b/app/FreeRTOSConfig.h @@ -51,7 +51,7 @@ #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES 5 #define configMINIMAL_STACK_SIZE ((unsigned short)40) -#define configMAX_TASK_NAME_LEN 20 +#define configMAX_TASK_NAME_LEN 10 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_TASK_NOTIFICATIONS 1 diff --git a/app/common.h b/app/common.h index 37a9dfd..c44faea 100644 --- a/app/common.h +++ b/app/common.h @@ -39,4 +39,23 @@ __typeof__ (b) _b = (b); \ _a < _b ? _a : _b; \ }) + +#define _APP_DEF_TASK(__NAME__, __STACK_SIZE__) \ + static StaticTask_t __NAME__##_task_memory; \ + static StackType_t __NAME__##_task_stack[__STACK_SIZE__] + +#define _APP_CREATE_TASK(__NAME__, __PRIO__) \ + xTaskCreateStatic(__NAME__##_task_entry, #__NAME__, sizeof(__NAME__##_task_stack), NULL, __PRIO__, __NAME__##_task_stack, &__NAME__##_task_memory) + +#define APP_DEF_TASK(__NAME__, __STACK_SIZE__) \ + _APP_DEF_TASK(__NAME__, __STACK_SIZE__) \ + TaskHandle_t __NAME__##_task + +#define APP_CREATE_TASK(__NAME__, __PRIO__) \ + __NAME__##_task = _APP_CREATE_TASK(__NAME__, __PRIO__) + +#define APP_DEF_CREATE_TASK(__NAME__, __PRIO__, __STACK_SIZE__) \ + _APP_DEF_TASK(__NAME__, __STACK_SIZE__); \ + _APP_CREATE_TASK(__NAME__, __PRIO__) + #endif //__APP_COMMON_H__ diff --git a/app/freertos_support.c b/app/freertos_support.c new file mode 100644 index 0000000..2e10043 --- /dev/null +++ b/app/freertos_support.c @@ -0,0 +1,20 @@ +#include "FreeRTOS.h" +#include "task.h" + +void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) { + static StaticTask_t xIdleTaskTCBBuffer; + static StackType_t xIdleStack[configMINIMAL_STACK_SIZE]; + *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; + *ppxIdleTaskStackBuffer = xIdleStack; + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} + +#if (configUSE_TIMERS == 1) +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; +} +#endif diff --git a/app/main.c b/app/main.c index b8f9931..c22de2c 100644 --- a/app/main.c +++ b/app/main.c @@ -1,35 +1,18 @@ #include +#include "common.h" #include "FreeRTOS.h" #include "task.h" #include "hal.h" -void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) { - static StaticTask_t xIdleTaskTCBBuffer; - static StackType_t xIdleStack[configMINIMAL_STACK_SIZE]; - *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; - *ppxIdleTaskStackBuffer = xIdleStack; - *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; -} - -#if (configUSE_TIMERS == 1) -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; -} -#endif - #define QRSCAN_STACK_SIZE 512 -static StaticTask_t qrscan_task_memory; -static StackType_t qrscan_task_stack[QRSCAN_STACK_SIZE]; -TaskHandle_t qrscan_task; +#define QRSCAN_TASK_PRIO 1 + int main(void) { hal_init(); - qrscan_task = xTaskCreateStatic(qrscan_task_entry, "QR Scan", QRSCAN_STACK_SIZE, NULL, 1, qrscan_task_stack, &qrscan_task_memory); + APP_DEF_CREATE_TASK(qrscan, QRSCAN_TASK_PRIO, QRSCAN_STACK_SIZE); + vTaskStartScheduler(); while(1) {