chap_9.LST
资源名称:USB_2.0.rar [点击查看]
上传用户:ids068
上传日期:2013-04-04
资源大小:639k
文件大小:73k
源码类别:
USB编程
开发平台:
C/C++
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 1
- C51 COMPILER V7.06, COMPILATION OF MODULE CHAP_9
- OBJECT MODULE PLACED IN chap_9.OBJ
- COMPILER INVOKED BY: C:KEILC51BINC51.EXE chap_9.c OPTIMIZE(2,SPEED) BROWSE DEBUG OBJECTEXTEND
- stmt level source
- 1 //***********************************************************************
- 2 // *
- 3 // P H I L I P S P R O P R I E T A R Y *
- 4 // *
- 5 // COPYRIGHT (c) 1999 BY PHILIPS SINGAPORE (APIC). *
- 6 // -- ALL RIGHTS RESERVED -- *
- 7 // *
- 8 // File Name : USBDebug.c *
- 9 // Author : Albert Goh *
- 10 // Created : 3 March 2000 *
- 11 // *
- 12 //***********************************************************************
- 13 //***********************************************************************
- 14 // *
- 15 // USBDebug has the ability to test the USB core in Bus enumeration or *
- 16 // in CBI/bulk mode. *
- 17 // *
- 18 //***********************************************************************
- 19 //***********************************************************************
- 20 // *
- 21 // Module History *
- 22 // ************** *
- 23 // *
- 24 // Date Version Author Changes *
- 25 // ==== ======= ====== ======= *
- 26 // 030300 0.1 Albert Created *
- 27 // *
- 28 //***********************************************************************
- 29
- 30 //***********************************************************************
- 31 //* *
- 32 //* Include Files Definition *
- 33 //* *
- 34 //***********************************************************************
- 35
- 36 #include "standard.h"
- 37 #include "Kernel.h"
- 38 #include "D14.h"
- 39 #include "usb.h"
- 40
- 41 extern volatile D14_CNTRL_REG xdata D14_Cntrl_Reg;
- 42 extern void Init_D14(void);
- 43 extern UC code Standard_Device_Descriptor[];
- 44 extern UC code Bulk_Interface_Descriptor[];
- 45 extern UC code Iso_Interface_Descriptor[];
- 46 extern UC code Standard_Config_Descriptor[];
- 47 extern UC code Standard_Manufacturer_String[];
- 48 extern UC code Standard_Product_String[];
- 49 extern UC code Standard_String_ID[];
- 50 extern UC code Bulk_In_Descriptor[];
- 51 extern UC code Bulk_Out_Descriptor[];
- 52 extern UC code Int_In_Descriptor[];
- 53 extern UC code Int_Out_Descriptor[];
- 54 extern UC code Iso_In_Descriptor[];
- 55 extern UC code Iso_Out_Descriptor[];
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 2
- 56 extern UC code Iso_In_Zero_Descriptor[];
- 57 extern UC code Iso_Out_Zero_Descriptor[];
- 58 extern UC code HS_Device_Descriptor[];
- 59 extern UC code HS_Device_Qualifier[];
- 60 extern UC code HS_Bulk_Interface_Descriptor[];
- 61 extern UC code HS_Bulk_In_Descriptor[];
- 62 extern UC code HS_Bulk_Out_Descriptor[];
- 63 extern UC code HS_Int_In_Descriptor[];
- 64 extern UC code HS_Int_Out_Descriptor[];
- 65 extern UC code Other_Speed_Config_Descriptor[];
- 66 extern UI count;
- 67 extern void Start_mSEC_Timer(Data);
- 68 extern void Start_SEC_Timer(Data);
- 69 extern void Check_Busy(void);
- 70 extern void TaskFile_Update(void);
- 71 extern UI Temp;
- 72 extern UC Device_Config_Value;
- 73 extern KERNEL Kernel_Flag;
- 74 extern DMA_INT_FLAG DMA_Int_Flag;
- 75 extern USB_INT_FLAG USB_Int_Flag;
- 76 extern USBCBW USB_CBW;
- 77 extern void Init_Device(void);
- 78 extern UC code Test_Packet[];
- 79 extern void Init_Endpoint(void);
- 80 extern void Init_Device(void);
- 81 extern void Set_USB(void);
- 82
- 83 //***********************************************************************
- 84 //* *
- 85 //* Prototype Routine Definition *
- 86 //* *
- 87 //***********************************************************************
- 88
- 89 void USB_Setup(void);
- 90 void reserved(void);
- 91 void Send_Device_Status(void);
- 92 void Send_Interface_Status(void);
- 93 void Send_Endpoint_Status(void);
- 94
- 95 void Vendor_Specific_Command(void);
- 96 void Send_Status(unsigned char tran_status);
- 97
- 98 void Set_Interface_Value(void);
- 99 void Get_Interface_Value(void);
- 100 void Process_Synch_Frame(void);
- 101
- 102 void get_status(void);
- 103 void clear_feature(void);
- 104 void set_feature(void);
- 105 void set_address(void);
- 106 void get_descriptor(void);
- 107 void get_config(void);
- 108 void set_config(void);
- 109 void get_interface(void);
- 110 void set_interface(void);
- 111
- 112 void Set_Descriptor(void);
- 113 void reserved(void);
- 114
- 115 void ep0in_ack(void);
- 116 void ep0out_ack(void);
- 117 void wait_ep0tx(void);
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 3
- 118 void wait_ep0rx(void);
- 119
- 120 //***********************************************************************
- 121 //* *
- 122 //* Variable Definition *
- 123 //* *
- 124 //***********************************************************************
- 125
- 126 USB_INT_FLAG USB_Int_Flag;
- 127 USB_DEVICE_REQ idata USB_Device_Request;
- 128 USB_DEVICE USB_Device;
- 129
- 130 UC code *Descriptor_Ptr;
- 131
- 132 UC idata Endpt_FIFO[MAX_BUF];
- 133 UI FIFO_Count;
- 134 UC VID[2],PID[2];
- 135 FILESIZE FileSize;
- 136 UI PIO_Count;
- 137 UC File_Number;
- 138 UC Current_File;
- 139 ULI bytecount;
- 140
- 141 //USB标准请求
- 142 code void (*StandardDeviceRequest[])(void) =
- 143 {
- 144 get_status,
- 145 clear_feature,
- 146 reserved,
- 147 set_feature,
- 148 reserved,
- 149 set_address,
- 150 get_descriptor,
- 151 reserved,
- 152 get_config,
- 153 set_config,
- 154 get_interface,
- 155 set_interface,
- 156 reserved,
- 157 reserved,
- 158 reserved,
- 159 reserved
- 160 };
- 161
- 162
- 163
- 164 //***********************************************************************
- 165 //* *
- 166 //* Routine Definition *
- 167 //* *
- 168 //***********************************************************************
- 169
- 170 //***********************************************************************
- 171 //* *
- 172 //* Routine : USB Debug Mode *
- 173 //* Input : USB Interrupt Register *
- 174 //* Output : None *
- 175 //* Function : Branch to respective ISR *
- 176 //* *
- 177 //***********************************************************************
- 178
- 179 void USB_Debug_Mode(void)
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 4
- 180 {
- 181 1 //端点0接收到setup包处理
- 182 1 if(USB_Int_Flag.BITS.EP0SETUP)
- 183 1 {
- 184 2 EA_DISABLE;
- 185 2 USB_Setup();
- 186 2 EA_ENABLE;
- 187 2 }
- 188 1
- 189 1 //挂起处理
- 190 1 if(USB_Int_Flag.BITS.SUSP)
- 191 1 {
- 192 2 //清除挂起标志
- 193 2 EA_DISABLE;
- 194 2 USB_Int_Flag.BITS.SUSP = 0;
- 195 2 EA_ENABLE;
- 196 2 //ISP1581进入挂起状态
- 197 2 D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 1;
- 198 2 D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 0;
- 199 2 }
- 200 1
- 201 1 //挂起恢复处理
- 202 1 if(USB_Int_Flag.BITS.RESUME)
- 203 1 {
- 204 2 //清除恢复标志
- 205 2 EA_DISABLE;
- 206 2 USB_Int_Flag.BITS.RESUME = 0;
- 207 2 EA_ENABLE;
- 208 2 //产生一个恢复信号
- 209 2 D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 1;
- 210 2 D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 0;
- 211 2 }
- 212 1
- 213 1 //高速状态
- 214 1 if(USB_Int_Flag.BITS.HS_STAT)
- 215 1 {
- 216 2 //清除高速状态标志
- 217 2 EA_DISABLE;
- 218 2 USB_Int_Flag.BITS.HS_STAT = 0;
- 219 2 EA_ENABLE;
- 220 2 if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- 221 2 {
- 222 3 //切换高速指示
- 223 3 HS_FS_LED = HIGH_SPEED_LED;
- 224 3 //设置高速模式状态
- 225 3 Kernel_Flag.BITS.HS_FS_State = HIGH_SPEED;
- 226 3 //重新配置高速端点
- 227 3 Init_Endpoint();
- 228 3
- 229 3 // PIO_Count = 64;
- 230 3 PIO_Count = 512;
- 231 3 }
- 232 2 }
- 233 1 }
- 234
- 235
- 236 //***********************************************************************
- 237 //* *
- 238 //* Routine : *
- 239 //* Input : None *
- 240 //* Output : None *
- 241 //* Function : *
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 5
- 242 //* *
- 243 //***********************************************************************
- 244 //建立包处理
- 245 void USB_Setup(void)
- 246 {
- 247 1 unsigned char type, req;
- 248 1
- 249 1 //清除EP0SETUP中断标志
- 250 1 USB_Int_Flag.BITS.EP0SETUP = 0;
- 251 1 //清除总线复位标志
- 252 1 Kernel_Flag.BITS.Bus_Reset = 0;
- 253 1 //选择端点0SETUP缓冲区
- 254 1 D14_Cntrl_Reg.D14_ENDPT_INDEX = 0x20;
- 255 1
- 256 1 //读取USB请求
- 257 1 //读取请求类型
- 258 1 USB_Device_Request.bmRequestType = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 259 1 //读取请求号
- 260 1 USB_Device_Request.bRequest = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 261 1 //读取16bit请求数据
- 262 1 USB_Device_Request.wValue = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 263 1 USB_Device_Request.wValue <<= 8;
- 264 1 USB_Device_Request.wValue |= D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 265 1 //读取16bit请求索引
- 266 1 USB_Device_Request.wIndex = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 267 1 USB_Device_Request.wIndex <<= 8;
- 268 1 USB_Device_Request.wIndex |= D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 269 1 //读取16bit长度
- 270 1 USB_Device_Request.wLength = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 271 1 USB_Device_Request.wLength <<= 8;
- 272 1 USB_Device_Request.wLength |= D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 273 1
- 274 1 //长度处理(高低8位对调)
- 275 1 Temp = USB_Device_Request.wLength;
- 276 1 USB_Device_Request.wLength = 0;
- 277 1 USB_Device_Request.wLength = (UC) Temp;
- 278 1 USB_Device_Request.wLength <<= 8;
- 279 1 Temp >>= 8;
- 280 1 USB_Device_Request.wLength |= Temp;
- 281 1
- 282 1 type = USB_Device_Request.bmRequestType & 0x60;
- 283 1 req = USB_Device_Request.bRequest & 0x0f;
- 284 1
- 285 1 //厂商请求
- 286 1 if (type == 0x40)
- 287 1 {
- 288 2 Vendor_Specific_Command();//厂商请求处理
- 289 2 }
- 290 1 else if (type == 0x00)
- 291 1 (*StandardDeviceRequest[req])();//调用标准请求
- 292 1 }
- 293
- 294 //***********************************************************************
- 295 //* *
- 296 //* Routine : *
- 297 //* Input : None *
- 298 //* Output : None *
- 299 //* Function : *
- 300 //* *
- 301 //***********************************************************************
- 302 //厂商请求处理
- 303 void Vendor_Specific_Command(void)
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 6
- 304 {
- 305 1 if(USB_Device_Request.bRequest == 0x0C)
- 306 1 {
- 307 2 switch (USB_Device_Request.wIndex)
- 308 2 {
- 309 3 case GET_FIRMWARE_VERSION ://获取固件版本
- 310 3 if(USB_Device_Request.wLength == 1)
- 311 3 {
- 312 4 //select endpoint
- 313 4 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 314 4 //set the data length to 1 byte
- 315 4 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 1;
- 316 4 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 317 4 //sent 0x21 as data
- 318 4 D14_Cntrl_Reg.D14_DATA_PORT_LSB = 0x22;//版本号*?***????????????????
- 319 4 wait_ep0tx();
- 320 4 ep0out_ack();
- 321 4 // ep0in_ack();
- 322 4 break;
- 323 4 }
- 324 3
- 325 3 case SETUP_DMA_REQUEST :
- 326 3 //Out Token Ack detected
- 327 3 wait_ep0rx();
- 328 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
- 329 3 //
- 330 3 FileSize.Size.Address[0] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 331 3 FileSize.Size.Address[1] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 332 3 FileSize.Size.Address[2] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 333 3 //读取传输字节数
- 334 3 Temp = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 335 3 bytecount = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 336 3 bytecount <<= 8;
- 337 3 bytecount |= Temp;
- 338 3 //读取传输方式
- 339 3 FileSize.Size.DIR = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- 340 3 ep0in_ack();
- 341 3 Kernel_Flag.BITS.Transfer_Start = 1;//标志传输数据开始
- 342 3 break;
- 343 3
- 344 3 default :
- 345 3 if(USB_Device_Request.bmRequestType == 0xC0)
- 346 3 {
- 347 4 ep0in_ack();
- 348 4 break;
- 349 4 }
- 350 3 if(USB_Device_Request.bmRequestType == 0x40)
- 351 3 {
- 352 4 D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
- 353 4 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- 354 4 while(!USB_Int_Flag.BITS.EP0SETUP)
- 355 4 {
- 356 5 //读取ISP1581中断寄存器
- 357 5 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 358 5 //回写ISP1581中断寄存器
- 359 5 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 360 5 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 361 5 return;
- 362 5 }
- 363 4 USB_Int_Flag.BITS.EP0TX = 0;
- 364 4 break;
- 365 4 }
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 7
- 366 3 }
- 367 2 }
- 368 1 }
- 369
- 370 //***********************************************************************
- 371 //* *
- 372 //* Routine : *
- 373 //* Input : None *
- 374 //* Output : None *
- 375 //* Function : *
- 376 //* *
- 377 //***********************************************************************
- 378
- 379 void reserved(void)
- 380 {
- 381 1 }
- 382
- 383
- 384 //Get_Descriptor()获取描述符
- 385 void get_descriptor(void)
- 386 {
- 387 1
- 388 1 switch(USB_Device_Request.wValue)
- 389 1 {
- 390 2 case 1://设备描述符
- 391 2 //选择描述符
- 392 2 if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- 393 2 Descriptor_Ptr = &Standard_Device_Descriptor[0]; //set pointer to device descriptor
- 394 2 if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
- 395 2 Descriptor_Ptr = &HS_Device_Descriptor[0]; //set pointer to device descriptor
- 396 2 count = *Descriptor_Ptr; //read in descriptor length
- 397 2 //选择端点号
- 398 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 399 2 //写下发送字节数
- 400 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 0x12;
- 401 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 402 2 //send descriptor
- 403 2 //发送描述符
- 404 2 while(count != 0)
- 405 2 {
- 406 3 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 407 3 count--;
- 408 3 Descriptor_Ptr++;
- 409 3 }
- 410 2 wait_ep0tx();
- 411 2 ep0out_ack();
- 412 2 break;
- 413 2
- 414 2 case 2 : //获取配置描述符
- 415 2 USB_Int_Flag.BITS.EP0RX = 0;
- 416 2 Temp = 64;
- 417 2 Descriptor_Ptr = &Standard_Config_Descriptor[0]; //set pointer to configuration descriptor
- 418 2 count = *Descriptor_Ptr; //get configuration Descriptor length
- 419 2 //选择端点号1
- 420 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 421 2 //check if only configuration descriptor required
- 422 2 //检查描述符长度,决定是只发送配置描述符还是描述符集合
- 423 2 if(count >= USB_Device_Request.wLength) //Send only Configuration descriptor
- 424 2 {
- 425 3 //写入发送字节数
- 426 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) USB_Device_Request.wLength;
- 427 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = (UC) (USB_Device_Request.wLength >> 8);
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 8
- 428 3 //send descriptor
- 429 3 //发送描述符
- 430 3 for(count = 0 ; count < USB_Device_Request.wLength ; count++)
- 431 3 {
- 432 4 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 433 4 Descriptor_Ptr++;
- 434 4 }
- 435 3 wait_ep0tx();
- 436 3 ep0out_ack();
- 437 3 }
- 438 2 else //send Configuration,Interface and Endpoint descriptor
- 439 2 {
- 440 3 //发送描述符集合(配置+接口+端点)
- 441 3 if(USB_Device_Request.wLength >= 32)
- 442 3 {
- 443 4 //写入配置描述符
- 444 4 while(count != 0)
- 445 4 {
- 446 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 447 5 count--;
- 448 5 Descriptor_Ptr++;
- 449 5 }
- 450 4 //选择高速还是全速接口描述符
- 451 4 if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- 452 4 Descriptor_Ptr = &Bulk_Interface_Descriptor[0]; //set pointer to interface descriptor
- 453 4 if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
- 454 4 Descriptor_Ptr = &HS_Bulk_Interface_Descriptor[0]; //set pointer to interface descriptor
- 455 4 count = *Descriptor_Ptr; //get the descriptor count
- 456 4 //写入接口描述符
- 457 4 while(count != 0)
- 458 4 {
- 459 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 460 5 count--;
- 461 5 Descriptor_Ptr++;
- 462 5 }
- 463 4 //选择高速还是全速端点1IN描述符
- 464 4 if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- 465 4 Descriptor_Ptr = &Int_In_Descriptor[0]; //set pointer to interface descriptor
- 466 4 if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
- 467 4 Descriptor_Ptr = &HS_Int_In_Descriptor[0]; //set pointer to interface descriptor
- 468 4 count = *Descriptor_Ptr; //read in descriptor length
- 469 4 //写入端点1IN描述符
- 470 4 while(count != 0)
- 471 4 {
- 472 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 473 5 count--;
- 474 5 Descriptor_Ptr++;
- 475 5 }
- 476 4 //选择高速还是全速端点1OUT描述符
- 477 4 if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- 478 4 Descriptor_Ptr = &Int_Out_Descriptor[0]; //set pointer to interface descriptor
- 479 4 if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
- 480 4 Descriptor_Ptr = &HS_Int_Out_Descriptor[0]; //set pointer to interface descriptor
- 481 4 count = *Descriptor_Ptr; //read in descriptor length
- 482 4 //写入端点1OUT描述符
- 483 4 while(count != 0)
- 484 4 {
- 485 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 486 5 count--;
- 487 5 Descriptor_Ptr++;
- 488 5 }
- 489 4 //选择高速还是全速端点2IN描述符
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 9
- 490 4 if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- 491 4 Descriptor_Ptr = &Bulk_In_Descriptor[0]; //set pointer to interface descriptor
- 492 4 if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
- 493 4 Descriptor_Ptr = &HS_Bulk_In_Descriptor[0]; //set pointer to interface descriptor
- 494 4 count = *Descriptor_Ptr; //read in descriptor length
- 495 4 //写入端点2IN描述符
- 496 4 while(count != 0)
- 497 4 {
- 498 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 499 5 count--;
- 500 5 Descriptor_Ptr++;
- 501 5 }
- 502 4 //选择高速还是全速端点2OUT描述符
- 503 4 if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- 504 4 Descriptor_Ptr = &Bulk_Out_Descriptor[0]; //set pointer to interface descriptor
- 505 4 if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
- 506 4 Descriptor_Ptr = &HS_Bulk_Out_Descriptor[0]; //set pointer to interface descriptor
- 507 4 count = *Descriptor_Ptr; //read in descriptor length
- 508 4 //写入端点2OUT描述符
- 509 4 while(count != 0)
- 510 4 {
- 511 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 512 5 count--;
- 513 5 Descriptor_Ptr++;
- 514 5 }
- 515 4 }
- 516 3 //使端点有效
- 517 3 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.VENDP = 1; //validate FIFO
- 518 3 wait_ep0tx();
- 519 3 ep0out_ack();
- 520 3 }
- 521 2 break;
- 522 2
- 523 2 case 3: //获取字符串描述符
- 524 2 Descriptor_Ptr = &Standard_String_ID[0]; //set pointer to interface descriptor
- 525 2 count = *Descriptor_Ptr; //get length
- 526 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 527 2 if(USB_Device_Request.wLength < count)
- 528 2 count = USB_Device_Request.wLength; //get the remaining length
- 529 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = count;
- 530 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 531 2 //send string ID
- 532 2 while(count != 0)
- 533 2 {
- 534 3 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
- 535 3 Descriptor_Ptr++;
- 536 3 count--;
- 537 3 }
- 538 2 wait_ep0tx();
- 539 2 ep0out_ack();
- 540 2 break;
- 541 2
- 542 2
- 543 2 case 4:
- 544 2 reserved();
- 545 2 break;
- 546 2
- 547 2 case 5: //获取端点描述符
- 548 2 Temp = 0;
- 549 2 if((USB_Device_Request.wValue & 0x00ff) > 0x0001)
- 550 2 {
- 551 3 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 10
- 552 3 while(!USB_Int_Flag.BITS.EP0SETUP)
- 553 3 {
- 554 4 //读取ISP1581中断寄存器
- 555 4 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 556 4 //回写ISP1581中断寄存器
- 557 4 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 558 4 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 559 4 return;
- 560 4 }
- 561 3 USB_Int_Flag.BITS.EP0TX = 0;
- 562 3 }
- 563 2 else
- 564 2 {
- 565 3 Descriptor_Ptr = &Bulk_Out_Descriptor[0]; //set pointer to Bulk Out endpoint descriptor
- 566 3 count = *Descriptor_Ptr; //read in descriptor length
- 567 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 568 3 if(count >= USB_Device_Request.wLength)
- 569 3 {
- 570 4 Temp = USB_Device_Request.wLength;
- 571 4 //send endpoint descriptor
- 572 4 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) Temp;
- 573 4 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = (UC) (Temp >> 8);
- 574 4 for(count = 0 ; count < USB_Device_Request.wLength ; count++)
- 575 4 {
- 576 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 577 5 Descriptor_Ptr++;
- 578 5 }
- 579 4 wait_ep0tx();
- 580 4 ep0out_ack();
- 581 4 }
- 582 3 else
- 583 3 {
- 584 4 USB_Device_Request.wLength -= count; //send Endpoint descriptor
- 585 4 Temp += count;
- 586 4 while(count != 0)
- 587 4 {
- 588 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 589 5 count--;
- 590 5 Descriptor_Ptr++;
- 591 5 }
- 592 4 Descriptor_Ptr = &Bulk_In_Descriptor[0]; //set pointer to Bulk In endpoint descriptor
- 593 4 count = *Descriptor_Ptr; //read in descriptor length
- 594 4 if(count >= USB_Device_Request.wLength)
- 595 4 {
- 596 5 Temp += USB_Device_Request.wLength;
- 597 5 //send endpoint descriptor
- 598 5 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) Temp;
- 599 5 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = (UC) (Temp >> 8);
- 600 5 for(count = 0 ; count < USB_Device_Request.wLength ; count++)
- 601 5 {
- 602 6 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 603 6 Descriptor_Ptr++;
- 604 6 }
- 605 5 wait_ep0tx();
- 606 5 ep0out_ack();
- 607 5 }
- 608 4 else
- 609 4 {
- 610 5 USB_Device_Request.wLength -= count; //send Endpoint descriptor
- 611 5 Temp += count;
- 612 5 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) Temp;
- 613 5 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = (UC) (Temp >> 8);
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 11
- 614 5 while(count != 0)
- 615 5 {
- 616 6 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 617 6 count--;
- 618 6 Descriptor_Ptr++;
- 619 6 }
- 620 5 wait_ep0tx();
- 621 5 ep0out_ack();
- 622 5 }
- 623 4 }
- 624 3 }
- 625 2 break;
- 626 2
- 627 2 case 6: //获取设备限制描述符
- 628 2 Descriptor_Ptr = &HS_Device_Qualifier[0]; //set pointer to High Speed device descriptor
- 629 2 count = *Descriptor_Ptr; //read in descriptor length
- 630 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 631 2 if(USB_Device_Request.wLength < count)
- 632 2 {
- 633 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) USB_Device_Request.wLength;
- 634 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 635 3 count = USB_Device_Request.wLength;
- 636 3 }
- 637 2 else
- 638 2 {
- 639 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = count;
- 640 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 641 3 }
- 642 2 while(count != 0)
- 643 2 {
- 644 3 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
- 645 3 Descriptor_Ptr++;
- 646 3 count--;
- 647 3 };
- 648 2 wait_ep0tx();
- 649 2 ep0out_ack();
- 650 2 break;
- 651 2
- 652 2 case 7 ://获取速度配置描述符
- 653 2 Temp = 64;
- 654 2 Descriptor_Ptr = &Other_Speed_Config_Descriptor[0]; //set pointer to configuration descriptor
- 655 2 count = *Descriptor_Ptr; //get configuration Descriptor length
- 656 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 657 2 if(count >= USB_Device_Request.wLength) //Send only Configuration descriptor
- 658 2 {
- 659 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) USB_Device_Request.wLength;
- 660 3 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = (UC) (USB_Device_Request.wLength >> 8);
- 661 3 for(count = 0 ; count < USB_Device_Request.wLength ; count++)
- 662 3 {
- 663 4 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 664 4 Descriptor_Ptr++;
- 665 4 }
- 666 3 wait_ep0tx();
- 667 3 ep0out_ack();
- 668 3 }
- 669 2 else //send Configuration,Interface and Endpoint descriptor
- 670 2 {
- 671 3 if(USB_Device_Request.wLength >= 32)
- 672 3 {
- 673 4 while(count != 0)
- 674 4 {
- 675 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 12
- 676 5 count--;
- 677 5 Descriptor_Ptr++;
- 678 5 }
- 679 4 Descriptor_Ptr = &Bulk_Interface_Descriptor[0]; //set pointer to interface descriptor
- 680 4 count = *Descriptor_Ptr; //get the descriptor count
- 681 4 while(count != 0)
- 682 4 {
- 683 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 684 5 count--;
- 685 5 Descriptor_Ptr++;
- 686 5 }
- 687 4 Descriptor_Ptr = &Int_In_Descriptor[0]; //set pointer to interface descriptor
- 688 4 count = *Descriptor_Ptr; //read in descriptor length
- 689 4 while(count != 0)
- 690 4 {
- 691 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 692 5 count--;
- 693 5 Descriptor_Ptr++;
- 694 5 }
- 695 4 Descriptor_Ptr = &Int_Out_Descriptor[0]; //set pointer to interface descriptor
- 696 4 count = *Descriptor_Ptr; //read in descriptor length
- 697 4 while(count != 0)
- 698 4 {
- 699 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 700 5 count--;
- 701 5 Descriptor_Ptr++;
- 702 5 }
- 703 4 Descriptor_Ptr = &Bulk_In_Descriptor[0]; //set pointer to interface descriptor
- 704 4 count = *Descriptor_Ptr; //read in descriptor length
- 705 4 while(count != 0)
- 706 4 {
- 707 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 708 5 count--;
- 709 5 Descriptor_Ptr++;
- 710 5 }
- 711 4 Descriptor_Ptr = &Bulk_Out_Descriptor[0]; //set pointer to interface descriptor
- 712 4 count = *Descriptor_Ptr; //read in descriptor length
- 713 4 while(count != 0)
- 714 4 {
- 715 5 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
- 716 5 count--;
- 717 5 Descriptor_Ptr++;
- 718 5 }
- 719 4 }
- 720 3 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.VENDP = 1; //validate FIFO
- 721 3 wait_ep0tx();
- 722 3 ep0out_ack();
- 723 3 }
- 724 2 break;
- 725 2
- 726 2 case 8:
- 727 2 break;
- 728 2
- 729 2 default :
- 730 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 731 2 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- 732 2 while(!USB_Int_Flag.BITS.EP0SETUP)
- 733 2 {
- 734 3 //读取ISP1581中断寄存器
- 735 3 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 736 3 //回写ISP1581中断寄存器
- 737 3 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 13
- 738 3 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 739 3 return;
- 740 3 }
- 741 2 USB_Int_Flag.BITS.EP0TX = 0;
- 742 2 break;
- 743 2 }
- 744 1 }
- 745
- 746 //Set_Address设置地址
- 747 void set_address(void)
- 748 {
- 749 1 USB_Int_Flag.BITS.EP0RX = 0;
- 750 1 D14_Cntrl_Reg.D14_ADDRESS.BITS.DEVADDR = (USB_Device_Request.wValue >> 8);//设置地址
- 751 1 //状态响应
- 752 1 ep0in_ack();
- 753 1 }
- 754
- 755 //Set_Config设置配置
- 756 void set_config(void)
- 757 {
- 758 1 USB_Int_Flag.BITS.EP0RX = 0;
- 759 1
- 760 1 if(USB_Device_Request.wValue == 0)
- 761 1 {
- 762 2 Device_Config_Value = 0;
- 763 2 ep0in_ack();
- 764 2 }
- 765 1 else if (USB_Device_Request.wValue == 0x0100)
- 766 1 {
- 767 2 //配置设备
- 768 2 Device_Config_Value = (UC) (USB_Device_Request.wValue >> 8);
- 769 2 // USB_Device.BITS.State = USB_Configured;
- 770 2 ep0in_ack();
- 771 2 }
- 772 1 else
- 773 1 {
- 774 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 775 2 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- 776 2 while(!USB_Int_Flag.BITS.EP0SETUP)
- 777 2 {
- 778 3 //读取ISP1581中断寄存器
- 779 3 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 780 3 //回写ISP1581中断寄存器
- 781 3 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 782 3 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 783 3 return;
- 784 3 }
- 785 2 USB_Int_Flag.BITS.EP0TX = 0;
- 786 2 }
- 787 1 }
- 788
- 789
- 790 //Get_Config获取配置
- 791 void get_config(void)
- 792 {
- 793 1 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 794 1 D14_Cntrl_Reg.D14_DATA_PORT_LSB = Device_Config_Value;
- 795 1 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.VENDP = 1;
- 796 1 wait_ep0tx();
- 797 1 ep0out_ack();
- 798 1 }
- 799
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 14
- 800 //Clear_Feature特性清除
- 801 void clear_feature(void)
- 802 {
- 803 1 unsigned char bRecipient = USB_Device_Request.bmRequestType & 0x0f;
- 804 1 //端点
- 805 1 if(bRecipient == 0x02 &&USB_Device_Request.wValue == 0x0000)
- 806 1 {
- 807 2 switch(USB_Device_Request.wIndex)
- 808 2 {
- 809 3 case 0x8000 :
- 810 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 811 3 break;
- 812 3 case 0x0000 :
- 813 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
- 814 3 break;
- 815 3 case 0x8100 :
- 816 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
- 817 3 break;
- 818 3 case 0x0100 :
- 819 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
- 820 3 break;
- 821 3 case 0x8200 :
- 822 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
- 823 3 break;
- 824 3 case 0x0200 :
- 825 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
- 826 3 break;
- 827 3 case 0x8300 :
- 828 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
- 829 3 break;
- 830 3 case 0x0300 :
- 831 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
- 832 3 break;
- 833 3 case 0x8400 :
- 834 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 9;
- 835 3 break;
- 836 3 case 0x0400 :
- 837 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 8;
- 838 3 break;
- 839 3 case 0x8500 :
- 840 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 11;
- 841 3 break;
- 842 3 case 0x0500 :
- 843 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 10;
- 844 3 break;
- 845 3 case 0x8600 :
- 846 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 13;
- 847 3 break;
- 848 3 case 0x0600 :
- 849 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 12;
- 850 3 break;
- 851 3 case 0x8700 :
- 852 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 15;
- 853 3 break;
- 854 3 case 0x0700 :
- 855 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 14;
- 856 3 break;
- 857 3 default :
- 858 3 break;
- 859 3 }
- 860 2 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 0;
- 861 2 Kernel_Flag.BITS.Endpt_Stall = 0;
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 15
- 862 2 D14_Cntrl_Reg.D14_ENDPT_TYPE.BITS.ENABLE = OFF; //disable FIFO
- 863 2 D14_Cntrl_Reg.D14_ENDPT_TYPE.BITS.ENABLE = ON; //disable FIFO
- 864 2 ep0in_ack();
- 865 2 USB_Device.BITS.Halt = 0;
- 866 2 }
- 867 1 else if(bRecipient == 0x00 && USB_Device_Request.wValue == 0x0100)
- 868 1 { //远程唤醒
- 869 2 USB_Device.BITS.Remote_Wakeup = 0;
- 870 2 ep0in_ack();
- 871 2 }
- 872 1 else
- 873 1 {
- 874 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 875 2 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- 876 2 while(!USB_Int_Flag.BITS.EP0SETUP)
- 877 2 {
- 878 3 //读取ISP1581中断寄存器
- 879 3 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 880 3 //回写ISP1581中断寄存器
- 881 3 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 882 3 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 883 3 return;
- 884 3 }
- 885 2 USB_Int_Flag.BITS.EP0TX = 0;
- 886 2 }
- 887 1 }
- 888
- 889 //Get_Status获取设备状态
- 890 void get_status(void)
- 891 {
- 892 1 if(USB_Device_Request.bmRequestType == 0x80)
- 893 1 {
- 894 2 //端点0IN返回0x01,0x00两字节
- 895 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 896 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 2;
- 897 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 898 2 D14_Cntrl_Reg.D14_DATA_PORT_LSB = 1;
- 899 2 D14_Cntrl_Reg.D14_DATA_PORT_MSB = 0;
- 900 2 //等待发送完毕
- 901 2 wait_ep0tx();
- 902 2 ep0out_ack();
- 903 2 }
- 904 1
- 905 1 if(USB_Device_Request.bmRequestType == 0x81)
- 906 1 {
- 907 2 //端点0IN返回0x00,0x00两字节
- 908 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 909 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 2;
- 910 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 911 2 D14_Cntrl_Reg.D14_DATA_PORT_LSB = 0;
- 912 2 D14_Cntrl_Reg.D14_DATA_PORT_MSB = 0;
- 913 2 wait_ep0tx();
- 914 2 ep0out_ack();
- 915 2 }
- 916 1
- 917 1 if(USB_Device_Request.bmRequestType == 0x82)
- 918 1 {
- 919 2 Temp = 0;
- 920 2 Temp = USB_Device.BITS.Halt;
- 921 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 922 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 2;
- 923 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 16
- 924 2 D14_Cntrl_Reg.D14_DATA_PORT_LSB = (UC) Temp;
- 925 2 D14_Cntrl_Reg.D14_DATA_PORT_MSB = (UC) (Temp >> 8);
- 926 2 wait_ep0tx();
- 927 2 ep0out_ack();
- 928 2 }
- 929 1 }
- 930
- 931
- 932
- 933 //Set_Feature特性设置
- 934 //不支持测试模式
- 935 void set_feature(void)
- 936 {
- 937 1 unsigned char bRecipient = USB_Device_Request.bmRequestType & 0x0f;
- 938 1 //端点
- 939 1 if(bRecipient == 0x02 && USB_Device_Request.wValue == 0x0000)
- 940 1 {
- 941 2 switch(USB_Device_Request.wIndex)
- 942 2 {
- 943 3 case 0x8000 :
- 944 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 945 3 break;
- 946 3 case 0x0000 :
- 947 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
- 948 3 break;
- 949 3 case 0x8100 :
- 950 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
- 951 3 break;
- 952 3 case 0x0100 :
- 953 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
- 954 3 break;
- 955 3 case 0x8200 :
- 956 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
- 957 3 break;
- 958 3 case 0x0200 :
- 959 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
- 960 3 break;
- 961 3 case 0x8300 :
- 962 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
- 963 3 break;
- 964 3 case 0x0300 :
- 965 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
- 966 3 break;
- 967 3 case 0x8400 :
- 968 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 9;
- 969 3 break;
- 970 3 case 0x0400 :
- 971 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 8;
- 972 3 break;
- 973 3 case 0x8500 :
- 974 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 11;
- 975 3 break;
- 976 3 case 0x0500 :
- 977 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 10;
- 978 3 break;
- 979 3 case 0x8600 :
- 980 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 13;
- 981 3 break;
- 982 3 case 0x0600 :
- 983 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 12;
- 984 3 break;
- 985 3 case 0x8700 :
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 17
- 986 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 15;
- 987 3 break;
- 988 3 case 0x0700 :
- 989 3 D14_Cntrl_Reg.D14_ENDPT_INDEX = 14;
- 990 3 break;
- 991 3 default :
- 992 3 break;
- 993 3 }
- 994 2 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- 995 2 Kernel_Flag.BITS.Endpt_Stall = 1;
- 996 2 D14_Cntrl_Reg.D14_ENDPT_TYPE.BITS.ENABLE = OFF; //disable FIFO
- 997 2 //D14_Cntrl_Reg.D14_ENDPT_TYPE.BITS.ENABLE = ON; //disable FIFO
- 998 2 ep0in_ack();
- 999 2 USB_Device.BITS.Halt = 0;
- 1000 2 }
- 1001 1 else if(bRecipient == 0x00 && USB_Device_Request.wValue == 0x0100)
- 1002 1 { //远程唤醒
- 1003 2 USB_Device.BITS.Remote_Wakeup = 1;
- 1004 2 ep0in_ack();
- 1005 2 }
- 1006 1 else
- 1007 1 {
- 1008 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 1009 2 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- 1010 2 while(!USB_Int_Flag.BITS.EP0SETUP)
- 1011 2 {
- 1012 3 //读取ISP1581中断寄存器
- 1013 3 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 1014 3 //回写ISP1581中断寄存器
- 1015 3 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 1016 3 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 1017 3 return;
- 1018 3 }
- 1019 2 USB_Int_Flag.BITS.EP0TX = 0;
- 1020 2 }
- 1021 1 }
- 1022
- 1023
- 1024 //Get_Interface 获取接口状态
- 1025 void get_interface(void)
- 1026 {
- 1027 1 if(USB_Device_Request.wValue != 0)
- 1028 1 {
- 1029 2 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
- 1030 2 while(!USB_Int_Flag.BITS.EP0SETUP)
- 1031 2 {
- 1032 3 //读取ISP1581中断寄存器
- 1033 3 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 1034 3 //回写ISP1581中断寄存器
- 1035 3 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 1036 3 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 1037 3 return;
- 1038 3 }
- 1039 2 USB_Int_Flag.BITS.EP0TX = 0;
- 1040 2 }
- 1041 1 else
- 1042 1 {
- 1043 2 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 1044 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 1;
- 1045 2 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
- 1046 2 if(!USB_Device.BITS.Alter_Interface)
- 1047 2 D14_Cntrl_Reg.D14_DATA_PORT_LSB = 0;
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 18
- 1048 2 else
- 1049 2 D14_Cntrl_Reg.D14_DATA_PORT_LSB = 1;
- 1050 2 wait_ep0tx();
- 1051 2 ep0in_ack();
- 1052 2 }
- 1053 1 }
- 1054
- 1055
- 1056 //Set_Interface 设置接口状态
- 1057 void set_interface(void)
- 1058 {
- 1059 1 if(USB_Device_Request.wIndex == 0 && USB_Device_Request.wValue == 0x0100)
- 1060 1 USB_Device.BITS.Alter_Interface = 1;
- 1061 1
- 1062 1 if(USB_Device_Request.wIndex == 0x0100 && USB_Device_Request.wValue == 0)
- 1063 1 USB_Device.BITS.Alter_Interface = 0;
- 1064 1
- 1065 1 if(USB_Device_Request.wIndex == 0 && USB_Device_Request.wValue == 0)
- 1066 1 USB_Device.BITS.Alter_Interface = 0;
- 1067 1
- 1068 1 ep0in_ack();
- 1069 1 }
- 1070
- 1071
- 1072
- 1073 //端点0IN状态响应
- 1074 void ep0in_ack(void)
- 1075 {
- 1076 1 D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
- 1077 1 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
- 1078 1 wait_ep0tx();
- 1079 1 }
- 1080
- 1081 //端点0IN状态响应
- 1082 void wait_ep0tx(void)
- 1083 {
- 1084 1 //end of status stage
- 1085 1 while(!USB_Int_Flag.BITS.EP0TX)
- 1086 1 {
- 1087 2 //读取ISP1581中断寄存器
- 1088 2 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 1089 2 //回写ISP1581中断寄存器
- 1090 2 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 1091 2 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 1092 2 return;
- 1093 2 }
- 1094 1 USB_Int_Flag.BITS.EP0TX = 0;
- 1095 1 }
- 1096
- 1097 //端点0OUT状态响应
- 1098 void ep0out_ack(void)
- 1099 {
- 1100 1 //设置状态响应
- 1101 1 //acknowledge status stage
- 1102 1 D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
- 1103 1 D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
- 1104 1 // D14_Cntrl_Reg.D14_CONTROL_FUNCTION.VALUE = 2;
- 1105 1 wait_ep0rx();
- 1106 1 }
- 1107
- 1108 //端点0OUT状态响应
- 1109 void wait_ep0rx(void)
- C51 COMPILER V7.06 CHAP_9 07/02/2003 09:29:11 PAGE 19
- 1110 {
- 1111 1 while(!USB_Int_Flag.BITS.EP0RX)
- 1112 1 {
- 1113 2 //读取ISP1581中断寄存器
- 1114 2 USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
- 1115 2 //回写ISP1581中断寄存器
- 1116 2 D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
- 1117 2 if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
- 1118 2 return;
- 1119 2 }
- 1120 1 USB_Int_Flag.BITS.EP0RX = 0;
- 1121 1 }
- 1122
- 1123 #pragma disable
- 1124 unsigned int read_endpoint(unsigned char endp,unsigned int len,unsigned char *buf)
- 1125 {
- 1126 1 unsigned int datalen;
- 1127 1 D14_Cntrl_Reg.D14_ENDPT_INDEX = endp;
- 1128 1 len = D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB;
- 1129 1 len <<= 8;
- 1130 1 len += D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB;
- 1131 1 datalen=len;
- 1132 1 while(datalen-- != 0)
- 1133 1 {
- 1134 2 *buf = D14_Cntrl_Reg.D14_DATA_PORT_LSB; //fill up FIFO
- 1135 2 buf++;
- 1136 2 }
- 1137 1 return len;
- 1138 1 }
- 1139
- 1140 unsigned int write_endpoint(unsigned char endp,unsigned int len,unsigned char *buf)
- 1141 {
- 1142 1 unsigned int datalen;
- 1143 1 D14_Cntrl_Reg.D14_ENDPT_INDEX = endp;
- 1144 1 D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (unsigned char) len;
- 1145 1 D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = (unsigned char) (len>>8);
- 1146 1 datalen=len;
- 1147 1 while(datalen-- != 0)
- 1148 1 {
- 1149 2 D14_Cntrl_Reg.D14_DATA_PORT_LSB = *buf; //fill up FIFO
- 1150 2 buf++;
- 1151 2 }
- 1152 1 return len;
- 1153 1
- 1154 1 }
- 1155
- 1156
- 1157
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 5036 ----
- CONSTANT SIZE = 48 ----
- XDATA SIZE = ---- ----
- PDATA SIZE = ---- ----
- DATA SIZE = 32 20
- IDATA SIZE = 72 ----
- BIT SIZE = ---- ----
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)