Nirvana Jay / Mbed 2 deprecated F7DISCO_Demo

Dependencies:   BSP_DISCO_F746NG_patch mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbh_pipes.c Source File

usbh_pipes.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    usbh_pipes.c
00004   * @author  MCD Application Team
00005   * @version V3.2.2
00006   * @date    07-July-2015
00007   * @brief   This file implements functions for opening and closing Pipes
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */ 
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "usbh_pipes.h"
00030 
00031 /** @addtogroup USBH_LIB
00032   * @{
00033   */
00034 
00035 /** @addtogroup USBH_LIB_CORE
00036 * @{
00037 */
00038   
00039 /** @defgroup USBH_PIPES
00040   * @brief This file includes opening and closing Pipes
00041   * @{
00042   */ 
00043 
00044 /** @defgroup USBH_PIPES_Private_Defines
00045   * @{
00046   */ 
00047 /**
00048   * @}
00049   */ 
00050 
00051 /** @defgroup USBH_PIPES_Private_TypesDefinitions
00052   * @{
00053   */ 
00054 /**
00055   * @}
00056   */ 
00057 
00058 
00059 /** @defgroup USBH_PIPES_Private_Macros
00060   * @{
00061   */ 
00062 /**
00063   * @}
00064   */ 
00065 
00066 
00067 /** @defgroup USBH_PIPES_Private_Variables
00068   * @{
00069   */ 
00070 
00071 /**
00072   * @}
00073   */ 
00074 
00075 
00076 /** @defgroup USBH_PIPES_Private_Functions
00077   * @{
00078   */ 
00079 static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost);
00080 
00081 
00082 /**
00083   * @brief  USBH_Open_Pipe
00084   *         Open a  pipe
00085   * @param  phost: Host Handle
00086   * @param  pipe_num: Pipe Number
00087   * @param  dev_address: USB Device address allocated to attached device
00088   * @param  speed : USB device speed (Full/Low)
00089   * @param  ep_type: end point type (Bulk/int/ctl)
00090   * @param  mps: max pkt size
00091   * @retval USBH Status
00092   */
00093 USBH_StatusTypeDef USBH_OpenPipe  (USBH_HandleTypeDef *phost,
00094                             uint8_t pipe_num,
00095                             uint8_t epnum,
00096                             uint8_t dev_address,
00097                             uint8_t speed,
00098                             uint8_t ep_type,
00099                             uint16_t mps)
00100 {
00101 
00102   USBH_LL_OpenPipe(phost,
00103                         pipe_num,
00104                         epnum,
00105                         dev_address,
00106                         speed,
00107                         ep_type,
00108                         mps);
00109   
00110   return USBH_OK; 
00111 
00112 }
00113 
00114 /**
00115   * @brief  USBH_ClosePipe
00116   *         Close a  pipe
00117   * @param  phost: Host Handle
00118   * @param  pipe_num: Pipe Number
00119   * @retval USBH Status
00120   */
00121 USBH_StatusTypeDef USBH_ClosePipe  (USBH_HandleTypeDef *phost,
00122                             uint8_t pipe_num)
00123 {
00124 
00125   USBH_LL_ClosePipe(phost, pipe_num);
00126   
00127   return USBH_OK; 
00128 
00129 }
00130 
00131 /**
00132   * @brief  USBH_Alloc_Pipe
00133   *         Allocate a new Pipe
00134   * @param  phost: Host Handle
00135   * @param  ep_addr: End point for which the Pipe to be allocated
00136   * @retval Pipe number
00137   */
00138 uint8_t USBH_AllocPipe  (USBH_HandleTypeDef *phost, uint8_t ep_addr)
00139 {
00140   uint16_t pipe;
00141   
00142   pipe =  USBH_GetFreePipe(phost);
00143 
00144   if (pipe != 0xFFFF)
00145   {
00146     phost->Pipes[pipe] = 0x8000 | ep_addr;
00147   }
00148   return pipe;
00149 }
00150 
00151 /**
00152   * @brief  USBH_Free_Pipe
00153   *         Free the USB Pipe
00154   * @param  phost: Host Handle
00155   * @param  idx: Pipe number to be freed 
00156   * @retval USBH Status
00157   */
00158 USBH_StatusTypeDef USBH_FreePipe  (USBH_HandleTypeDef *phost, uint8_t idx)
00159 {
00160    if(idx < 11)
00161    {
00162      phost->Pipes[idx] &= 0x7FFF;
00163    }
00164    return USBH_OK;
00165 }
00166 
00167 /**
00168   * @brief  USBH_GetFreePipe
00169   * @param  phost: Host Handle
00170   *         Get a free Pipe number for allocation to a device endpoint
00171   * @retval idx: Free Pipe number
00172   */
00173 static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost)
00174 {
00175   uint8_t idx = 0;
00176   
00177   for (idx = 0 ; idx < 11 ; idx++)
00178   {
00179     if ((phost->Pipes[idx] & 0x8000) == 0)
00180     {
00181        return idx;
00182     } 
00183   }
00184   return 0xFFFF;
00185 }
00186 /**
00187 * @}
00188 */ 
00189 
00190 /**
00191 * @}
00192 */ 
00193 
00194 /**
00195 * @}
00196 */
00197 
00198 /**
00199 * @}
00200 */ 
00201 
00202 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00203 
00204