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