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
This commit is contained in:
hathach
2013-11-01 14:44:14 +07:00
parent f797c4e02a
commit f2ae5b541f
6 changed files with 125 additions and 87 deletions

View File

@@ -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) )
p_msc->csw.status = MSC_CSW_STATUS_FAILED;
}else
{
ASSERT( dcd_pipe_queue_xfer(p_msc->edpt_in, p_buffer, p_msc->cbw.xfer_bytes) == TUSB_ERROR_NONE, VOID_RETURN);
} 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 );
}

View File

@@ -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
}

View File

@@ -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);
}
}

View File

@@ -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