STM32 USB Host Library 学习笔记 (2) USBH_InterruptSendData() USBH_ClrFeature()

 1 /**
 2   * @brief  USBH_InterruptSendData
 3   *         Sends the data on Interrupt OUT Endpoint
 4   * @param  pdev: Selected device
 5   * @param  buff: Buffer pointer from where the data needs to be copied
 6   * @param  length: Length of the data to be sent
 7   * @param  hc_num: Host channel Number
 8   * @retval Status. 
 9   */
10 USBH_Status USBH_InterruptSendData( USB_OTG_CORE_HANDLE *pdev, 
11                                 uint8_t *buff, 
12                                 uint8_t length,
13                                 uint8_t hc_num)
14 {
15 
16   pdev->host.hc[hc_num].ep_is_in = 0;  
17   pdev->host.hc[hc_num].xfer_buff = buff;
18   pdev->host.hc[hc_num].xfer_len = length;
19   
20   if(pdev->host.hc[hc_num].toggle_in == 0)
21   {
22     pdev->host.hc[hc_num].data_pid = HC_PID_DATA0;
23   }
24   else
25   {
26     pdev->host.hc[hc_num].data_pid = HC_PID_DATA1;
27   }
28 
29   pdev->host.hc[hc_num].toggle_in ^= 1;  
30   
31   HCD_SubmitRequest (pdev , hc_num);  
32   
33   return USBH_OK;
34 }

toggle_in or toggle_out ?

 1 /**
 2   * @brief  USBH_BulkSendData
 3   *         Sends the Bulk Packet to the device
 4   * @param  pdev: Selected device
 5   * @param  buff: Buffer pointer from which the Data will be sent to Device
 6   * @param  length: Length of the data to be sent
 7   * @param  hc_num: Host channel Number
 8   * @retval Status
 9   */
10 USBH_Status USBH_BulkSendData ( USB_OTG_CORE_HANDLE *pdev, 
11                                 uint8_t *buff, 
12                                 uint16_t length,
13                                 uint8_t hc_num)
14 { 
15   pdev->host.hc[hc_num].ep_is_in = 0;
16   pdev->host.hc[hc_num].xfer_buff = buff;
17   pdev->host.hc[hc_num].xfer_len = length;  
18 
19  /* Set the Data Toggle bit as per the Flag */
20   if ( pdev->host.hc[hc_num].toggle_out == 0)
21   { /* Put the PID 0 */
22       pdev->host.hc[hc_num].data_pid = HC_PID_DATA0;    
23   }
24  else
25  { /* Put the PID 1 */
26       pdev->host.hc[hc_num].data_pid = HC_PID_DATA1 ;
27  }
28 
29   HCD_SubmitRequest (pdev , hc_num);   
30   return USBH_OK;
31 }
  else if (hcint.b.chhltd) // usb_hcd_int.c
  {
    MASK_HOST_INT_CHH (num);
    
    if(pdev->host.HC_Status[num] == HC_XFRC)
    {
      pdev->host.URB_State[num] = URB_DONE;  
      
      if (hcchar.b.eptype == EP_TYPE_BULK)
      {
        pdev->host.hc[num].toggle_out ^= 1; 
      }
    }
  }

 1 /**
 2 * @brief  USBH_ClrFeature
 3 *         This request is used to clear or disable a specific feature.
 4 
 5 * @param  pdev: Selected device
 6 * @param  ep_num: endpoint number 
 7 * @param  hc_num: Host channel number 
 8 * @retval Status
 9 */
10 USBH_Status USBH_ClrFeature(USB_OTG_CORE_HANDLE *pdev,
11                             USBH_HOST *phost,
12                             uint8_t ep_num, 
13                             uint8_t hc_num) 
14 {
15   
16   phost->Control.setup.b.bmRequestType = USB_H2D | 
17                                          USB_REQ_RECIPIENT_ENDPOINT |
18                                          USB_REQ_TYPE_STANDARD;
19   
20   phost->Control.setup.b.bRequest = USB_REQ_CLEAR_FEATURE;
21   phost->Control.setup.b.wValue.w = FEATURE_SELECTOR_ENDPOINT;
22   phost->Control.setup.b.wIndex.w = ep_num;
23   phost->Control.setup.b.wLength.w = 0;           
24   
25   if ((ep_num & USB_REQ_DIR_MASK ) == USB_D2H)
26   { /* EP Type is IN */
27     pdev->host.hc[hc_num].toggle_in = 0; 
28   }
29   else
30   {/* EP Type is OUT */
31     pdev->host.hc[hc_num].toggle_out = 0; 
32   }
33   
34   return USBH_CtlReq(pdev, phost, 0 , 0 );   
35 }

posted @ 2012-09-01 23:32  IAmAProgrammer  阅读(3284)  评论(0编辑  收藏  举报