Dependencies:   mbed

Committer:
slowness
Date:
Fri Aug 26 12:19:16 2011 +0000
Revision:
0:4359b47b3d7c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
slowness 0:4359b47b3d7c 1 /*
slowness 0:4359b47b3d7c 2 **************************************************************************************************************
slowness 0:4359b47b3d7c 3 * NXP USB Host Stack
slowness 0:4359b47b3d7c 4 *
slowness 0:4359b47b3d7c 5 * (c) Copyright 2008, NXP SemiConductors
slowness 0:4359b47b3d7c 6 * (c) Copyright 2008, OnChip Technologies LLC
slowness 0:4359b47b3d7c 7 * All Rights Reserved
slowness 0:4359b47b3d7c 8 *
slowness 0:4359b47b3d7c 9 * www.nxp.com
slowness 0:4359b47b3d7c 10 * www.onchiptech.com
slowness 0:4359b47b3d7c 11 *
slowness 0:4359b47b3d7c 12 * File : usbhost_ms.c
slowness 0:4359b47b3d7c 13 * Programmer(s) : Ravikanth.P
slowness 0:4359b47b3d7c 14 * Version :
slowness 0:4359b47b3d7c 15 *
slowness 0:4359b47b3d7c 16 **************************************************************************************************************
slowness 0:4359b47b3d7c 17 */
slowness 0:4359b47b3d7c 18
slowness 0:4359b47b3d7c 19 /*
slowness 0:4359b47b3d7c 20 **************************************************************************************************************
slowness 0:4359b47b3d7c 21 * INCLUDE HEADER FILES
slowness 0:4359b47b3d7c 22 **************************************************************************************************************
slowness 0:4359b47b3d7c 23 */
slowness 0:4359b47b3d7c 24
slowness 0:4359b47b3d7c 25 #include "usbhost_ms.h"
slowness 0:4359b47b3d7c 26
slowness 0:4359b47b3d7c 27 /*
slowness 0:4359b47b3d7c 28 **************************************************************************************************************
slowness 0:4359b47b3d7c 29 * GLOBAL VARIABLES
slowness 0:4359b47b3d7c 30 **************************************************************************************************************
slowness 0:4359b47b3d7c 31 */
slowness 0:4359b47b3d7c 32
slowness 0:4359b47b3d7c 33 USB_INT32U MS_BlkSize;
slowness 0:4359b47b3d7c 34
slowness 0:4359b47b3d7c 35 /*
slowness 0:4359b47b3d7c 36 **************************************************************************************************************
slowness 0:4359b47b3d7c 37 * INITIALIZE MASS STORAGE INTERFACE
slowness 0:4359b47b3d7c 38 *
slowness 0:4359b47b3d7c 39 * Description: This function initializes the mass storage interface
slowness 0:4359b47b3d7c 40 *
slowness 0:4359b47b3d7c 41 * Arguments : None
slowness 0:4359b47b3d7c 42 *
slowness 0:4359b47b3d7c 43 * Returns : OK if Success
slowness 0:4359b47b3d7c 44 * ERR_INVALID_BOOTSIG if Failed
slowness 0:4359b47b3d7c 45 *
slowness 0:4359b47b3d7c 46 **************************************************************************************************************
slowness 0:4359b47b3d7c 47 */
slowness 0:4359b47b3d7c 48
slowness 0:4359b47b3d7c 49 USB_INT32S MS_Init (USB_INT32U *blkSize, USB_INT32U *numBlks, USB_INT08U *inquiryResult)
slowness 0:4359b47b3d7c 50 {
slowness 0:4359b47b3d7c 51 USB_INT08U retry;
slowness 0:4359b47b3d7c 52 USB_INT32S rc;
slowness 0:4359b47b3d7c 53
slowness 0:4359b47b3d7c 54 MS_GetMaxLUN(); /* Get maximum logical unit number */
slowness 0:4359b47b3d7c 55 retry = 80;
slowness 0:4359b47b3d7c 56 while(retry) {
slowness 0:4359b47b3d7c 57 rc = MS_TestUnitReady(); /* Test whether the unit is ready */
slowness 0:4359b47b3d7c 58 if (rc == OK) {
slowness 0:4359b47b3d7c 59 break;
slowness 0:4359b47b3d7c 60 }
slowness 0:4359b47b3d7c 61 MS_GetSenseInfo(); /* Get sense information */
slowness 0:4359b47b3d7c 62 retry--;
slowness 0:4359b47b3d7c 63 }
slowness 0:4359b47b3d7c 64 if (rc != OK) {
slowness 0:4359b47b3d7c 65 PRINT_Err(rc);
slowness 0:4359b47b3d7c 66 return (rc);
slowness 0:4359b47b3d7c 67 }
slowness 0:4359b47b3d7c 68 rc = MS_ReadCapacity(numBlks, blkSize); /* Read capacity of the disk */
slowness 0:4359b47b3d7c 69 MS_BlkSize = *blkSize; // Set global
slowness 0:4359b47b3d7c 70 rc = MS_Inquire (inquiryResult);
slowness 0:4359b47b3d7c 71 return (rc);
slowness 0:4359b47b3d7c 72 }
slowness 0:4359b47b3d7c 73 /*
slowness 0:4359b47b3d7c 74 **************************************************************************************************************
slowness 0:4359b47b3d7c 75 * PARSE THE CONFIGURATION
slowness 0:4359b47b3d7c 76 *
slowness 0:4359b47b3d7c 77 * Description: This function is used to parse the configuration
slowness 0:4359b47b3d7c 78 *
slowness 0:4359b47b3d7c 79 * Arguments : None
slowness 0:4359b47b3d7c 80 *
slowness 0:4359b47b3d7c 81 * Returns : OK if Success
slowness 0:4359b47b3d7c 82 * ERR_INVALID_BOOTSIG if Failed
slowness 0:4359b47b3d7c 83 *
slowness 0:4359b47b3d7c 84 **************************************************************************************************************
slowness 0:4359b47b3d7c 85 */
slowness 0:4359b47b3d7c 86
slowness 0:4359b47b3d7c 87 USB_INT32S MS_ParseConfiguration (void)
slowness 0:4359b47b3d7c 88 {
slowness 0:4359b47b3d7c 89 volatile USB_INT08U *desc_ptr;
slowness 0:4359b47b3d7c 90 USB_INT08U ms_int_found;
slowness 0:4359b47b3d7c 91
slowness 0:4359b47b3d7c 92
slowness 0:4359b47b3d7c 93 desc_ptr = TDBuffer;
slowness 0:4359b47b3d7c 94 ms_int_found = 0;
slowness 0:4359b47b3d7c 95
slowness 0:4359b47b3d7c 96 if (desc_ptr[1] != USB_DESCRIPTOR_TYPE_CONFIGURATION) {
slowness 0:4359b47b3d7c 97 return (ERR_BAD_CONFIGURATION);
slowness 0:4359b47b3d7c 98 }
slowness 0:4359b47b3d7c 99 desc_ptr += desc_ptr[0];
slowness 0:4359b47b3d7c 100
slowness 0:4359b47b3d7c 101 while (desc_ptr != TDBuffer + ReadLE16U(&TDBuffer[2])) {
slowness 0:4359b47b3d7c 102
slowness 0:4359b47b3d7c 103 switch (desc_ptr[1]) {
slowness 0:4359b47b3d7c 104
slowness 0:4359b47b3d7c 105 case USB_DESCRIPTOR_TYPE_INTERFACE: /* If it is an interface descriptor */
slowness 0:4359b47b3d7c 106 if (desc_ptr[5] == MASS_STORAGE_CLASS && /* check if the class is mass storage */
slowness 0:4359b47b3d7c 107 desc_ptr[6] == MASS_STORAGE_SUBCLASS_SCSI && /* check if the subclass is SCSI */
slowness 0:4359b47b3d7c 108 desc_ptr[7] == MASS_STORAGE_PROTOCOL_BO) { /* check if the protocol is Bulk only */
slowness 0:4359b47b3d7c 109 ms_int_found = 1;
slowness 0:4359b47b3d7c 110 desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
slowness 0:4359b47b3d7c 111 }
slowness 0:4359b47b3d7c 112 break;
slowness 0:4359b47b3d7c 113
slowness 0:4359b47b3d7c 114 case USB_DESCRIPTOR_TYPE_ENDPOINT: /* If it is an endpoint descriptor */
slowness 0:4359b47b3d7c 115 if ((desc_ptr[3] & 0x03) == 0x02) { /* If it is Bulk endpoint */
slowness 0:4359b47b3d7c 116 if (desc_ptr[2] & 0x80) { /* If it is In endpoint */
slowness 0:4359b47b3d7c 117 EDBulkIn->Control = 1 | /* USB address */
slowness 0:4359b47b3d7c 118 ((desc_ptr[2] & 0x7F) << 7) | /* Endpoint address */
slowness 0:4359b47b3d7c 119 (2 << 11) | /* direction */
slowness 0:4359b47b3d7c 120 (ReadLE16U(&desc_ptr[4]) << 16); /* MaxPkt Size */
slowness 0:4359b47b3d7c 121 desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
slowness 0:4359b47b3d7c 122 } else { /* If it is Out endpoint */
slowness 0:4359b47b3d7c 123 EDBulkOut->Control = 1 | /* USB address */
slowness 0:4359b47b3d7c 124 ((desc_ptr[2] & 0x7F) << 7) | /* Endpoint address */
slowness 0:4359b47b3d7c 125 (1 << 11) | /* direction */
slowness 0:4359b47b3d7c 126 (ReadLE16U(&desc_ptr[4]) << 16); /* MaxPkt Size */
slowness 0:4359b47b3d7c 127 desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
slowness 0:4359b47b3d7c 128 }
slowness 0:4359b47b3d7c 129 } else { /* If it is not bulk end point */
slowness 0:4359b47b3d7c 130 desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
slowness 0:4359b47b3d7c 131 }
slowness 0:4359b47b3d7c 132 break;
slowness 0:4359b47b3d7c 133
slowness 0:4359b47b3d7c 134 default: /* If the descriptor is neither interface nor endpoint */
slowness 0:4359b47b3d7c 135 desc_ptr += desc_ptr[0]; /* Move to next descriptor start */
slowness 0:4359b47b3d7c 136 break;
slowness 0:4359b47b3d7c 137 }
slowness 0:4359b47b3d7c 138 }
slowness 0:4359b47b3d7c 139 if (ms_int_found) {
slowness 0:4359b47b3d7c 140 PRINT_Log("Mass Storage device connected\n");
slowness 0:4359b47b3d7c 141 return (OK);
slowness 0:4359b47b3d7c 142 } else {
slowness 0:4359b47b3d7c 143 PRINT_Log("Not a Mass Storage device\n");
slowness 0:4359b47b3d7c 144 return (ERR_NO_MS_INTERFACE);
slowness 0:4359b47b3d7c 145 }
slowness 0:4359b47b3d7c 146 }
slowness 0:4359b47b3d7c 147
slowness 0:4359b47b3d7c 148 /*
slowness 0:4359b47b3d7c 149 **************************************************************************************************************
slowness 0:4359b47b3d7c 150 * GET MAXIMUM LOGICAL UNIT
slowness 0:4359b47b3d7c 151 *
slowness 0:4359b47b3d7c 152 * Description: This function returns the maximum logical unit from the device
slowness 0:4359b47b3d7c 153 *
slowness 0:4359b47b3d7c 154 * Arguments : None
slowness 0:4359b47b3d7c 155 *
slowness 0:4359b47b3d7c 156 * Returns : OK if Success
slowness 0:4359b47b3d7c 157 * ERR_INVALID_BOOTSIG if Failed
slowness 0:4359b47b3d7c 158 *
slowness 0:4359b47b3d7c 159 **************************************************************************************************************
slowness 0:4359b47b3d7c 160 */
slowness 0:4359b47b3d7c 161
slowness 0:4359b47b3d7c 162 USB_INT32S MS_GetMaxLUN (void)
slowness 0:4359b47b3d7c 163 {
slowness 0:4359b47b3d7c 164 USB_INT32S rc;
slowness 0:4359b47b3d7c 165
slowness 0:4359b47b3d7c 166
slowness 0:4359b47b3d7c 167 rc = Host_CtrlRecv(USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE,
slowness 0:4359b47b3d7c 168 MS_GET_MAX_LUN_REQ,
slowness 0:4359b47b3d7c 169 0,
slowness 0:4359b47b3d7c 170 0,
slowness 0:4359b47b3d7c 171 1,
slowness 0:4359b47b3d7c 172 TDBuffer);
slowness 0:4359b47b3d7c 173 return (rc);
slowness 0:4359b47b3d7c 174 }
slowness 0:4359b47b3d7c 175
slowness 0:4359b47b3d7c 176 /*
slowness 0:4359b47b3d7c 177 **************************************************************************************************************
slowness 0:4359b47b3d7c 178 * GET SENSE INFORMATION
slowness 0:4359b47b3d7c 179 *
slowness 0:4359b47b3d7c 180 * Description: This function is used to get sense information from the device
slowness 0:4359b47b3d7c 181 *
slowness 0:4359b47b3d7c 182 * Arguments : None
slowness 0:4359b47b3d7c 183 *
slowness 0:4359b47b3d7c 184 * Returns : OK if Success
slowness 0:4359b47b3d7c 185 * ERROR if Failed
slowness 0:4359b47b3d7c 186 *
slowness 0:4359b47b3d7c 187 **************************************************************************************************************
slowness 0:4359b47b3d7c 188 */
slowness 0:4359b47b3d7c 189
slowness 0:4359b47b3d7c 190 USB_INT32S MS_GetSenseInfo (void)
slowness 0:4359b47b3d7c 191 {
slowness 0:4359b47b3d7c 192 USB_INT32S rc;
slowness 0:4359b47b3d7c 193
slowness 0:4359b47b3d7c 194
slowness 0:4359b47b3d7c 195 Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_REQUEST_SENSE, 6);
slowness 0:4359b47b3d7c 196 rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
slowness 0:4359b47b3d7c 197 if (rc == OK) {
slowness 0:4359b47b3d7c 198 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, 18);
slowness 0:4359b47b3d7c 199 if (rc == OK) {
slowness 0:4359b47b3d7c 200 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
slowness 0:4359b47b3d7c 201 if (rc == OK) {
slowness 0:4359b47b3d7c 202 if (TDBuffer[12] != 0) {
slowness 0:4359b47b3d7c 203 rc = ERR_MS_CMD_FAILED;
slowness 0:4359b47b3d7c 204 }
slowness 0:4359b47b3d7c 205 }
slowness 0:4359b47b3d7c 206 }
slowness 0:4359b47b3d7c 207 }
slowness 0:4359b47b3d7c 208 return (rc);
slowness 0:4359b47b3d7c 209 }
slowness 0:4359b47b3d7c 210
slowness 0:4359b47b3d7c 211 /*
slowness 0:4359b47b3d7c 212 **************************************************************************************************************
slowness 0:4359b47b3d7c 213 * TEST UNIT READY
slowness 0:4359b47b3d7c 214 *
slowness 0:4359b47b3d7c 215 * Description: This function is used to test whether the unit is ready or not
slowness 0:4359b47b3d7c 216 *
slowness 0:4359b47b3d7c 217 * Arguments : None
slowness 0:4359b47b3d7c 218 *
slowness 0:4359b47b3d7c 219 * Returns : OK if Success
slowness 0:4359b47b3d7c 220 * ERROR if Failed
slowness 0:4359b47b3d7c 221 *
slowness 0:4359b47b3d7c 222 **************************************************************************************************************
slowness 0:4359b47b3d7c 223 */
slowness 0:4359b47b3d7c 224
slowness 0:4359b47b3d7c 225 USB_INT32S MS_TestUnitReady (void)
slowness 0:4359b47b3d7c 226 {
slowness 0:4359b47b3d7c 227 USB_INT32S rc;
slowness 0:4359b47b3d7c 228
slowness 0:4359b47b3d7c 229
slowness 0:4359b47b3d7c 230 Fill_MSCommand(0, 0, 0, MS_DATA_DIR_NONE, SCSI_CMD_TEST_UNIT_READY, 6);
slowness 0:4359b47b3d7c 231 rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
slowness 0:4359b47b3d7c 232 if (rc == OK) {
slowness 0:4359b47b3d7c 233 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
slowness 0:4359b47b3d7c 234 if (rc == OK) {
slowness 0:4359b47b3d7c 235 if (TDBuffer[12] != 0) {
slowness 0:4359b47b3d7c 236 rc = ERR_MS_CMD_FAILED;
slowness 0:4359b47b3d7c 237 }
slowness 0:4359b47b3d7c 238 }
slowness 0:4359b47b3d7c 239 }
slowness 0:4359b47b3d7c 240 return (rc);
slowness 0:4359b47b3d7c 241 }
slowness 0:4359b47b3d7c 242
slowness 0:4359b47b3d7c 243 /*
slowness 0:4359b47b3d7c 244 **************************************************************************************************************
slowness 0:4359b47b3d7c 245 * READ CAPACITY
slowness 0:4359b47b3d7c 246 *
slowness 0:4359b47b3d7c 247 * Description: This function is used to read the capacity of the mass storage device
slowness 0:4359b47b3d7c 248 *
slowness 0:4359b47b3d7c 249 * Arguments : None
slowness 0:4359b47b3d7c 250 *
slowness 0:4359b47b3d7c 251 * Returns : OK if Success
slowness 0:4359b47b3d7c 252 * ERROR if Failed
slowness 0:4359b47b3d7c 253 *
slowness 0:4359b47b3d7c 254 **************************************************************************************************************
slowness 0:4359b47b3d7c 255 */
slowness 0:4359b47b3d7c 256
slowness 0:4359b47b3d7c 257 USB_INT32S MS_ReadCapacity (USB_INT32U *numBlks, USB_INT32U *blkSize)
slowness 0:4359b47b3d7c 258 {
slowness 0:4359b47b3d7c 259 USB_INT32S rc;
slowness 0:4359b47b3d7c 260
slowness 0:4359b47b3d7c 261
slowness 0:4359b47b3d7c 262 Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_READ_CAPACITY, 10);
slowness 0:4359b47b3d7c 263 rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
slowness 0:4359b47b3d7c 264 if (rc == OK) {
slowness 0:4359b47b3d7c 265 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, 8);
slowness 0:4359b47b3d7c 266 if (rc == OK) {
slowness 0:4359b47b3d7c 267 if (numBlks)
slowness 0:4359b47b3d7c 268 *numBlks = ReadBE32U(&TDBuffer[0]);
slowness 0:4359b47b3d7c 269 if (blkSize)
slowness 0:4359b47b3d7c 270 *blkSize = ReadBE32U(&TDBuffer[4]);
slowness 0:4359b47b3d7c 271 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
slowness 0:4359b47b3d7c 272 if (rc == OK) {
slowness 0:4359b47b3d7c 273 if (TDBuffer[12] != 0) {
slowness 0:4359b47b3d7c 274 rc = ERR_MS_CMD_FAILED;
slowness 0:4359b47b3d7c 275 }
slowness 0:4359b47b3d7c 276 }
slowness 0:4359b47b3d7c 277 }
slowness 0:4359b47b3d7c 278 }
slowness 0:4359b47b3d7c 279 return (rc);
slowness 0:4359b47b3d7c 280 }
slowness 0:4359b47b3d7c 281
slowness 0:4359b47b3d7c 282
slowness 0:4359b47b3d7c 283
slowness 0:4359b47b3d7c 284 USB_INT32S MS_Inquire (USB_INT08U *response)
slowness 0:4359b47b3d7c 285 {
slowness 0:4359b47b3d7c 286 USB_INT32S rc;
slowness 0:4359b47b3d7c 287 USB_INT32U i;
slowness 0:4359b47b3d7c 288
slowness 0:4359b47b3d7c 289 Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_INQUIRY, 6);
slowness 0:4359b47b3d7c 290 rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
slowness 0:4359b47b3d7c 291 if (rc == OK) {
slowness 0:4359b47b3d7c 292 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, INQUIRY_LENGTH);
slowness 0:4359b47b3d7c 293 if (rc == OK) {
slowness 0:4359b47b3d7c 294 if (response) {
slowness 0:4359b47b3d7c 295 for ( i = 0; i < INQUIRY_LENGTH; i++ )
slowness 0:4359b47b3d7c 296 *response++ = *TDBuffer++;
slowness 0:4359b47b3d7c 297 #if 0
slowness 0:4359b47b3d7c 298 MemCpy (response, TDBuffer, INQUIRY_LENGTH);
slowness 0:4359b47b3d7c 299 StrNullTrailingSpace (response->vendorID, SCSI_INQUIRY_VENDORCHARS);
slowness 0:4359b47b3d7c 300 StrNullTrailingSpace (response->productID, SCSI_INQUIRY_PRODUCTCHARS);
slowness 0:4359b47b3d7c 301 StrNullTrailingSpace (response->productRev, SCSI_INQUIRY_REVCHARS);
slowness 0:4359b47b3d7c 302 #endif
slowness 0:4359b47b3d7c 303 }
slowness 0:4359b47b3d7c 304 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
slowness 0:4359b47b3d7c 305 if (rc == OK) {
slowness 0:4359b47b3d7c 306 if (TDBuffer[12] != 0) { // bCSWStatus byte
slowness 0:4359b47b3d7c 307 rc = ERR_MS_CMD_FAILED;
slowness 0:4359b47b3d7c 308 }
slowness 0:4359b47b3d7c 309 }
slowness 0:4359b47b3d7c 310 }
slowness 0:4359b47b3d7c 311 }
slowness 0:4359b47b3d7c 312 return (rc);
slowness 0:4359b47b3d7c 313 }
slowness 0:4359b47b3d7c 314
slowness 0:4359b47b3d7c 315 /*
slowness 0:4359b47b3d7c 316 **************************************************************************************************************
slowness 0:4359b47b3d7c 317 * RECEIVE THE BULK DATA
slowness 0:4359b47b3d7c 318 *
slowness 0:4359b47b3d7c 319 * Description: This function is used to receive the bulk data
slowness 0:4359b47b3d7c 320 *
slowness 0:4359b47b3d7c 321 * Arguments : None
slowness 0:4359b47b3d7c 322 *
slowness 0:4359b47b3d7c 323 * Returns : OK if Success
slowness 0:4359b47b3d7c 324 * ERR_INVALID_BOOTSIG if Failed
slowness 0:4359b47b3d7c 325 *
slowness 0:4359b47b3d7c 326 **************************************************************************************************************
slowness 0:4359b47b3d7c 327 */
slowness 0:4359b47b3d7c 328
slowness 0:4359b47b3d7c 329 USB_INT32S MS_BulkRecv ( USB_INT32U block_number,
slowness 0:4359b47b3d7c 330 USB_INT16U num_blocks,
slowness 0:4359b47b3d7c 331 volatile USB_INT08U *user_buffer)
slowness 0:4359b47b3d7c 332 {
slowness 0:4359b47b3d7c 333 USB_INT32S rc;
slowness 0:4359b47b3d7c 334 int i;
slowness 0:4359b47b3d7c 335 volatile USB_INT08U *c = user_buffer;
slowness 0:4359b47b3d7c 336 for (i=0;i<MS_BlkSize*num_blocks;i++)
slowness 0:4359b47b3d7c 337 *c++ = 0;
slowness 0:4359b47b3d7c 338
slowness 0:4359b47b3d7c 339
slowness 0:4359b47b3d7c 340 Fill_MSCommand(block_number, MS_BlkSize, num_blocks, MS_DATA_DIR_IN, SCSI_CMD_READ_10, 10);
slowness 0:4359b47b3d7c 341
slowness 0:4359b47b3d7c 342 rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
slowness 0:4359b47b3d7c 343 if (rc == OK) {
slowness 0:4359b47b3d7c 344 rc = Host_ProcessTD(EDBulkIn, TD_IN, user_buffer, MS_BlkSize * num_blocks);
slowness 0:4359b47b3d7c 345 if (rc == OK) {
slowness 0:4359b47b3d7c 346 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
slowness 0:4359b47b3d7c 347 if (rc == OK) {
slowness 0:4359b47b3d7c 348 if (TDBuffer[12] != 0) {
slowness 0:4359b47b3d7c 349 rc = ERR_MS_CMD_FAILED;
slowness 0:4359b47b3d7c 350 }
slowness 0:4359b47b3d7c 351 }
slowness 0:4359b47b3d7c 352 }
slowness 0:4359b47b3d7c 353 }
slowness 0:4359b47b3d7c 354 return (rc);
slowness 0:4359b47b3d7c 355 }
slowness 0:4359b47b3d7c 356
slowness 0:4359b47b3d7c 357 /*
slowness 0:4359b47b3d7c 358 **************************************************************************************************************
slowness 0:4359b47b3d7c 359 * SEND BULK DATA
slowness 0:4359b47b3d7c 360 *
slowness 0:4359b47b3d7c 361 * Description: This function is used to send the bulk data
slowness 0:4359b47b3d7c 362 *
slowness 0:4359b47b3d7c 363 * Arguments : None
slowness 0:4359b47b3d7c 364 *
slowness 0:4359b47b3d7c 365 * Returns : OK if Success
slowness 0:4359b47b3d7c 366 * ERR_INVALID_BOOTSIG if Failed
slowness 0:4359b47b3d7c 367 *
slowness 0:4359b47b3d7c 368 **************************************************************************************************************
slowness 0:4359b47b3d7c 369 */
slowness 0:4359b47b3d7c 370
slowness 0:4359b47b3d7c 371 USB_INT32S MS_BulkSend ( USB_INT32U block_number,
slowness 0:4359b47b3d7c 372 USB_INT16U num_blocks,
slowness 0:4359b47b3d7c 373 volatile USB_INT08U *user_buffer)
slowness 0:4359b47b3d7c 374 {
slowness 0:4359b47b3d7c 375 USB_INT32S rc;
slowness 0:4359b47b3d7c 376
slowness 0:4359b47b3d7c 377
slowness 0:4359b47b3d7c 378 Fill_MSCommand(block_number, MS_BlkSize, num_blocks, MS_DATA_DIR_OUT, SCSI_CMD_WRITE_10, 10);
slowness 0:4359b47b3d7c 379
slowness 0:4359b47b3d7c 380 rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE);
slowness 0:4359b47b3d7c 381 if (rc == OK) {
slowness 0:4359b47b3d7c 382 rc = Host_ProcessTD(EDBulkOut, TD_OUT, user_buffer, MS_BlkSize * num_blocks);
slowness 0:4359b47b3d7c 383 if (rc == OK) {
slowness 0:4359b47b3d7c 384 rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE);
slowness 0:4359b47b3d7c 385 if (rc == OK) {
slowness 0:4359b47b3d7c 386 if (TDBuffer[12] != 0) {
slowness 0:4359b47b3d7c 387 rc = ERR_MS_CMD_FAILED;
slowness 0:4359b47b3d7c 388 }
slowness 0:4359b47b3d7c 389 }
slowness 0:4359b47b3d7c 390 }
slowness 0:4359b47b3d7c 391 }
slowness 0:4359b47b3d7c 392 return (rc);
slowness 0:4359b47b3d7c 393 }
slowness 0:4359b47b3d7c 394
slowness 0:4359b47b3d7c 395 /*
slowness 0:4359b47b3d7c 396 **************************************************************************************************************
slowness 0:4359b47b3d7c 397 * FILL MASS STORAGE COMMAND
slowness 0:4359b47b3d7c 398 *
slowness 0:4359b47b3d7c 399 * Description: This function is used to fill the mass storage command
slowness 0:4359b47b3d7c 400 *
slowness 0:4359b47b3d7c 401 * Arguments : None
slowness 0:4359b47b3d7c 402 *
slowness 0:4359b47b3d7c 403 * Returns : OK if Success
slowness 0:4359b47b3d7c 404 * ERR_INVALID_BOOTSIG if Failed
slowness 0:4359b47b3d7c 405 *
slowness 0:4359b47b3d7c 406 **************************************************************************************************************
slowness 0:4359b47b3d7c 407 */
slowness 0:4359b47b3d7c 408
slowness 0:4359b47b3d7c 409 void Fill_MSCommand (USB_INT32U block_number,
slowness 0:4359b47b3d7c 410 USB_INT32U block_size,
slowness 0:4359b47b3d7c 411 USB_INT16U num_blocks,
slowness 0:4359b47b3d7c 412 MS_DATA_DIR direction,
slowness 0:4359b47b3d7c 413 USB_INT08U scsi_cmd,
slowness 0:4359b47b3d7c 414 USB_INT08U scsi_cmd_len)
slowness 0:4359b47b3d7c 415 {
slowness 0:4359b47b3d7c 416 USB_INT32U data_len;
slowness 0:4359b47b3d7c 417 static USB_INT32U tag_cnt = 0;
slowness 0:4359b47b3d7c 418 USB_INT32U cnt;
slowness 0:4359b47b3d7c 419
slowness 0:4359b47b3d7c 420
slowness 0:4359b47b3d7c 421 for (cnt = 0; cnt < CBW_SIZE; cnt++) {
slowness 0:4359b47b3d7c 422 TDBuffer[cnt] = 0;
slowness 0:4359b47b3d7c 423 }
slowness 0:4359b47b3d7c 424 switch(scsi_cmd) {
slowness 0:4359b47b3d7c 425
slowness 0:4359b47b3d7c 426 case SCSI_CMD_TEST_UNIT_READY:
slowness 0:4359b47b3d7c 427 data_len = 0;
slowness 0:4359b47b3d7c 428 break;
slowness 0:4359b47b3d7c 429 case SCSI_CMD_READ_CAPACITY:
slowness 0:4359b47b3d7c 430 data_len = 8;
slowness 0:4359b47b3d7c 431 break;
slowness 0:4359b47b3d7c 432 case SCSI_CMD_REQUEST_SENSE:
slowness 0:4359b47b3d7c 433 data_len = 18;
slowness 0:4359b47b3d7c 434 break;
slowness 0:4359b47b3d7c 435 case SCSI_CMD_INQUIRY:
slowness 0:4359b47b3d7c 436 data_len = 36;
slowness 0:4359b47b3d7c 437 break;
slowness 0:4359b47b3d7c 438 default:
slowness 0:4359b47b3d7c 439 data_len = block_size * num_blocks;
slowness 0:4359b47b3d7c 440 break;
slowness 0:4359b47b3d7c 441 }
slowness 0:4359b47b3d7c 442 WriteLE32U(TDBuffer, CBW_SIGNATURE);
slowness 0:4359b47b3d7c 443 WriteLE32U(&TDBuffer[4], tag_cnt);
slowness 0:4359b47b3d7c 444 WriteLE32U(&TDBuffer[8], data_len);
slowness 0:4359b47b3d7c 445 TDBuffer[12] = (direction == MS_DATA_DIR_NONE) ? 0 : direction;
slowness 0:4359b47b3d7c 446 TDBuffer[14] = scsi_cmd_len; /* Length of the CBW */
slowness 0:4359b47b3d7c 447 TDBuffer[15] = scsi_cmd;
slowness 0:4359b47b3d7c 448 if ((scsi_cmd == SCSI_CMD_REQUEST_SENSE)
slowness 0:4359b47b3d7c 449 || (scsi_cmd == SCSI_CMD_INQUIRY)) {
slowness 0:4359b47b3d7c 450 TDBuffer[19] = (USB_INT08U)data_len;
slowness 0:4359b47b3d7c 451 } else {
slowness 0:4359b47b3d7c 452 WriteBE32U(&TDBuffer[17], block_number);
slowness 0:4359b47b3d7c 453 }
slowness 0:4359b47b3d7c 454 WriteBE16U(&TDBuffer[22], num_blocks);
slowness 0:4359b47b3d7c 455 }