⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainloop.lst

📁 飞利浦usb D12芯片fireware 源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 262          /*Receive         = Enabled   */
 263          /*Auto Addressing    = Disabled   */
 264          void init_serial(void)
 265          {
 266   1      #ifdef __C51__
 267   1              SCON = 0X52;
 268   1              PCON = 0X80 | PCON;
 269   1              TMOD = 0X20;
 270   1              TCON = 0x69;    /* TCON */
 271   1              TH1 = 0xF3;
 272   1      #endif
 273   1      }
 274          
 275          void on_exit(void)
 276          {
 277   1      #ifndef __C51__
                      unsigned char c;
              
                      disable();
              
                      c = inportb(0x21);
                      c |= 0x20;
                      outportb(0x21, c);
              
                      setvect(0xD, OldUsbIsr);
              
                      setvect(0x8, OldTimerIsr);
              
                      disconnect_USB();
              
                      enable();
              
C51 COMPILER V8.02   MAINLOOP                                                              07/27/2007 11:10:49 PAGE 20  

                      farfree(privateBuffer);
              #endif
 296   1      }
 297          
 298          void main(void)
 299          {
 300   1      
 301   1              BOOL in_loop = TRUE;
 302   1              unsigned char key, i;
 303   1      #ifndef __C51__
                      unsigned long ClockSec, last_clk;
              #endif
 306   1              
 307   1              init_port();
 308   1      
 309   1              init_serial();
 310   1      
 311   1              init_timer0();
 312   1      
 313   1              init_special_interrupts();
 314   1      
 315   1              printf("\nPDIUSBD12 evaluation board firmware V2.2.\n");
 316   1              printf("Copyright (c) Philips Semiconductors, 1998.\n");
 317   1      
 318   1              /* Power on reset, lightup LEDs for 1 sec,
 319   1                 disconnect and reconnect Soft-Connect */
 320   1              printf("Re-connect PDIUSBD12 evaluation board to USB.\n");
 321   1              reconnect_USB();
 322   1      
 323   1              /* Main program loop */
 324   1      
 325   1              while( in_loop ){
 326   2      
 327   2      #ifdef __C51__
 328   2                      if (bEPPflags.bits.timer){
 329   3                              DISABLE;
 330   3                              bEPPflags.bits.timer = 0;
 331   3                              ENABLE;
 332   3      
 333   3                              if(bEPPflags.bits.configuration)
 334   3                                      check_key_LED();
 335   3                      }
 336   2      
 337   2                      if(RI)   {
 338   3                              key = _getkey();
 339   3      #else
                              if (bEPPflags.bits.timer){
                                      DISABLE;
                                      bEPPflags.bits.timer = 0;
                                      ENABLE;
              
                                      if(bEPPflags.bits.configuration)
                                              check_key_LED();
              
                                      ClockSec = ClockTicks*10/182;
                                      if(ClockSec != last_clk) {
                                              printf("Idle time = %ld sec.\r", (ClockTicks - ClockIsr)*10/182);
                                              last_clk = ClockSec;
                                      }
                              }
              
                              if( bioskey(1) ) {
C51 COMPILER V8.02   MAINLOOP                                                              07/27/2007 11:10:49 PAGE 21  

                                      key = bioskey(0);
                                      key &= 0xff;
              #endif
 359   3                              switch(key) {
 360   4                                      case 0x1b: /* ESC */
 361   4      #ifndef __C51__
                                                      in_loop = FALSE;
              #endif
 364   4                                              break;
 365   4                                      case 'r':
 366   4                                              D12_SendResume();
 367   4                                              break;
 368   4                                      case 'i':
 369   4                                              if(bEPPflags.bits.control_state == USB_IDLE)
 370   4                                                      printf("Control state = USB_IDLE.");
 371   4                                              else if(bEPPflags.bits.control_state == USB_RECEIVE)
 372   4                                                      printf("Control state = USB_RECEIVE.");
 373   4                                              else if(bEPPflags.bits.control_state == USB_TRANSMIT)
 374   4                                                      printf("Control state = USB_TRANSMIT.");
 375   4                                              printf(" ControlData.wCount = %x.\n", ControlData.wCount);
 376   4      #ifndef __C51__
                                                      printf("Endpoint 4 (Bulk Out) Status = %x, Endpoint 5 (Bulk In) Status = %x.\n",
                                                         D12_ReadEndpointStatus(4), D12_ReadEndpointStatus(5));
                                                      printf("ioSize = %x, ioCount = %x.\n", ioSize, ioCount);
              #else
 381   4                                              printf("Endpoint 4 (Bulk Out) Status = %bx, Endpoint 5 (Bulk In) Status = %bx.\n",
 382   4                                                 D12_ReadEndpointStatus(4), D12_ReadEndpointStatus(5));
 383   4      #endif
 384   4                                              if(bEPPflags.bits.dma_state == DMA_IDLE)
 385   4                                                      printf("DMA_State = DMA_IDLE.\n");
 386   4                                              else if(bEPPflags.bits.dma_state == DMA_RUNNING)
 387   4                                                      printf("DMA_State = DMA_RUNNING.\n");
 388   4                                              else if(bEPPflags.bits.dma_state == DMA_PENDING)
 389   4                                                      printf("DMA_State = DMA_PENDING.\n");
 390   4      
 391   4      #ifndef __C51__
                                                      printf("Last Device Request: bmRequestType = 0x%x, bRequest= 0x%x, wValue = 0x%x, wLength = 0x%x, wIn
             -dex = 0x%x.\n",
                                                              ControlData.DeviceRequest.bmRequestType,
                                                              ControlData.DeviceRequest.bRequest,
                                                              ControlData.DeviceRequest.wValue,
                                                              ControlData.DeviceRequest.wLength,
                                                              ControlData.DeviceRequest.wIndex);
              #else
 399   4                                              MCU_HOSTDACK = 1;
 400   4                                              printf("CPLD counter read back = 0x%bx, 0x%bx.\n", inportb(CPLD_CNT0),
 401   4                                                      inportb(CPLD_CNT1));
 402   4                                              MCU_HOSTDACK = 0;
 403   4                                              printf("Last Device Request: bmRequestType = 0x%bx, bRequest= 0x%bx, wValue = 0x%x, wLength = 0x%x, w
             -Index = 0x%x.\n",
 404   4      
 405   4                                                      ControlData.DeviceRequest.bmRequestType,
 406   4                                                      ControlData.DeviceRequest.bRequest,
 407   4                                                      ControlData.DeviceRequest.wValue,
 408   4                                                      ControlData.DeviceRequest.wLength,
 409   4                                                      ControlData.DeviceRequest.wIndex);
 410   4      #endif
 411   4      
 412   4                                              printf("Data: ");
 413   4                                              for(i = 0; i < ControlData.DeviceRequest.wLength; i ++)
 414   4      #ifndef __C51__
                                                              printf("0x%x, ", *((ControlData.dataBuffer)+i));
C51 COMPILER V8.02   MAINLOOP                                                              07/27/2007 11:10:49 PAGE 22  

              #else
 417   4                                                      printf("0x%bx, ", *((ControlData.dataBuffer)+i));
 418   4      #endif
 419   4                                              printf("\n");
 420   4      
 421   4                                              break;
 422   4                                      case '\r':
 423   4                                              reconnect_USB();
 424   4                                              break;
 425   4      
 426   4                                      case 'v':
 427   4                                              if(bEPPflags.bits.verbose == 0) {
 428   5                                                      printf("Verbose Mode = ON.\n");
 429   5                                                      DISABLE;
 430   5                                                      bEPPflags.bits.verbose = 1;
 431   5                                                      ENABLE;
 432   5                                              }
 433   4                                              else {
 434   5                                                      printf("Verbose Mode = OFF.\n");
 435   5                                                      DISABLE;
 436   5                                                      bEPPflags.bits.verbose = 0;
 437   5                                                      ENABLE;
 438   5                                              }
 439   4                                              break;
 440   4                                      default:
 441   4                                              break;
 442   4                              }
 443   3                      }
 444   2      
 445   2      
 446   2                      if (bEPPflags.bits.bus_reset) {
 447   3                              DISABLE;
 448   3                              bEPPflags.bits.bus_reset = 0;
 449   3                              ENABLE;
 450   3                              printf("Bus reset!\n");
 451   3                      } // if bus reset
 452   2      
 453   2                      if (bEPPflags.bits.suspend) {
 454   3                              DISABLE;
 455   3                              bEPPflags.bits.suspend= 0;
 456   3                              ENABLE;
 457   3                              suspend_change();
 458   3                              printf("Suspend change!\n");
 459   3                      } // if suspend change
 460   2      
 461   2                      if (bEPPflags.bits.setup_packet){
 462   3                              DISABLE;
 463   3                              bEPPflags.bits.setup_packet = 0;
 464   3                              ENABLE;
 465   3                              control_handler();
 466   3                      } // if setup_packet
 467   2      
 468   2                      if(bEPPflags.bits.setup_dma) {
 469   3                              DISABLE;
 470   3                              bEPPflags.bits.setup_dma = 0;
 471   3                              ENABLE;
 472   3                              setup_dma();
 473   3                      } // if setup_dma
 474   2      
 475   2              } // Main Loop
 476   1      
 477   1              on_exit();
C51 COMPILER V8.02   MAINLOOP                                                              07/27/2007 11:10:49 PAGE 23  

 478   1      }
 479          
 480          void suspend_change(void)
 481          {
 482   1      }
 483          
 484          void stall_ep0(void)
 485          {
 486   1              D12_SetEndpointStatus(0, 1);
 487   1              D12_SetEndpointStatus(1, 1);
 488   1      }
 489          
 490          void disconnect_USB(void)
 491          {
 492   1              // Initialize D12 configuration
 493   1              D12_SetMode(D12_NOLAZYCLOCK|D12_CLOCKRUNNING, D12_SETTOONE | D12_CLOCK_12M);
 494   1      }
 495          
 496          void connect_USB(void)
 497          {
 498   1              // reset event flags
 499   1              DISABLE;
 500   1              bEPPflags.value = 0;
 501   1              ENABLE;
 502   1      
 503   1              // V2.1 enable normal+sof interrupt
 504   1              D12_SetDMA(D12_ENDP4INTENABLE | D12_ENDP5INTENABLE);
 505   1      
 506   1              // Initialize D12 configuration
 507   1              D12_SetMode(D12_NOLAZYCLOCK|D12_CLOCKRUNNING|D12_SOFTCONNECT, D12_SETTOONE | D12_CLOCK_12M);
 508   1      }
 509          
 510          
 511          void reconnect_USB(void)
 512          {
 513   1              unsigned long clk_cnt;
 514   1      
 515   1      #ifndef __C51__
                      D12Eval_outportb(0xF, 0xF);
              #else
 518   1              MCU_LED0 = 0;
 519   1              MCU_LED1 = 0;
 520   1      #endif
 521   1              disconnect_USB();
 522   1      
 523   1              printf("Wait for 1 second ...\n");
 524   1      
 525   1              clk_cnt = ClockTicks;
 526   1              while(ClockTicks < clk_cnt + 20)
 527   1                      ;
 528   1      
 529   1              connect_USB();
 530   1      
 531   1      #ifndef __C51__
                      D12Eval_outportb(0x0, 0xF);
              #else
 534   1              MCU_LED0 = 1;
 535   1              MCU_LED1 = 1;
 536   1      #endif
 537   1      }
 538          
 539          void init_unconfig(void)
C51 COMPILER V8.02   MAINLOOP                                                              07/27/2007 11:10:49 PAGE 24  

 540          {
 541   1              unsigned char i;
 542   1      
 543   1              D12_SetE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -