diff --git a/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c b/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c index f0952927..2ec14a4a 100644 --- a/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c +++ b/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c @@ -406,8 +406,8 @@ void xfer_complete_isr(uint8_t port, uint32_t reg_complete) if (p_qtd->int_on_complete) { - tusb_event_t event = ( p_qtd->xact_err || p_qtd->halted || p_qtd->buffer_err ) ? TUSB_EVENT_XFER_ERROR : TUSB_EVENT_XFER_COMPLETE; - usbd_xfer_isr(edpt_hdl, event, p_qtd->expected_bytes - p_qtd->total_bytes); // only number of bytes in the IOC qtd + bool succeeded = ( p_qtd->xact_err || p_qtd->halted || p_qtd->buffer_err ) ? false : true; + tusb_dcd_xfer_complete(edpt_hdl, p_qtd->expected_bytes - p_qtd->total_bytes, succeeded); // only number of bytes in the IOC qtd } } } @@ -481,9 +481,9 @@ void hal_dcd_isr(uint8_t port) .port = port, .index = 0, }; - tusb_event_t event = ( p_qtd->xact_err || p_qtd->halted || p_qtd->buffer_err ) ? TUSB_EVENT_XFER_ERROR : TUSB_EVENT_XFER_COMPLETE; + bool succeeded = ( p_qtd->xact_err || p_qtd->halted || p_qtd->buffer_err ) ? false : true; - usbd_xfer_isr(edpt_hdl, event, 0); // TODO xferred bytes for control xfer is not needed yet !!!! + tusb_dcd_xfer_complete(edpt_hdl, 0, succeeded); // TODO xferred bytes for control xfer is not needed yet !!!! } } } diff --git a/tinyusb/device/dcd_lpc175x_6x.c b/tinyusb/device/dcd_lpc175x_6x.c index 4328fbf1..274fc462 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 8a5691dc..559da4a0 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 f090bc14..55bce562 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 2b7734f1..9e066646 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);