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