diff options
| author | hathach <[email protected]> | 2018-05-17 19:19:55 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-05-17 19:19:55 +0700 |
| commit | 61cc8666fc2bf277deb156c07b405849aeeb677c (patch) | |
| tree | e00f19f6aaac34a6a8be4da71b1c8521bbc40c98 /tinyusb | |
| parent | d6794074e1c6e8a3640d69ff719a230160b05992 (diff) | |
complete osal queue, semaphore static API
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/device/usbd.c | 76 | ||||
| -rw-r--r-- | tinyusb/osal/osal_freeRTOS.h | 10 |
2 files changed, 46 insertions, 40 deletions
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index fb968b3c0..7fa73edbc 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -46,6 +46,16 @@ #include "usbd.h"
#include "device/usbd_pvt.h"
+#define USBD_TASK_QUEUE_DEPTH 16
+
+#ifndef CFG_TUD_TASK_STACKSIZE
+#define CFG_TUD_TASK_STACKSIZE 150
+#endif
+
+#ifndef CFG_TUD_TASK_PRIO
+#define CFG_TUD_TASK_PRIO 0
+#endif
+
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
@@ -73,7 +83,7 @@ typedef struct { }usbd_device_info_t;
//--------------------------------------------------------------------+
-// INTERNAL VARIABLE
+// Class & Device Driver
//--------------------------------------------------------------------+
CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t usbd_enum_buffer[CFG_TUD_ENUM_BUFFER_SIZE];
@@ -129,34 +139,10 @@ enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_ // .bDeviceClass =
//};
-//--------------------------------------------------------------------+
-// INTERNAL FUNCTION
-//--------------------------------------------------------------------+
-static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number);
-static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer);
-
-//--------------------------------------------------------------------+
-// APPLICATION API
-//--------------------------------------------------------------------+
-bool tud_n_mounted(uint8_t rhport)
-{
- return usbd_devices[rhport].state == TUSB_DEVICE_STATE_CONFIGURED;
-}
-
-bool tud_n_set_descriptors(uint8_t rhport, tud_desc_init_t const* desc_cfg)
-{
- _usbd_descs[rhport] = *desc_cfg;
- return true;
-}
-
//--------------------------------------------------------------------+
-// IMPLEMENTATION
+// DCD Event
//--------------------------------------------------------------------+
-
-//------------- OSAL Task -------------//
-enum { USBD_TASK_QUEUE_DEPTH = 16 };
-
typedef enum
{
USBD_EVENTID_SETUP_RECEIVED = 1,
@@ -183,17 +169,33 @@ typedef struct ATTR_ALIGNED(4) VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct");
-#ifndef CFG_TUD_TASK_STACKSIZE
-#define CFG_TUD_TASK_STACKSIZE 150
-#endif
+/*------------- event queue -------------*/
+OSAL_QUEUE_DEF(_usbd_qdef, USBD_TASK_QUEUE_DEPTH, usbd_task_event_t);
+static osal_queue_t _usbd_q;
-#ifndef CFG_TUD_TASK_PRIO
-#define CFG_TUD_TASK_PRIO 0
-#endif
+/*------------- control transfer semaphore -------------*/
+static osal_semaphore_def_t _usbd_sem_def;
+/*static*/ osal_semaphore_t _usbd_ctrl_sem;
+//--------------------------------------------------------------------+
+// INTERNAL FUNCTION
+//--------------------------------------------------------------------+
+static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number);
+static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer);
-static osal_queue_t _usbd_q;
-/*static*/ osal_semaphore_t _usbd_ctrl_sem;
+//--------------------------------------------------------------------+
+// APPLICATION API
+//--------------------------------------------------------------------+
+bool tud_n_mounted(uint8_t rhport)
+{
+ return usbd_devices[rhport].state == TUSB_DEVICE_STATE_CONFIGURED;
+}
+
+bool tud_n_set_descriptors(uint8_t rhport, tud_desc_init_t const* desc_cfg)
+{
+ _usbd_descs[rhport] = *desc_cfg;
+ return true;
+}
//--------------------------------------------------------------------+
// IMPLEMENTATION
@@ -212,10 +214,10 @@ tusb_error_t usbd_init (void) #endif
//------------- Task init -------------//
- _usbd_q = osal_queue_create(USBD_TASK_QUEUE_DEPTH, sizeof(usbd_task_event_t));
+ _usbd_q = osal_queue_create(&_usbd_qdef);
VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
- _usbd_ctrl_sem = osal_semaphore_create(1, 0);
+ _usbd_ctrl_sem = osal_semaphore_create(&_usbd_sem_def);
VERIFY(_usbd_q, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
osal_task_create(usbd_task, "usbd", CFG_TUD_TASK_STACKSIZE, NULL, CFG_TUD_TASK_PRIO);
@@ -509,7 +511,7 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event) case USBD_BUS_EVENT_RESET :
memclr_(&usbd_devices[rhport], sizeof(usbd_device_info_t));
osal_queue_flush(_usbd_q);
- osal_semaphore_reset(_usbd_ctrl_sem);
+ osal_semaphore_reset_isr(_usbd_ctrl_sem);
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
{
if ( usbd_class_drivers[i].close ) usbd_class_drivers[i].close( rhport );
diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index 0348617ae..ce9e95927 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -83,11 +83,15 @@ static inline void osal_task_delay(uint32_t msec) //--------------------------------------------------------------------+ // QUEUE API //--------------------------------------------------------------------+ +#define OSAL_QUEUE_DEF(_name, _depth, _type) \ + uint8_t _name##_##buf[_depth*sizeof(_type)];\ + osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };\ + typedef struct { - uint16_t queue_sz; + uint16_t depth; uint16_t item_sz; - void* pool; + void* buf; StaticQueue_t sq; }osal_queue_def_t; @@ -96,7 +100,7 @@ typedef QueueHandle_t osal_queue_t; static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) { - return xQueueCreateStatic(qdef->queue_sz, qdef->item_sz, qdef->pool, &qdef->sq); + return xQueueCreateStatic(qdef->depth, qdef->item_sz, qdef->buf, &qdef->sq); } static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) |
