USB_Standard_Requests.LST
上传用户:gxz1972
上传日期:2019-09-13
资源大小:323k
文件大小:22k
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 1
- C51 COMPILER V7.02b, COMPILATION OF MODULE USB_STANDARD_REQUESTS
- OBJECT MODULE PLACED IN USB_Standard_Requests.OBJ
- COMPILER INVOKED BY: C:KeilC51BINc51.exe USB_Standard_Requests.c DB OE
- stmt level source
- 1 //-----------------------------------------------------------------------------
- 2 // USB_Standard_Requests.c
- 3 //-----------------------------------------------------------------------------
- 4 // Copyright 2007 Vson Technology, Inc.
- 5 // http://www.usbmcu.com
- 6 //
- 7 // Program Description:
- 8 //
- 9 //
- 10 //
- 11 //
- 12 //
- 13 // MCU: C8051F347
- 14 // Tool chain: Keil C51 7.50 / Keil EVAL C51
- 15 // Silicon Laboratories IDE version 2.6
- 16 // Command Line:
- 17 // Project Name: TR1000
- 18 //
- 19 //
- 20 // Release 1.0
- 21 // -All changes by Brin Cai
- 22 // -24 JUL 2007
- 23 //
- 24 //
- 25
- 26 //-----------------------------------------------------------------------------
- 27 // Includes
- 28 //-----------------------------------------------------------------------------
- 29
- 30 #include "Include_H.h"
- 31
- 32 //-----------------------------------------------------------------------------
- 33 // USB_Standard_Requests.c Global Variables
- 34 //-----------------------------------------------------------------------------
- 35
- 36 BYTE bEpState;
- 37 UINT uNumBytes;
- 38 PIF_STATUS pIfStatus;
- 39
- 40
- 41 //------------------------------------------------------------------------
- 42 // Standard Request Routines
- 43 //------------------------------------------------------------------------
- 44 //
- 45 // These functions should be called when an endpoint0 command has
- 46 // been received with a corresponding "bRequest" field.
- 47 //
- 48 // - Each routine performs all command field checking, and
- 49 // modifies fields of the Ep0Status structure accordingly
- 50 //
- 51 // After a call to a standard request routine, the calling routine
- 52 // should check Ep0Status.bEpState to determine the required action
- 53 // (i.e., send a STALL for EP_ERROR, load the FIFO for EP_TX).
- 54 // For transmit status, the data pointer (Ep0Status.pData),
- 55 // and data length (Ep0Status.uNumBytes) are prepared before the
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 2
- 56 // standard request routine returns. The calling routine must write
- 57 // the data to the FIFO and handle all data transfer
- 58
- 59 //-----------------------------------------------------------------------------
- 60 // SetAddressRequest
- 61 //-----------------------------------------------------------------------------
- 62 //
- 63 // Return Value : None
- 64 // Parameters : None
- 65 //
- 66 //-----------------------------------------------------------------------------
- 67 void SetAddressRequest ()
- 68 {
- 69 1 // Index and Length fields must be zero
- 70 1 // Device state must be default or addressed
- 71 1 if ((gEp0Command.wIndex.i) || (gEp0Command.wLength.i) ||
- 72 1 (gDeviceStatus.bDevState == DEV_CONFIG))
- 73 1 {
- 74 2 bEpState = EP_ERROR;
- 75 2 }
- 76 1
- 77 1 else
- 78 1 {
- 79 2 // Assign new function address
- 80 2 UWRITE_BYTE(FADDR, gEp0Command.wValue.c[1]);
- 81 2 if (gDeviceStatus.bDevState == DEV_DEFAULT &&
- 82 2 gEp0Command.wValue.c[1] != 0)
- 83 2 {
- 84 3 gDeviceStatus.bDevState = DEV_ADDRESS;
- 85 3 }
- 86 2 if (gDeviceStatus.bDevState == DEV_ADDRESS &&
- 87 2 gEp0Command.wValue.c[1] == 0)
- 88 2 {
- 89 3 gDeviceStatus.bDevState = DEV_ADDRESS;
- 90 3 }
- 91 2 bEpState = EP_IDLE;
- 92 2 }
- 93 1 gEp0Status.bEpState = bEpState;
- 94 1 }
- 95
- 96 //-----------------------------------------------------------------------------
- 97 // SetFeatureRequest
- 98 //-----------------------------------------------------------------------------
- 99 //
- 100 // Return Value : None
- 101 // Parameters : None
- 102 //
- 103 //-----------------------------------------------------------------------------
- 104 void SetFeatureRequest ()
- 105 {
- 106 1 // Length field must be zero
- 107 1 // Device state must be configured, or addressed with Command Index
- 108 1 // field == 0
- 109 1 if ((gEp0Command.wLength.i != 0) ||
- 110 1 (gDeviceStatus.bDevState == DEV_DEFAULT) ||
- 111 1 (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
- 112 1 {
- 113 2 bEpState = EP_ERROR;
- 114 2 }
- 115 1
- 116 1 // Handle based on recipient
- 117 1 switch(gEp0Command.bmRequestType & CMD_MASK_RECIP)
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 3
- 118 1 {
- 119 2 // Device Request - Return error as remote wakeup is not supported
- 120 2 case CMD_RECIP_DEV:
- 121 2 bEpState = EP_ERROR;
- 122 2 break;
- 123 2
- 124 2 // Endpoint Request
- 125 2 case CMD_RECIP_EP:
- 126 2 if (gEp0Command.wValue.i == ENDPOINT_HALT)
- 127 2 {
- 128 3 bEpState = HaltEndpoint(gEp0Command.wIndex.i);
- 129 3 break;
- 130 3 }
- 131 2 else
- 132 2 {
- 133 3 bEpState = EP_ERROR;
- 134 3 break;
- 135 3 }
- 136 2 default:
- 137 2 bEpState = EP_ERROR;
- 138 2 break;
- 139 2 }
- 140 1 gEp0Status.bEpState = bEpState;
- 141 1 }
- 142
- 143 //-----------------------------------------------------------------------------
- 144 // ClearFeatureRequest
- 145 //-----------------------------------------------------------------------------
- 146 //
- 147 // Return Value : None
- 148 // Parameters : None
- 149 //
- 150 //-----------------------------------------------------------------------------
- 151 void ClearFeatureRequest ()
- 152 {
- 153 1 // Length field must be zero
- 154 1 // Device state must be configured, or addressed with Command Index
- 155 1 // field == 0
- 156 1 if ((gEp0Command.wLength.i != 0) || (gDeviceStatus.bDevState == DEV_DEFAULT) ||
- 157 1 (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
- 158 1 {
- 159 2 bEpState = EP_ERROR;
- 160 2 }
- 161 1
- 162 1 // Handle based on recipient
- 163 1 switch(gEp0Command.bmRequestType & CMD_MASK_RECIP)
- 164 1 {
- 165 2 // Device Request
- 166 2 case CMD_RECIP_DEV:
- 167 2 // Remote wakeup not supported
- 168 2 bEpState = EP_ERROR;
- 169 2 break;
- 170 2
- 171 2 // Endpoint Request
- 172 2 case CMD_RECIP_EP:
- 173 2 if (gEp0Command.wValue.i == ENDPOINT_HALT)
- 174 2 {
- 175 3 // Enable the selected endpoint.
- 176 3 bEpState = EnableEndpoint(gEp0Command.wIndex.i);
- 177 3 break;
- 178 3 }
- 179 2 else
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 4
- 180 2 {
- 181 3 bEpState = EP_ERROR;
- 182 3 break;
- 183 3 }
- 184 2 default:
- 185 2 bEpState = EP_ERROR;
- 186 2 break;
- 187 2 }
- 188 1 gEp0Status.bEpState = bEpState;
- 189 1 }
- 190
- 191 //-----------------------------------------------------------------------------
- 192 // SetConfigurationRequest
- 193 //-----------------------------------------------------------------------------
- 194 //
- 195 // Return Value : None
- 196 // Parameters : None
- 197 //
- 198 //-----------------------------------------------------------------------------
- 199 void SetConfigurationRequest ()
- 200 {
- 201 1 // Index and Length fields must be zero
- 202 1 // Device state must be addressed or configured
- 203 1 if ((gEp0Command.wIndex.i) || (gEp0Command.wLength.i) ||
- 204 1 (gDeviceStatus.bDevState == DEV_DEFAULT))
- 205 1 {
- 206 2 bEpState = EP_ERROR;
- 207 2 }
- 208 1
- 209 1 else
- 210 1 {
- 211 2 // Make sure assigned configuration exists
- 212 2 if (gEp0Command.wValue.c[1] >
- 213 2 gDescriptorMap.bStdDevDsc[std_bNumConfigurations])
- 214 2 {
- 215 3 bEpState = EP_ERROR;
- 216 3 }
- 217 2
- 218 2 // Handle zero configuration assignment
- 219 2 else if (gEp0Command.wValue.c[1] == 0)
- 220 2 gDeviceStatus.bDevState = DEV_ADDRESS;
- 221 2
- 222 2 // Select the assigned configuration
- 223 2 else
- 224 2 bEpState = SetConfiguration(gEp0Command.wValue.c[1]);
- 225 2 }
- 226 1 gEp0Status.bEpState = bEpState;
- 227 1 }
- 228
- 229
- 230 //-----------------------------------------------------------------------------
- 231 // SetInterfaceRequest
- 232 //-----------------------------------------------------------------------------
- 233 //
- 234 // Return Value : None
- 235 // Parameters : None
- 236 //
- 237 //-----------------------------------------------------------------------------
- 238 void SetInterfaceRequest()
- 239 {
- 240 1 /*
- 241 1 // Length field must be zero
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 5
- 242 1 if ((gEp0Command.wLength.i) || (gDeviceStatus.bDevState != DEV_CONFIG))
- 243 1 bEpState = EP_ERROR;
- 244 1
- 245 1 else
- 246 1 {
- 247 1 // Check that target interface exists for this configuration
- 248 1 if(gEp0Command.wIndex.i > gDeviceStatus.bNumInterf - 1)
- 249 1 bEpState = EP_ERROR;
- 250 1
- 251 1 else
- 252 1 {
- 253 1 // Get pointer to interface status structure
- 254 1 pIfStatus = (PIF_STATUS)&gDeviceStatus.IfStatus;
- 255 1
- 256 1 // Check that alternate setting exists for the interface
- 257 1 if (gEp0Command.wValue.i > pIfStatus->bNumAlts)
- 258 1 bEpState = EP_ERROR;
- 259 1
- 260 1 // Assign alternate setting
- 261 1 else
- 262 1 {
- 263 1 pIfStatus->bCurrentAlt = gEp0Command.wValue.i;
- 264 1 bEpState = SetInterface(pIfStatus);
- 265 1 }
- 266 1 }
- 267 1 }
- 268 1 gEp0Status.bEpState = bEpState;
- 269 1 */
- 270 1 }
- 271
- 272 //-----------------------------------------------------------------------------
- 273 // GetStatusRequest
- 274 //-----------------------------------------------------------------------------
- 275 //
- 276 // Return Value : None
- 277 // Parameters : None
- 278 //
- 279 //-----------------------------------------------------------------------------
- 280 void GetStatusRequest ()
- 281 {
- 282 1 // Value field must be zero; Length field must be 2
- 283 1 if ((gEp0Command.wValue.i != 0) || (gEp0Command.wLength.i != 0x02) ||
- 284 1 (gDeviceStatus.bDevState == DEV_DEFAULT) ||
- 285 1 (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
- 286 1 {
- 287 2 bEpState = EP_ERROR;
- 288 2 }
- 289 1
- 290 1 else
- 291 1 {
- 292 2 // Check for desired status (device, interface, endpoint)
- 293 2 switch (gEp0Command.bmRequestType & CMD_MASK_RECIP)
- 294 2 {
- 295 3 // Device
- 296 3 case CMD_RECIP_DEV:
- 297 3 // Index must be zero for a Device status request
- 298 3 if (gEp0Command.wIndex.i != 0)
- 299 3 bEpState = EP_ERROR;
- 300 3 else
- 301 3 {
- 302 4 // Prepare data_out for transmission
- 303 4 gEp0Status.wData.c[1] = 0;
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 6
- 304 4 gEp0Status.wData.c[0] = gDeviceStatus.bRemoteWakeupStatus;
- 305 4 gEp0Status.wData.c[0] |= gDeviceStatus.bSelfPoweredStatus;
- 306 4 }
- 307 3 break;
- 308 3
- 309 3 // Interface
- 310 3 case CMD_RECIP_IF:
- 311 3 // Prepare data_out for transmission
- 312 3 gEp0Status.wData.i = 0;
- 313 3 break;
- 314 3
- 315 3 // Endpoint
- 316 3 case CMD_RECIP_EP:
- 317 3 // Prepare data_out for transmission
- 318 3 gEp0Status.wData.i = 0;
- 319 3 if (GetEpStatus(gEp0Command.wIndex.i) == EP_HALTED)
- 320 3 gEp0Status.wData.c[0] |= 0x01;
- 321 3 break;
- 322 3
- 323 3 // Other cases unsupported
- 324 3 default:
- 325 3 bEpState = EP_ERROR;
- 326 3 break;
- 327 3 }
- 328 2
- 329 2 // Endpoint0 state assignment
- 330 2 bEpState = EP_TX;
- 331 2
- 332 2 // Point ep0 data pointer to transmit data_out
- 333 2 gEp0Status.pData = (BYTE *)&gEp0Status.wData.i;
- 334 2 gEp0Status.uNumBytes = 2;
- 335 2 }
- 336 1 gEp0Status.bEpState = bEpState;
- 337 1 }
- 338
- 339 //-----------------------------------------------------------------------------
- 340 // GetDescriptorRequest
- 341 //-----------------------------------------------------------------------------
- 342 //
- 343 // Return Value : None
- 344 // Parameters : None
- 345 //
- 346 //-----------------------------------------------------------------------------
- 347 void GetDescriptorRequest ()
- 348 {
- 349 1 WORD wTempInt;
- 350 1
- 351 1 // This request is valid in all device states
- 352 1 // Switch on requested descriptor (Value field)
- 353 1 switch (gEp0Command.wValue.c[0])
- 354 1 {
- 355 2 // Device Descriptor Request
- 356 2 case DSC_DEVICE:
- 357 2 // Get size of the requested descriptor
- 358 2 uNumBytes = STD_DSC_SIZE;
- 359 2 // Prep to send the requested length
- 360 2 if (uNumBytes > gEp0Command.wLength.i)
- 361 2 {
- 362 3 uNumBytes = gEp0Command.wLength.i;
- 363 3 }
- 364 2 // Point data pointer to the requested descriptor
- 365 2 gEp0Status.pData = (void*)&gDescriptorMap.bStdDevDsc;
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 7
- 366 2 bEpState = EP_TX;
- 367 2 break;
- 368 2
- 369 2 // Configuration Descriptor Request
- 370 2 case DSC_CONFIG:
- 371 2 // Make sure requested descriptor exists
- 372 2 if (gEp0Command.wValue.c[1] >
- 373 2 gDescriptorMap.bStdDevDsc[std_bNumConfigurations])
- 374 2 {
- 375 3 bEpState = EP_ERROR;
- 376 3 }
- 377 2 else
- 378 2 {
- 379 3 // Get total length of this configuration descriptor
- 380 3 // (includes all associated interface and endpoints)
- 381 3 wTempInt.c[1] = gDescriptorMap.bCfg1[cfg_wTotalLength_lsb];
- 382 3 wTempInt.c[0] = gDescriptorMap.bCfg1[cfg_wTotalLength_msb];
- 383 3 uNumBytes = wTempInt.i;
- 384 3
- 385 3 // Prep to transmit the requested length
- 386 3 if (uNumBytes > gEp0Command.wLength.i)
- 387 3 {
- 388 4 uNumBytes = gEp0Command.wLength.i;
- 389 4 }
- 390 3 // Point data pointer to requested descriptor
- 391 3 gEp0Status.pData = &gDescriptorMap.bCfg1;
- 392 3 bEpState = EP_TX;
- 393 3 }
- 394 2 break;
- 395 2 }
- 396 1 gEp0Status.uNumBytes = uNumBytes;
- 397 1 gEp0Status.bEpState = bEpState;
- 398 1 }
- 399
- 400 //-----------------------------------------------------------------------------
- 401 // GetConfigurationRequest
- 402 //-----------------------------------------------------------------------------
- 403 //
- 404 // Return Value : None
- 405 // Parameters : None
- 406 //
- 407 //-----------------------------------------------------------------------------
- 408 void GetConfigurationRequest ()
- 409 {
- 410 1 // Length field must be 1; Index field must be 0;
- 411 1 // Value field must be 0
- 412 1 if ((gEp0Command.wLength.i != 1) || (gEp0Command.wIndex.i) ||
- 413 1 (gEp0Command.wValue.i) || (gDeviceStatus.bDevState == DEV_DEFAULT))
- 414 1 {
- 415 2 bEpState = EP_ERROR;
- 416 2 }
- 417 1
- 418 1 else if (gDeviceStatus.bDevState == DEV_ADDRESS)
- 419 1 {
- 420 2 // Prepare data_out for transmission
- 421 2 gEp0Status.wData.i = 0;
- 422 2 // Point ep0 data pointer to transmit data_out
- 423 2 gEp0Status.pData = (BYTE *)&gEp0Status.wData.i;
- 424 2 // ep0 state assignment
- 425 2 bEpState = EP_TX;
- 426 2 }
- 427 1
- C51 COMPILER V7.02b USB_STANDARD_REQUESTS 11/30/2007 14:07:13 PAGE 8
- 428 1 else
- 429 1 {
- 430 2 // Index to desired field
- 431 2 gEp0Status.pData = (void *)&gDescriptorMap.bCfg1[cfg_bConfigurationValue];
- 432 2
- 433 2 // ep0 state assignment
- 434 2 bEpState = EP_TX;
- 435 2 }
- 436 1 gEp0Status.uNumBytes = 1;
- 437 1 gEp0Status.bEpState = bEpState;
- 438 1 }
- 439
- 440 //-----------------------------------------------------------------------------
- 441 // GetInterfaceRequest
- 442 //-----------------------------------------------------------------------------
- 443 //
- 444 // Return Value : None
- 445 // Parameters : None
- 446 //
- 447 //-----------------------------------------------------------------------------
- 448 void GetInterfaceRequest ()
- 449 {
- 450 1 // Value field must be 0; Length field must be 1
- 451 1 if ((gEp0Command.wValue.i) || (gEp0Command.wLength.i != 1) ||
- 452 1 (gDeviceStatus.bDevState != DEV_CONFIG))
- 453 1 {
- 454 2 bEpState = EP_ERROR;
- 455 2 }
- 456 1
- 457 1 else
- 458 1 {
- 459 2 // Make sure requested interface exists
- 460 2 if (gEp0Command.wIndex.i > gDeviceStatus.bNumInterf - 1)
- 461 2 bEpState = EP_ERROR;
- 462 2 else
- 463 2 {
- 464 3 // Get current interface setting
- 465 3 gEp0Status.pData = (void *)&gDeviceStatus.IfStatus->bCurrentAlt;
- 466 3
- 467 3 // Length must be 1
- 468 3 gEp0Status.uNumBytes = 1;
- 469 3 bEpState = EP_TX;
- 470 3 }
- 471 2 }
- 472 1 gEp0Status.bEpState = bEpState;
- 473 1 }
- 474
- 475 //-----------------------------------------------------------------------------
- 476 // End Of File
- 477 //-----------------------------------------------------------------------------
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 608 ----
- CONSTANT SIZE = ---- ----
- XDATA SIZE = ---- ----
- PDATA SIZE = ---- ----
- DATA SIZE = 6 2
- IDATA SIZE = ---- ----
- BIT SIZE = ---- ----
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)