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 MSR_EE_SHIFT (15u)
104 static inline bool osif_IsIsrContext(
void)
107 uint32_t msr = MFMSR();
109 if ((msr & (1u<<MSR_EE_SHIFT)) == 0u)
117 #error "No method to check ISR Context"
135 vTaskDelay(MSEC_TO_TICK(delay));
154 return (uint32_t)((((uint64_t) xTaskGetTickCount()) * 1000u) / configTICK_RATE_HZ);
165 const uint32_t timeout)
170 uint32_t timeoutTicks;
172 TaskHandle_t mutex_holder_handle;
173 TaskHandle_t current_task_handle;
174 BaseType_t operation_status = pdFAIL;
181 mutex_holder_handle = xSemaphoreGetMutexHolder(*pMutex);
182 current_task_handle = xTaskGetCurrentTaskHandle();
185 if (mutex_holder_handle == current_task_handle)
194 timeoutTicks = portMAX_DELAY;
198 timeoutTicks = MSEC_TO_TICK(timeout);
202 operation_status = xSemaphoreTake(*pMutex, timeoutTicks);
208 return osif_ret_code;
225 TaskHandle_t mutex_holder_handle;
226 TaskHandle_t current_task_handle;
227 BaseType_t operation_status = pdFAIL;
234 mutex_holder_handle = xSemaphoreGetMutexHolder(*pMutex);
235 current_task_handle = xTaskGetCurrentTaskHandle();
238 if (mutex_holder_handle != current_task_handle)
244 operation_status = xSemaphoreGive(*pMutex);
249 return osif_ret_code;
268 *pMutex = xSemaphoreCreateMutex();
275 return osif_ret_code;
293 vSemaphoreDelete(*pMutex);
308 const uint32_t timeout)
312 uint32_t timeoutTicks;
313 BaseType_t operation_status;
319 timeoutTicks = portMAX_DELAY;
323 timeoutTicks = MSEC_TO_TICK(timeout);
327 operation_status = xSemaphoreTake(*pSem, timeoutTicks);
331 return osif_ret_code;
345 BaseType_t operation_status = pdFAIL;
349 bool is_isr = osif_IsIsrContext();
353 BaseType_t taskWoken = pdFALSE;
354 operation_status = xSemaphoreGiveFromISR(*pSem, &taskWoken);
356 if (operation_status == pdPASS)
359 #if FEATURE_OSIF_FREERTOS_ISR_CONTEXT_METHOD == 1
360 portYIELD_FROM_ISR(taskWoken);
361 #elif FEATURE_OSIF_FREERTOS_ISR_CONTEXT_METHOD == 2
362 if (taskWoken == pdTRUE)
364 portYIELD_FROM_ISR();
372 operation_status = xSemaphoreGive(*pSem);
378 return osif_ret_code;
389 const uint8_t initValue)
395 *pSem = xSemaphoreCreateCounting(0xFFu, initValue);
402 return osif_ret_code;
417 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