test
Dependents: Production_version1_0 Production_ver1_0 USBHost_TEST USBHost_Test5 ... more
Fork of USBHost by
Diff: USBHostMSD/USBHostMSD.cpp
- Revision:
- 37:f1e388e7b752
- Parent:
- 33:6c4cab4d356f
--- a/USBHostMSD/USBHostMSD.cpp Sun Apr 30 04:17:16 2017 +0000 +++ b/USBHostMSD/USBHostMSD.cpp Thu Jul 20 10:13:56 2017 +0100 @@ -72,6 +72,11 @@ break; if (msd_device_found) { + /* As this is done in a specific thread + * this lock is taken to avoid to process a disconnection in + * usb process during the device registering */ + USBHost::Lock Lock(host); + bulk_in = dev->getEndpoint(msd_intf, BULK_ENDPOINT, IN); bulk_out = dev->getEndpoint(msd_intf, BULK_ENDPOINT, OUT); @@ -122,13 +127,15 @@ } -int USBHostMSD::testUnitReady() { +int USBHostMSD::testUnitReady() +{ USB_DBG("Test unit ready"); return SCSITransfer(NULL, 6, DEVICE_TO_HOST, 0, 0); } -int USBHostMSD::readCapacity() { +int USBHostMSD::readCapacity() +{ USB_DBG("Read capacity"); uint8_t cmd[10] = {0x25,0,0,0,0,0,0,0,0,0}; uint8_t result[8]; @@ -142,7 +149,8 @@ } -int USBHostMSD::SCSIRequestSense() { +int USBHostMSD::SCSIRequestSense() +{ USB_DBG("Request sense"); uint8_t cmd[6] = {0x03,0,0,0,18,0}; uint8_t result[18]; @@ -151,7 +159,8 @@ } -int USBHostMSD::inquiry(uint8_t lun, uint8_t page_code) { +int USBHostMSD::inquiry(uint8_t lun, uint8_t page_code) +{ USB_DBG("Inquiry"); uint8_t evpd = (page_code == 0) ? 0 : 1; uint8_t cmd[6] = {0x12, uint8_t((lun << 5) | evpd), page_code, 0, 36, 0}; @@ -174,7 +183,8 @@ return status; } -int USBHostMSD::checkResult(uint8_t res, USBEndpoint * ep) { +int USBHostMSD::checkResult(uint8_t res, USBEndpoint * ep) +{ // if ep stalled: send clear feature if (res == USB_TYPE_STALL_ERROR) { res = host->controlWrite( dev, @@ -194,7 +204,8 @@ } -int USBHostMSD::SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len) { +int USBHostMSD::SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len) +{ int res = 0; @@ -277,7 +288,8 @@ } -int USBHostMSD::dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction) { +int USBHostMSD::dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction) +{ uint8_t cmd[10]; memset(cmd,0,10); cmd[0] = (direction == DEVICE_TO_HOST) ? 0x28 : 0x2A; @@ -293,7 +305,8 @@ return SCSITransfer(cmd, 10, direction, buf, blockSize*nbBlock); } -int USBHostMSD::getMaxLun() { +int USBHostMSD::getMaxLun() +{ uint8_t buf[1], res; res = host->controlRead( dev, USB_RECIPIENT_INTERFACE | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS, 0xfe, 0, msd_intf, buf, 1);