Przeglądaj źródła

change osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data) signature to osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data)
- support any size queue message (instead of fixed uint32_t)

hathach 13 lat temu
rodzic
commit
e14aa4197d

+ 26 - 0
demos/host/keyboard_app.c

@@ -63,6 +63,32 @@ static inline uint8_t keycode_to_ascii(uint8_t keycode)
 }
 
 
+//--------------------------------------------------------------------+
+// tinyusb callback (ISR context)
+//--------------------------------------------------------------------+
+//void tusbh_hid_keyboard_isr(uint8_t dev_addr, uint8_t instance_num, tusb_event_t event)
+//{
+//  switch(event)
+//  {
+//    case TUSB_EVENT_INTERFACE_OPEN:
+//      tusbh_hid_keyboard_get_report(dev_addr, 0, (uint8_t*) &keyboard_report); // first report
+//    break;
+//
+//    case TUSB_EVENT_INTERFACE_CLOSE:
+//
+//    break;
+//
+//    case TUSB_EVENT_XFER_COMPLETE:
+//      tusbh_hid_keyboard_get_report(dev_addr, 0, (uint8_t*) &keyboard_report);
+//    break;
+//
+//    case TUSB_EVENT_XFER_ERROR:
+//    break;
+//
+//    default:
+//  }
+//}
+
 void keyboard_app_task(void)
 {
   for (uint8_t dev_addr = 1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)

+ 2 - 1
tests/test/test_osal_freeRTOS.c

@@ -76,7 +76,8 @@ void test_(void)
   osal_semaphore_post(sem_hdl);
   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error);
 
-  osal_queue_send(queue_hdl, 0x1234);
+  uint32_t item = 0x1234;
+  osal_queue_send(queue_hdl, &item);
   osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_NORMAL, &error);
 
 }

+ 10 - 6
tests/test/test_osal_none.c

@@ -50,7 +50,7 @@ uint32_t statements[10];
 OSAL_SEM_DEF(sem);
 osal_semaphore_handle_t sem_hdl;
 
-OSAL_QUEUE_DEF(queue, QUEUE_DEPTH, uin32_t);
+OSAL_QUEUE_DEF(queue, QUEUE_DEPTH, uint32_t);
 osal_queue_handle_t queue_hdl;
 
 void setUp(void)
@@ -97,9 +97,9 @@ void test_queue_create(void)
 void test_queue_send(void)
 {
   uint32_t const item = 0x1234;
-  osal_queue_send(queue_hdl, item);
+  osal_queue_send(queue_hdl, &item);
   TEST_ASSERT_EQUAL(1, queue_hdl->count);
-  TEST_ASSERT_EQUAL(item, queue_hdl->buffer[queue_hdl->rd_idx]);
+  TEST_ASSERT_EQUAL_MEMORY(&item, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), 4);
 }
 // blocking service such as semaphore wait need to be invoked within a task's loop
 
@@ -196,6 +196,7 @@ tusb_error_t sample_task_with_queue(void)
 void test_task_with_queue(void)
 {
   uint32_t i = 0;
+  uint32_t item;
 
   sample_task_with_queue();
   // several invoke before queue is available
@@ -204,14 +205,17 @@ void test_task_with_queue(void)
   TEST_ASSERT_EQUAL(1, statements[0]);
 
   // invoke after posting semaphore
-  osal_queue_send(queue_hdl, 0x1111);
+  item = 0x1111;
+  osal_queue_send(queue_hdl, &item);
   sample_task_with_queue();
   TEST_ASSERT_EQUAL(1, statements[1]);
   sample_task_with_queue();
   TEST_ASSERT_EQUAL(1, statements[1]);
 
-  osal_queue_send(queue_hdl, 0x2222);
-  osal_queue_send(queue_hdl, 0x3333);
+  item = 0x2222;
+  osal_queue_send(queue_hdl, &item);
+  item = 0x3333;
+  osal_queue_send(queue_hdl, &item);
   sample_task_with_queue();
   TEST_ASSERT_EQUAL(1, statements[2]);
   TEST_ASSERT_EQUAL(1, statements[3]);

+ 1 - 1
tinyusb/hal/hal_lpc43xx.c

@@ -78,7 +78,7 @@ tusb_error_t hal_init(void)
 #if TUSB_CFG_CONTROLLER1_MODE
   /* connect CLK_USB1 to 60 MHz clock */
   CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_USB1); /* FIXME Run base BASE_USB1_CLK clock from PLL1 (assume PLL1 is 60 MHz, no division required) */
-  LPC_CREG->CREG0 &= ~(1<<5); /* Turn on the phy */
+  //LPC_CREG->CREG0 &= ~(1<<5); /* Turn on the phy */
   LPC_SCU->SFSUSB = (TUSB_CFG_CONTROLLER1_MODE & TUSB_MODE_HOST) ? 0x16 : 0x12; // enable USB1 with on-chip FS PHY
 
   #if TUSB_CFG_CONTROLLER1_MODE & TUSB_MODE_HOST

+ 3 - 4
tinyusb/host/usbh.c

@@ -90,7 +90,7 @@ usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1] TUSB_CFG_ATTR_USBRAM
 
 //------------- Enumeration Task Data -------------//
 OSAL_TASK_DEF(enum_task, usbh_enumeration_task, 128, OSAL_PRIO_HIGH);
