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 --- .../boards/embedded_artists/ea4357/board_ea4357.c | 7 +- demos/device/src/mscd_app.c | 2 +- demos/device/src/tusb_config.h | 4 +- tinyusb/class/msc_device.c | 101 +++++++++++---------- tinyusb/class/msc_device.h | 2 +- 5 files changed, 61 insertions(+), 55 deletions(-) diff --git a/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c b/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c index f65e46b6f..09d4e121c 100644 --- a/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c +++ b/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c @@ -75,8 +75,13 @@ void board_init(void) //------------- USB -------------// // USB0 Power: EA4357 channel B U20 GPIO26 active low (base board), P2_3 on LPC4357 - scu_pinmux(0x2, 3, MD_PUP | MD_EZI, FUNC7); // USB0 VBus Power + scu_pinmux(0x02, 3, MD_PUP | MD_EZI, FUNC7); // USB0 VBus Power + #if TUSB_CFG_CONTROLLER_0_MODE & TUSB_MODE_DEVICE + scu_pinmux(0x09, 5, GPIO_PDN, FUNC4); // P9_5 (GPIO5[18]) (GPIO28 on oem base) as USB connect, active low. + GPIO_SetDir(5, BIT_(18), 1); + #endif + // USB1 Power: EA4357 channel A U20 is enabled by SJ5 connected to pad 1-2, no more action required // TODO Remove R170, R171, solder a pair of 15K to USB1 D+/D- to test with USB1 Host diff --git a/demos/device/src/mscd_app.c b/demos/device/src/mscd_app.c index ad689549f..fa125d769 100644 --- a/demos/device/src/mscd_app.c +++ b/demos/device/src/mscd_app.c @@ -97,7 +97,7 @@ static scsi_mode_parameters_t msc_dev_mode_para TUSB_CFG_ATTR_USBRAM = //--------------------------------------------------------------------+ // tinyusb callback (ISR context) //--------------------------------------------------------------------+ -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) { // read10 & write10 has their own callback and MUST not be handled here switch (scsi_cmd[0]) diff --git a/demos/device/src/tusb_config.h b/demos/device/src/tusb_config.h index bfc225351..278093572 100644 --- a/demos/device/src/tusb_config.h +++ b/demos/device/src/tusb_config.h @@ -82,10 +82,10 @@ #define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor, remove //------------- CLASS -------------// -#define TUSB_CFG_DEVICE_HID_KEYBOARD 1 +#define TUSB_CFG_DEVICE_HID_KEYBOARD 0 #define TUSB_CFG_DEVICE_HID_MOUSE 0 #define TUSB_CFG_DEVICE_HID_GENERIC 0 -#define TUSB_CFG_DEVICE_MSC 0 +#define TUSB_CFG_DEVICE_MSC 1 #define TUSB_CFG_DEVICE_CDC 0 //--------------------------------------------------------------------+ 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