summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-03-01 11:42:13 +0700
committerhathach <[email protected]>2018-03-01 11:42:13 +0700
commit40935fc01ca33b6123c1626f930faf9b48e0b2b0 (patch)
treebe38b953e522cca805a51f6962d4916b49f51d80
parent329fdc026c4536b218438577c90491bc0b69fff8 (diff)
more osal clean up
-rw-r--r--demos/device/src/cdc_device_app.c2
-rw-r--r--demos/host/src/cdc_serial_host_app.c2
-rw-r--r--tinyusb/class/msc_host.c2
-rw-r--r--tinyusb/device/usbd.c2
-rw-r--r--tinyusb/host/usbh.c2
-rw-r--r--tinyusb/osal/osal_freeRTOS.h81
-rw-r--r--tinyusb/osal/osal_none.h106
7 files changed, 102 insertions, 95 deletions
diff --git a/demos/device/src/cdc_device_app.c b/demos/device/src/cdc_device_app.c
index f07f703ad..427b9a159 100644
--- a/demos/device/src/cdc_device_app.c
+++ b/demos/device/src/cdc_device_app.c
@@ -88,7 +88,7 @@ void tusbd_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id,
{
fifo_write(&fifo_serial, serial_rx_buffer+i);
}
- (void) osal_semaphore_post(sem_hdl); // notify main task
+ osal_semaphore_post(sem_hdl); // notify main task
break;
case TUSB_EVENT_XFER_ERROR:
diff --git a/demos/host/src/cdc_serial_host_app.c b/demos/host/src/cdc_serial_host_app.c
index dd7d1373c..4c31eb442 100644
--- a/demos/host/src/cdc_serial_host_app.c
+++ b/demos/host/src/cdc_serial_host_app.c
@@ -86,7 +86,7 @@ void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id
{
case TUSB_EVENT_XFER_COMPLETE:
received_bytes = xferred_bytes;
- (void) osal_semaphore_post(sem_hdl); // notify main task
+ osal_semaphore_post(sem_hdl); // notify main task
break;
case TUSB_EVENT_XFER_ERROR:
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
}