summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-11-01 14:44:14 +0700
committerhathach <[email protected]>2013-11-01 14:44:14 +0700
commitf2ae5b541faba4b0ea28b010cbf9eda53ff59d70 (patch)
tree6063126507c43a7b8e5bc7deaffbe2408c1a36a1 /tinyusb
parentf797c4e02a1a2451e6ba9beca5a1be74fd0bf1ab (diff)
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
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/msc_device.c15
-rw-r--r--tinyusb/device/dcd.h1
-rw-r--r--tinyusb/device/dcd_lpc43xx.c26
-rw-r--r--tinyusb/device/usbd.c49
4 files changed, 62 insertions, 29 deletions
diff --git a/tinyusb/class/msc_device.c b/tinyusb/class/msc_device.c
index 7b2011ccf..f02a1584c 100644
--- a/tinyusb/class/msc_device.c
+++ b/tinyusb/class/msc_device.c
@@ -149,24 +149,21 @@ void mscd_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_b
p_msc->csw.data_residue = 0; // TODO expected length, response length
//------------- Data Phase -------------//
- if ( (p_msc->cbw.dir & BIT_(7)) && p_buffer == NULL )
+ if ( BIT_TEST_(p_msc->cbw.dir, 7) && p_buffer == NULL )
{ // application does not provide data to response --> possibly unsupported SCSI command
ASSERT( TUSB_ERROR_NONE == dcd_pipe_stall(p_msc->edpt_in), VOID_RETURN );
- }
-
- if ( p_msc->cbw.dir & BIT_(7) )
- {
- ASSERT( dcd_pipe_queue_xfer(p_msc->edpt_in, p_buffer, p_msc->cbw.xfer_bytes) == TUSB_ERROR_NONE, VOID_RETURN);
- } else
+ p_msc->csw.status = MSC_CSW_STATUS_FAILED;
+ }else
{
- ASSERT( dcd_pipe_queue_xfer(p_msc->edpt_out, p_buffer, p_msc->cbw.xfer_bytes) == TUSB_ERROR_NONE, VOID_RETURN);
+ ASSERT( dcd_pipe_queue_xfer( BIT_TEST_(p_msc->cbw.dir, 7) ? p_msc->edpt_in : p_msc->edpt_out,
+ p_buffer, p_msc->cbw.xfer_bytes) == TUSB_ERROR_NONE, VOID_RETURN);
}
//------------- Status Phase -------------//
ASSERT( dcd_pipe_xfer( p_msc->edpt_in , &p_msc->csw, sizeof(msc_cmd_status_wrapper_t), true) == TUSB_ERROR_NONE, VOID_RETURN );
//------------- Queue the next CBW -------------//
-// ASSERT( dcd_pipe_xfer( p_msc->edpt_out, &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true) == TUSB_ERROR_NONE, VOID_RETURN );
+ ASSERT( dcd_pipe_xfer( p_msc->edpt_out, &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true) == TUSB_ERROR_NONE, VOID_RETURN );
}
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