Skip to content

Commit

Permalink
port: freertos: implement signals API
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Szczys <[email protected]>
  • Loading branch information
szczys committed Sep 12, 2024
1 parent dba267b commit ec188c1
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions port/freertos/golioth_sys_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,59 @@ int golioth_sys_sem_get_fd(golioth_sys_sem_t sem)
return -1;
}

/*--------------------------------------------------
* Signals
*------------------------------------------------*/

golioth_sys_signal_t golioth_sys_signal_create(void)
{
return xTaskGetCurrentTaskHandle();
}

bool golioth_sys_signal_poll(golioth_sys_signal_t sig, int32_t ms_to_wait)
{
if (!sig)
{
return false;
}

TickType_t ticks_to_wait = (ms_to_wait < 0 ? portMAX_DELAY : pdMS_TO_TICKS(ms_to_wait));

return (pdPASS == ulTaskNotifyTake(pdTRUE, ticks_to_wait));
}

bool golioth_sys_signal_raise(golioth_sys_signal_t sig)
{
if (!sig)
{
return false;
}

BaseType_t xHigherPriorityTaskWoken = pdFALSE;

vTaskNotifyGiveFromISR((TaskHandle_t) sig, &xHigherPriorityTaskWoken);

portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return true;
}

void golioth_sys_signal_reset(golioth_sys_signal_t sig)
{
if (!sig)
{
return;
}

xTaskNotifyStateClear((TaskHandle_t) sig);
}

void golioth_sys_signal_destroy(golioth_sys_signal_t sig)
{
/* We didn't allocate any memory for TaskHandle_t */
(void) sig;
return;
}

/*--------------------------------------------------
* Software Timers
*------------------------------------------------*/
Expand Down

0 comments on commit ec188c1

Please sign in to comment.