USB_Utilities.LST
上传用户:gxz1972
上传日期:2019-09-13
资源大小:323k
文件大小:16k
- C51 COMPILER V7.02b USB_UTILITIES 11/30/2007 14:07:14 PAGE 1
- C51 COMPILER V7.02b, COMPILATION OF MODULE USB_UTILITIES
- OBJECT MODULE PLACED IN USB_Utilities.OBJ
- COMPILER INVOKED BY: C:KeilC51BINc51.exe USB_Utilities.c DB OE
- stmt level source
- 1 //-----------------------------------------------------------------------------
- 2 // USB_Utilities.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
- 28 #include "Include_H.h"
- 29
- 30 //-----------------------------------------------------------------------------
- 31 // HaltEndpoint
- 32 //-----------------------------------------------------------------------------
- 33 //
- 34 // Return Value : None
- 35 // Parameters :
- 36 // 1) UINT uEp
- 37 //
- 38 //-----------------------------------------------------------------------------
- 39 BYTE HaltEndpoint (UINT uEp)
- 40 {
- 41 1 BYTE bReturnState, bIndex;
- 42 1
- 43 1 // Save current INDEX value and target selected endpoint
- 44 1 UREAD_BYTE (INDEX, bIndex);
- 45 1 UWRITE_BYTE (INDEX, (BYTE)uEp & 0x00EF);
- 46 1
- 47 1 // Halt selected endpoint and update its status flag
- 48 1 switch (uEp)
- 49 1 {
- 50 2 case EP1_IN:
- 51 2 UWRITE_BYTE (EINCSRL, rbInSDSTL);
- 52 2 gEp1InStatus.bEpState = EP_HALTED;
- 53 2 bReturnState = EP_IDLE; // Return success flag
- 54 2 break;
- 55 2 case EP2_OUT:
- C51 COMPILER V7.02b USB_UTILITIES 11/30/2007 14:07:14 PAGE 2
- 56 2 UWRITE_BYTE (EOUTCSRL, rbOutSDSTL);
- 57 2 gEp2OutStatus.bEpState = EP_HALTED;
- 58 2 bReturnState = EP_IDLE; // Return success flag
- 59 2 break;
- 60 2 default:
- 61 2 bReturnState = EP_ERROR; // Return error flag
- 62 2 // if endpoint not found
- 63 2 break;
- 64 2 }
- 65 1
- 66 1 UWRITE_BYTE (INDEX, bIndex); // Restore saved INDEX
- 67 1 return bReturnState;
- 68 1 }
- 69
- 70 //-----------------------------------------------------------------------------
- 71 // EnableEndpoint
- 72 //-----------------------------------------------------------------------------
- 73 //
- 74 // Return Value : None
- 75 // Parameters :
- 76 // 1) UINT uEp
- 77 //
- 78 //-----------------------------------------------------------------------------
- 79 BYTE EnableEndpoint (UINT uEp)
- 80 {
- 81 1 BYTE bReturnState, bIndex;
- 82 1
- 83 1 // Save current INDEX value and target selected endpoint
- 84 1 UREAD_BYTE (INDEX, bIndex);
- 85 1 UWRITE_BYTE (INDEX, (BYTE)uEp & 0x00EF);
- 86 1
- 87 1 // Flag selected endpoint has HALTED
- 88 1 switch (uEp)
- 89 1 {
- 90 2 case EP1_IN:
- 91 2 // Disable STALL condition and clear the data toggle
- 92 2 UWRITE_BYTE (EINCSRL, rbInCLRDT);
- 93 2 gEp1InStatus.bEpState = EP_IDLE; // Return success
- 94 2 bReturnState = EP_IDLE;
- 95 2 break;
- 96 2 case EP2_OUT:
- 97 2 // Disable STALL condition and clear the data toggle
- 98 2 UWRITE_BYTE (EOUTCSRL, rbOutCLRDT);
- 99 2 gEp2OutStatus.bEpState = EP_IDLE;// Return success
- 100 2 bReturnState = EP_IDLE;
- 101 2 break;
- 102 2 default:
- 103 2 bReturnState = EP_ERROR; // Return error
- 104 2 // if no endpoint found
- 105 2 break;
- 106 2 }
- 107 1
- 108 1 UWRITE_BYTE (INDEX, bIndex); // Restore INDEX
- 109 1
- 110 1 return bReturnState;
- 111 1 }
- 112
- 113 //-----------------------------------------------------------------------------
- 114 // GetEpStatus
- 115 //-----------------------------------------------------------------------------
- 116 //
- 117 // Return Value : None
- C51 COMPILER V7.02b USB_UTILITIES 11/30/2007 14:07:14 PAGE 3
- 118 // Parameters :
- 119 // 1) UINT uEp
- 120 //
- 121 //-----------------------------------------------------------------------------
- 122 BYTE GetEpStatus (UINT uEp)
- 123 {
- 124 1 BYTE bReturnState;
- 125 1
- 126 1 // Get selected endpoint status
- 127 1 switch (uEp)
- 128 1 {
- 129 2 case EP1_IN:
- 130 2 bReturnState = gEp1InStatus.bEpState;
- 131 2 break;
- 132 2 case EP2_OUT:
- 133 2 bReturnState = gEp2OutStatus.bEpState;
- 134 2 break;
- 135 2 default:
- 136 2 bReturnState = EP_ERROR;
- 137 2 break;
- 138 2 }
- 139 1
- 140 1 return bReturnState;
- 141 1 }
- 142
- 143 //-----------------------------------------------------------------------------
- 144 // SetConfiguration
- 145 //-----------------------------------------------------------------------------
- 146 //
- 147 // Return Value : None
- 148 // Parameters :
- 149 // 1) BYTE SelectConfig
- 150 //
- 151 //-----------------------------------------------------------------------------
- 152 BYTE SetConfiguration(BYTE SelectConfig)
- 153 {
- 154 1 BYTE bReturnState = EP_IDLE; // Endpoint state return value
- 155 1
- 156 1 PIF_STATUS pIfStatus; // Pointer to interface status
- 157 1 // structure
- 158 1
- 159 1 // Store address of selected config desc
- 160 1 gDeviceStatus.pConfig = &gDescriptorMap.bCfg1;
- 161 1
- 162 1 // Confirm that this configuration descriptor matches the requested
- 163 1 // configuration value
- 164 1 if (gDeviceStatus.pConfig[cfg_bConfigurationValue] != SelectConfig)
- 165 1 {
- 166 2 bReturnState = EP_ERROR;
- 167 2 }
- 168 1
- 169 1 else
- 170 1 {
- 171 2 // Store number of interfaces for this configuration
- 172 2 gDeviceStatus.bNumInterf = gDeviceStatus.pConfig[cfg_bNumInterfaces];
- 173 2
- 174 2 // Store total number of interface descriptors for this configuration
- 175 2 gDeviceStatus.bTotalInterfDsc = MAX_IF;
- 176 2
- 177 2 // Get pointer to the interface status structure
- 178 2 pIfStatus = (PIF_STATUS)&gDeviceStatus.IfStatus[0];
- 179 2
- C51 COMPILER V7.02b USB_UTILITIES 11/30/2007 14:07:14 PAGE 4
- 180 2 // Build Interface status structure for Interface0
- 181 2 pIfStatus->bIfNumber = 0; // Set interface number
- 182 2 pIfStatus->bCurrentAlt = 0; // Select alternate number zero
- 183 2 pIfStatus->bNumAlts = 0; // No other alternates
- 184 2
- 185 2 SetInterface(pIfStatus); // Configure Interface0, Alternate0
- 186 2
- 187 2 gDeviceStatus.bDevState = DEV_CONFIG;// Set device state to configured
- 188 2 gDeviceStatus.bCurrentConfig = SelectConfig;// Store current config
- 189 2 }
- 190 1
- 191 1 return bReturnState;
- 192 1 }
- 193
- 194 //-----------------------------------------------------------------------------
- 195 // SetInterface
- 196 //-----------------------------------------------------------------------------
- 197 //
- 198 // Return Value : None
- 199 // Parameters :
- 200 // 1) PIF_STATUS pIfStatus
- 201 //
- 202 //-----------------------------------------------------------------------------
- 203 BYTE SetInterface(PIF_STATUS pIfStatus)
- 204 {
- 205 1 BYTE bReturnState = EP_IDLE;
- 206 1 BYTE bIndex;
- 207 1
- 208 1 // Save current INDEX value
- 209 1 UREAD_BYTE (INDEX, bIndex);
- 210 1
- 211 1 // Add actions for each possible interface alternate selections
- 212 1 switch(pIfStatus->bIfNumber)
- 213 1 {
- 214 2 // Configure endpoints for interface0
- 215 2 case 0:
- 216 2 // Configure Endpoint1 IN
- 217 2 UWRITE_BYTE(INDEX, 1); // Index to Endpoint1 registers
- 218 2
- 219 2 // direction = IN ; Double-buffering enabled
- 220 2 UWRITE_BYTE(EINCSRH, (rbInDIRSEL | rbInDBIEN));
- 221 2 gEp1InStatus.uNumBytes = 0; // Reset byte counter
- 222 2 gEp1InStatus.uMaxP = EP1_IN_MAXP;// Set maximum packet size
- 223 2 gEp1InStatus.bEp = EP1_IN; // Set endpoint address
- 224 2 gEp1InStatus.bEpState = EP_IDLE; // Set endpoint state
- 225 2
- 226 2 // Endpoint2 OUT
- 227 2 UWRITE_BYTE(INDEX, 2); // Index to Endpoint2 registers
- 228 2 // Double-buffering enabled ; direction = OUT
- 229 2 UWRITE_BYTE(EOUTCSRH, rbOutDBOEN);
- 230 2 gEp2OutStatus.uNumBytes = 0; // Reset byte counter
- 231 2 gEp2OutStatus.uMaxP = EP2_OUT_MAXP;// Set maximum packet size
- 232 2 gEp2OutStatus.bEp = EP2_OUT; // Set endpoint number
- 233 2 gEp2OutStatus.bEpState = EP_IDLE;// Set endpoint state
- 234 2
- 235 2 UWRITE_BYTE(INDEX, 0); // Return to index 0
- 236 2
- 237 2 break;
- 238 2
- 239 2 // Configure endpoints for interface1
- 240 2 case 1:
- 241 2
- C51 COMPILER V7.02b USB_UTILITIES 11/30/2007 14:07:14 PAGE 5
- 242 2 // Configure endpoints for interface2
- 243 2 case 2:
- 244 2
- 245 2 // Default (error)
- 246 2 default:
- 247 2 bReturnState = EP_ERROR;
- 248 2 }
- 249 1 UWRITE_BYTE (INDEX, bIndex); // Restore INDEX
- 250 1
- 251 1 return bReturnState;
- 252 1 }
- 253
- 254 //-----------------------------------------------------------------------------
- 255 // SetInterface
- 256 //-----------------------------------------------------------------------------
- 257 //
- 258 // Return Value : None
- 259 // Parameters :
- 260 // 1) BYTE bEp
- 261 // 2) UINT uNumBytes
- 262 // 3) BYTE * pData
- 263 //
- 264 // Read from the selected endpoint FIFO
- 265 //
- 266 //-----------------------------------------------------------------------------
- 267 void FIFORead (BYTE bEp, UINT uNumBytes, BYTE * pData)
- 268 {
- 269 1 BYTE TargetReg;
- 270 1 UINT i;
- 271 1
- 272 1 // If >0 bytes requested,
- 273 1 if (uNumBytes)
- 274 1 {
- 275 2 TargetReg = FIFO_EP0 + bEp; // Find address for target
- 276 2 // endpoint FIFO
- 277 2
- 278 2 USB0ADR = (TargetReg & 0x3F); // Set address (mask out bits7-6)
- 279 2 USB0ADR |= 0xC0; // Set auto-read and initiate
- 280 2 // first read
- 281 2
- 282 2 // Unload <NumBytes> from the selected FIFO
- 283 2
- 284 2 //Read NumBytes-1
- 285 2 for(i=0;i<uNumBytes-1;i++)
- 286 2 {
- 287 3 while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
- 288 3 pData[i] = USB0DAT; // Copy data byte
- 289 3 }
- 290 2
- 291 2 //Read the last byte
- 292 2 while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
- 293 2 pData[i] = USB0DAT; // Copy data byte
- 294 2 USB0ADR = 0; // Clear auto-read
- 295 2 }
- 296 1 }
- 297
- 298 //-----------------------------------------------------------------------------
- 299 // FIFOWrite
- 300 //-----------------------------------------------------------------------------
- 301 //
- 302 // Return Value : None
- 303 // Parameters :
- C51 COMPILER V7.02b USB_UTILITIES 11/30/2007 14:07:14 PAGE 6
- 304 // 1) BYTE bEp
- 305 // 2) UINT uNumBytes
- 306 // 3) BYTE * pData
- 307 //
- 308 // Write to the selected endpoint FIFO
- 309 //
- 310 //-----------------------------------------------------------------------------
- 311 void FIFOWrite (BYTE bEp, UINT uNumBytes, BYTE * pData)
- 312 {
- 313 1 BYTE TargetReg;
- 314 1 UINT i;
- 315 1
- 316 1 // If >0 bytes requested,
- 317 1 if (uNumBytes)
- 318 1 {
- 319 2 TargetReg = FIFO_EP0 + bEp; // Find address for target //FIO_EP0==0X20
- 320 2 // endpoint FIFO
- 321 2
- 322 2 while(USB0ADR & 0x80); // Wait for BUSY->'0'
- 323 2 // (register available)
- 324 2 USB0ADR = (TargetReg & 0x3F); // Set address (mask out bits7-6)
- 325 2
- 326 2 // Write <NumBytes> to the selected FIFO
- 327 2 for(i=0;i<uNumBytes;i++)
- 328 2 {
- 329 3 USB0DAT = pData[i];
- 330 3 while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
- 331 3 }
- 332 2 }
- 333 1 }
- 334
- 335 //-----------------------------------------------------------------------------
- 336 // End Of File
- 337 //-----------------------------------------------------------------------------
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 566 ----
- CONSTANT SIZE = ---- ----
- XDATA SIZE = ---- ----
- PDATA SIZE = ---- ----
- DATA SIZE = ---- 12
- IDATA SIZE = ---- ----
- BIT SIZE = ---- ----
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)