-OSAL_QUEUE_DEF(enum_queue, ENUM_QUEUE_DEPTH, uin32_t);
+OSAL_QUEUE_DEF(enum_queue, ENUM_QUEUE_DEPTH, uint32_t);
 osal_queue_handle_t enum_queue_hdl;
 STATIC_ uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE] TUSB_CFG_ATTR_USBRAM;
 
@@ -205,8 +205,7 @@ void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event)
 void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed)
 {
   osal_queue_send(enum_queue_hdl,
-   *( (uint32_t*) ( &(usbh_enumerate_t){ .core_id = hostid, .speed = speed} ) )
-   );
+                  &(usbh_enumerate_t){ .core_id = hostid, .speed = speed} );
 }
 
 void usbh_device_unplugged_isr(uint8_t hostid)
@@ -262,7 +261,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
 
   OSAL_TASK_LOOP_BEGIN
 
-  osal_queue_receive(enum_queue_hdl, (uint32_t*)(&enum_entry), OSAL_TIMEOUT_WAIT_FOREVER, &error);
+  osal_queue_receive(enum_queue_hdl, &enum_entry, OSAL_TIMEOUT_WAIT_FOREVER, &error);
 
   TASK_ASSERT( hcd_port_connect_status(enum_entry.core_id) ); // device may be unplugged
   usbh_devices[0].core_id  = enum_entry.core_id; // TODO refractor integrate to device_pool

+ 1 - 1
tinyusb/osal/osal.h

@@ -173,7 +173,7 @@ typedef osal_queue_t * osal_queue_handle_t;
 
 osal_queue_handle_t  osal_queue_create  (osal_queue_t *p_queue);
 void                 osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error);
-tusb_error_t         osal_queue_send    (osal_queue_handle_t const queue_hdl, uint32_t data);
+tusb_error_t         osal_queue_send    (osal_queue_handle_t const queue_hdl, const void * data);
 void osal_queue_flush(osal_queue_handle_t const queue_hdl);
 
 //--------------------------------------------------------------------+

+ 3 - 3
tinyusb/osal/osal_freeRTOS.h

@@ -126,11 +126,11 @@ static inline void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint
   (*p_error) = ( xQueueReceive(queue_hdl, p_data, osal_tick_from_msec(msec)) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
 }
 
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data) ATTR_ALWAYS_INLINE;
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data)
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data) ATTR_ALWAYS_INLINE;
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data)
 {
   portBASE_TYPE taskWaken;
-  return ( xQueueSendFromISR(queue_hdl, &data, &taskWaken) == pdTRUE ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_QUEUE_FAILED;
+  return ( xQueueSendFromISR(queue_hdl, data, &taskWaken) == pdTRUE ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_QUEUE_FAILED;
 }
 
 #ifdef __cplusplus

+ 16 - 11
tinyusb/osal/osal_none.h

@@ -203,11 +203,12 @@ static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl)
 // QUEUE API
 //--------------------------------------------------------------------+
 typedef struct{
-           uint32_t * const buffer     ; ///< buffer pointer
-           uint8_t const depth        ; ///< buffer size
-  volatile uint8_t count          ; ///< bytes in fifo
-  volatile uint8_t wr_idx       ; ///< write pointer
-  volatile uint8_t rd_idx       ; ///< read pointer
+           void *  const buffer    ; ///< buffer pointer
+           uint8_t const depth     ; ///< max items
+           uint8_t const item_size ; ///< size of each item
+  volatile uint8_t count           ; ///< number of items in queue
+  volatile uint8_t wr_idx          ; ///< write pointer
+  volatile uint8_t rd_idx          ; ///< read pointer
 } osal_queue_t;
 
 typedef osal_queue_t * osal_queue_handle_t;
@@ -216,8 +217,9 @@ typedef osal_queue_t * osal_queue_handle_t;
 #define OSAL_QUEUE_DEF(name, queue_depth, type)\
   uint32_t name##_buffer[queue_depth];\
   osal_queue_t name = {\
-      .buffer = name##_buffer,\
-      .depth   = queue_depth\
+      .buffer    = name##_buffer,\
+      .depth     = queue_depth,\
+      .item_size = sizeof(type)\
   }
 
 static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue) ATTR_ALWAYS_INLINE;
@@ -228,12 +230,15 @@ static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue
 }
 
 // when queue is full, it will overwrite the oldest data in the queue
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data) ATTR_ALWAYS_INLINE;
-static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data)
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data) ATTR_ALWAYS_INLINE;
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, const void * data)
 {
   //TODO mutex lock hal_interrupt_disable
 
-  queue_hdl->buffer[queue_hdl->wr_idx] = data;
+  memcpy( queue_hdl->buffer + (queue_hdl->wr_idx * queue_hdl->item_size),
+          data,
+          queue_hdl->item_size);
+
   queue_hdl->wr_idx = (queue_hdl->wr_idx + 1) % queue_hdl->depth;
 
   if (queue_hdl->depth == queue_hdl->count) // queue is full, 1st rd is overwritten
@@ -266,7 +271,7 @@ static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl)
         return TUSB_ERROR_OSAL_WAITING;\
     } else{\
       /*TODO mutex lock hal_interrupt_disable */\
-      *p_data = queue_hdl->buffer[queue_hdl->rd_idx];\
+      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 */\