From f2ae5b541faba4b0ea28b010cbf9eda53ff59d70 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 1 Nov 2013 14:44:14 +0700 Subject: add dcd pipe clear stall - tusb_error_t dcd_pipe_clear_stall(uint8_t coreid, uint8_t edpt_addr) but does not take endpoint_handle_t as input complete msc device driver add usbd clear stall endpoint --- tinyusb/device/dcd.h | 1 + tinyusb/device/dcd_lpc43xx.c | 26 ++++++++++++++--------- tinyusb/device/usbd.c | 49 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 20 deletions(-) (limited to 'tinyusb/device') diff --git a/tinyusb/device/dcd.h b/tinyusb/device/dcd.h index fa947bf11..744c77bb7 100644 --- a/tinyusb/device/dcd.h +++ b/tinyusb/device/dcd.h @@ -93,6 +93,7 @@ endpoint_handle_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const tusb_error_t dcd_pipe_queue_xfer(endpoint_handle_t edpt_hdl, void * buffer, uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, void * buffer, uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; tusb_error_t dcd_pipe_stall(endpoint_handle_t edpt_hdl) ATTR_WARN_UNUSED_RESULT; +tusb_error_t dcd_pipe_clear_stall(uint8_t coreid, uint8_t edpt_addr); // TODO coreid + endpoint address are part of endpoint handle, not endpoint handle #ifdef __cplusplus } diff --git a/tinyusb/device/dcd_lpc43xx.c b/tinyusb/device/dcd_lpc43xx.c index fc594d4b5..f7a219ad8 100644 --- a/tinyusb/device/dcd_lpc43xx.c +++ b/tinyusb/device/dcd_lpc43xx.c @@ -356,6 +356,15 @@ tusb_error_t dcd_pipe_stall(endpoint_handle_t edpt_hdl) return TUSB_ERROR_NONE; } +tusb_error_t dcd_pipe_clear_stall(uint8_t coreid, uint8_t edpt_addr) +{ + volatile uint32_t * reg_control = (&LPC_USB0->ENDPTCTRL0) + edpt_phy2log( edpt_addr2phy(edpt_addr) ); + + (*reg_control) &= ~(ENDPTCTRL_MASK_STALL << ((edpt_addr & TUSB_DIR_DEV_TO_HOST_MASK) ? 16 : 0)); + + return TUSB_ERROR_NONE; +} + endpoint_handle_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, uint8_t class_code) { // TODO USB1 only has 4 non-control enpoint (USB0 has 5) @@ -446,13 +455,8 @@ tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, void* buffer, uint16_t t } //------------- Device Controller Driver's Interrupt Handler -------------// -void xfer_complete_isr(uint8_t coreid, uint8_t reg_complete) +void xfer_complete_isr(uint8_t coreid, uint32_t reg_complete) { - if (reg_complete & BIT_(3+16)) - { - hal_debugger_breakpoint(); - } - // TODO currently exclude control for(uint8_t ep_idx = 2; ep_idx < DCD_QHD_MAX; ep_idx++) { @@ -506,6 +510,7 @@ void dcd_isr(uint8_t coreid) if (int_status & INT_MASK_USB) { + //------------- Set up Received -------------// if (LPC_USB0->ENDPTSETUPSTAT) { // 23.10.10.2 Operational model for setup transfers tusb_control_request_t control_request = dcd_data.qhd[0].setup_request; @@ -527,11 +532,12 @@ void dcd_isr(uint8_t coreid) usbd_setup_received_isr(coreid, &control_request); } - if (LPC_USB0->ENDPTCOMPLETE) - { - uint32_t edpt_complete = LPC_USB0->ENDPTCOMPLETE; - LPC_USB0->ENDPTCOMPLETE = edpt_complete; // acknowledge + //------------- Transfer Complete -------------// + uint32_t edpt_complete = LPC_USB0->ENDPTCOMPLETE; + LPC_USB0->ENDPTCOMPLETE = edpt_complete; // acknowledge + if (edpt_complete) + { xfer_complete_isr(coreid, edpt_complete); } } diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index 88b85a8d9..13ea27054 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -96,6 +96,20 @@ void usbd_bus_reset(uint32_t coreid) memclr_(&usbd_devices[coreid], sizeof(usbd_device_info_t)); } +tusb_error_t usbd_init (void) +{ + ASSERT_STATUS ( usbd_string_descriptor_init() ); + + ASSERT_STATUS ( dcd_init() ); + + dcd_controller_connect(0); // TODO USB1 + + return TUSB_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// CONTROL REQUEST +//--------------------------------------------------------------------+ tusb_error_t usbh_set_configure_received(uint8_t coreid, uint8_t config_number) { dcd_controller_set_configuration(coreid, config_number); @@ -174,6 +188,12 @@ void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request) { //------------- Standard Control such as those in enumeration -------------// case TUSB_REQUEST_RECIPIENT_DEVICE: + if (p_request->bmRequestType_bit.type != TUSB_REQUEST_TYPE_STANDARD) + { + error = TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; + break; + } + switch ( p_request->bRequest ) { case TUSB_REQUEST_GET_DESCRIPTOR: @@ -210,6 +230,25 @@ void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request) } break; + //------------- Endpoint Request -------------// + case TUSB_REQUEST_RECIPIENT_ENDPOINT: + if (p_request->bmRequestType_bit.type != TUSB_REQUEST_TYPE_STANDARD) + { + error = TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; + break; + } + + switch ( p_request->bRequest ) + { + case TUSB_REQUEST_CLEAR_FEATURE: + dcd_pipe_clear_stall(coreid, u16_low_u8(p_request->wIndex) ); + dcd_pipe_control_xfer(coreid, TUSB_DIR_HOST_TO_DEV, NULL, 0); // zero length + break; + + default: error = TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; break; + } + break; + default: error = TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; break; } @@ -220,16 +259,6 @@ void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request) } } -tusb_error_t usbd_init (void) -{ - ASSERT_STATUS ( usbd_string_descriptor_init() ); - - ASSERT_STATUS ( dcd_init() ); - - dcd_controller_connect(0); // TODO USB1 - - return TUSB_ERROR_NONE; -} //--------------------------------------------------------------------+ // USBD-CLASS API -- cgit v1.3.1