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

📄 chap_9.lst

📁 周立功的LPC214x固件程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
  201   2                          //为“0”时,返回输出(OUT)端点的状态
  202   2                  c = USB_SelectEndpoint(endp * 2 + 1);               /* 读 IN 端点状态       read status of the IN endpoint */
  203   2              else
  204   2                  c = USB_SelectEndpoint(endp * 2);                   /* 读 OUT 端点状态      read status of the OUT endpoint */
  205   2              if(c & USB_STALL)
  206   2                  txdat[0] = 1;                                       /* 端点已被禁止         the endpoint is stalled */
  207   2              else
  208   2                  txdat[0] = 0;                                       /* 端点已解禁           the endpoint is unstalled */
  209   2              txdat[1] = 0;
  210   2              single_transmit(txdat, 2);                              /* 发送16ibt到USB主机   transmit 16-bit to USB host */
  211   2      
  212   2          }
  213   1          else
  214   1              stall_ep0();                                            /* 非标准请求,禁止逻辑端点0 */
  215   1                                                                      /* not standard request, stall logical endpoint 0 */    
  216   1      }                                                               
  217          
  218          
  219          /********************************************************************************************************
             -*******
  220          ** 函数名称: clear_feature()                        Name:     clear_feature()
  221          ** 功能描述: 清除特性                               Function: clear feature
  222          *********************************************************************************************************
             -*******/
  223          void clear_feature(void)
  224          {
  225   1          INT8U endp;
  226   1          INT8U bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
  227   1                                                                      /* 获取请求类型          get request type */
  228   1          if (bRecipient == USB_RECIPIENT_DEVICE                  
  229   1              && ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP)
  230   1          {   /* request device */
  231   2              DISABLE();                              
  232   2              bEPPflags.bits.remote_wakeup = 0;                       /* 清除远程唤醒特性     clear reamote wakeup feature */ 
  233   2              ENABLE();
  234   2              single_transmit(0, 0);                                  /* 返回一个空包         return an empty packet */
  235   2          }
  236   1          
  237   1          else if (bRecipient == USB_RECIPIENT_ENDPOINT
  238   1              && ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL)
  239   1          {
  240   2              /* request endpoint */
  241   2              endp = (INT8U)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
  242   2              if (ControlData.DeviceRequest.wIndex & (INT8U)USB_ENDPOINT_DIRECTION_MASK)
  243   2                  USB_SetEndpointStatus(endp * 2 + 1, 0);             /* 解禁 IN 端点         the IN endpoint is unstalled */
  244   2              else
  245   2                  USB_SetEndpointStatus(endp * 2, 0);                 /* 解禁 OUT 端点        the OUT endpoint is unstalled */
  246   2              single_transmit(0, 0);                                  /* 发送空包表示执行成功 return an empty packet indicate perform sucessfu
             -lly */
  247   2          } else
  248   1              stall_ep0();                                            /* 不成功,禁止逻辑端点0 not the request, stall logical endpoint 0 */                            
  249   1      }
