]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/usbpsu_v1_4/src/xusb_wrapper.c
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / usbpsu_v1_4 / src / xusb_wrapper.c
1 /******************************************************************************
2  *
3  * Copyright (C) 2017 Xilinx, Inc.  All rights reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * Use of the Software is limited solely to applications:
16  * (a) running on a Xilinx device, or
17  * (b) that interact with a Xilinx device through a bus or interconnect.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22  * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  *
27  * Except as contained in this notice, the name of the Xilinx shall not be used
28  * in advertising or otherwise to promote the sale, use or other dealings in
29  * this Software without prior written authorization from Xilinx.
30  *
31  ******************************************************************************/
32 /*****************************************************************************/
33 /**
34  *
35  * @file xusb_wrapper.c
36  *
37  * This file contains implementation of USBPSU Driver wrappers.
38  *
39  * <pre>
40  * MODIFICATION HISTORY:
41  *
42  * Ver   Who    Date     Changes
43  * ----- ----   -------- -------------------------------------------------------
44  * 1.0   BK     12/01/18 First release
45  *       MYK    12/01/18 Added hibernation support for device mode
46  *       vak    13/03/18 Moved the setup interrupt system calls from driver to
47  *                       example.
48  *
49  * </pre>
50  *
51  *****************************************************************************/
52
53 /***************************** Include Files *********************************/
54 #include "xusb_wrapper.h"
55
56 /************************** Variable Definitions *****************************/
57
58 /************************** Function Prototypes ******************************/
59 Usb_Config* LookupConfig(u16 DeviceId)
60 {
61         return XUsbPsu_LookupConfig(DeviceId);
62 }
63
64 void CacheInit(void)
65 {
66
67 }
68
69 s32 CfgInitialize(struct Usb_DevData *InstancePtr,
70                         Usb_Config *ConfigPtr, u32 BaseAddress)
71 {
72         PrivateData.AppData = InstancePtr;
73         InstancePtr->PrivateData = (void *)&PrivateData;
74
75         return XUsbPsu_CfgInitialize((struct XUsbPsu *)InstancePtr->PrivateData,
76                         ConfigPtr, BaseAddress);
77 }
78
79 void Set_Ch9Handler(
80                 void *InstancePtr,
81                 void (*func)(struct Usb_DevData *, SetupPacket *))
82 {
83         XUsbPsu_set_ch9handler((struct XUsbPsu *)InstancePtr, func);
84 }
85
86 void Set_RstHandler(void *InstancePtr, void (*func)(struct Usb_DevData *))
87 {
88         XUsbPsu_set_rsthandler((struct XUsbPsu *)InstancePtr, func);
89 }
90
91 void Set_Disconnect(void *InstancePtr, void (*func)(struct Usb_DevData *))
92 {
93         XUsbPsu_set_disconnect((struct XUsbPsu *)InstancePtr, func);
94 }
95
96 void EpConfigure(void *UsbInstance, u8 EndpointNo, u8 dir, u32 Type)
97 {
98         (void)UsbInstance;
99         (void)EndpointNo;
100         (void)dir;
101         (void)Type;
102 }
103
104 s32 ConfigureDevice(void *UsbInstance, u8 *MemPtr, u32 memSize)
105 {
106         (void)UsbInstance;
107         (void)MemPtr;
108         (void)memSize;
109         return XST_SUCCESS;
110 }
111
112 void SetEpHandler(void *InstancePtr, u8 Epnum,
113                         u8 Dir, void (*Handler)(void *, u32, u32))
114 {
115         XUsbPsu_SetEpHandler((struct XUsbPsu *)InstancePtr, Epnum, Dir, Handler);
116 }
117
118 s32 Usb_Start(void *InstancePtr)
119 {
120         return XUsbPsu_Start((struct XUsbPsu *)InstancePtr);
121 }
122
123 void *Get_DrvData(void *InstancePtr)
124 {
125         return XUsbPsu_get_drvdata((struct XUsbPsu *)InstancePtr);
126 }
127
128 void Set_DrvData(void *InstancePtr, void *data)
129 {
130         XUsbPsu_set_drvdata((struct XUsbPsu *)InstancePtr, data);
131 }
132
133 s32 IsEpStalled(void *InstancePtr, u8 Epnum, u8 Dir)
134 {
135         return XUsbPsu_IsEpStalled((struct XUsbPsu *)InstancePtr, Epnum, Dir);
136 }
137
138 void EpClearStall(void *InstancePtr, u8 Epnum, u8 Dir)
139 {
140         XUsbPsu_EpClearStall((struct XUsbPsu *)InstancePtr, Epnum, Dir);
141 }
142
143 s32 EpBufferSend(void *InstancePtr, u8 UsbEp,
144                         u8 *BufferPtr, u32 BufferLen)
145 {
146         if (UsbEp == 0 && BufferLen == 0)
147                 return XST_SUCCESS;
148         else
149                 return XUsbPsu_EpBufferSend((struct XUsbPsu *)InstancePtr,
150                                                 UsbEp, BufferPtr, BufferLen);
151
152 }
153
154 s32 EpBufferRecv(void *InstancePtr, u8 UsbEp,
155                                 u8 *BufferPtr, u32 Length)
156 {
157         return XUsbPsu_EpBufferRecv((struct XUsbPsu *)InstancePtr, UsbEp,
158                         BufferPtr, Length);
159 }
160
161 void EpSetStall(void *InstancePtr, u8 Epnum, u8 Dir)
162 {
163         XUsbPsu_EpSetStall((struct XUsbPsu *)InstancePtr, Epnum, Dir);
164 }
165
166 void SetBits(void *InstancePtr, u32 TestSel)
167 {
168         (void)InstancePtr;
169         (void)TestSel;
170 }
171
172 s32 SetDeviceAddress(void *InstancePtr, u16 Addr)
173 {
174         return XUsbPsu_SetDeviceAddress((struct XUsbPsu *)InstancePtr, Addr);
175 }
176
177 s32 SetU1SleepTimeout(void *InstancePtr, u8 Sleep)
178 {
179         return XUsbPsu_SetU1SleepTimeout((struct XUsbPsu *)InstancePtr, Sleep);
180 }
181
182 s32 SetU2SleepTimeout(void *InstancePtr, u8 Sleep)
183 {
184         return XUsbPsu_SetU2SleepTimeout((struct XUsbPsu *)InstancePtr, Sleep);
185 }
186
187 s32 AcceptU1U2Sleep(void *InstancePtr)
188 {
189         return XUsbPsu_AcceptU1U2Sleep((struct XUsbPsu *)InstancePtr);
190
191 }
192
193 s32 U1SleepEnable(void *InstancePtr)
194 {
195         return XUsbPsu_U1SleepEnable((struct XUsbPsu *)InstancePtr);
196 }
197
198 s32 U2SleepEnable(void *InstancePtr)
199 {
200         return XUsbPsu_U2SleepEnable((struct XUsbPsu *)InstancePtr);
201 }
202
203 s32 U1SleepDisable(void *InstancePtr)
204 {
205         return XUsbPsu_U1SleepDisable((struct XUsbPsu *)InstancePtr);
206 }
207
208 s32 U2SleepDisable(void *InstancePtr)
209 {
210         return XUsbPsu_U2SleepDisable((struct XUsbPsu *)InstancePtr);
211 }
212
213 s32 EpEnable(void *InstancePtr, u8 UsbEpNum, u8 Dir, u16 Maxsize, u8 Type)
214 {
215         return XUsbPsu_EpEnable((struct XUsbPsu *)InstancePtr, UsbEpNum, Dir,
216                         Maxsize, Type, FALSE);
217 }
218
219 s32 EpDisable(void *InstancePtr, u8 UsbEpNum, u8 Dir)
220 {
221         return XUsbPsu_EpDisable((struct XUsbPsu *)InstancePtr, UsbEpNum, Dir);
222 }
223
224 void Usb_SetSpeed(void *InstancePtr, u32 Speed)
225 {
226         XUsbPsu_SetSpeed((struct XUsbPsu *)InstancePtr, Speed);
227 }
228
229 /****************************************************************************/
230 /**
231 * Sets speed of the Core for connecting to Host
232 *
233 * @param        InstancePtr is a pointer to the Usb_DevData instance.
234 *
235 * @return       XST_SUCCESS else XST_FAILURE
236 *
237 * @note         None.
238 *
239 *****************************************************************************/
240 s32 IsSuperSpeed(struct Usb_DevData *InstancePtr)
241 {
242         if (InstancePtr->Speed != XUSBPSU_SPEED_SUPER) {
243                 return XST_FAILURE;
244         }
245
246         return XST_SUCCESS;
247 }
248
249 /****************************************************************************/
250 /**
251 * Set the Config state
252 *
253 * @param        InstancePtr is a private member of Usb_DevData instance.
254 * @param        Flag is the config value.
255 *
256 * @return       None.
257 *
258 * @note         None.
259 *
260 *****************************************************************************/
261 void SetConfigDone(void *InstancePtr, u8 Flag)
262 {
263         ((struct XUsbPsu *)InstancePtr)->IsConfigDone = Flag;
264 }
265
266 /****************************************************************************/
267 /**
268 * Get the Config state
269 *
270 * @param        InstancePtr is a private member of Usb_DevData instance.
271 *
272 * @return       Current configuration value
273 *
274 * @note         None.
275 *
276 *****************************************************************************/
277 u8 GetConfigDone(void *InstancePtr)
278 {
279         return (((struct XUsbPsu *)InstancePtr)->IsConfigDone);
280 }
281
282 void Ep0StallRestart(void *InstancePtr)
283 {
284         XUsbPsu_Ep0StallRestart((struct XUsbPsu *)InstancePtr);
285 }
286
287 /******************************************************************************/
288 /**
289  * This function sets Endpoint Interval.
290  *
291  * @param       InstancePtr is a private member of Usb_DevData instance.
292  * @param       UsbEpnum is Endpoint Number.
293  * @param       Dir is Endpoint Direction(In/Out).
294  * @param       Interval is the data transfer service interval
295  *
296  * @return      None.
297  *
298  * @note        None.
299  *
300  ******************************************************************************/
301 void SetEpInterval(void *InstancePtr, u8 UsbEpNum, u8 Dir, u32 Interval)
302 {
303         u32 PhyEpNum;
304         struct XUsbPsu_Ep *Ept;
305
306         PhyEpNum = PhysicalEp(UsbEpNum, Dir);
307         Ept = &((struct XUsbPsu *)InstancePtr)->eps[PhyEpNum];
308         Ept->Interval = Interval;
309 }
310
311 void StopTransfer(void *InstancePtr, u8 EpNum, u8 Dir)
312 {
313         XUsbPsu_StopTransfer((struct XUsbPsu *)InstancePtr, EpNum, Dir, TRUE);
314 }
315
316 s32 StreamOn(void *InstancePtr, u8 EpNum, u8 Dir, u8 *BufferPtr)
317 {
318         (void)InstancePtr;
319         (void)EpNum;
320         (void)Dir;
321         (void)BufferPtr;
322         /* Streaming will start on TxferNotReady Event */
323         return XST_SUCCESS;
324 }
325
326 void StreamOff(void *InstancePtr, u8 EpNum, u8 Dir)
327 {
328         StopTransfer((struct XUsbPsu *)InstancePtr, EpNum, Dir);
329 }