diff --git a/freertos.c b/freertos.c index 7cd05f5..1e0e3fd 100644 --- a/freertos.c +++ b/freertos.c @@ -60,8 +60,7 @@ #define STACK_MAIN 160 #define STACK_MSG 230 -#define STACK_LP 180 -#define STACK_HP 150 +#define STACK_JOBRUNNER 150 osThreadId tskMainHandle; uint32_t mainTaskBuffer[ STACK_MAIN ]; @@ -71,19 +70,11 @@ osThreadId tskMsgHandle; uint32_t msgTaskBuffer[ STACK_MSG ]; osStaticThreadDef_t msgTaskControlBlock; -osThreadId tskSchedLPHandle; -uint32_t schedLowBuffer[ STACK_LP ]; -osStaticThreadDef_t schedLowControlBlock; +osThreadId tskJobRunnerHandle; +uint32_t jobRunnerBuffer[ STACK_JOBRUNNER ]; +osStaticThreadDef_t jobRunnerControlBlock; -osThreadId tskSchedHPHandle; -uint32_t schedHighBuffer[ STACK_HP ]; -osStaticThreadDef_t schedHighControlBlock; - -osMessageQId queSchedLPHandle; -uint8_t myQueue01Buffer[ LP_SCHED_CAPACITY * sizeof( struct sched_que_item ) ]; -osStaticMessageQDef_t myQueue01ControlBlock; - -osMessageQId queSchedHPHandle; +osMessageQId queSchedHandle; uint8_t myQueue02Buffer[ HP_SCHED_CAPACITY * sizeof( struct sched_que_item ) ]; osStaticMessageQDef_t myQueue02ControlBlock; @@ -104,7 +95,7 @@ osStaticSemaphoreDef_t myBinarySem01ControlBlock; /* Function prototypes -------------------------------------------------------*/ void TaskMain(void const * argument); extern void TaskSchedLP(void const * argument); -extern void TaskSchedHP(void const * argument); +extern void TaskJobQueue(void const *argument); extern void TaskMessaging(void const * argument); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ @@ -146,8 +137,7 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackTy void MX_FREERTOS_Init(void) { /* USER CODE BEGIN Init */ stackmon_register("Main", mainTaskBuffer, sizeof(mainTaskBuffer)); - stackmon_register("Job Queue Low", schedLowBuffer, sizeof(schedLowBuffer)); - stackmon_register("Job Queue High", schedHighBuffer, sizeof(schedHighBuffer)); + stackmon_register("JobRunner", jobRunnerBuffer, sizeof(jobRunnerBuffer)); stackmon_register("Messaging", msgTaskBuffer, sizeof(msgTaskBuffer)); /* USER CODE END Init */ @@ -179,13 +169,9 @@ void MX_FREERTOS_Init(void) { osThreadStaticDef(tskMain, TaskMain, osPriorityHigh, 0, STACK_MAIN, mainTaskBuffer, &mainTaskControlBlock); tskMainHandle = osThreadCreate(osThread(tskMain), NULL); - /* definition and creation of tskSchedLP */ - osThreadStaticDef(tskSchedLP, TaskSchedLP, osPriorityLow, 0, STACK_LP, schedLowBuffer, &schedLowControlBlock); - tskSchedLPHandle = osThreadCreate(osThread(tskSchedLP), NULL); - - /* definition and creation of tskSchedHP */ - osThreadStaticDef(tskSchedHP, TaskSchedHP, osPriorityAboveNormal, 0, STACK_HP, schedHighBuffer, &schedHighControlBlock); - tskSchedHPHandle = osThreadCreate(osThread(tskSchedHP), NULL); + /* definition and creation of tskJobRunner */ + osThreadStaticDef(tskJobRunner, TaskJobQueue, osPriorityAboveNormal, 0, STACK_JOBRUNNER, jobRunnerBuffer, &jobRunnerControlBlock); + tskJobRunnerHandle = osThreadCreate(osThread(tskJobRunner), NULL); /* definition and creation of TaskMessaging */ osThreadStaticDef(tskMsg, TaskMessaging, osPriorityNormal, 0, STACK_MSG, msgTaskBuffer, &msgTaskControlBlock); @@ -196,13 +182,10 @@ void MX_FREERTOS_Init(void) { /* USER CODE END RTOS_THREADS */ /* Create the queue(s) */ - /* definition and creation of queSchedLP */ - osMessageQStaticDef(queSchedLP, LP_SCHED_CAPACITY, struct sched_que_item, myQueue01Buffer, &myQueue01ControlBlock); - queSchedLPHandle = osMessageCreate(osMessageQ(queSchedLP), NULL); /* definition and creation of queSchedHP */ osMessageQStaticDef(queSchedHP, HP_SCHED_CAPACITY, struct sched_que_item, myQueue02Buffer, &myQueue02ControlBlock); - queSchedHPHandle = osMessageCreate(osMessageQ(queSchedHP), NULL); + queSchedHandle = osMessageCreate(osMessageQ(queSchedHP), NULL); /* definition and creation of queRxData */ osMessageQStaticDef(queRxData, RX_QUE_CAPACITY, struct rx_que_item, myQueue03Buffer, &myQueue03ControlBlock); diff --git a/tasks/sched_queue.h b/tasks/sched_queue.h index f192eb1..14662ee 100644 --- a/tasks/sched_queue.h +++ b/tasks/sched_queue.h @@ -5,7 +5,7 @@ #ifndef GEX_SCHED_QUEUE_H #define GEX_SCHED_QUEUE_H -#include +#include typedef struct sched_que_item Job; typedef void (*ScheduledJobCb) (Job *job); @@ -35,7 +35,6 @@ struct rx_que_item { uint8_t data[64]; }; -#define LP_SCHED_CAPACITY 5 #define HP_SCHED_CAPACITY 5 #define RX_QUE_CAPACITY 16 diff --git a/tasks/task_sched.c b/tasks/task_sched.c index ade3b9c..274c6be 100644 --- a/tasks/task_sched.c +++ b/tasks/task_sched.c @@ -5,23 +5,18 @@ #include "platform.h" #include "task_sched.h" -extern osMessageQId queSchedLPHandle; -extern osMessageQId queSchedHPHandle; +extern osMessageQId queSchedHandle; -volatile uint32_t jobQueHighWaterMarkHP = 0; -volatile uint32_t jobQueHighWaterMarkLP = 0; +volatile uint32_t jobQueHighWaterMark = 0; /** * Schedule a function for later execution in the jobs thread * * @param callback - the callback function - * @param prio - priority, selects which job queue to use - * @param data1 - first data object, NULL if not needed; usually context/handle - * @param data2 - second data object, NULL if not needed; usually data/argument */ -void scheduleJob(Job *job, enum task_sched_prio prio) +void scheduleJob(Job *job) { - QueueHandle_t que = (prio == TSK_SCHED_LOW ? queSchedLPHandle : queSchedHPHandle); + QueueHandle_t que = queSchedHandle; assert_param(que != NULL); assert_param(job->cb != NULL); @@ -44,44 +39,22 @@ void scheduleJob(Job *job, enum task_sched_prio prio) } #if USE_STACK_MONITOR - if (prio == TSK_SCHED_LOW) { - jobQueHighWaterMarkLP = MAX(jobQueHighWaterMarkLP, count); - } else { - jobQueHighWaterMarkHP = MAX(jobQueHighWaterMarkHP, count); - } + jobQueHighWaterMark = MAX(jobQueHighWaterMark, count); #endif } /** - * Low priority task queue handler - * - * @param argument - */ -void TaskSchedLP (const void * argument) -{ - dbg("> Low priority queue task started!"); - - struct sched_que_item job; - while (1) { - xQueueReceive(queSchedLPHandle, &job, osWaitForever); - - assert_param(job.cb != NULL); - job.cb(&job); - } -} - -/** - * High priority task queue handler + * job queue handler (for use in interrupts to do longer stuff on a thread) * * @param argument */ -void TaskSchedHP (const void * argument) +void TaskJobQueue(const void *argument) { dbg("> High priority queue task started!"); struct sched_que_item job; while (1) { - xQueueReceive(queSchedHPHandle, &job, osWaitForever); + xQueueReceive(queSchedHandle, &job, osWaitForever); assert_param(job.cb != NULL); job.cb(&job); diff --git a/tasks/task_sched.h b/tasks/task_sched.h index c9c14b0..0841991 100644 --- a/tasks/task_sched.h +++ b/tasks/task_sched.h @@ -8,22 +8,13 @@ #include "platform.h" #include "sched_queue.h" -enum task_sched_prio { - TSK_SCHED_LOW = 0, - TSK_SCHED_HIGH = 1, -}; - #if USE_STACK_MONITOR -extern volatile uint32_t jobQueHighWaterMarkHP; -extern volatile uint32_t jobQueHighWaterMarkLP; +extern volatile uint32_t jobQueHighWaterMark; #endif -extern osThreadId tskSchedLPHandle; -void TaskSchedLP (const void * argument); - -extern osThreadId tskSchedHPHandle; -void TaskSchedHP (const void * argument); +extern osThreadId tskJobRunnerHandle; +void TaskJobQueue(const void *argument); -void scheduleJob(Job *job, enum task_sched_prio prio); +void scheduleJob(Job *job); #endif //GEX_TASK_SCHED_H diff --git a/utils/stacksmon.c b/utils/stacksmon.c index 01498e7..12078d8 100644 --- a/utils/stacksmon.c +++ b/utils/stacksmon.c @@ -14,7 +14,7 @@ struct stackhandle { uint32_t len; }; -#define STACK_NUM 16 +#define STACK_NUM 8 static uint32_t nextidx = 0; static struct stackhandle stacks[STACK_NUM]; @@ -64,9 +64,9 @@ void stackmon_dump(void) ); } - PUTS("\033[36m>> QUEUES\033[m\r\n"); - PRINTF(" Used slots: \033[33mHP %"PRIu32", LP %"PRIu32"\033[m\r\n", - jobQueHighWaterMarkHP, jobQueHighWaterMarkLP); + PUTS("\033[36m>> JOB QUEUE\033[m\r\n"); + PRINTF(" Used slots: \033[33m%"PRIu32"\033[m\r\n", + jobQueHighWaterMark); PRINTF("\033[1m---------------------------\033[m\r\n\r\n"); }