interface to chr_6dm and Baro bmp085

Dependencies:   mbed

Committer:
belloula
Date:
Mon Oct 17 19:43:06 2011 +0000
Revision:
0:d07617f8ede9

        

Who changed what in which revision?

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