diff options
Diffstat (limited to 'applications/freertos/main.cpp')
-rw-r--r-- | applications/freertos/main.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/applications/freertos/main.cpp b/applications/freertos/main.cpp index 81631ef..1e71e7f 100644 --- a/applications/freertos/main.cpp +++ b/applications/freertos/main.cpp @@ -120,18 +120,22 @@ void *ethosu_mutex_create(void) { return (void *)sem; } -void ethosu_mutex_lock(void *mutex) { +int ethosu_mutex_lock(void *mutex) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(mutex); if (xSemaphoreTake(handle, portMAX_DELAY) != pdTRUE) { printf("Error: Failed to lock mutex.\n"); + return -1; } + return 0; } -void ethosu_mutex_unlock(void *mutex) { +int ethosu_mutex_unlock(void *mutex) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(mutex); if (xSemaphoreGive(handle) != pdTRUE) { printf("Error: Failed to unlock mutex.\n"); + return -1; } + return 0; } void *ethosu_semaphore_create(void) { @@ -142,31 +146,32 @@ void *ethosu_semaphore_create(void) { return (void *)sem; } -void ethosu_semaphore_take(void *sem) { +int ethosu_semaphore_take(void *sem) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(sem); if (xSemaphoreTake(handle, portMAX_DELAY) != pdTRUE) { printf("Error: Failed to take semaphore.\n"); + return -1; } + return 0; } -void ethosu_semaphore_give(void *sem) { +int ethosu_semaphore_give(void *sem) { SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(sem); - BaseType_t ret; if (xPortIsInsideInterrupt()) { - ret = xSemaphoreGiveFromISR(handle, NULL); - if (ret != pdTRUE) { - printf("Error: Failed to give semaphore from ISR. ret - 0x%08lx\n", ret); + if (xSemaphoreGiveFromISR(handle, NULL) != pdTRUE) { + printf("Error: Failed to give semaphore from ISR.\n"); + return -1; } } else { - ret = xSemaphoreGive(handle); - if (ret != pdTRUE) { - /* The next line is in comment because xSemaphoreGive returns pdFAIL when - calling it twice in a row during this application run. - This failure doesn't affect the final result of the FreeRTOS application. */ - /* printf("Error: Failed to give semaphore. ret - 0x%08x\n", ret); */ + /* A FreeRTOS binary semaphore is fundamentally a queue that can only hold one item. If the queue is full, + * xSemaphoreGive will return a pdFALSE value. Ignoring the return value in here, as a semaphore give failure + * does not affect the application correctness. */ + if (xSemaphoreGive(handle) != pdTRUE) { + // do nothing } } + return 0; } } |