From 73ac4b4c8069744f09a20bec1e892d1eed8fd4c3 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 9 Mar 2014 15:30:57 +0700 Subject: rename tusbd_msc_scsi_received_isr to tusbd_msc_scsi_cb fix the status phase true --> false ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_in , p_csw, sizeof(msc_cmd_status_wrapper_t), false) ); board ea4357 added P9_5 pull down for device connect --- tinyusb/class/msc_device.c | 101 +++++++++++++++++++++++---------------------- tinyusb/class/msc_device.h | 2 +- 2 files changed, 52 insertions(+), 51 deletions(-) (limited to 'tinyusb') diff --git a/tinyusb/class/msc_device.c b/tinyusb/class/msc_device.c index ae1e61618..6a9251d19 100644 --- a/tinyusb/class/msc_device.c +++ b/tinyusb/class/msc_device.c @@ -66,6 +66,7 @@ STATIC_VAR mscd_interface_t mscd_data TUSB_CFG_ATTR_USBRAM; //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ +static bool read10_write10_data_xfer(mscd_interface_t* p_msc); //--------------------------------------------------------------------+ // USBD-CLASS API @@ -136,52 +137,6 @@ tusb_error_t mscd_control_request_subtask(uint8_t coreid, tusb_control_request_t return TUSB_ERROR_NONE; } -// return true if data phase is complete, false if not yet complete -static bool read10_write10_data_xfer(mscd_interface_t* p_msc) -{ - msc_cmd_block_wrapper_t * const p_cbw = &p_msc->cbw; - msc_cmd_status_wrapper_t * const p_csw = &p_msc->csw; - - scsi_read10_t* p_readwrite = (scsi_read10_t*) &p_cbw->command; // read10 & write10 has the same format - - endpoint_handle_t const edpt_hdl = BIT_TEST_(p_cbw->dir, 7) ? p_msc->edpt_in : p_msc->edpt_out; - - uint32_t const lba = __be2n(p_readwrite->lba); - uint16_t const block_count = __be2n_16(p_readwrite->block_count); - void *p_buffer = NULL; - - uint16_t xferred_block = (SCSI_CMD_READ_10 == p_cbw->command[0]) ? tusbd_msc_read10_cb (edpt_hdl.coreid, p_cbw->lun, &p_buffer, lba, block_count) : - tusbd_msc_write10_cb(edpt_hdl.coreid, p_cbw->lun, &p_buffer, lba, block_count); - xferred_block = min16_of(xferred_block, block_count); - - uint16_t const xferred_byte = xferred_block * (p_cbw->xfer_bytes / block_count); - - if ( 0 == xferred_block ) - { // xferred_block is zero will cause pipe is stalled & status in CSW set to failed - p_csw->data_residue = p_cbw->xfer_bytes; - p_csw->status = MSC_CSW_STATUS_FAILED; - - (void) dcd_pipe_stall(edpt_hdl); - - return true; - } else if (xferred_block < block_count) - { - ASSERT_STATUS( dcd_pipe_xfer( edpt_hdl, p_buffer, xferred_byte, true) ); - - // adjust lba, block_count, xfer_bytes for the next call - p_readwrite->lba = __n2be(lba+xferred_block); - p_readwrite->block_count = __n2be_16(block_count - xferred_block); - p_cbw->xfer_bytes -= xferred_byte; - - return false; - }else - { - p_csw->status = MSC_CSW_STATUS_PASSED; - ASSERT_STATUS( dcd_pipe_queue_xfer( edpt_hdl, p_buffer, xferred_byte) ); - return true; - } -} - //--------------------------------------------------------------------+ // MSCD APPLICATION CALLBACK //--------------------------------------------------------------------+ @@ -195,7 +150,7 @@ tusb_error_t mscd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32 msc_cmd_status_wrapper_t * const p_csw = &p_msc->csw; //------------- new CBW received -------------// - if ( !is_waiting_read10_write10) + if ( !is_waiting_read10_write10 ) { if ( endpointhandle_is_equal(p_msc->edpt_in, edpt_hdl) ) return TUSB_ERROR_NONE; // bulk in interrupt for dcd to clean up @@ -213,9 +168,9 @@ tusb_error_t mscd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32 void *p_buffer = NULL; uint16_t actual_length = (uint16_t) p_cbw->xfer_bytes; - p_csw->status = tusbd_msc_scsi_received_isr(edpt_hdl.coreid, p_cbw->lun, p_cbw->command, &p_buffer, &actual_length); + p_csw->status = tusbd_msc_scsi_cb(edpt_hdl.coreid, p_cbw->lun, p_cbw->command, &p_buffer, &actual_length); - //------------- Data Phase -------------// + //------------- Data Phase (non READ10, WRITE10) -------------// if ( p_cbw->xfer_bytes ) { ASSERT( p_cbw->xfer_bytes >= actual_length, TUSB_ERROR_INVALID_PARA ); @@ -247,7 +202,7 @@ tusb_error_t mscd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32 // Either bulk in & out can be stalled in the data phase, dcd must make sure these queued transfer will be resumed after host clear stall if (!is_waiting_read10_write10) { - ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_in , p_csw, sizeof(msc_cmd_status_wrapper_t), true) ); // need to be true for dcd to clean up qtd !! + ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_in , p_csw, sizeof(msc_cmd_status_wrapper_t), false) ); //------------- Queue the next CBW -------------// ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_out, p_cbw, sizeof(msc_cmd_block_wrapper_t), true) ); @@ -256,4 +211,50 @@ tusb_error_t mscd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32 return TUSB_ERROR_NONE; } +// return true if data phase is complete, false if not yet complete +static bool read10_write10_data_xfer(mscd_interface_t* p_msc) +{ + msc_cmd_block_wrapper_t * const p_cbw = &p_msc->cbw; + msc_cmd_status_wrapper_t * const p_csw = &p_msc->csw; + + scsi_read10_t* p_readwrite = (scsi_read10_t*) &p_cbw->command; // read10 & write10 has the same format + + endpoint_handle_t const edpt_hdl = BIT_TEST_(p_cbw->dir, 7) ? p_msc->edpt_in : p_msc->edpt_out; + + uint32_t const lba = __be2n(p_readwrite->lba); + uint16_t const block_count = __be2n_16(p_readwrite->block_count); + void *p_buffer = NULL; + + uint16_t xferred_block = (SCSI_CMD_READ_10 == p_cbw->command[0]) ? tusbd_msc_read10_cb (edpt_hdl.coreid, p_cbw->lun, &p_buffer, lba, block_count) : + tusbd_msc_write10_cb(edpt_hdl.coreid, p_cbw->lun, &p_buffer, lba, block_count); + xferred_block = min16_of(xferred_block, block_count); + + uint16_t const xferred_byte = xferred_block * (p_cbw->xfer_bytes / block_count); + + if ( 0 == xferred_block ) + { // xferred_block is zero will cause pipe is stalled & status in CSW set to failed + p_csw->data_residue = p_cbw->xfer_bytes; + p_csw->status = MSC_CSW_STATUS_FAILED; + + (void) dcd_pipe_stall(edpt_hdl); + + return true; + } else if (xferred_block < block_count) + { + ASSERT_STATUS( dcd_pipe_xfer( edpt_hdl, p_buffer, xferred_byte, true) ); + + // adjust lba, block_count, xfer_bytes for the next call + p_readwrite->lba = __n2be(lba+xferred_block); + p_readwrite->block_count = __n2be_16(block_count - xferred_block); + p_cbw->xfer_bytes -= xferred_byte; + + return false; + }else + { + p_csw->status = MSC_CSW_STATUS_PASSED; + ASSERT_STATUS( dcd_pipe_queue_xfer( edpt_hdl, p_buffer, xferred_byte) ); + return true; + } +} + #endif diff --git a/tinyusb/class/msc_device.h b/tinyusb/class/msc_device.h index 8f824380a..eba3e0b92 100644 --- a/tinyusb/class/msc_device.h +++ b/tinyusb/class/msc_device.h @@ -114,7 +114,7 @@ uint16_t tusbd_msc_write10_cb(uint8_t coreid, uint8_t lun, void** pp_buffer, uin * \note Although this callback is called by tinyusb device task (non-isr context), however as all the classes share * the same task (to save resource), any delay in this callback will cause delay in reponse on other classes. */ -msc_csw_status_t tusbd_msc_scsi_received_isr (uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[16], void ** pp_buffer, uint16_t* p_length); +msc_csw_status_t tusbd_msc_scsi_cb (uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[16], void ** pp_buffer, uint16_t* p_length); /** @} */ /** @} */ -- cgit v1.3.1