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