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