diff options
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/msc_host.c | 2 | ||||
| -rw-r--r-- | tinyusb/device/usbd.c | 2 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 2 | ||||
| -rw-r--r-- | tinyusb/osal/osal_freeRTOS.h | 81 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 106 |
5 files changed, 100 insertions, 93 deletions
diff --git a/tinyusb/class/msc_host.c b/tinyusb/class/msc_host.c index f4859c1eb..00186ddd9 100644 --- a/tinyusb/class/msc_host.c +++ b/tinyusb/class/msc_host.c @@ -407,7 +407,7 @@ void msch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes tuh_msc_isr(pipe_hdl.dev_addr, event, xferred_bytes);
}else
{ // still initializing under open subtask
- ASSERT( TUSB_ERROR_NONE == osal_semaphore_post(msch_sem_hdl), VOID_RETURN );
+ osal_semaphore_post(msch_sem_hdl);
}
}
}
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index 46437e36f..bbe8290e1 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -441,7 +441,7 @@ void usbd_xfer_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xfer {
if (edpt_hdl.class_code == 0 ) // Control Transfer
{
- ASSERT( TUSB_ERROR_NONE == osal_semaphore_post( usbd_control_xfer_sem_hdl ), VOID_RETURN);
+ osal_semaphore_post( usbd_control_xfer_sem_hdl );
}else
{
usbd_task_event_t task_event =
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index 8ab25a19a..e1fb320bd 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -253,7 +253,7 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t even {
usbh_devices[ pipe_hdl.dev_addr ].control.pipe_status = event;
// usbh_devices[ pipe_hdl.dev_addr ].control.xferred_bytes = xferred_bytes; not yet neccessary
- ASSERT( TUSB_ERROR_NONE == osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl ), VOID_RETURN);
+ osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl );
}else if (usbh_class_drivers[class_index].isr)
{
usbh_class_drivers[class_index].isr(pipe_hdl, event, xferred_bytes);
diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index 0e043ded6..da68a5059 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -80,22 +80,59 @@ static inline void osal_task_delay(uint32_t msec) } //--------------------------------------------------------------------+ +// QUEUE API +//--------------------------------------------------------------------+ +typedef xQueueHandle osal_queue_t; + +static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size) +{ + return xQueueCreate(depth, 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 : osal_tick_from_msec(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; +} + +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); + } +} + +static inline void osal_queue_flush(osal_queue_t const queue_hdl) +{ + xQueueReset(queue_hdl); +} + +//--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ typedef xSemaphoreHandle osal_semaphore_t; -// create FreeRTOS binary semaphore with zero as init value TODO: omit semaphore take from vSemaphoreCreateBinary API, should double checks this -//#define osal_semaphore_create(x) xSemaphoreCreateBinary() - static inline osal_semaphore_t osal_semaphore_create(uint32_t max, uint32_t init) { return xSemaphoreCreateCounting(max, init); } // TODO add timeout (with instant return from ISR option) for semaphore post & queue send -static inline tusb_error_t osal_semaphore_post(osal_semaphore_t sem_hdl) +static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) { - return (xSemaphoreGive(sem_hdl) == pdTRUE) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_SEMAPHORE_FAILED; + if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) + { + return xSemaphoreGive(sem_hdl); + }else + { + return xSemaphoreGiveFromISR(sem_hdl, NULL); + } } static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) @@ -116,7 +153,7 @@ typedef xSemaphoreHandle osal_mutex_t; #define osal_mutex_create(x) xSemaphoreCreateMutex() -static inline tusb_error_t osal_mutex_release(osal_mutex_t mutex_hdl) +static inline bool osal_mutex_release(osal_mutex_t mutex_hdl) { return osal_semaphore_post(mutex_hdl); } @@ -132,39 +169,7 @@ static inline void osal_mutex_reset(osal_mutex_t mutex_hdl) xSemaphoreGive(mutex_hdl); } -//--------------------------------------------------------------------+ -// QUEUE API -//--------------------------------------------------------------------+ -typedef xQueueHandle osal_queue_t; - -static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size) -{ - return xQueueCreate(depth, 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 : osal_tick_from_msec(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; -} - -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); - } -} -static inline void osal_queue_flush(osal_queue_t const queue_hdl) -{ - xQueueReset(queue_hdl); -} #ifdef __cplusplus } diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index bf0a82d8d..469722ec7 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -151,6 +151,57 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u condition, TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false")
//--------------------------------------------------------------------+
+// QUEUE API
+//--------------------------------------------------------------------+
+typedef fifo_t* osal_queue_t;
+
+static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size)
+{
+ fifo_t* ff = (fifo_t* ) tu_malloc( sizeof(fifo_t) );
+ uint8_t* buf = (uint8_t*) tu_malloc( depth*item_size );
+
+ VERIFY( ff && buf, NULL);
+
+ *ff = (fifo_t) {
+ .buffer = buf, .depth = depth, .item_size = item_size,
+ .count = 0, .wr_idx =0, .rd_idx = 0, .overwritable = false
+ };
+
+ return (osal_queue_t) ff;
+}
+
+
+static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data)
+{
+ return fifo_write( (fifo_t*) queue_hdl, data);
+}
+
+static inline void osal_queue_flush(osal_queue_t const queue_hdl)
+{
+ queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
+}
+
+#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
+ do {\
+ timeout = osal_tick_get();\
+ state = __LINE__; case __LINE__:\
+ if( queue_hdl->count == 0 ) {\
+ if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( timeout + osal_tick_from_msec(msec) <= osal_tick_get() )) /* time out */ \
+ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
+ else\
+ return TUSB_ERROR_OSAL_WAITING;\
+ } else{\
+ /*TODO mutex lock hal_interrupt_disable */\
+ memcpy(p_data, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), queue_hdl->item_size);\
+ queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\
+ queue_hdl->count--;\
+ /*TODO mutex unlock hal_interrupt_enable */\
+ *(p_error) = TUSB_ERROR_NONE;\
+ }\
+ }while(0)
+
+
+//--------------------------------------------------------------------+
// Semaphore API
//--------------------------------------------------------------------+
typedef struct
@@ -173,11 +224,10 @@ static inline osal_semaphore_t osal_semaphore_create(uint32_t max_count, uint32_ return sem_data;
}
-static inline tusb_error_t osal_semaphore_post(osal_semaphore_t sem_hdl)
+static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl)
{
if (sem_hdl->count < sem_hdl->max_count ) sem_hdl->count++;
-
- return TUSB_ERROR_NONE;
+ return true;
}
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
@@ -210,7 +260,7 @@ static inline osal_mutex_t osal_mutex_create(void) return osal_semaphore_create(1, 0);
}
-static inline tusb_error_t osal_mutex_release(osal_mutex_t mutex_hdl)
+static inline bool osal_mutex_release(osal_mutex_t mutex_hdl)
{
return osal_semaphore_post(mutex_hdl);
}
@@ -223,55 +273,7 @@ static inline void osal_mutex_reset(osal_mutex_t mutex_hdl) #define osal_mutex_wait osal_semaphore_wait
-//--------------------------------------------------------------------+
-// QUEUE API
-//--------------------------------------------------------------------+
-typedef fifo_t* osal_queue_t;
-
-static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size)
-{
- fifo_t* ff = (fifo_t* ) tu_malloc( sizeof(fifo_t) );
- uint8_t* buf = (uint8_t*) tu_malloc( depth*item_size );
-
- VERIFY( ff && buf, NULL);
-
- *ff = (fifo_t) {
- .buffer = buf, .depth = depth, .item_size = item_size,
- .count = 0, .wr_idx =0, .rd_idx = 0, .overwritable = false
- };
-
- return (osal_queue_t) ff;
-}
-
-
-static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data)
-{
- return fifo_write( (fifo_t*) queue_hdl, data);
-}
-
-static inline void osal_queue_flush(osal_queue_t const queue_hdl)
-{
- queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
-}
-#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
- do {\
- timeout = osal_tick_get();\
- state = __LINE__; case __LINE__:\
- if( queue_hdl->count == 0 ) {\
- if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( timeout + osal_tick_from_msec(msec) <= osal_tick_get() )) /* time out */ \
- *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
- else\
- return TUSB_ERROR_OSAL_WAITING;\
- } else{\
- /*TODO mutex lock hal_interrupt_disable */\
- memcpy(p_data, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), queue_hdl->item_size);\
- queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\
- queue_hdl->count--;\
- /*TODO mutex unlock hal_interrupt_enable */\
- *(p_error) = TUSB_ERROR_NONE;\
- }\
- }while(0)
#ifdef __cplusplus
}
|
