1 /***************************************************************************//**
2 * \file cy_usbfs_dev_drv_pvt.h
3 * \version 2.20.2
4 *
5 * Provides API declarations of the USBFS driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2018-2020 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 *     http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24 
25 /** \cond INTERNAL */
26 
27 #if !defined(CY_USBFS_DEV_DRV_PVT_H)
28 #define CY_USBFS_DEV_DRV_PVT_H
29 
30 #include "cy_usbfs_dev_drv.h"
31 
32 #if defined (CY_IP_MXUSBFS) && defined (CY_IP_MXPERI)
33 
34 #if defined(__cplusplus)
35 extern "C" {
36 #endif
37 
38 /*******************************************************************************
39 *                              Function Prototypes
40 *******************************************************************************/
41 
42 __STATIC_INLINE uint8_t  GetEndpointActiveMode(bool inDirection, uint8_t attributes);
43 __STATIC_INLINE uint32_t GetEndpointInactiveMode(uint32_t mode);
44 
45 /* DMA configuration functions */
46 cy_en_usbfs_dev_drv_status_t DmaInit(cy_stc_usbfs_dev_drv_config_t const *config,
47                                      cy_stc_usbfs_dev_drv_context_t      *context);
48 
49 void DmaDisable(cy_stc_usbfs_dev_drv_context_t *context);
50 
51 cy_en_usbfs_dev_drv_status_t DmaEndpointInit(USBFS_Type *base,
52                                              cy_en_usbfs_dev_drv_ep_management_mode_t mode,
53                                              bool useReg16,
54                                              cy_stc_usbfs_dev_drv_endpoint_data_t *endpointData);
55 
56 void DmaOutEndpointRestore(cy_stc_usbfs_dev_drv_endpoint_data_t *endpoint);
57 
58 cy_en_usbfs_dev_drv_status_t GetEndpointBuffer(uint32_t size,
59                                                uint32_t *idx,
60                                                cy_stc_usbfs_dev_drv_context_t *context);
61 
62 /* Endpoint restore functions (driver specific) */
63 void RestoreEndpointHwBuffer(USBFS_Type *base,
64                              cy_en_usbfs_dev_drv_ep_management_mode_t mode,
65                              cy_stc_usbfs_dev_drv_endpoint_data_t *endpointData);
66 
67 void RestoreEndpointRamBuffer(USBFS_Type *base,
68                               cy_stc_usbfs_dev_drv_endpoint_data_t *endpointData);
69 
70 /* Endpoint buffer allocation functions (driver specific) */
71 cy_en_usbfs_dev_drv_status_t AddEndpointHwBuffer(USBFS_Type *base,
72                                                  cy_stc_usb_dev_ep_config_t const *config,
73                                                  cy_stc_usbfs_dev_drv_context_t   *context);
74 
75 cy_en_usbfs_dev_drv_status_t AddEndpointRamBuffer(USBFS_Type *base,
76                                                   cy_stc_usb_dev_ep_config_t const *config,
77                                                   cy_stc_usbfs_dev_drv_context_t   *context);
78 
79 /* Endpoint buffer allocation functions (driver specific) */
80 cy_en_usbfs_dev_drv_status_t LoadInEndpointCpu(USBFS_Type    *base,
81                                                uint32_t      endpoint,
82                                                uint8_t const *buffer,
83                                                uint32_t      size,
84                                                cy_stc_usbfs_dev_drv_context_t *context);
85 
86 cy_en_usbfs_dev_drv_status_t LoadInEndpointDma(USBFS_Type    *base,
87                                                uint32_t      endpoint,
88                                                uint8_t const *buffer,
89                                                uint32_t      size,
90                                                cy_stc_usbfs_dev_drv_context_t *context);
91 
92 cy_en_usbfs_dev_drv_status_t LoadInEndpointDmaAuto(USBFS_Type    *base,
93                                                    uint32_t      endpoint,
94                                                    uint8_t const *buffer,
95                                                    uint32_t      size,
96                                                    cy_stc_usbfs_dev_drv_context_t *context);
97 
98 cy_en_usbfs_dev_drv_status_t ReadOutEndpointCpu(USBFS_Type *base,
99                                                 uint32_t   endpoint,
100                                                 uint8_t    *buffer,
101                                                 uint32_t   size,
102                                                 uint32_t   *actSize,
103                                                            cy_stc_usbfs_dev_drv_context_t *context);
104 
105 cy_en_usbfs_dev_drv_status_t ReadOutEndpointDma(USBFS_Type *base,
106                                                 uint32_t   endpoint,
107                                                 uint8_t    *buffer,
108                                                 uint32_t   size,
109                                                 uint32_t   *actSize,
110                                                 cy_stc_usbfs_dev_drv_context_t *context);
111 
112 cy_en_usbfs_dev_drv_status_t ReadOutEndpointDmaAuto(USBFS_Type *base,
113                                                     uint32_t   endpoint,
114                                                     uint8_t    *buffer,
115                                                     uint32_t   size,
116                                                     uint32_t   *actSize,
117                                                     cy_stc_usbfs_dev_drv_context_t *context);
118 
119 cy_en_usbfs_dev_drv_status_t DynamicEndpointReConfiguration(USBFS_Type *base,
120                                                             bool        inDirection,
121                                                             uint32_t    endpoint);
122 
123 
124 /*******************************************************************************
125 *                              Internal Constants
126 *******************************************************************************/
127 
128 /* Endpoint attributes */
129 #define ENDPOINT_ATTR_MASK    (0x03U)
130 #define ENDPOINT_TYPE_ISOC    (0x01U)
131 
132 /* Returns size to access 16-bit registers */
133 #define GET_SIZE16(size)          (((size) / 2U) + ((size) & 0x01U))
134 
135 /* Conversion macros */
136 #define IS_EP_VALID(endpoint)       CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint)
137 #define EP2PHY(endpoint)            CY_USBFS_DEV_DRV_EP2PHY(endpoint)
138 #define EP2MASK(endpont)            CY_USBFS_DEV_DRV_EP2MASK(endpoint)
139 
140 #define EPADDR2EP(endpointAddr)     CY_USBFS_DEV_DRV_EPADDR2EP(endpointAddr)
141 #define EPADDR2PHY(endpointAddr)    CY_USBFS_DEV_DRV_EPADDR2PHY(endpointAddr)
142 #define IS_EP_DIR_IN(endpointAddr)  CY_USBFS_DEV_DRV_IS_EP_DIR_IN(endpointAddr)
143 #define IS_EP_DIR_OUT(endpointAddr) CY_USBFS_DEV_DRV_IS_EP_DIR_OUT(endpointAddr)
144 
145 #define IS_EP_ISOC(mode)            ((CY_USBFS_DEV_DRV_EP_CR_ISO_IN  == (mode)) || \
146                                      (CY_USBFS_DEV_DRV_EP_CR_ISO_OUT == (mode)))
147 
148 
149 /*******************************************************************************
150 *                         In-line Function Implementation
151 *******************************************************************************/
152 
153 /*******************************************************************************
154 * Function Name: GetEndpointActiveMode
155 ****************************************************************************//**
156 *
157 * Returns active SIE mode to be written into endpoint control register.
158 *
159 * \param inDirection
160 * True - endpoint direction is IN; False - endpoint direction is OUT.
161 *
162 * \param attributes
163 * The data endpoint type attributes.
164 *
165 * \return
166 * Active SIE mode.
167 *
168 *******************************************************************************/
GetEndpointActiveMode(bool inDirection,uint8_t attributes)169 __STATIC_INLINE uint8_t GetEndpointActiveMode(bool inDirection, uint8_t attributes)
170 {
171     uint8_t epMode;
172 
173     if (ENDPOINT_TYPE_ISOC == (attributes & ENDPOINT_ATTR_MASK))
174     {
175         epMode = (inDirection) ? CY_USBFS_DEV_DRV_EP_CR_ISO_IN : CY_USBFS_DEV_DRV_EP_CR_ISO_OUT;
176     }
177     else
178     {
179         epMode = (inDirection) ? CY_USBFS_DEV_DRV_EP_CR_ACK_IN : CY_USBFS_DEV_DRV_EP_CR_ACK_OUT;
180     }
181 
182     return epMode;
183 }
184 
185 
186 /*******************************************************************************
187 * Function Name: GetEndpointInactiveMode
188 ****************************************************************************//**
189 *
190 * Returns inactive SIE mode to be written into endpoint control register.
191 *
192 * \param mode
193 * Active SIE mode.
194 *
195 * \return
196 * Inactive SIE mode.
197 *
198 *******************************************************************************/
GetEndpointInactiveMode(uint32_t mode)199 __STATIC_INLINE uint32_t GetEndpointInactiveMode(uint32_t mode)
200 {
201     switch(mode)
202     {
203     case CY_USBFS_DEV_DRV_EP_CR_ACK_IN:
204         mode = CY_USBFS_DEV_DRV_EP_CR_NAK_IN;
205         break;
206 
207     case CY_USBFS_DEV_DRV_EP_CR_ACK_OUT:
208         mode = CY_USBFS_DEV_DRV_EP_CR_NAK_OUT;
209         break;
210 
211     case CY_USBFS_DEV_DRV_EP_CR_ISO_OUT:
212     case CY_USBFS_DEV_DRV_EP_CR_ISO_IN:
213         /* Ignore traffic to endpoint. Wait for endpoint load or enable */
214         mode = CY_USBFS_DEV_DRV_EP_CR_DISABLE;
215         mode = CY_USBFS_DEV_DRV_EP_CR_DISABLE;
216         break;
217 
218     default:
219         /* Unknown mode: disable endpoint */
220         mode = CY_USBFS_DEV_DRV_EP_CR_DISABLE;
221         break;
222     }
223 
224     return mode;
225 }
226 
227 
228 #if defined(__cplusplus)
229 }
230 #endif
231 
232 #endif /* CY_IP_MXUSBFS */
233 
234 #endif /* (CY_USBFS_DEV_DRV_PVT_H) */
235 
236 /** \endcond */
237 
238 /* [] END OF FILE */
239