C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 1 C51 COMPILER V7.06, COMPILATION OF MODULE USB OBJECT MODULE PLACED IN USB.OBJ COMPILER INVOKED BY: d:\Keil777\C51\BIN\C51.EXE USB.C BROWSE DEBUG OBJECTEXTEND stmt level source 1 #include "isp1362.h" 2 #include "reg.h" 3 4 unsigned int device_info(char mode, char itype, char index) 5 { 6 1 static int iManufacturer=0; 7 1 static int iProduct=0; 8 1 static int iInterface=0; 9 1 static int MaxPacSize=0; 10 1 11 1 if(mode=='W') 12 1 { 13 2 if(itype=='M') {iManufacturer=index;} 14 2 if(itype=='P') {iProduct =index;} 15 2 if(itype=='I') {iInterface =index;} 16 2 if(itype=='S') {MaxPacSize =index;} 17 2 } 18 1 19 1 if(mode=='R') 20 1 { 21 2 if(itype=='M') {return(iManufacturer);} 22 2 if(itype=='P') {return(iProduct) ;} 23 2 if(itype=='I') {return(iInterface) ;} 24 2 if(itype=='S') {return(MaxPacSize) ;} 25 2 } 26 1 27 1 if(mode=='S') 28 1 { 29 2 printf("\niManufacturer = %4X",iManufacturer); *** WARNING C206 IN LINE 29 OF USB.C: 'printf': missing function-prototype *** ERROR C267 IN LINE 29 OF USB.C: 'printf': requires ANSI-style prototype 30 2 printf("\niProduct = %4X",iProduct ); 31 2 printf("\niInterface = %4X",iInterface ); 32 2 printf("\nMaxPacSize = %4X",MaxPacSize ); 33 2 } 34 1 35 1 return 0; 36 1 } 37 38 unsigned int set_address(int old_addr, int new_addr, int port) 39 { 40 1 unsigned int cbuf[128]; 41 1 unsigned int rbuf[128]; 42 1 unsigned int uni_req[4]={0x0500,0x0000,0x0000,0x0000}; 43 1 unsigned int mycode=0; 44 1 unsigned int tcnt; 45 1 46 1 uni_req[1]=new_addr; 47 1 48 1 w16(HcUpInt,0x100); 49 1 50 1 r32(HcATLDone); 51 1 r32(HcATLDone); 52 1 53 1 make_ptd(cbuf,SETUP,0,8,0,old_addr,port); C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 2 54 1 array_app(cbuf+4,uni_req,4); 55 1 tcnt=send_control(cbuf,rbuf); 56 1 mycode=(*rbuf&0xF000)>>12; 57 1 58 1 if(tcnt==0) 59 1 { 60 2 mycode|=0xF000; 61 2 } 62 1 63 1 if(mycode==0) 64 1 { 65 2 //send out DATA IN packet 66 2 make_ptd(cbuf,IN,0,0,1,old_addr,port); 67 2 tcnt=send_control(cbuf,rbuf); 68 2 mycode=(*rbuf&0xF000)>>12; 69 2 if(tcnt==0) 70 2 { 71 3 mycode|=0xF000; 72 3 } 73 2 } 74 1 75 1 r32(HcATLDone); 76 1 77 1 return(mycode); 78 1 } 79 80 void set_config(int addr, int config) 81 { 82 1 unsigned int cbuf[128]; 83 1 unsigned int rbuf[128]; 84 1 unsigned int uni_req[4]={0x0900,0x0000,0x0000,0x0000}; 85 1 unsigned int tcnt; 86 1 unsigned int mycode=0; 87 1 88 1 uni_req[1]=config; 89 1 90 1 w16(HcUpInt,0x100); 91 1 92 1 r32(HcATLDone); 93 1 r32(HcATLDone); 94 1 95 1 make_ptd(cbuf,SETUP,0,8,0,addr,addr); 96 1 array_app(cbuf+4,uni_req,4); 97 1 tcnt=send_control(cbuf,rbuf); 98 1 99 1 if(tcnt==0) { mycode|=0xF000;} 100 1 mycode=mycode | (*rbuf&0xF000)>>12; 101 1 102 1 if(mycode==0) 103 1 { 104 2 //send out DATA IN packet 105 2 make_ptd(cbuf,IN,0,0,1,addr,addr); 106 2 tcnt=send_control(cbuf,rbuf); 107 2 108 2 if(tcnt==0) { mycode|=0xF000;} 109 2 mycode=mycode | (*rbuf&0xF000)>>12; 110 2 } 111 1 112 1 r32(HcATLDone); 113 1 r32(HcATLDone); 114 1 115 1 return(mycode); C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 3 116 1 } 117 118 119 unsigned int get_control_old(unsigned int *rptr,unsigned int addr,char control_type,unsigned int extra,int - port) 120 { 121 1 unsigned int cbuf[128]; 122 1 unsigned int rbuf[128]; 123 1 unsigned int cnt=0,lcnt=0; 124 1 unsigned int toggle_cnt=0; 125 1 unsigned int word_size; 126 1 unsigned int DesSize,MaxSize,RemainSize; 127 1 unsigned int LocalLimit; 128 1 129 1 unsigned int dev_req[4]={0x0680,0x0100 ,0x0000,0x8}; 130 1 unsigned int cfg_req[4]={0x0680,0x0200 ,0x0000,0x8}; 131 1 unsigned int str_req[4]={0x0680,0x0300 ,0x0000,0x8}; 132 1 unsigned int int_req[4]={0x0680,0x0400 ,0x0000,0x8}; 133 1 unsigned int end_req[4]={0x0680,0x0500 ,0x0000,0x8}; 134 1 unsigned int hid_req[4]={0x0681,0x2100 ,0x0000,0x8}; 135 1 136 1 unsigned int ccode=0; 137 1 unsigned int stage=1; 138 1 unsigned int tout; //timeout indicator 139 1 140 1 //STAGE 1 : Send out first setup packet 141 1 make_ptd(cbuf,SETUP,0,8,0,addr,port); 142 1 if(control_type=='D') {array_app(cbuf+4,dev_req,4);} 143 1 if(control_type=='C') {array_app(cbuf+4,cfg_req,4);} 144 1 if(control_type=='S') {array_app(cbuf+4,str_req,4);} 145 1 if(control_type=='I') {array_app(cbuf+4,int_req,4);} 146 1 if(control_type=='E') {array_app(cbuf+4,end_req,4);} 147 1 if(control_type=='H') {array_app(cbuf+4,hid_req,4);} 148 1 149 1 if(control_type=='S') 150 1 { 151 2 cbuf[5]=cbuf[5]|extra; //This is for string processing 152 2 } 153 1 154 1 tout=send_control(cbuf,rbuf); 155 1 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 156 1 157 1 if(ccode==0) 158 1 { 159 2 toggle_cnt++; 160 2 make_ptd(cbuf,IN,0,8,toggle_cnt%2,addr,port); 161 2 tout=send_control(cbuf,rbuf); 162 2 ccode|=(rbuf[0]&0xF000)>>12; 163 2 164 2 if(ccode==0x09) //Descriptor Size is less than 8 165 2 { 166 3 ccode=0; 167 3 } 168 2 169 2 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 170 2 171 2 if(control_type!='C') 172 2 { 173 3 DesSize=((rbuf[4]&0x00FF)); 174 3 } 175 2 176 2 if(control_type=='C') C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 4 177 2 { 178 3 DesSize=rbuf[5]; 179 3 } 180 2 181 2 if(control_type!='D') 182 2 { 183 3 MaxSize=addr_info(addr,'R','M',MaxSize); 184 3 } 185 2 186 2 if(control_type=='D') 187 2 { 188 3 MaxSize=(rbuf[7]&0xFF00)>>8; 189 3 if(MaxSize<8) {MaxSize==8;} 190 3 191 3 addr_info(addr,'W','M',MaxSize); 192 3 } 193 2 194 2 if(control_type=='H') 195 2 { 196 3 DesSize=(rbuf[7]&0xFF00)>>8; 197 3 if(DesSize<8) {DesSize==8;} 198 3 } 199 2 200 2 } 201 1 202 1 if(ccode==0) 203 1 { 204 2 //send out DATA OUT packet 205 2 make_ptd(cbuf,OUT,0,0,toggle_cnt%2,addr,port); 206 2 tout=send_control(cbuf,rbuf); 207 2 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 208 2 209 2 ccode|=(rbuf[0]&0xF000)>>12; 210 2 } 211 1 //STAGE 1: END 212 1 213 1 if(ccode==0) 214 1 { 215 2 stage=2; 216 2 217 2 hid_req[1]=0x2200; //Change HID req into HID report descriptor 218 2 219 2 //STAGE 2 220 2 make_ptd(cbuf,SETUP,0,8,0,addr,port); 221 2 if(control_type=='D') {array_app(cbuf+4,dev_req,4);} 222 2 if(control_type=='C') {array_app(cbuf+4,cfg_req,4);} 223 2 if(control_type=='S') {array_app(cbuf+4,str_req,4);} 224 2 if(control_type=='I') {array_app(cbuf+4,int_req,4);} 225 2 if(control_type=='E') {array_app(cbuf+4,end_req,4);} 226 2 if(control_type=='H') {array_app(cbuf+4,hid_req,4);} 227 2 228 2 if(control_type=='S') 229 2 { 230 3 cbuf[5]=cbuf[5]|extra; 231 3 } 232 2 233 2 cbuf[7]=DesSize; 234 2 tout=send_control(cbuf,rbuf); 235 2 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 236 2 237 2 word_size=(DesSize+1)>>1; 238 2 C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 5 239 2 RemainSize=DesSize; 240 2 241 2 toggle_cnt=0; 242 2 cnt=0; 243 2 do 244 2 { 245 3 //send out DATA IN packet 246 3 toggle_cnt++; 247 3 248 3 //The last transaction where remaining data size < max pac size 249 3 if(RemainSize>12; 264 3 265 3 RemainSize=RemainSize-MaxSize; 266 3 267 3 LocalLimit=MaxSize>>1; 268 3 269 3 if(ccode==0)//Data In is sucessful 270 3 { 271 4 lcnt=0; 272 4 do 273 4 { 274 5 //Copy the data located right after the 8 bytes PTD 275 5 *(rptr+cnt)=rbuf[4+lcnt]; 276 5 277 5 cnt++; 278 5 lcnt++; 279 5 } 280 4 while(lcnt<(LocalLimit)); 281 4 } 282 3 283 3 } 284 2 while((cnt>12; 297 2 //STAGE 3: END 298 2 } 299 1 300 1 return( (ccode)|(stage<<8) ); C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 6 301 1 302 1 // byte 0 indicates the error code 303 1 // byte 2 indicates at which stage the error was encountered 304 1 // byte 3 is F if time-out, else 0 305 1 } 306 307 unsigned int get_control(unsigned int *rptr,unsigned int addr,char control_type,unsigned int extra,int por -t) 308 { 309 1 unsigned int cbuf[128]; 310 1 unsigned int rbuf[128]; 311 1 unsigned int cnt=0,lcnt=0; 312 1 unsigned int toggle_cnt=0; 313 1 unsigned int word_size; 314 1 unsigned int DesSize,MaxSize; 315 1 316 1 unsigned int dev_req[4]={0x0680,0x0100 ,0x0000,0x8}; 317 1 unsigned int cfg_req[4]={0x0680,0x0200 ,0x0000,0x8}; 318 1 unsigned int str_req[4]={0x0680,0x0300 ,0x0000,0x8}; 319 1 unsigned int int_req[4]={0x0680,0x0400 ,0x0000,0x8}; 320 1 unsigned int end_req[4]={0x0680,0x0500 ,0x0000,0x8}; 321 1 unsigned int hid_req[4]={0x0681,0x2100 ,0x0000,0x8}; 322 1 323 1 unsigned int ccode=0; 324 1 unsigned int stage=1; 325 1 unsigned int tout; //timeout indicator 326 1 327 1 //STAGE 1 : Send out first setup packet 328 1 make_ptd(cbuf,SETUP,0,8,0,addr,port); 329 1 if(control_type=='D') {array_app(cbuf+4,dev_req,4);} 330 1 if(control_type=='C') {array_app(cbuf+4,cfg_req,4);} 331 1 if(control_type=='S') {array_app(cbuf+4,str_req,4);} 332 1 if(control_type=='I') {array_app(cbuf+4,int_req,4);} 333 1 if(control_type=='E') {array_app(cbuf+4,end_req,4);} 334 1 if(control_type=='H') {array_app(cbuf+4,hid_req,4);} 335 1 336 1 if(control_type=='S') 337 1 { 338 2 cbuf[5]=cbuf[5]|extra; //This is for string processing 339 2 } 340 1 341 1 tout=send_control(cbuf,rbuf); 342 1 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 343 1 344 1 if(ccode==0) 345 1 { 346 2 toggle_cnt++; 347 2 make_ptd(cbuf,IN,0,8,toggle_cnt%2,addr,port); 348 2 tout=send_control(cbuf,rbuf); 349 2 ccode|=(rbuf[0]&0xF000)>>12; 350 2 351 2 if(ccode==0x09) //Descriptor Size is less than 8 352 2 { 353 3 ccode=0; 354 3 } 355 2 356 2 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 357 2 358 2 if(control_type!='C') 359 2 { 360 3 DesSize=((rbuf[4]&0x00FF)); 361 3 } C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 7 362 2 363 2 if(control_type=='C') 364 2 { 365 3 DesSize=rbuf[5]; 366 3 } 367 2 368 2 if(control_type!='D') 369 2 { 370 3 MaxSize=addr_info(addr,'R','M',MaxSize); 371 3 } 372 2 373 2 if(control_type=='D') 374 2 { 375 3 MaxSize=(rbuf[7]&0xFF00)>>8; 376 3 if(MaxSize<8) {MaxSize==8;} 377 3 378 3 addr_info(addr,'W','M',MaxSize); 379 3 } 380 2 381 2 if(control_type=='H') 382 2 { 383 3 DesSize=(rbuf[7]&0xFF00)>>8; 384 3 if(DesSize<8) {DesSize==8;} 385 3 } 386 2 } 387 1 388 1 if(ccode==0) 389 1 { 390 2 //send out DATA OUT packet 391 2 make_ptd(cbuf,OUT,0,0,toggle_cnt%2,addr,port); 392 2 tout=send_control(cbuf,rbuf); 393 2 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 394 2 395 2 ccode|=(rbuf[0]&0xF000)>>12; 396 2 } 397 1 //STAGE 1: END 398 1 399 1 if(ccode==0) 400 1 { 401 2 stage=2; 402 2 403 2 hid_req[1]=0x2200; //Change HID req into HID report descriptor 404 2 405 2 //STAGE 2 406 2 make_ptd(cbuf,SETUP,0,8,0,addr,port); 407 2 if(control_type=='D') {array_app(cbuf+4,dev_req,4);} 408 2 if(control_type=='C') {array_app(cbuf+4,cfg_req,4);} 409 2 if(control_type=='S') {array_app(cbuf+4,str_req,4);} 410 2 if(control_type=='I') {array_app(cbuf+4,int_req,4);} 411 2 if(control_type=='E') {array_app(cbuf+4,end_req,4);} 412 2 if(control_type=='H') {array_app(cbuf+4,hid_req,4);} 413 2 414 2 if(control_type=='S') 415 2 { 416 3 cbuf[5]=cbuf[5]|extra; 417 3 } 418 2 419 2 cbuf[7]=DesSize; 420 2 tout=send_control(cbuf,rbuf); 421 2 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 422 2 423 2 word_size=(DesSize+1)>>1; C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 8 424 2 425 2 cnt=0; 426 2 427 2 //send out DATA IN packet 428 2 new_make_ptd(cbuf,IN,0,MaxSize,1,addr,port,DesSize); 429 2 430 2 tout=send_control(cbuf,rbuf); 431 2 if(tout==0) {ccode|=0xF000;} //Indicates Timeout in transaction 432 2 433 2 ccode|=(rbuf[0]&0xF000)>>12; 434 2 435 2 if(ccode==0)//Data In is sucessful 436 2 { 437 3 lcnt=0; 438 3 do 439 3 { 440 4 //Copy the data located right after the 8 bytes PTD 441 4 *(rptr+cnt)=rbuf[4+lcnt]; 442 4 443 4 cnt++; 444 4 lcnt++; 445 4 } 446 3 while(lcnt>12; 460 2 //STAGE 3: END 461 2 } 462 1 463 1 return( (ccode)|(stage<<8) ); 464 1 // byte 0 indicates the error code 465 1 // byte 2 indicates at which stage the error was encountered 466 1 // byte 3 is F if time-out, else 0 467 1 } 468 469 unsigned int set_sound(int addr,int port,int r0,int r1,int r2,int r3,int d0) 470 { 471 1 unsigned int cbuf[128]; 472 1 unsigned int rbuf[128]; 473 1 unsigned int uni_req[4]={0x0212,0x0201,0x0200,0x0002}; 474 1 unsigned int audio_req[4]={0xF416,0x0,0x0,0x0}; 475 1 unsigned int mycode=0; 476 1 unsigned int tcnt; 477 1 478 1 uni_req[0]=r0; 479 1 uni_req[1]=r1; 480 1 uni_req[2]=r2; 481 1 uni_req[3]=r3; 482 1 483 1 audio_req[0]=d0; 484 1 485 1 w16(HcUpInt,0x100); C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 9 486 1 487 1 r32(HcATLDone); 488 1 r32(HcATLDone); 489 1 490 1 make_ptd(cbuf,SETUP,0,8,0,addr,port); 491 1 array_app(cbuf+4,uni_req,4); 492 1 tcnt=send_control(cbuf,rbuf); 493 1 mycode=(*rbuf&0xF000)>>12; 494 1 495 1 if(tcnt==0) 496 1 { 497 2 mycode|=0xF000; 498 2 } 499 1 500 1 if(mycode==0) 501 1 { 502 2 //send out DATA IN packet 503 2 make_ptd(cbuf,OUT,0,2,1,addr,port); 504 2 array_app(cbuf+4,audio_req,4); 505 2 tcnt=send_control(cbuf,rbuf); 506 2 mycode=(*rbuf&0xF000)>>12; 507 2 if(tcnt==0) 508 2 { 509 3 mycode|=0xF000; 510 3 } 511 2 } 512 1 r32(HcATLDone); 513 1 514 1 if(mycode==0) 515 1 { 516 2 //send out DATA IN packet 517 2 make_ptd(cbuf,IN,0,0,1,addr,port); 518 2 tcnt=send_control(cbuf,rbuf); 519 2 mycode=(*rbuf&0xF000)>>12; 520 2 if(tcnt==0) 521 2 { 522 3 mycode|=0xF000; 523 3 } 524 2 } 525 1 526 1 r32(HcATLDone); 527 1 528 1 return(mycode); 529 1 } 530 531 unsigned int set_interface(int addr, int interface, int port) 532 { 533 1 unsigned int cbuf[128]; 534 1 unsigned int rbuf[128]; 535 1 unsigned int uni_req[4]={0x0B01,0x0000,0x0001,0x0000}; 536 1 unsigned int mycode=0; 537 1 unsigned int tcnt; 538 1 539 1 uni_req[1]=interface; 540 1 541 1 w16(HcUpInt,0x100); 542 1 543 1 r32(HcATLDone); 544 1 r32(HcATLDone); 545 1 546 1 make_ptd(cbuf,SETUP,0,8,0,addr,port); 547 1 array_app(cbuf+4,uni_req,4); C51 COMPILER V7.06 USB 08/02/2005 13:30:05 PAGE 10 548 1 tcnt=send_control(cbuf,rbuf); 549 1 mycode=(*rbuf&0xF000)>>12; 550 1 551 1 if(tcnt==0) 552 1 { 553 2 mycode|=0xF000; 554 2 } 555 1 556 1 if(mycode==0) 557 1 { 558 2 //send out DATA IN packet 559 2 make_ptd(cbuf,IN,0,0,1,addr,port); 560 2 tcnt=send_control(cbuf,rbuf); 561 2 mycode=(*rbuf&0xF000)>>12; 562 2 if(tcnt==0) 563 2 { 564 3 mycode|=0xF000; 565 3 } 566 2 } 567 1 568 1 r32(HcATLDone); 569 1 570 1 return(mycode); 571 1 } 572 573 574 575 576 C51 COMPILATION COMPLETE. 1 WARNING(S), 1 ERROR(S)