hathach 8 лет назад
Родитель
Сommit
40935fc01c

+ 1 - 1
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:

+ 1 - 1
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:

+ 1 - 1
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);
     }
   }
 }

+ 1 - 1
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 =

+ 1 - 1
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);

+ 43 - 38
tinyusb/osal/osal_freeRTOS.h

@@ -79,23 +79,60 @@ static inline void osal_task_delay(uint32_t msec)
   vTaskDelay( (TUSB_CFG_TICKS_HZ * msec) / 1000 );
 }
 
+//--------------------------------------------------------------------+
+// 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
  }

+ 54 - 52
tinyusb/osal/osal_none.h

@@ -150,6 +150,57 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u
     ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, ,\
                                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
 //--------------------------------------------------------------------+
@@ -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
  }