hal_usb.lst

来自「非常全的nrf2401设计资料」· LST 代码 · 共 960 行 · 第 1/3 页

LST
960
字号
C51 COMPILER V7.50   HAL_USB                                                               04/09/2009 10:12:51 PAGE 11  

 601   4                     case 0x01:
 602   4                         g_hal_usb.state = CONFIGURED;
 603   4                         g_hal_usb.bm_state |= USB_BM_STATE_CONFIGURED;
 604   4                         g_hal_usb.current_config = 0x01;
 605   4                         USB_EP0_HSNAK();
 606   4                         break;
 607   4                     default:
 608   4                         USB_EP0_STALL();
 609   4                         break;
 610   4                 }
 611   3                 break;
 612   3              case USB_REQ_GET_INTERFACE: // GET_INTERFACE
 613   3                  i_usb.map->in0buf[0] = g_hal_usb.current_alt_interface;
 614   3                  i_usb.map->in0bc = 0x01;
 615   3                  break;
 616   3              case USB_REQ_SET_INTERFACE: // SET_INTERFACE
 617   3              case USB_REQ_SYNCH_FRAME:   // SYNCH_FRAME
 618   3                 USB_EP0_STALL();  // We do not support any of these
 619   3                 break;
 620   3              default:
 621   3                 USB_EP0_STALL();
 622   3                 break;
 623   3              };
 624   2          } 
 625   1          // bmRequestType = 0 01 xxxxx : Data transfer direction: Host-to-device, Type: Class
 626   1          else if( ( req.bmRequestType & 0x60 ) == 0x20 )  // Class request
 627   1          {
 628   2              if( req.wLength != 0 && ((req.bmRequestType & 0x80) == 0x00) )
 629   2              {
 630   3                  // If there is a OUT-transaction associated with the Control-Transfer-Write we call the callba
             -ck
 631   3                  // when the OUT-transaction is finished. Note that this function do not handle several out tra
             -nsactions.
 632   3                  i_usb.map->out0bc = 0xff;
 633   3              }
 634   2              else
 635   2              {
 636   3                  ret = g_hal_usb.device_req(&req, &data_ptr, &data_size);
 637   3                  usb_process_dev_req_cb_response(ret, &req, data_ptr, data_size);
 638   3              }
 639   2              // Call the callback function. Data to be sent back to the host is store by the callback in data_p
             -tr and the size in data_size.
 640   2          } 
 641   1          else  // Unknown request type
 642   1          {
 643   2              USB_EP0_STALL();
 644   2          }
 645   1      }
 646          
 647          static void isr_sof()
 648          {
 649   1      }
 650          
 651          static void isr_sutok()
 652          {
 653   1          i_usb.packetizer.data_ptr = NULL;
 654   1          i_usb.packetizer.data_size = 0;
 655   1          i_usb.packetizer.pkt_size = 0;
 656   1      }
 657          
 658          static void isr_suspend()
 659          {
C51 COMPILER V7.50   HAL_USB                                                               04/09/2009 10:12:51 PAGE 12  

 660   1          uint8_t allow_remote_wu = 0;
 661   1      
 662   1          g_hal_usb.bm_state &= ~(USB_BM_STATE_HOST_WU); // We clear the flag that indicates that the host awoke
             - the MCU via USB here
 663   1       
 664   1          if( g_hal_usb.state == CONFIGURED )
 665   1          {
 666   2              if( ( g_hal_usb.bm_state & USB_BM_STATE_ALLOW_REMOTE_WAKEUP ) == USB_BM_STATE_ALLOW_REMOTE_WAKEUP 
             -)
 667   2              {
 668   3                  allow_remote_wu = 1;
 669   3              }
 670   2          }
 671   1      
 672   1          g_hal_usb.state = SUSPENDED;
 673   1      
 674   1          if( g_hal_usb.suspend != NULL ) 
 675   1          {
 676   2              g_hal_usb.suspend(allow_remote_wu);
 677   2          }
 678   1      }
 679          
 680          static void isr_usbreset()
 681          {
 682   1          g_hal_usb.state = DEFAULT;
 683   1          g_hal_usb.current_config = 0;
 684   1          g_hal_usb.current_alt_interface = 0;
 685   1          g_hal_usb.bm_state = 0;
 686   1          if( g_hal_usb.reset != NULL ) g_hal_usb.reset();
 687   1      }
 688          
 689          // For now we only support one out-transaction in a Control Transfer Write
 690          static void isr_ep0out()
 691          {
 692   1          hal_usb_dev_req_resp_t ret;
 693   1          uint8_t* data_ptr;
 694   1          uint16_t data_size;
 695   1          i_usb.packetizer.data_size = 0;
 696   1          req.misc_data = i_usb.map->out0buf;
 697   1          ret = g_hal_usb.device_req(&req, &data_ptr, &data_size);
 698   1          usb_process_dev_req_cb_response(ret, &req, data_ptr, data_size);
 699   1      }
 700          
 701          //lint --e{528} suppress "usb_wu() not referenced"
 702          void usb_wu(void) interrupt USB_WU // address: 0x005b
 703          {
 704   1      #define ICH4
 705   1      #ifdef ICH4
 706   1          uint8_t t;
 707   1      #endif
 708   1      
 709   1          // Check if the wakeup source is the pin to the USB controller
 710   1          // If it is by the pin to the USB controller we want to start
 711   1          // a remote wakeup
 712   1          if( ( i_usb.map->usbcs & 0x80 ) == 0x80 )
 713   1          {
 714   2              // Reset the wakesrc indicator
 715   2              i_usb.map->usbcs = 0x80;
 716   2      
 717   2              // If we are allowed to perform a remote wakeup do that
 718   2              if( ( g_hal_usb.bm_state & USB_BM_STATE_ALLOW_REMOTE_WAKEUP ) == USB_BM_STATE_ALLOW_REMOTE_WAKEUP 
             -)
C51 COMPILER V7.50   HAL_USB                                                               04/09/2009 10:12:51 PAGE 13  

 719   2              {
 720   3      #ifdef ICH4
 721   3                  // Force the J state on the USB lines
 722   3                  i_usb.map->usbcs |= 0x02;
 723   3          
 724   3                  // Typical 5.4us delay
 725   3                  _nop_();
 726   3                  _nop_();
 727   3          
 728   3                  t = i_usb.map->usbcs;
 729   3          
 730   3                  // Stop J state on the USB lines
 731   3                  t &= ~0x02;
 732   3          
 733   3                  // Signal remote resume
 734   3                  t |= 0x01;
 735   3          
 736   3                  // We have to set this register in one operation to avoid
 737   3                  // idle state is restored between the forced J and resume state
 738   3                  i_usb.map->usbcs = t;
 739   3      #else
                          i_usb.map->usbcs |= 0x01;  // Turn on the resume signal on the USB bus
              #endif
 742   3                  delay_ms(7); //.1.7.7 Resume: The remote wakeup device must hold the resume signaling for at 
 743   3                                // least 1 ms but for no more than 15ms
 744   3          
 745   3                  i_usb.map->usbcs &= ~0x01; // Turn off the resume signal on the USB bus
 746   3              }
 747   2          }
 748   1          else 
 749   1          {
 750   2              // We are awoken by the bus
 751   2              g_hal_usb.bm_state |= USB_BM_STATE_HOST_WU;
 752   2          }
 753   1      
 754   1          if( ( g_hal_usb.bm_state & USB_BM_STATE_CONFIGURED ) == USB_BM_STATE_CONFIGURED )
 755   1          {
 756   2              g_hal_usb.state = CONFIGURED;
 757   2          }
 758   1          else
 759   1          {
 760   2              g_hal_usb.state = DEFAULT;
 761   2          }
 762   1      
 763   1          // Call resume callback
 764   1          g_hal_usb.resume();
 765   1      }
 766          
 767          // This function processes the response from the EP callback
 768          static void usb_process_ep_response(uint8_t ret, uint8_t* cs_ptr, uint8_t* bc_ptr)
 769          {
 770   1          if( ret == 0xff ) // Clear the OUTx busy flag enabling reception of the next OUT from USB-host
 771   1          {
 772   2              *bc_ptr = 0xff;
 773   2          }
 774   1          else if( ( ret & 0x80 ) == 0x80 )  // STALL
 775   1          {
 776   2              *cs_ptr = 0x01;
 777   2          }
 778   1          else if( ( ret & 0x60 ) == 0x60 ) // NAK
 779   1          {
 780   2              *cs_ptr = 0x02;
C51 COMPILER V7.50   HAL_USB                                                               04/09/2009 10:12:51 PAGE 14  

 781   2          }
 782   1          else if( ret == 0 ) // Zero length data
 783   1          {
 784   2              *bc_ptr = 0;
 785   2          }
 786   1          else
 787   1          {
 788   2              *bc_ptr = ret;
 789   2          }
 790   1      }
 791          
 792          //lint --e{528} suppress "usb_irq(void) not referenced"
 793          void usb_irq(void) interrupt USB_IRQ // address: 0x0063
 794          {
 795   1          uint8_t ep;
 796   1          uint8_t ret;
 797   1          xdata uint8_t *cs_ptr;
 798   1          xdata uint8_t *buf_ptr;
 799   1          xdata uint8_t *bc_ptr;
 800   1      
 801   1           switch(i_usb.map->ivec)
 802   1           {
 803   2           case INT_SUDAV:
 804   2              i_usb.map->usbirq = 0x01;
 805   2              isr_sudav();
 806   2              break;
 807   2           case INT_SOF:
 808   2              i_usb.map->usbirq = 0x02;
 809   2              isr_sof();
 810   2              break;
 811   2           case INT_SUTOK:
 812   2              i_usb.map->usbirq = 0x04;
 813   2              isr_sutok();
 814   2            break;
 815   2           case INT_SUSPEND:
 816   2              i_usb.map->usbirq = 0x08;
 817   2              isr_suspend();
 818   2              break;
 819   2           case INT_USBRESET:
 820   2              i_usb.map->usbirq = 0x10;
 821   2              isr_usbreset();
 822   2              break;
 823   2           case INT_EP0IN:
 824   2              i_usb.map->in_irq = 0x01;
 825   2              packetizer_isr_ep0_in();
 826   2              break;
 827   2           case INT_EP0OUT:
 828   2              i_usb.map->out_irq = 0x01;
 829   2              isr_ep0out();
 830   2              break;
 831   2           case INT_EP1IN:
 832   2           case INT_EP2IN:
 833   2           case INT_EP3IN:
 834   2           case INT_EP4IN:
 835   2           case INT_EP5IN:
 836   2              // Calculate IN endpoint number
 837   2              ep = ( (i_usb.map->ivec) - INT_EP0IN ) / (INT_EP2IN - INT_EP1IN);
 838   2      
 839   2              // Clear interrupt 
 840   2              i_usb.map->in_irq = ( 1 << ep );
 841   2      
 842   2              cs_ptr = CALCULATE_CS_IN_PTR(ep);
C51 COMPILER V7.50   HAL_USB                                                               04/09/2009 10:12:51 PAGE 15  

 843   2              buf_ptr = CALCULATE_BUF_IN_PTR(ep);
 844   2              bc_ptr = CALCULATE_BC_IN_PTR(ep);
 845   2          
 846   2              // Call registered callback
 847   2              ret = i_usb.endpoint_in_isr[ep - 1](buf_ptr, bc_ptr);
 848   2              usb_process_ep_response(ret, cs_ptr, bc_ptr);
 849   2              break;
 850   2           case INT_EP1OUT:
 851   2           case INT_EP2OUT:
 852   2           case INT_EP3OUT:
 853   2           case INT_EP4OUT:
 854   2           case INT_EP5OUT:
 855   2              // Calculate OUT endpoint number
 856   2              ep = ( (i_usb.map->ivec) - INT_EP0OUT) / (INT_EP2OUT - INT_EP1OUT); 
 857   2      
 858   2              // Clear interrupt
 859   2              i_usb.map->out_irq = ( 1 << ep );
 860   2              
 861   2              cs_ptr = CALCULATE_CS_OUT_PTR(ep);
 862   2              buf_ptr = CALCULATE_BUF_OUT_PTR(ep);
 863   2              bc_ptr = CALCULATE_BC_OUT_PTR(ep);
 864   2      
 865   2              // Call registered callback
 866   2              ret = (i_usb.endpoint_out_isr[ep - 1])(buf_ptr, bc_ptr);
 867   2              usb_process_ep_response(ret, cs_ptr, bc_ptr);
 868   2              break;
 869   2           default:
 870   2              break;
 871   2           };
 872   1      }
 873          
 874          static void delay_ms(uint8_t ms)
 875          {
 876   1          uint16_t i, j;
 877   1          
 878   1          for(i = 0; i < ms; i++ )
 879   1          {
 880   2              for( j = 0; j < 1403; j++) // 196
 881   2              {
 882   3                  _nop_();
 883   3              }
 884   2          }
 885   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   3843    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     79      93
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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