final

Dependencies:   mbed FATFileSystem

Fork of KL46Z-USBHostMSD_HelloWorld by Norimasa Okamoto

Committer:
homzovam
Date:
Sat Apr 04 20:16:39 2015 +0000
Revision:
4:77d6450f34d7
prijimac-funkcni final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
homzovam 4:77d6450f34d7 1 /* mbed USBHost Library
homzovam 4:77d6450f34d7 2 * Copyright (c) 2006-2013 ARM Limited
homzovam 4:77d6450f34d7 3 *
homzovam 4:77d6450f34d7 4 * Licensed under the Apache License, Version 2.0 (the "License");
homzovam 4:77d6450f34d7 5 * you may not use this file except in compliance with the License.
homzovam 4:77d6450f34d7 6 * You may obtain a copy of the License at
homzovam 4:77d6450f34d7 7 *
homzovam 4:77d6450f34d7 8 * http://www.apache.org/licenses/LICENSE-2.0
homzovam 4:77d6450f34d7 9 *
homzovam 4:77d6450f34d7 10 * Unless required by applicable law or agreed to in writing, software
homzovam 4:77d6450f34d7 11 * distributed under the License is distributed on an "AS IS" BASIS,
homzovam 4:77d6450f34d7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
homzovam 4:77d6450f34d7 13 * See the License for the specific language governing permissions and
homzovam 4:77d6450f34d7 14 * limitations under the License.
homzovam 4:77d6450f34d7 15 */
homzovam 4:77d6450f34d7 16
homzovam 4:77d6450f34d7 17 #include "USBHostMSD.h"
homzovam 4:77d6450f34d7 18
homzovam 4:77d6450f34d7 19 #if USBHOST_MSD
homzovam 4:77d6450f34d7 20
homzovam 4:77d6450f34d7 21 #include "dbg.h"
homzovam 4:77d6450f34d7 22
homzovam 4:77d6450f34d7 23 #define CBW_SIGNATURE 0x43425355
homzovam 4:77d6450f34d7 24 #define CSW_SIGNATURE 0x53425355
homzovam 4:77d6450f34d7 25
homzovam 4:77d6450f34d7 26 #define DEVICE_TO_HOST 0x80
homzovam 4:77d6450f34d7 27 #define HOST_TO_DEVICE 0x00
homzovam 4:77d6450f34d7 28
homzovam 4:77d6450f34d7 29 #define GET_MAX_LUN (0xFE)
homzovam 4:77d6450f34d7 30 #define BO_MASS_STORAGE_RESET (0xFF)
homzovam 4:77d6450f34d7 31
homzovam 4:77d6450f34d7 32 USBHostMSD::USBHostMSD(const char * rootdir) : FATFileSystem(rootdir)
homzovam 4:77d6450f34d7 33 {
homzovam 4:77d6450f34d7 34 host = USBHost::getHostInst();
homzovam 4:77d6450f34d7 35 init();
homzovam 4:77d6450f34d7 36 }
homzovam 4:77d6450f34d7 37
homzovam 4:77d6450f34d7 38 void USBHostMSD::init() {
homzovam 4:77d6450f34d7 39 dev_connected = false;
homzovam 4:77d6450f34d7 40 dev = NULL;
homzovam 4:77d6450f34d7 41 bulk_in = NULL;
homzovam 4:77d6450f34d7 42 bulk_out = NULL;
homzovam 4:77d6450f34d7 43 dev_connected = false;
homzovam 4:77d6450f34d7 44 blockSize = 0;
homzovam 4:77d6450f34d7 45 blockCount = 0;
homzovam 4:77d6450f34d7 46 msd_intf = -1;
homzovam 4:77d6450f34d7 47 msd_device_found = false;
homzovam 4:77d6450f34d7 48 disk_init = false;
homzovam 4:77d6450f34d7 49 dev_connected = false;
homzovam 4:77d6450f34d7 50 nb_ep = 0;
homzovam 4:77d6450f34d7 51 }
homzovam 4:77d6450f34d7 52
homzovam 4:77d6450f34d7 53
homzovam 4:77d6450f34d7 54 bool USBHostMSD::connected()
homzovam 4:77d6450f34d7 55 {
homzovam 4:77d6450f34d7 56 return dev_connected;
homzovam 4:77d6450f34d7 57 }
homzovam 4:77d6450f34d7 58
homzovam 4:77d6450f34d7 59 bool USBHostMSD::connect()
homzovam 4:77d6450f34d7 60 {
homzovam 4:77d6450f34d7 61
homzovam 4:77d6450f34d7 62 if (dev_connected) {
homzovam 4:77d6450f34d7 63 return true;
homzovam 4:77d6450f34d7 64 }
homzovam 4:77d6450f34d7 65
homzovam 4:77d6450f34d7 66 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
homzovam 4:77d6450f34d7 67 if ((dev = host->getDevice(i)) != NULL) {
homzovam 4:77d6450f34d7 68
homzovam 4:77d6450f34d7 69 USB_DBG("Trying to connect MSD device\r\n");
homzovam 4:77d6450f34d7 70
homzovam 4:77d6450f34d7 71 if(host->enumerate(dev, this))
homzovam 4:77d6450f34d7 72 break;
homzovam 4:77d6450f34d7 73
homzovam 4:77d6450f34d7 74 if (msd_device_found) {
homzovam 4:77d6450f34d7 75 bulk_in = dev->getEndpoint(msd_intf, BULK_ENDPOINT, IN);
homzovam 4:77d6450f34d7 76 bulk_out = dev->getEndpoint(msd_intf, BULK_ENDPOINT, OUT);
homzovam 4:77d6450f34d7 77
homzovam 4:77d6450f34d7 78 if (!bulk_in || !bulk_out)
homzovam 4:77d6450f34d7 79 continue;
homzovam 4:77d6450f34d7 80
homzovam 4:77d6450f34d7 81 /*USB_INFO("New MSD device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, msd_intf);
homzovam 4:77d6450f34d7 82 dev->setName("MSD", msd_intf);
homzovam 4:77d6450f34d7 83 host->registerDriver(dev, msd_intf, this, &USBHostMSD::init);*/
homzovam 4:77d6450f34d7 84
homzovam 4:77d6450f34d7 85 dev_connected = true;
homzovam 4:77d6450f34d7 86 return true;
homzovam 4:77d6450f34d7 87 }
homzovam 4:77d6450f34d7 88 } //if()
homzovam 4:77d6450f34d7 89 } //for()
homzovam 4:77d6450f34d7 90 init();
homzovam 4:77d6450f34d7 91 return false;
homzovam 4:77d6450f34d7 92 }
homzovam 4:77d6450f34d7 93
homzovam 4:77d6450f34d7 94 /*virtual*/ void USBHostMSD::setVidPid(uint16_t vid, uint16_t pid)
homzovam 4:77d6450f34d7 95 {
homzovam 4:77d6450f34d7 96 // we don't check VID/PID for MSD driver
homzovam 4:77d6450f34d7 97 }
homzovam 4:77d6450f34d7 98
homzovam 4:77d6450f34d7 99 /*virtual*/ bool USBHostMSD::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
homzovam 4:77d6450f34d7 100 {
homzovam 4:77d6450f34d7 101 if ((msd_intf == -1) &&
homzovam 4:77d6450f34d7 102 (intf_class == MSD_CLASS) &&
homzovam 4:77d6450f34d7 103 (intf_subclass == 0x06) &&
homzovam 4:77d6450f34d7 104 (intf_protocol == 0x50)) {
homzovam 4:77d6450f34d7 105 msd_intf = intf_nb;
homzovam 4:77d6450f34d7 106 return true;
homzovam 4:77d6450f34d7 107 }
homzovam 4:77d6450f34d7 108 return false;
homzovam 4:77d6450f34d7 109 }
homzovam 4:77d6450f34d7 110
homzovam 4:77d6450f34d7 111 /*virtual*/ bool USBHostMSD::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
homzovam 4:77d6450f34d7 112 {
homzovam 4:77d6450f34d7 113 if (intf_nb == msd_intf) {
homzovam 4:77d6450f34d7 114 if (type == BULK_ENDPOINT) {
homzovam 4:77d6450f34d7 115 nb_ep++;
homzovam 4:77d6450f34d7 116 if (nb_ep == 2)
homzovam 4:77d6450f34d7 117 msd_device_found = true;
homzovam 4:77d6450f34d7 118 return true;
homzovam 4:77d6450f34d7 119 }
homzovam 4:77d6450f34d7 120 }
homzovam 4:77d6450f34d7 121 return false;
homzovam 4:77d6450f34d7 122 }
homzovam 4:77d6450f34d7 123
homzovam 4:77d6450f34d7 124
homzovam 4:77d6450f34d7 125 int USBHostMSD::testUnitReady() {
homzovam 4:77d6450f34d7 126 USB_DBG("Test unit ready");
homzovam 4:77d6450f34d7 127 return SCSITransfer(NULL, 6, DEVICE_TO_HOST, 0, 0);
homzovam 4:77d6450f34d7 128 }
homzovam 4:77d6450f34d7 129
homzovam 4:77d6450f34d7 130
homzovam 4:77d6450f34d7 131 int USBHostMSD::readCapacity() {
homzovam 4:77d6450f34d7 132 USB_DBG("Read capacity");
homzovam 4:77d6450f34d7 133 uint8_t cmd[10] = {0x25,0,0,0,0,0,0,0,0,0};
homzovam 4:77d6450f34d7 134 uint8_t result[8];
homzovam 4:77d6450f34d7 135 int status = SCSITransfer(cmd, 10, DEVICE_TO_HOST, result, 8);
homzovam 4:77d6450f34d7 136 if (status == 0) {
homzovam 4:77d6450f34d7 137 blockCount = (result[0] << 24) | (result[1] << 16) | (result[2] << 8) | result[3];
homzovam 4:77d6450f34d7 138 blockSize = (result[4] << 24) | (result[5] << 16) | (result[6] << 8) | result[7];
homzovam 4:77d6450f34d7 139 //USB_INFO("MSD [dev: %p] - blockCount: %lld, blockSize: %d, Capacity: %lld\r\n", dev, blockCount, blockSize, blockCount*blockSize);
homzovam 4:77d6450f34d7 140 }
homzovam 4:77d6450f34d7 141 return status;
homzovam 4:77d6450f34d7 142 }
homzovam 4:77d6450f34d7 143
homzovam 4:77d6450f34d7 144
homzovam 4:77d6450f34d7 145 int USBHostMSD::SCSIRequestSense() {
homzovam 4:77d6450f34d7 146 USB_DBG("Request sense");
homzovam 4:77d6450f34d7 147 uint8_t cmd[6] = {0x03,0,0,0,18,0};
homzovam 4:77d6450f34d7 148 uint8_t result[18];
homzovam 4:77d6450f34d7 149 int status = SCSITransfer(cmd, 6, DEVICE_TO_HOST, result, 18);
homzovam 4:77d6450f34d7 150 return status;
homzovam 4:77d6450f34d7 151 }
homzovam 4:77d6450f34d7 152
homzovam 4:77d6450f34d7 153
homzovam 4:77d6450f34d7 154 int USBHostMSD::inquiry(uint8_t lun, uint8_t page_code) {
homzovam 4:77d6450f34d7 155 USB_DBG("Inquiry");
homzovam 4:77d6450f34d7 156 uint8_t evpd = (page_code == 0) ? 0 : 1;
homzovam 4:77d6450f34d7 157 uint8_t cmd[6] = {0x12, uint8_t((lun << 5) | evpd), page_code, 0, 36, 0};
homzovam 4:77d6450f34d7 158 uint8_t result[36];
homzovam 4:77d6450f34d7 159 int status = SCSITransfer(cmd, 6, DEVICE_TO_HOST, result, 36);
homzovam 4:77d6450f34d7 160 if (status == 0) {
homzovam 4:77d6450f34d7 161 char vid_pid[17];
homzovam 4:77d6450f34d7 162 memcpy(vid_pid, &result[8], 8);
homzovam 4:77d6450f34d7 163 vid_pid[8] = 0;
homzovam 4:77d6450f34d7 164 //USB_INFO("MSD [dev: %p] - Vendor ID: %s", dev, vid_pid);
homzovam 4:77d6450f34d7 165
homzovam 4:77d6450f34d7 166 memcpy(vid_pid, &result[16], 16);
homzovam 4:77d6450f34d7 167 vid_pid[16] = 0;
homzovam 4:77d6450f34d7 168 //USB_INFO("MSD [dev: %p] - Product ID: %s", dev, vid_pid);
homzovam 4:77d6450f34d7 169
homzovam 4:77d6450f34d7 170 memcpy(vid_pid, &result[32], 4);
homzovam 4:77d6450f34d7 171 vid_pid[4] = 0;
homzovam 4:77d6450f34d7 172 //USB_INFO("MSD [dev: %p] - Product rev: %s", dev, vid_pid);
homzovam 4:77d6450f34d7 173 }
homzovam 4:77d6450f34d7 174 return status;
homzovam 4:77d6450f34d7 175 }
homzovam 4:77d6450f34d7 176
homzovam 4:77d6450f34d7 177 int USBHostMSD::checkResult(uint8_t res, USBEndpoint * ep) {
homzovam 4:77d6450f34d7 178 // if ep stalled: send clear feature
homzovam 4:77d6450f34d7 179 if (res == USB_TYPE_STALL_ERROR) {
homzovam 4:77d6450f34d7 180 res = host->controlWrite( dev,
homzovam 4:77d6450f34d7 181 USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD,
homzovam 4:77d6450f34d7 182 CLEAR_FEATURE,
homzovam 4:77d6450f34d7 183 0, ep->getAddress(), NULL, 0);
homzovam 4:77d6450f34d7 184 // set state to IDLE if clear feature successful
homzovam 4:77d6450f34d7 185 if (res == USB_TYPE_OK) {
homzovam 4:77d6450f34d7 186 ep->setState(USB_TYPE_IDLE);
homzovam 4:77d6450f34d7 187 }
homzovam 4:77d6450f34d7 188 }
homzovam 4:77d6450f34d7 189
homzovam 4:77d6450f34d7 190 if (res != USB_TYPE_OK)
homzovam 4:77d6450f34d7 191 return -1;
homzovam 4:77d6450f34d7 192
homzovam 4:77d6450f34d7 193 return 0;
homzovam 4:77d6450f34d7 194 }
homzovam 4:77d6450f34d7 195
homzovam 4:77d6450f34d7 196
homzovam 4:77d6450f34d7 197 int USBHostMSD::SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len) {
homzovam 4:77d6450f34d7 198
homzovam 4:77d6450f34d7 199 int res = 0;
homzovam 4:77d6450f34d7 200
homzovam 4:77d6450f34d7 201 cbw.Signature = CBW_SIGNATURE;
homzovam 4:77d6450f34d7 202 cbw.Tag = 0;
homzovam 4:77d6450f34d7 203 cbw.DataLength = transfer_len;
homzovam 4:77d6450f34d7 204 cbw.Flags = flags;
homzovam 4:77d6450f34d7 205 cbw.LUN = 0;
homzovam 4:77d6450f34d7 206 cbw.CBLength = cmd_len;
homzovam 4:77d6450f34d7 207 memset(cbw.CB,0,sizeof(cbw.CB));
homzovam 4:77d6450f34d7 208 if (cmd) {
homzovam 4:77d6450f34d7 209 memcpy(cbw.CB,cmd,cmd_len);
homzovam 4:77d6450f34d7 210 }
homzovam 4:77d6450f34d7 211
homzovam 4:77d6450f34d7 212 // send the cbw
homzovam 4:77d6450f34d7 213 USB_DBG("Send CBW");
homzovam 4:77d6450f34d7 214 res = host->bulkWrite(dev, bulk_out,(uint8_t *)&cbw, 31);
homzovam 4:77d6450f34d7 215 if (checkResult(res, bulk_out))
homzovam 4:77d6450f34d7 216 return -1;
homzovam 4:77d6450f34d7 217
homzovam 4:77d6450f34d7 218 // data stage if needed
homzovam 4:77d6450f34d7 219 if (data) {
homzovam 4:77d6450f34d7 220 USB_DBG("data stage");
homzovam 4:77d6450f34d7 221 if (flags == HOST_TO_DEVICE) {
homzovam 4:77d6450f34d7 222
homzovam 4:77d6450f34d7 223 res = host->bulkWrite(dev, bulk_out, data, transfer_len);
homzovam 4:77d6450f34d7 224 if (checkResult(res, bulk_out))
homzovam 4:77d6450f34d7 225 return -1;
homzovam 4:77d6450f34d7 226
homzovam 4:77d6450f34d7 227 } else if (flags == DEVICE_TO_HOST) {
homzovam 4:77d6450f34d7 228
homzovam 4:77d6450f34d7 229 res = host->bulkRead(dev, bulk_in, data, transfer_len);
homzovam 4:77d6450f34d7 230 if (checkResult(res, bulk_in))
homzovam 4:77d6450f34d7 231 return -1;
homzovam 4:77d6450f34d7 232 }
homzovam 4:77d6450f34d7 233 }
homzovam 4:77d6450f34d7 234
homzovam 4:77d6450f34d7 235 // status stage
homzovam 4:77d6450f34d7 236 csw.Signature = 0;
homzovam 4:77d6450f34d7 237 USB_DBG("Read CSW");
homzovam 4:77d6450f34d7 238 res = host->bulkRead(dev, bulk_in,(uint8_t *)&csw, 13);
homzovam 4:77d6450f34d7 239 if (checkResult(res, bulk_in))
homzovam 4:77d6450f34d7 240 return -1;
homzovam 4:77d6450f34d7 241
homzovam 4:77d6450f34d7 242 if (csw.Signature != CSW_SIGNATURE) {
homzovam 4:77d6450f34d7 243 return -1;
homzovam 4:77d6450f34d7 244 }
homzovam 4:77d6450f34d7 245
homzovam 4:77d6450f34d7 246 USB_DBG("recv csw: status: %d", csw.Status);
homzovam 4:77d6450f34d7 247
homzovam 4:77d6450f34d7 248 // ModeSense?
homzovam 4:77d6450f34d7 249 if ((csw.Status == 1) && (cmd[0] != 0x03)) {
homzovam 4:77d6450f34d7 250 USB_DBG("request mode sense");
homzovam 4:77d6450f34d7 251 return SCSIRequestSense();
homzovam 4:77d6450f34d7 252 }
homzovam 4:77d6450f34d7 253
homzovam 4:77d6450f34d7 254 // perform reset recovery
homzovam 4:77d6450f34d7 255 if ((csw.Status == 2) && (cmd[0] != 0x03)) {
homzovam 4:77d6450f34d7 256
homzovam 4:77d6450f34d7 257 // send Bulk-Only Mass Storage Reset request
homzovam 4:77d6450f34d7 258 res = host->controlWrite( dev,
homzovam 4:77d6450f34d7 259 USB_RECIPIENT_INTERFACE | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS,
homzovam 4:77d6450f34d7 260 BO_MASS_STORAGE_RESET,
homzovam 4:77d6450f34d7 261 0, msd_intf, NULL, 0);
homzovam 4:77d6450f34d7 262
homzovam 4:77d6450f34d7 263 // unstall both endpoints
homzovam 4:77d6450f34d7 264 res = host->controlWrite( dev,
homzovam 4:77d6450f34d7 265 USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD,
homzovam 4:77d6450f34d7 266 CLEAR_FEATURE,
homzovam 4:77d6450f34d7 267 0, bulk_in->getAddress(), NULL, 0);
homzovam 4:77d6450f34d7 268
homzovam 4:77d6450f34d7 269 res = host->controlWrite( dev,
homzovam 4:77d6450f34d7 270 USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD,
homzovam 4:77d6450f34d7 271 CLEAR_FEATURE,
homzovam 4:77d6450f34d7 272 0, bulk_out->getAddress(), NULL, 0);
homzovam 4:77d6450f34d7 273
homzovam 4:77d6450f34d7 274 }
homzovam 4:77d6450f34d7 275
homzovam 4:77d6450f34d7 276 return csw.Status;
homzovam 4:77d6450f34d7 277 }
homzovam 4:77d6450f34d7 278
homzovam 4:77d6450f34d7 279
homzovam 4:77d6450f34d7 280 int USBHostMSD::dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction) {
homzovam 4:77d6450f34d7 281 uint8_t cmd[10];
homzovam 4:77d6450f34d7 282 memset(cmd,0,10);
homzovam 4:77d6450f34d7 283 cmd[0] = (direction == DEVICE_TO_HOST) ? 0x28 : 0x2A;
homzovam 4:77d6450f34d7 284
homzovam 4:77d6450f34d7 285 cmd[2] = (block >> 24) & 0xff;
homzovam 4:77d6450f34d7 286 cmd[3] = (block >> 16) & 0xff;
homzovam 4:77d6450f34d7 287 cmd[4] = (block >> 8) & 0xff;
homzovam 4:77d6450f34d7 288 cmd[5] = block & 0xff;
homzovam 4:77d6450f34d7 289
homzovam 4:77d6450f34d7 290 cmd[7] = (nbBlock >> 8) & 0xff;
homzovam 4:77d6450f34d7 291 cmd[8] = nbBlock & 0xff;
homzovam 4:77d6450f34d7 292
homzovam 4:77d6450f34d7 293 return SCSITransfer(cmd, 10, direction, buf, blockSize*nbBlock);
homzovam 4:77d6450f34d7 294 }
homzovam 4:77d6450f34d7 295
homzovam 4:77d6450f34d7 296 int USBHostMSD::getMaxLun() {
homzovam 4:77d6450f34d7 297 uint8_t buf[1], res;
homzovam 4:77d6450f34d7 298 res = host->controlRead( dev, USB_RECIPIENT_INTERFACE | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS,
homzovam 4:77d6450f34d7 299 0xfe, 0, msd_intf, buf, 1);
homzovam 4:77d6450f34d7 300 USB_DBG("max lun: %d", buf[0]);
homzovam 4:77d6450f34d7 301 return res;
homzovam 4:77d6450f34d7 302 }
homzovam 4:77d6450f34d7 303
homzovam 4:77d6450f34d7 304 int USBHostMSD::disk_initialize() {
homzovam 4:77d6450f34d7 305 USB_DBG("FILESYSTEM: init");
homzovam 4:77d6450f34d7 306 /* U16 */int i, timeout = 10;
homzovam 4:77d6450f34d7 307
homzovam 4:77d6450f34d7 308 getMaxLun();
homzovam 4:77d6450f34d7 309
homzovam 4:77d6450f34d7 310 for (i = 0; i < timeout; i++) {
homzovam 4:77d6450f34d7 311 wait_ms(100); //Thread::wait(100);
homzovam 4:77d6450f34d7 312 if (!testUnitReady())
homzovam 4:77d6450f34d7 313 break;
homzovam 4:77d6450f34d7 314 }
homzovam 4:77d6450f34d7 315
homzovam 4:77d6450f34d7 316 if (i == timeout) {
homzovam 4:77d6450f34d7 317 disk_init = false;
homzovam 4:77d6450f34d7 318 return -1;
homzovam 4:77d6450f34d7 319 }
homzovam 4:77d6450f34d7 320
homzovam 4:77d6450f34d7 321 inquiry(0, 0);
homzovam 4:77d6450f34d7 322 disk_init = 1;
homzovam 4:77d6450f34d7 323 return readCapacity();
homzovam 4:77d6450f34d7 324 }
homzovam 4:77d6450f34d7 325
homzovam 4:77d6450f34d7 326 int USBHostMSD::disk_write(const uint8_t *buffer, uint64_t block_number) {
homzovam 4:77d6450f34d7 327 USB_DBG("FILESYSTEM: write block: %lld", block_number);
homzovam 4:77d6450f34d7 328 if (!disk_init) {
homzovam 4:77d6450f34d7 329 disk_initialize();
homzovam 4:77d6450f34d7 330 }
homzovam 4:77d6450f34d7 331 if (!disk_init)
homzovam 4:77d6450f34d7 332 return -1;
homzovam 4:77d6450f34d7 333 return dataTransfer((uint8_t *)buffer, block_number, 1, HOST_TO_DEVICE);
homzovam 4:77d6450f34d7 334 }
homzovam 4:77d6450f34d7 335
homzovam 4:77d6450f34d7 336 int USBHostMSD::disk_read(uint8_t * buffer, uint64_t block_number) {
homzovam 4:77d6450f34d7 337 USB_DBG("FILESYSTEM: read block %lld", block_number);
homzovam 4:77d6450f34d7 338 if (!disk_init) {
homzovam 4:77d6450f34d7 339 disk_initialize();
homzovam 4:77d6450f34d7 340 }
homzovam 4:77d6450f34d7 341 if (!disk_init)
homzovam 4:77d6450f34d7 342 return -1;
homzovam 4:77d6450f34d7 343 return dataTransfer((uint8_t *)buffer, block_number, 1, DEVICE_TO_HOST);
homzovam 4:77d6450f34d7 344 }
homzovam 4:77d6450f34d7 345
homzovam 4:77d6450f34d7 346 uint64_t USBHostMSD::disk_sectors() {
homzovam 4:77d6450f34d7 347 USB_DBG("FILESYSTEM: sectors");
homzovam 4:77d6450f34d7 348 if (!disk_init) {
homzovam 4:77d6450f34d7 349 disk_initialize();
homzovam 4:77d6450f34d7 350 }
homzovam 4:77d6450f34d7 351 if (!disk_init)
homzovam 4:77d6450f34d7 352 return 0;
homzovam 4:77d6450f34d7 353 return blockCount;
homzovam 4:77d6450f34d7 354 }
homzovam 4:77d6450f34d7 355
homzovam 4:77d6450f34d7 356 #endif