2 ******************************************************************************
4 * @author MCD Application Team
7 * @brief This file implements functions for opening and closing host channels
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
25 /** @addtogroup USBH_LIB
29 /** @addtogroup USBH_LIB_CORE
33 /** @defgroup USBH_HCS
34 * @brief This file includes opening and closing host channels
38 /** @defgroup USBH_HCS_Private_Defines
45 /** @defgroup USBH_HCS_Private_TypesDefinitions
53 /** @defgroup USBH_HCS_Private_Macros
61 /** @defgroup USBH_HCS_Private_Variables
70 /** @defgroup USBH_HCS_Private_FunctionPrototypes
73 static uint16_t USBH_GetFreeChannel (USB_OTG_CORE_HANDLE *pdev);
79 /** @defgroup USBH_HCS_Private_Functions
86 * @brief USBH_Open_Channel
88 * @param pdev : Selected device
89 * @param hc_num: Host channel Number
90 * @param dev_address: USB Device address allocated to attached device
91 * @param speed : USB device speed (Full/Low)
92 * @param ep_type: end point type (Bulk/int/ctl)
93 * @param mps: max pkt size
96 uint8_t USBH_Open_Channel (USB_OTG_CORE_HANDLE *pdev,
104 pdev->host.hc[hc_num].ep_num = pdev->host.channel[hc_num]& 0x7F;
105 pdev->host.hc[hc_num].ep_is_in = (pdev->host.channel[hc_num] & 0x80 ) == 0x80;
106 pdev->host.hc[hc_num].dev_addr = dev_address;
107 pdev->host.hc[hc_num].ep_type = ep_type;
108 pdev->host.hc[hc_num].max_packet = mps;
109 pdev->host.hc[hc_num].speed = speed;
110 pdev->host.hc[hc_num].toggle_in = 0;
111 pdev->host.hc[hc_num].toggle_out = 0;
112 if(speed == HPRT0_PRTSPD_HIGH_SPEED)
114 pdev->host.hc[hc_num].do_ping = 1;
117 USB_OTG_HC_Init(pdev, hc_num) ;
124 * @brief USBH_Modify_Channel
126 * @param pdev : Selected device
127 * @param hc_num: Host channel Number
128 * @param dev_address: USB Device address allocated to attached device
129 * @param speed : USB device speed (Full/Low)
130 * @param ep_type: end point type (Bulk/int/ctl)
131 * @param mps: max pkt size
134 uint8_t USBH_Modify_Channel (USB_OTG_CORE_HANDLE *pdev,
144 pdev->host.hc[hc_num].dev_addr = dev_address;
147 if((pdev->host.hc[hc_num].max_packet != mps) && (mps != 0))
149 pdev->host.hc[hc_num].max_packet = mps;
152 if((pdev->host.hc[hc_num].speed != speed ) && (speed != 0 ))
154 pdev->host.hc[hc_num].speed = speed;
157 USB_OTG_HC_Init(pdev, hc_num);
163 * @brief USBH_Alloc_Channel
164 * Allocate a new channel for the pipe
165 * @param ep_addr: End point for which the channel to be allocated
166 * @retval hc_num: Host channel number
168 uint8_t USBH_Alloc_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr)
172 hc_num = USBH_GetFreeChannel(pdev);
174 if (hc_num != HC_ERROR)
176 pdev->host.channel[hc_num] = HC_USED | ep_addr;
182 * @brief USBH_Free_Pipe
183 * Free the USB host channel
184 * @param idx: Channel number to be freed
187 uint8_t USBH_Free_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t idx)
191 pdev->host.channel[idx] &= HC_USED_MASK;
198 * @brief USBH_DeAllocate_AllChannel
199 * Free all USB host channel
200 * @param pdev : core instance
203 uint8_t USBH_DeAllocate_AllChannel (USB_OTG_CORE_HANDLE *pdev)
207 for (idx = 2; idx < HC_MAX ; idx ++)
209 pdev->host.channel[idx] = 0;
215 * @brief USBH_GetFreeChannel
216 * Get a free channel number for allocation to a device endpoint
218 * @retval idx: Free Channel number
220 static uint16_t USBH_GetFreeChannel (USB_OTG_CORE_HANDLE *pdev)
224 for (idx = 0 ; idx < HC_MAX ; idx++)
226 if ((pdev->host.channel[idx] & HC_USED) == 0)
251 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/