| 1 |
/** |
| 2 |
****************************************************************************** |
| 3 |
* @file usbh_pipes.c |
| 4 |
* @author MCD Application Team |
| 5 |
* @version V3.0.0 |
| 6 |
* @date 18-February-2014 |
| 7 |
* @brief This file implements functions for opening and closing Pipes |
| 8 |
****************************************************************************** |
| 9 |
* @attention |
| 10 |
* |
| 11 |
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> |
| 12 |
* |
| 13 |
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
| 14 |
* You may not use this file except in compliance with the License. |
| 15 |
* You may obtain a copy of the License at: |
| 16 |
* |
| 17 |
* http://www.st.com/software_license_agreement_liberty_v2 |
| 18 |
* |
| 19 |
* Unless required by applicable law or agreed to in writing, software |
| 20 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 21 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 |
* See the License for the specific language governing permissions and |
| 23 |
* limitations under the License. |
| 24 |
* |
| 25 |
****************************************************************************** |
| 26 |
*/ |
| 27 |
|
| 28 |
/* Includes ------------------------------------------------------------------*/ |
| 29 |
#include "usbh_pipes.h" |
| 30 |
|
| 31 |
/** @addtogroup USBH_LIB |
| 32 |
* @{ |
| 33 |
*/ |
| 34 |
|
| 35 |
/** @addtogroup USBH_LIB_CORE |
| 36 |
* @{ |
| 37 |
*/ |
| 38 |
|
| 39 |
/** @defgroup USBH_PIPES |
| 40 |
* @brief This file includes opening and closing Pipes |
| 41 |
* @{ |
| 42 |
*/ |
| 43 |
|
| 44 |
/** @defgroup USBH_PIPES_Private_Defines |
| 45 |
* @{ |
| 46 |
*/ |
| 47 |
/** |
| 48 |
* @} |
| 49 |
*/ |
| 50 |
|
| 51 |
/** @defgroup USBH_PIPES_Private_TypesDefinitions |
| 52 |
* @{ |
| 53 |
*/ |
| 54 |
/** |
| 55 |
* @} |
| 56 |
*/ |
| 57 |
|
| 58 |
|
| 59 |
/** @defgroup USBH_PIPES_Private_Macros |
| 60 |
* @{ |
| 61 |
*/ |
| 62 |
/** |
| 63 |
* @} |
| 64 |
*/ |
| 65 |
|
| 66 |
|
| 67 |
/** @defgroup USBH_PIPES_Private_Variables |
| 68 |
* @{ |
| 69 |
*/ |
| 70 |
|
| 71 |
/** |
| 72 |
* @} |
| 73 |
*/ |
| 74 |
|
| 75 |
|
| 76 |
/** @defgroup USBH_PIPES_Private_Functions |
| 77 |
* @{ |
| 78 |
*/ |
| 79 |
static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost); |
| 80 |
|
| 81 |
|
| 82 |
/** |
| 83 |
* @brief USBH_Open_Pipe |
| 84 |
* Open a pipe |
| 85 |
* @param phost: Host Handle |
| 86 |
* @param pipe_num: Pipe Number |
| 87 |
* @param dev_address: USB Device address allocated to attached device |
| 88 |
* @param speed : USB device speed (Full/Low) |
| 89 |
* @param ep_type: end point type (Bulk/int/ctl) |
| 90 |
* @param mps: max pkt size |
| 91 |
* @retval USBH Status |
| 92 |
*/ |
| 93 |
USBH_StatusTypeDef USBH_OpenPipe (USBH_HandleTypeDef *phost, |
| 94 |
uint8_t pipe_num, |
| 95 |
uint8_t epnum, |
| 96 |
uint8_t dev_address, |
| 97 |
uint8_t speed, |
| 98 |
uint8_t ep_type, |
| 99 |
uint16_t mps) |
| 100 |
{ |
| 101 |
|
| 102 |
USBH_LL_OpenPipe(phost, |
| 103 |
pipe_num, |
| 104 |
epnum, |
| 105 |
dev_address, |
| 106 |
speed, |
| 107 |
ep_type, |
| 108 |
mps); |
| 109 |
|
| 110 |
return USBH_OK; |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* @brief USBH_ClosePipe |
| 116 |
* Close a pipe |
| 117 |
* @param phost: Host Handle |
| 118 |
* @param pipe_num: Pipe Number |
| 119 |
* @retval USBH Status |
| 120 |
*/ |
| 121 |
USBH_StatusTypeDef USBH_ClosePipe (USBH_HandleTypeDef *phost, |
| 122 |
uint8_t pipe_num) |
| 123 |
{ |
| 124 |
|
| 125 |
USBH_LL_ClosePipe(phost, pipe_num); |
| 126 |
|
| 127 |
return USBH_OK; |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* @brief USBH_Alloc_Pipe |
| 133 |
* Allocate a new Pipe |
| 134 |
* @param phost: Host Handle |
| 135 |
* @param ep_addr: End point for which the Pipe to be allocated |
| 136 |
* @retval Pipe number |
| 137 |
*/ |
| 138 |
uint8_t USBH_AllocPipe (USBH_HandleTypeDef *phost, uint8_t ep_addr) |
| 139 |
{ |
| 140 |
uint16_t pipe; |
| 141 |
|
| 142 |
pipe = USBH_GetFreePipe(phost); |
| 143 |
|
| 144 |
if (pipe != 0xFFFF) |
| 145 |
{ |
| 146 |
phost->Pipes[pipe] = 0x8000 | ep_addr; |
| 147 |
} |
| 148 |
return pipe; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* @brief USBH_Free_Pipe |
| 153 |
* Free the USB Pipe |
| 154 |
* @param phost: Host Handle |
| 155 |
* @param idx: Pipe number to be freed |
| 156 |
* @retval USBH Status |
| 157 |
*/ |
| 158 |
USBH_StatusTypeDef USBH_FreePipe (USBH_HandleTypeDef *phost, uint8_t idx) |
| 159 |
{ |
| 160 |
if(idx < 11) |
| 161 |
{ |
| 162 |
phost->Pipes[idx] &= 0x7FFF; |
| 163 |
} |
| 164 |
return USBH_OK; |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* @brief USBH_GetFreePipe |
| 169 |
* @param phost: Host Handle |
| 170 |
* Get a free Pipe number for allocation to a device endpoint |
| 171 |
* @retval idx: Free Pipe number |
| 172 |
*/ |
| 173 |
static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost) |
| 174 |
{ |
| 175 |
uint8_t idx = 0; |
| 176 |
|
| 177 |
for (idx = 0 ; idx < 11 ; idx++) |
| 178 |
{ |
| 179 |
if ((phost->Pipes[idx] & 0x8000) == 0) |
| 180 |
{ |
| 181 |
return idx; |
| 182 |
} |
| 183 |
} |
| 184 |
return 0xFFFF; |
| 185 |
} |
| 186 |
/** |
| 187 |
* @} |
| 188 |
*/ |
| 189 |
|
| 190 |
/** |
| 191 |
* @} |
| 192 |
*/ |
| 193 |
|
| 194 |
/** |
| 195 |
* @} |
| 196 |
*/ |
| 197 |
|
| 198 |
/** |
| 199 |
* @} |
| 200 |
*/ |
| 201 |
|
| 202 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
| 203 |
|
| 204 |
|