diff options
| author | hathach <[email protected]> | 2018-03-30 15:33:36 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-03-30 15:33:36 +0700 |
| commit | 82da013dadf2b2f69f362702ca40708fdec52df4 (patch) | |
| tree | bfa9a73206ace7aca38dbf008a8277a6ea2d20bc /tinyusb/osal/osal_freeRTOS.h | |
| parent | 97db3c7c3d7cfbbb19dbda09809aa39bb19608b9 (diff) | |
get freertos build
Diffstat (limited to 'tinyusb/osal/osal_freeRTOS.h')
| -rw-r--r-- | tinyusb/osal/osal_freeRTOS.h | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index f2fe668ae..b0a99ad38 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -56,10 +56,15 @@ extern "C" { #endif -//--------------------------------------------------------------------+ -// TICK API -//--------------------------------------------------------------------+ -#define osal_millis xTaskGetTickCount +#if 0 +// Helper to determine if we are in ISR to use ISR API (only cover ARM Cortex) +// Note: Actually we don't need this since any event signal (queue send, semaphore post) +// is done in ISR, other event receive (queue receive, semaphore wait ) in in thread +static inline bool in_isr(void) +{ + return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk); +} +#endif //--------------------------------------------------------------------+ // TASK API @@ -92,20 +97,12 @@ static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size) static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) { uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - - portBASE_TYPE result = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? xQueueReceiveFromISR(queue_hdl, p_data, NULL) : xQueueReceive(queue_hdl, p_data, ticks); - (*p_error) = ( result == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; + (*p_error) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); } static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data) { - if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) - { - return xQueueSendToFrontFromISR(queue_hdl, data, NULL); - }else - { - return xQueueSendToFront(queue_hdl, data, 0); - } + return xQueueSendToFrontFromISR(queue_hdl, data, NULL); } static inline void osal_queue_flush(osal_queue_t const queue_hdl) @@ -126,30 +123,13 @@ static inline osal_semaphore_t osal_semaphore_create(uint32_t max, uint32_t init // TODO add timeout (with instant return from ISR option) for semaphore post & queue send static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) { - if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) - { - return xSemaphoreGiveFromISR(sem_hdl, NULL); - }else - { - return xSemaphoreGive(sem_hdl); - } + return xSemaphoreGiveFromISR(sem_hdl, NULL); } static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) { uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - - BaseType_t result; - - if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) - { - result = xSemaphoreTakeFromISR(sem_hdl, NULL); - }else - { - result = xSemaphoreTake(sem_hdl, ticks); - } - - (*p_error) = result ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; + (*p_error) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); } static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl) @@ -167,12 +147,13 @@ typedef xSemaphoreHandle osal_mutex_t; static inline bool osal_mutex_release(osal_mutex_t mutex_hdl) { - return osal_semaphore_post(mutex_hdl); + return xSemaphoreGive(mutex_hdl); } static inline void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) { - osal_semaphore_wait(mutex_hdl, msec, p_error); + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); + (*p_error) = (xSemaphoreTake(mutex_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); } // TOOD remove |