ARM COMPILER V2.53,  Chap_9                                                                28/06/07  09:54:11  PAGE 5   

  250          
  251          
  252          /********************************************************************************************************
             -*******
  253          ** 函数名称: set_feature()                          Name:    set_feature() 
  254          ** 功能描述: 设置特性                               Function: set feature
  255          *********************************************************************************************************
             -*******/
  256          void set_feature(void)
  257          {
  258   1          INT8U endp;                                         
  259   1          INT8U bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
  260   1                                                                      /* 获取请求类型         get request type */
  261   1          if (bRecipient == USB_RECIPIENT_DEVICE                      /* 请求设备             request device */
  262   1              && ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP) 
  263   1          {   
  264   2              DISABLE();
  265   2              bEPPflags.bits.remote_wakeup = 1;                       /* 设置远程唤醒标志     set reamote wakeup flag */
  266   2              ENABLE();
  267   2              single_transmit(0, 0);                                  /* 返回一个空包         return an empty packet */
  268   2          }   
  269   1          
  270   1          else if (bRecipient == USB_RECIPIENT_ENDPOINT               /* 请求端点             request endpoint */
  271   1              && ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL)
  272   1          {
  273   2              endp = (INT8U)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
  274   2              if (ControlData.DeviceRequest.wIndex & (INT8U)USB_ENDPOINT_DIRECTION_MASK)
  275   2                  USB_SetEndpointStatus(endp * 2 + 1, 1);             /* IN 端点被禁止        the IN endpoint is stalled */
  276   2              else
  277   2                  USB_SetEndpointStatus(endp * 2, 1);                 /* OUT端点被禁止        the OUT endpoint is stalled */
  278   2              single_transmit(0, 0);                                  /* 返回一个空包         return an empty packet */
  279   2          } else
  280   1              stall_ep0();                                            /* 非标准请求,禁止逻辑端点0  not the request, stall logical endpoint 0 */
  281   1      }
  282          
  283          /********************************************************************************************************
             -*******
  284          ** 函数名称: set_address()                          Name:     set_address()
  285          ** 功能描述: 设置地址                               Function: set the address of the USB device 
  286          *********************************************************************************************************
             -*******/
  287          void set_address(void)
  288          {
  289   1          USB_SetAddressEnable((INT8U)(ControlData.DeviceRequest.wValue &
  290   1                               DEVICE_ADDRESS_MASK), 1);
  291   1      
  292   1          single_transmit(0, 0);                                      /* 返回一个空包     return an empty packet */
  293   1      }
  294          
  295          
  296          
  297          /********************************************************************************************************
             -*******
  298          ** 函数名称: get_descriptor()                       Name:     get_descriptor()
  299          ** 功能描述: 获取描述符                             Function: get the descriptor of the USB device 
  300          *********************************************************************************************************
             -*******/
  301          void get_descriptor(void)
  302          {   
  303   1          /* get the type of descriptor */                            /* 取得描述符类型 */
  304   1          INT8U bDescriptor = MSB(ControlData.DeviceRequest.wValue);  
  305   1      
  306   1          if (bDescriptor == USB_DEVICE_DESCRIPTOR_TYPE)
  307   1          {   /* get the device descriptor */                         /* 获取设备描述符 */
  308   2              code_transmit((INT8U *)&DeviceDescr, sizeof(USB_DEVICE_DESCRIPTOR));
  309   2          }
ARM COMPILER V2.53,  Chap_9                                                                28/06/07  09:54:11  PAGE 6   

  310   1          
  311   1          else if (bDescriptor == USB_CONFIGURATION_DESCRIPTOR_TYPE)
  312   1          {    /* get other descriptors */                            /* 获取其它描述符 */
  313   2               if (ControlData.DeviceRequest.wLength > CONFIG_DESCRIPTOR_LENGTH)
  314   2                   ControlData.DeviceRequest.wLength = CONFIG_DESCRIPTOR_LENGTH;
  315   2      
  316   2               /* transmit content of the descripotrs */              /* 传输描述符内容 */
  317   2               code_transmit((INT8U *)&(usb_descr.ConfigDescr), ControlData.DeviceRequest.wLength);
  318   2                                                          
  319   2          }else                                                       /* no the descriptor type, stall logical endpoint 0 */
  320   1               stall_ep0();                                           /* 没有要求的描述符,禁止逻辑端点0 */
  321   1      }
  322          
  323          
  324          /********************************************************************************************************
             -*******
  325          ** 函数名称: get_configuration()                    Name:     get_configuration()   
  326          ** 功能描述: 获取配置                               Function: get the configuration value of the USB device
  327          *********************************************************************************************************
             -*******/
  328          void get_configuration(void)
  329          {
  330   1          INT8U c = bEPPflags.bits.configuration;                     /* 取得配置值       get the configuration value */
  331   1              
  332   1          single_transmit(&c, 1);                                     /* 传输配置值       transmit configuration value */
  333   1      }
  334          
  335          
  336          /********************************************************************************************************
             -*******
  337          ** 函数名称: set_configuration()                    Name:     set_configuration()
  338          ** 功能描述: 设置配置                               Function: set the configuration value of the USB device 
  339          *********************************************************************************************************
             -*******/
  340          void set_configuration(void)
  341          {
  342   1          if (ControlData.DeviceRequest.wValue == 0)
  343   1          {   /* the recieved data is error */
  344   2              single_transmit(0, 0);                                  /* 传输一个空包             transmit an empty packet */
  345   2              DISABLE();
  346   2              bEPPflags.bits.configuration = 0;                       /* 标识设备未配置           flag the device not configured */
  347   2              ENABLE();
  348   2              init_unconfig();                                        /* 禁止除0外的所有逻辑端点  disable all endpoint except logical endpoint 0 */
  349   2          } 
  350   1          
  351   1          else if (ControlData.DeviceRequest.wValue == 1)
  352   1          {   /* configure the device */ 
  353   2              single_transmit(0, 0);                                  /* 传输一个空包             transmit an empty packet */
  354   2              init_unconfig();                                        /* 禁止除0外的所有逻辑端点  disable all endpoint except logical endpoint 0 */
  355   2              init_config();                                          /* 使能全部端点             enable all endpoint */
  356   2              DISABLE();
  357   2              bEPPflags.bits.configuration = 1;                       /* 标识设备已被配置         flag the device configured */
  358   2              ENABLE();
  359   2          } else                                                      /* no the descriptor type, stall logical endpoint 0 */
  360   1              stall_ep0();                                            /* 没有要求的描述符,禁止逻辑端点0 */
  361   1      }
  362          
  363          
  364          /********************************************************************************************************
             -*******
  365          ** 函数名称: get_interface()                        Name     : get_interface()
  366          ** 功能描述: 获取接口信息                           Function : get the information of the interface 
  367          *********************************************************************************************************
             -*******/
  368          void get_interface(void)
  369          {
ARM COMPILER V2.53,  Chap_9                                                                28/06/07  09:54:11  PAGE 7   

  370   1          INT8U txdat = 0;                                            /* 只有一个接口              there only is a interface */
  371   1          single_transmit(&txdat, 1);                                 /* 传输一个字节              transmit a byte */
  372   1      }
  373          
  374          
  375          /********************************************************************************************************
             -*******
  376          ** 函数名称: set_interface()                        Name:     set_interface()
  377          ** 功能描述: 设置接口信息                           Function: set the information of the interface 
  378          *********************************************************************************************************
             -*******/
  379          void set_interface(void)
  380          {
  381   1          if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0)
  382   1              single_transmit(0, 0);                                  /* 返回一个空包,表示执行成功       return an empty packet indicate perfo
             -rm sucessfully */
  383   1          else        
  384   1              stall_ep0();                                            /* 没有要求的描述符,禁止逻辑端点0  no the request, stall logical endpoint 0 */      
  385   1      }
  386          
  387          
  388          /********************************************************************************************************
             -*******
  389          ** 函数名称: control_handler()                      Name     : control_handler()
  390          ** 功能描述: 控制传输                               Function : deal with control transfer   
  391          *********************************************************************************************************
             -*******/
  392          void control_handler()
  393          {
  394   1          INT8U type, req;

⌨️ 快捷键说明

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