From 43cf0fb3dfeb87fadeed3b1c0f4ca9ae49df0422 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 11 Mar 2018 13:59:37 +0700 Subject: refactor dcd_xfer_complete --- tinyusb/device/dcd_lpc175x_6x.c | 6 +++--- tinyusb/device/dcd_lpc_11uxx_13uxx.c | 4 ++-- tinyusb/device/usbd.c | 6 +++--- tinyusb/tusb_dcd.h | 7 +++++-- 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'tinyusb') diff --git a/tinyusb/device/dcd_lpc175x_6x.c b/tinyusb/device/dcd_lpc175x_6x.c index 4328fbf1c..274fc462c 100644 --- a/tinyusb/device/dcd_lpc175x_6x.c +++ b/tinyusb/device/dcd_lpc175x_6x.c @@ -165,9 +165,9 @@ static void endpoint_non_control_isr(uint32_t eot_int) .index = ep_id, .class_code = dcd_data.class_code[ep_id] }; - tusb_event_t event = (p_last_dd->status == DD_STATUS_NORMAL || p_last_dd->status == DD_STATUS_DATA_UNDERUN) ? TUSB_EVENT_XFER_COMPLETE : TUSB_EVENT_XFER_ERROR; + bool succeeded = (p_last_dd->status == DD_STATUS_NORMAL || p_last_dd->status == DD_STATUS_DATA_UNDERUN) ? true : false; - usbd_xfer_isr(edpt_hdl, event, p_last_dd->present_count); // report only xferred bytes in the IOC qtd + tusb_dcd_xfer_complete(edpt_hdl, p_last_dd->present_count, succeeded); // report only xferred bytes in the IOC qtd } } } @@ -208,7 +208,7 @@ static void endpoint_control_isr(void) dcd_data.control_dma.int_on_complete = 0; // FIXME xferred_byte for control xfer is not needed now !!! - usbd_xfer_isr(edpt_hdl, TUSB_EVENT_XFER_COMPLETE, 0); + tusb_dcd_xfer_complete(edpt_hdl, 0, true); } } } diff --git a/tinyusb/device/dcd_lpc_11uxx_13uxx.c b/tinyusb/device/dcd_lpc_11uxx_13uxx.c index 8a5691dc4..559da4a0f 100644 --- a/tinyusb/device/dcd_lpc_11uxx_13uxx.c +++ b/tinyusb/device/dcd_lpc_11uxx_13uxx.c @@ -256,7 +256,7 @@ static void endpoint_non_control_isr(uint32_t int_status) dcd_data.current_ioc = BIT_CLR_(dcd_data.current_ioc, edpt_hdl.index); // TODO no way determine if the transfer is failed or not - usbd_xfer_isr(edpt_hdl, TUSB_EVENT_XFER_COMPLETE, dcd_data.current_td[ep_id].xferred_total); + tusb_dcd_xfer_complete(edpt_hdl, dcd_data.current_td[ep_id].xferred_total, true); } //------------- Next TD is available -------------// @@ -291,7 +291,7 @@ static void endpoint_control_isr(uint32_t int_status) dcd_data.current_ioc = BIT_CLR_(dcd_data.current_ioc, ep_id); // FIXME xferred_byte for control xfer is not needed now !!! - usbd_xfer_isr(edpt_hdl, TUSB_EVENT_XFER_COMPLETE, 0); + tusb_dcd_xfer_complete(edpt_hdl, 0, true); } } } diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index f090bc141..55bce5626 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -498,7 +498,7 @@ void tusb_dcd_setup_received(uint8_t port, uint8_t const* p_request) osal_queue_send(usbd_queue_hdl, &task_event); } -void usbd_xfer_isr(edpt_hdl_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes) +void tusb_dcd_xfer_complete(edpt_hdl_t edpt_hdl, uint32_t xferred_bytes, bool succeeded) { if (edpt_hdl.index == 0 ) { @@ -508,9 +508,9 @@ void usbd_xfer_isr(edpt_hdl_t edpt_hdl, tusb_event_t event, uint32_t xferred_byt { usbd_task_event_t task_event = { - .port = edpt_hdl.port, + .port = edpt_hdl.port, .event_id = USBD_EVENTID_XFER_DONE, - .sub_event_id = event + .sub_event_id = succeeded ? TUSB_EVENT_XFER_COMPLETE : TUSB_EVENT_XFER_ERROR }; task_event.xfer_done.xferred_byte = xferred_bytes; diff --git a/tinyusb/tusb_dcd.h b/tinyusb/tusb_dcd.h index 2b7734f13..9e066646d 100644 --- a/tinyusb/tusb_dcd.h +++ b/tinyusb/tusb_dcd.h @@ -75,10 +75,13 @@ void tusb_dcd_disconnect (uint8_t port); void tusb_dcd_set_address (uint8_t port, uint8_t dev_addr); void tusb_dcd_set_config (uint8_t port, uint8_t config_num); -/*------------- Event function -------------*/ +/*------------------------------------------------------------------*/ +/* Event Function + * Called by DCD to notify USBD + *------------------------------------------------------------------*/ void tusb_dcd_bus_event(uint8_t port, usbd_bus_event_type_t bus_event); void tusb_dcd_setup_received(uint8_t port, uint8_t const* p_request); -void usbd_xfer_isr(edpt_hdl_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes); +void tusb_dcd_xfer_complete(edpt_hdl_t edpt_hdl, uint32_t xferred_bytes, bool succeeded); //------------- PIPE API -------------// bool tusb_dcd_control_xfer(uint8_t port, tusb_direction_t dir, uint8_t * p_buffer, uint16_t length, bool int_on_complete); -- cgit v1.3.1