enhance device msc response in case of STALL response

This commit is contained in:
hathach 2018-07-25 22:21:14 +07:00
parent 544f9c1315
commit be7b0caf2d
1 changed files with 27 additions and 18 deletions

View File

@ -348,7 +348,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
memmove(_mscd_buf, _mscd_buf+nbytes, xferred_bytes-nbytes);
}
// simulate an transfer complete with adjusted params
// simulate an transfer complete with adjusted parameters --> this driver callback will fired again
dcd_xfer_complete(rhport, p_msc->ep_out, xferred_bytes-nbytes, true);
return TUSB_ERROR_NONE; // skip the rest
@ -394,6 +394,14 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
}
if ( p_msc->stage == MSC_STAGE_STATUS )
{
// Either endpoints is stalled, need to wait until it is cleared by host
if ( dcd_edpt_stalled(rhport, p_msc->ep_in) || dcd_edpt_stalled(rhport, p_msc->ep_out) )
{
// simulate an transfer complete with adjusted parameters --> this driver callback will fired again
dcd_xfer_complete(rhport, p_msc->ep_out, 0, true);
}
else
{
// Invoke complete callback if defined
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
@ -417,6 +425,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
//------------- Queue the next CBW -------------//
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
}
}
return TUSB_ERROR_NONE;
}
@ -450,7 +459,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
}
else if ( nbytes == 0 )
{
// zero means not ready -> try again later by simulate an transfer complete
// zero means not ready -> simulate an transfer complete so that this driver callback will fired again
dcd_xfer_complete(rhport, p_msc->ep_in, 0, true);
}
else