64 #if !defined (USING_OS_FREERTOS)
65 #error "Wrong OSIF selected. Please define symbol USING_OS_FREERTOS in project settings or change the OSIF variant"
79 #define MSEC_TO_TICK(msec) (pdMS_TO_TICKS(msec))
88 #if FEATURE_OSIF_FREERTOS_ISR_CONTEXT_METHOD == 1
90 static inline bool osif_IsIsrContext(
void)
101 #elif FEATURE_OSIF_FREERTOS_ISR_CONTEXT_METHOD == 2
103 #define SPRG0_ADDR (272)
104 static inline bool osif_IsIsrContext(
void)
106 uint32_t interrupt_level = MFSPR(SPRG0_ADDR);
107 bool is_isr = (bool)(interrupt_level > 0u);
111 #error "No method to check ISR Context"
131 vTaskDelay(MSEC_TO_TICK(delay));
150 return (uint32_t)((((uint64_t) xTaskGetTickCount()) * 1000u) / configTICK_RATE_HZ);
161 const uint32_t timeout)
166 uint32_t timeoutTicks;
168 TaskHandle_t mutex_holder_handle;
169 TaskHandle_t current_task_handle;
170 BaseType_t operation_status = pdFAIL;
177 mutex_holder_handle = xSemaphoreGetMutexHolder(*pMutex);
178 current_task_handle = xTaskGetCurrentTaskHandle();
181 if (mutex_holder_handle == current_task_handle)
190 timeoutTicks = portMAX_DELAY;
194 timeoutTicks = MSEC_TO_TICK(timeout);
198 operation_status = xSemaphoreTake(*pMutex, timeoutTicks);
204 return osif_ret_code;
221 TaskHandle_t mutex_holder_handle;
222 TaskHandle_t current_task_handle;
223 BaseType_t operation_status = pdFAIL;
230 mutex_holder_handle = xSemaphoreGetMutexHolder(*pMutex);
231 current_task_handle = xTaskGetCurrentTaskHandle();
234 if (mutex_holder_handle != current_task_handle)
240 operation_status = xSemaphoreGive(*pMutex);
245 return osif_ret_code;
264 *pMutex = xSemaphoreCreateMutex();
271 return osif_ret_code;
289 vSemaphoreDelete(*pMutex);
304 const uint32_t timeout)
308 uint32_t timeoutTicks;
309 BaseType_t operation_status;
315 timeoutTicks = portMAX_DELAY;
319 timeoutTicks = MSEC_TO_TICK(timeout);
323 operation_status = xSemaphoreTake(*pSem, timeoutTicks);
327 return osif_ret_code;
341 BaseType_t operation_status = pdFAIL;
345 bool is_isr = osif_IsIsrContext();
349 BaseType_t taskWoken = pdFALSE;
350 operation_status = xSemaphoreGiveFromISR(*pSem, &taskWoken);
352 if (operation_status == pdPASS)
355 portYIELD_FROM_ISR(taskWoken);
361 operation_status = xSemaphoreGive(*pSem);
367 return osif_ret_code;
378 const uint8_t initValue)
384 *pSem = xSemaphoreCreateCounting(0xFFu, initValue);
391 return osif_ret_code;
406 vSemaphoreDelete(*pSem);
status_t OSIF_MutexDestroy(const mutex_t *const pMutex)
Destroys a previously created mutex.
status_t OSIF_SemaDestroy(const semaphore_t *const pSem)
Destroys a previously created semaphore.
void OSIF_TimeDelay(uint32_t delay)
Delays execution for a number of milliseconds.
status_t OSIF_MutexUnlock(const mutex_t *const pMutex)
Unlocks a previously locked mutex.
status_t OSIF_MutexLock(const mutex_t *const pMutex, const uint32_t timeout)
Waits for a mutex and locks it.
uint32_t OSIF_GetMilliseconds(void)
Returns the number of miliseconds elapsed since starting the internal timer or starting the scheduler...
status_t OSIF_SemaCreate(semaphore_t *const pSem, const uint8_t initValue)
Creates a semaphore with a given value.
status_t OSIF_MutexCreate(mutex_t *const pMutex)
Create an unlocked mutex.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
#define S32_SCB_ICSR_VECTACTIVE_SHIFT
status_t OSIF_SemaWait(semaphore_t *const pSem, const uint32_t timeout)
Decrement a semaphore with timeout.
#define OSIF_WAIT_FOREVER
status_t OSIF_SemaPost(semaphore_t *const pSem)
Increment a semaphore.
#define S32_SCB_ICSR_VECTACTIVE_MASK