Skip to content

Commit

Permalink
Task should be not blocked if flag which are we waiting for has been …
Browse files Browse the repository at this point in the history
…already set (ARM-software#86)

- added task notification if unrequested flag is set in order to mark FreeRTOS task notify state as taskNOTIFICATION_RECEIVED again
  • Loading branch information
lkasperowicz authored Mar 8, 2024
1 parent ed3c7d4 commit bb8a350
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMSIS/RTOS2/FreeRTOS/Source/cmsis_os2.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,12 @@ uint32_t osThreadFlagsGet (void) {
Wait for one or more Thread Flags of the current running thread to become signaled.
*/
uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) {
TaskHandle_t hTask;
uint32_t rflags, nval;
uint32_t clear;
TickType_t t0, td, tout;
BaseType_t rval;
BaseType_t notify = pdFALSE;

if (IRQ_Context() != 0U) {
rflags = (uint32_t)osErrorISR;
Expand All @@ -1022,6 +1024,11 @@ uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout)
rflags &= flags;
rflags |= nval;

if ((rflags & ~flags) != 0) {
/* Other flags already set, notify task to change its state */
notify = pdTRUE;
}

if ((options & osFlagsWaitAll) == osFlagsWaitAll) {
if ((flags & rflags) == flags) {
break;
Expand Down Expand Up @@ -1063,6 +1070,15 @@ uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout)
while (rval != pdFAIL);
}

if (notify == pdTRUE) {
hTask = xTaskGetCurrentTaskHandle();

/* Ensure task is already notified without changing existing flags */
if (xTaskNotify(hTask, 0, eNoAction) != pdPASS) {
rflags = (uint32_t)osError;
}
}

/* Return flags before clearing */
return (rflags);
}
Expand Down

0 comments on commit bb8a350

Please sign in to comment.