summaryrefslogtreecommitdiff
path: root/src/device/usbd.c
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-12-05 17:45:38 +0700
committerGitHub <[email protected]>2018-12-05 17:45:38 +0700
commitb2ec8230d9acffbc0df280832b0341b82584b226 (patch)
tree25e4eae94d5731873fee9da2bfe216eec6d0cc2a /src/device/usbd.c
parentcf60b206528fc955bbdd1bfec2c7016a985313ea (diff)
parent27793cbd3dba550f9a7124d5e539325904b795e8 (diff)
Merge pull request #19 from hathach/devlocal
queue lock/unlock with isr
Diffstat (limited to 'src/device/usbd.c')
-rw-r--r--src/device/usbd.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index ddb63cebb..78eebf76b 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -161,8 +161,9 @@ enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_
//--------------------------------------------------------------------+
OSAL_TASK_DEF(_usbd_task_def, "usbd", usbd_task, CFG_TUD_TASK_PRIO, CFG_TUD_TASK_STACK_SZ);
-/*------------- event queue -------------*/
-OSAL_QUEUE_DEF(_usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
+// Event queue
+// role device/host is used by OS NONE for mutex (disable usb isr) only
+OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
static osal_queue_t _usbd_q;
//--------------------------------------------------------------------+
@@ -188,11 +189,11 @@ bool tud_mounted(void)
//--------------------------------------------------------------------+
// USBD Task
//--------------------------------------------------------------------+
-tusb_error_t usbd_init (void)
+bool usbd_init (void)
{
// Init device queue & task
_usbd_q = osal_queue_create(&_usbd_qdef);
- TU_VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
+ TU_ASSERT(_usbd_q != NULL);
osal_task_create(&_usbd_task_def);
@@ -200,17 +201,10 @@ tusb_error_t usbd_init (void)
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init();
// Init device controller driver
- #if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE)
- dcd_init(0);
- dcd_int_enable(0);
- #endif
-
- #if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE)
- dcd_init(1);
- dcd_int_enable(1);
- #endif
+ TU_ASSERT(dcd_init(TUD_OPT_RHPORT));
+ dcd_int_enable(TUD_OPT_RHPORT);
- return TUSB_ERROR_NONE;
+ return true;
}
static void usbd_reset(uint8_t rhport)
@@ -268,14 +262,14 @@ static void usbd_task_body(void)
break;
case DCD_EVENT_BUS_RESET:
- // note: if task is too slow, we could clear the event of the new attached
usbd_reset(event.rhport);
+ // TODO remove since if task is too slow, we could clear the event of the new attached
osal_queue_reset(_usbd_q);
break;
case DCD_EVENT_UNPLUGGED:
- // note: if task is too slow, we could clear the event of the new attached
usbd_reset(event.rhport);
+ // TODO remove since if task is too slow, we could clear the event of the new attached
osal_queue_reset(_usbd_q);
tud_umount_cb(); // invoke callback
@@ -587,6 +581,11 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr)
TU_ASSERT(event->xfer_complete.result == XFER_RESULT_SUCCESS,);
break;
+ // Not an DCD event, just a convenient way to defer ISR function should we need
+ case USBD_EVT_FUNC_CALL:
+ osal_queue_send(_usbd_q, event, in_isr);
+ break;
+
default: break;
}
}
@@ -622,6 +621,8 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_
//--------------------------------------------------------------------+
// Helper
//--------------------------------------------------------------------+
+
+// Helper to parse an pair of endpoint descriptors (IN & OUT)
tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
{
for(int i=0; i<2; i++)
@@ -645,7 +646,8 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d
return TUSB_ERROR_NONE;
}
-void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr )
+// Helper to defer an isr function
+void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr)
{
dcd_event_t event =
{
@@ -656,7 +658,7 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr )
event.func_call.func = func;
event.func_call.param = param;
- osal_queue_send(_usbd_q, &event, in_isr);
+ dcd_event_handler(&event, in_isr);
}
#endif