]> git.sur5r.net Git - freertos/blob
414670255154cda2d0d19a1b06448b245b561a6e
[freertos] /
1 /*\r
2  * @brief USB Endpoint definitions for the LPC11Uxx microcontrollers\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\r
9  * Software that is described herein is for illustrative purposes only\r
10  * which provides customers with programming information regarding the\r
11  * LPC products.  This software is supplied "AS IS" without any warranties of\r
12  * any kind, and NXP Semiconductors and its licensor disclaim any and\r
13  * all warranties, express or implied, including all implied warranties of\r
14  * merchantability, fitness for a particular purpose and non-infringement of\r
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility\r
16  * or liability for the use of the software, conveys no license or rights under any\r
17  * patent, copyright, mask work right, or any other intellectual property rights in\r
18  * or to any products. NXP Semiconductors reserves the right to make changes\r
19  * in the software without notification. NXP Semiconductors also makes no\r
20  * representation or warranty that such application will be suitable for the\r
21  * specified use without further testing or modification.\r
22  *\r
23  * @par\r
24  * Permission to use, copy, modify, and distribute this software and its\r
25  * documentation is hereby granted, under NXP Semiconductors' and its\r
26  * licensor's relevant copyrights in the software, without fee, provided that it\r
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This\r
28  * copyright, permission, and disclaimer notice must appear in all copies of\r
29  * this code.\r
30  */\r
31 \r
32 /** @ingroup Group_EndpointRW\r
33  *  @defgroup Group_EndpointRW_LPC11Uxx Endpoint Data Reading and Writing (LPC11Uxx, LPC1347)\r
34  *  @brief Endpoint data read/write definitions for the LPC11Uxx and LPC1347 architecture.\r
35  *\r
36  *  Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.\r
37  */\r
38 \r
39 /** @ingroup Group_EndpointPrimitiveRW\r
40  *  @defgroup Group_EndpointPrimitiveRW_LPC11Uxx Read/Write of Primitive Data Types (LPC11Uxx, LPC1347)\r
41  *  @brief Endpoint primitive read/write definitions for the LPC11Uxx and LPC1347 architecture.\r
42  *\r
43  *  Functions, macros, variables, enums and types related to data reading and writing of primitive data types\r
44  *  from and to endpoints.\r
45  */\r
46 \r
47 /** @ingroup Group_EndpointPacketManagement\r
48  *  @defgroup Group_EndpointPacketManagement_LPC11Uxx Endpoint Packet Management (LPC11Uxx, LPC1347)\r
49  *  @brief Endpoint packet management definitions for the NXP LPC11Uxx and LPC1347 architecture.\r
50  *\r
51  *  Functions, macros, variables, enums and types related to packet management of endpoints.\r
52  */\r
53 \r
54 /** @ingroup Group_EndpointManagement\r
55  *  @defgroup Group_EndpointManagement_LPC11Uxx Endpoint Management (LPC11Uxx, LPC1347)\r
56  *  @brief Endpoint management definitions for the NXP LPC11Uxx and LPC1347 architecture.\r
57  *\r
58  *  Functions, macros and enums related to endpoint management when in USB Device mode. This\r
59  *  module contains the endpoint management macros, as well as endpoint interrupt and data\r
60  *  send/receive functions for various data types.\r
61  *\r
62  *  @{\r
63  */\r
64 \r
65 #ifndef __ENDPOINT_LPC11UXX_H__\r
66 #define __ENDPOINT_LPC11UXX_H__\r
67 \r
68                 #include "../EndpointCommon.h"\r
69 \r
70                 #if defined(__cplusplus)\r
71 extern "C" {\r
72                 #endif\r
73 \r
74                 #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
75                         #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.\r
76                 #endif\r
77 \r
78         #if !defined(__DOXYGEN__)\r
79 \r
80                                 #define ENDPOINT_DETAILS_MAXEP             5\r
81                                 #define ENDPOINT_DETAILS_MAXEP0         ENDPOINT_DETAILS_MAXEP\r
82                                 #define ENDPOINT_DETAILS_MAXEP1         ENDPOINT_DETAILS_MAXEP\r
83         \r
84                 #if defined(USB_DEVICE_ROM_DRIVER)\r
85 \r
86 typedef struct _ROM {\r
87         const unsigned p_usbd;\r
88         const unsigned p_clib;\r
89         const unsigned p_cand;\r
90                         #ifdef PWRROMD_PRESENT\r
91         const PWRD *pPWRD;\r
92                         #else\r
93         const unsigned p_pwrd;\r
94                         #endif /* PWRROMD_PRESENT */\r
95                         #ifdef DIVROMD_PRESENT\r
96         const LPC_ROM_DIV_STRUCT *pROMDiv;\r
97                         #else\r
98         const unsigned p_dev1;\r
99                         #endif /* DIVROMD_PRESENT */\r
100         const unsigned p_dev2;\r
101         const unsigned p_dev3;\r
102         const unsigned p_dev4;\r
103 }  ROM_FUNCTION_TABLE;\r
104 \r
105                         #define ROM_FUNCTION_TABLE_PTR_ADDR         (0x1FFF1FF8UL)\r
106                         #define ROM_USBD_PTR ((*(ROM_FUNCTION_TABLE * *) (ROM_FUNCTION_TABLE_PTR_ADDR))->p_usbd)\r
107 \r
108                         #define ROMDRIVER_USB0_BASE LPC_USB0_BASE\r
109                         #define ROMDRIVER_USB1_BASE LPC_USB0_BASE\r
110                         #define ROMDRIVER_MEM_SIZE  0x500\r
111 extern uint8_t usb_RomDriver_buffer[ROMDRIVER_MEM_SIZE];\r
112 \r
113                         #define ROMDRIVER_MSC_MEM_SIZE  0x100\r
114 extern uint8_t usb_RomDriver_MSC_buffer[ROMDRIVER_MSC_MEM_SIZE];\r
115 \r
116                         #define ROMDRIVER_CDC_MEM_SIZE  0x8\r
117 extern uint8_t usb_RomDriver_CDC_buffer[ROMDRIVER_CDC_MEM_SIZE];\r
118 \r
119                         #if (USB_FORCED_FULLSPEED)\r
120                                 #define CDC_MAX_BULK_EP_SIZE            64\r
121                         #else\r
122                                 #define CDC_MAX_BULK_EP_SIZE            512\r
123                         #endif\r
124 extern uint8_t UsbdCdc_EPIN_buffer[CDC_MAX_BULK_EP_SIZE];\r
125 extern uint8_t UsbdCdc_EPOUT_buffer[CDC_MAX_BULK_EP_SIZE];\r
126 \r
127                         #define ROMDRIVER_HID_MEM_SIZE  0x8\r
128 extern uint8_t usb_RomDriver_HID_buffer[ROMDRIVER_HID_MEM_SIZE];\r
129 \r
130                 #endif\r
131 \r
132 void Endpoint_ClearEndpoints(uint8_t corenum);\r
133 \r
134 bool Endpoint_ConfigureEndpoint_Prv(uint8_t corenum,\r
135                                                                         const uint8_t Number,\r
136                                                                         const uint8_t UECFG0XData,\r
137                                                                         const uint8_t UECFG1XData);\r
138 \r
139         #endif\r
140                         #define USED_PHYSICAL_ENDPOINTS (ENDPOINT_DETAILS_MAXEP * 2)/* This macro effect memory size of the DCD */\r
141 \r
142                         #define USB_EN              (0x1 << 7)  /* Device Enable */\r
143                         #define USB_SETUP_RCVD      (0x1 << 8)  /* SETUP token received */\r
144                         #define USB_PLL_ON          (0x1 << 9)  /* PLL is always ON */\r
145                         #define USB_LPM             (0x1 << 11) /* LPM is supported */\r
146                         #define USB_IntOnNAK_AO     (0x1 << 12) /* Device Interrupt on NAK BULK OUT */\r
147                         #define USB_IntOnNAK_AI     (0x1 << 13) /* Device Interrupt on NAK BULK IN */\r
148                         #define USB_IntOnNAK_CO     (0x1 << 14) /* Device Interrupt on NAK CTRL OUT */\r
149                         #define USB_IntOnNAK_CI     (0x1 << 15) /* Device Interrupt on NAK CTRL IN */\r
150                         #define USB_DCON            (0x1 << 16) /* Device connect */\r
151                         #define USB_DSUS            (0x1 << 17) /* Device Suspend */\r
152                         #define USB_LPM_SUS         (0x1 << 19) /* LPM suspend */\r
153                         #define USB_REMOTE_WAKE     (0x1 << 20) /* LPM Remote Wakeup */\r
154                         #define USB_DCON_C          (0x1 << 24) /* Device connection change */\r
155                         #define USB_DSUS_C          (0x1 << 25) /* Device SUSPEND change */\r
156                         #define USB_DRESET_C        (0x1 << 26) /* Device RESET */\r
157                         #define USB_VBUS_DBOUNCE    (0x1 << 28) /* Device VBUS detect */\r
158 \r
159                         #define EP0_INT             (0x1 << 0)\r
160                         #define EP1_INT             (0x1 << 1)\r
161                         #define EP2_INT             (0x1 << 2)\r
162                         #define EP3_INT             (0x1 << 3)\r
163                         #define EP4_INT             (0x1 << 4)\r
164                         #define EP5_INT             (0x1 << 5)\r
165                         #define EP6_INT             (0x1 << 6)\r
166                         #define EP7_INT             (0x1 << 7)\r
167                         #define EP8_INT             (0x1 << 8)\r
168                         #define EP9_INT             (0x1 << 9)\r
169                         #define FRAME_INT           (0x1 << 30)\r
170                         #define DEV_STAT_INT        (0x80000000)\r
171 \r
172                         #define PKT_LNGTH_MASK      0x000003FF\r
173 \r
174                         #define ERR_NOERROR         0x00\r
175                         #define ERR_PID_ENCODE      0x01\r
176                         #define ERR_UNKNOWN_PID     0x02\r
177                         #define ERR_UNEXPECT_PKT    0x03\r
178                         #define ERR_TCRC            0x04\r
179                         #define ERR_DCRC            0x05\r
180                         #define ERR_TIMEOUT         0x06\r
181                         #define ERR_BABBIE          0x07\r
182                         #define ERR_EOF_PKT         0x08\r
183                         #define ERR_TX_RX_NAK       0x09\r
184                         #define ERR_SENT_STALL      0x0A\r
185                         #define ERR_BUF_OVERRUN     0x0B\r
186                         #define ERR_SENT_EPT_PKT    0x0C\r
187                         #define ERR_BIT_STUFF       0x0D\r
188                         #define ERR_SYNC            0x0E\r
189                         #define ERR_TOGGLE_BIT      0x0F\r
190 extern void WrCmdDat (uint32_t cmd, uint32_t val);\r
191 \r
192 extern void WrCmd (uint32_t cmd);\r
193 \r
194 void HAL11UXX_WriteEndPoint(uint8_t EPNum, uint8_t *pData, uint32_t cnt);\r
195 \r
196 void DcdDataTransfer(uint8_t EPNum, uint8_t *pData, uint32_t length);\r
197 \r
198 void Endpoint_Streaming(uint8_t corenum, uint8_t *buffer, uint16_t packetsize,\r
199                                                 uint16_t totalpackets, uint16_t dummypackets);\r
200 \r
201 extern USB_CMD_STAT EndPointCmdStsList[10][2];\r
202 \r
203 /*static inline */ bool Endpoint_ConfigureEndpoint(uint8_t corenum,\r
204                                                                                                          const uint8_t Number,\r
205                                                                                                    const uint8_t Type,\r
206                                                                                                    const uint8_t Direction,\r
207                                                                                                    const uint16_t Size,\r
208                                                                                                    const uint8_t Banks) /*ATTR_ALWAYS_INLINE*/;\r
209 \r
210 PRAGMA_ALWAYS_INLINE\r
211 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;\r
212 \r
213 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)\r
214 {}\r
215 \r
216 PRAGMA_ALWAYS_INLINE\r
217 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;\r
218 \r
219 static inline void Endpoint_EnableEndpoint(void)\r
220 {}\r
221 \r
222 PRAGMA_ALWAYS_INLINE\r
223 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;\r
224 \r
225 static inline void Endpoint_DisableEndpoint(void)\r
226 {}\r
227 \r
228 PRAGMA_ALWAYS_INLINE\r
229 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
230 \r
231 static inline bool Endpoint_IsEnabled(void)\r
232 {\r
233         return true;\r
234 }\r
235 \r
236 PRAGMA_ALWAYS_INLINE\r
237 static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;\r
238 \r
239 static inline uint8_t Endpoint_GetBusyBanks(void)\r
240 {\r
241         return 0;\r
242 }\r
243 \r
244 static inline void Endpoint_AbortPendingIN(void)\r
245 {}\r
246 \r
247 PRAGMA_ALWAYS_INLINE\r
248 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
249 \r
250 static inline bool Endpoint_IsConfigured(void)\r
251 {\r
252         //                              return ((UESTA0X & (1 << CFGOK)) ? true : false);\r
253         return true;\r
254 }\r
255 \r
256 PRAGMA_ALWAYS_INLINE\r
257 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
258 \r
259 static inline uint8_t Endpoint_GetEndpointInterrupts(void)\r
260 {\r
261         return 0;                               // TODO not yet implemented\r
262 }\r
263 \r
264 PRAGMA_ALWAYS_INLINE\r
265 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT\r
266 ATTR_ALWAYS_INLINE;\r
267 \r
268 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)\r
269 {\r
270         return (Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false;\r
271 }\r
272 \r
273 PRAGMA_ALWAYS_INLINE\r
274 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
275 \r
276 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum)\r
277 {\r
278         if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {\r
279                 return usb_data_buffer_size[corenum];\r
280         }\r
281         else {\r
282                 return usb_data_buffer_OUT_size[corenum];\r
283         }\r
284 }\r
285 \r
286 PRAGMA_ALWAYS_INLINE\r
287 static inline bool Endpoint_IsINReady(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
288 \r
289 static inline bool Endpoint_IsINReady(uint8_t corenum)\r
290 {\r
291         uint32_t PhyEP =\r
292                 (endpointselected[corenum] == ENDPOINT_CONTROLEP) ? (ENDPOINT_CONTROLEP + 1) : endpointhandle(corenum)[endpointselected[corenum]];\r
293         return EndPointCmdStsList[PhyEP][0].Active ? false : true;\r
294 }\r
295 \r
296 PRAGMA_ALWAYS_INLINE\r
297 static inline bool Endpoint_IsOUTReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
298 \r
299 static inline bool Endpoint_IsOUTReceived(uint8_t corenum)\r
300 {\r
301         return                          /*EndPointCmdStsList[ endpointhandle(corenum)[endpointselected] ][0].Active == 0 &&*/\r
302                    EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].NBytes != 0x200;\r
303 }\r
304 \r
305 PRAGMA_ALWAYS_INLINE\r
306 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
307 \r
308 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum)\r
309 {\r
310         return LPC_USB->DEVCMDSTAT & USB_SETUP_RCVD ? true : false;\r
311 }\r
312 \r
313 PRAGMA_ALWAYS_INLINE\r
314 static inline void Endpoint_ClearSETUP(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
315 \r
316 static inline void Endpoint_ClearSETUP(uint8_t corenum)\r
317 {\r
318         LPC_USB->DEVCMDSTAT |= USB_SETUP_RCVD;\r
319         usb_data_buffer_index[corenum] = 0;\r
320 }\r
321 \r
322 PRAGMA_ALWAYS_INLINE\r
323 static inline void Endpoint_ClearIN(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
324 \r
325 static inline void Endpoint_ClearIN(uint8_t corenum)\r
326 {\r
327         uint8_t PhyEP = (endpointselected[corenum] == ENDPOINT_CONTROLEP ? 1 : endpointhandle(corenum)[endpointselected[corenum]]);\r
328         if (PhyEP == 1) {\r
329                 DcdDataTransfer(PhyEP, usb_data_buffer[corenum], usb_data_buffer_index[corenum]);\r
330                 usb_data_buffer_index[corenum] = 0;\r
331         }\r
332         else {\r
333                 DcdDataTransfer(PhyEP, usb_data_buffer_IN[corenum], usb_data_buffer_IN_index[corenum]);\r
334                 usb_data_buffer_IN_index[corenum] = 0;\r
335         }\r
336 }\r
337 \r
338 PRAGMA_ALWAYS_INLINE\r
339 static inline void Endpoint_ClearOUT(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
340 \r
341 static inline void Endpoint_ClearOUT(uint8_t corenum)\r
342 {\r
343         if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {\r
344                 usb_data_buffer_index[corenum] = 0;\r
345         }\r
346         else {usb_data_buffer_OUT_index[corenum] = 0; }\r
347 \r
348         EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].NBytes = 0x200;\r
349 }\r
350 \r
351 PRAGMA_ALWAYS_INLINE\r
352 static inline void Endpoint_StallTransaction(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
353 \r
354 static inline void Endpoint_StallTransaction(uint8_t corenum)\r
355 {\r
356         EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].Stall = 1;\r
357         if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {\r
358                 EndPointCmdStsList[1][0].Stall = 1;\r
359         }\r
360 }\r
361 \r
362 PRAGMA_ALWAYS_INLINE\r
363 static inline void Endpoint_ClearStall(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
364 \r
365 static inline void Endpoint_ClearStall(uint8_t corenum)\r
366 {\r
367         EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].Stall = 0;\r
368 }\r
369 \r
370 PRAGMA_ALWAYS_INLINE\r
371 static inline bool Endpoint_IsStalled(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
372 \r
373 static inline bool Endpoint_IsStalled(uint8_t corenum)\r
374 {\r
375         return EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].Stall ? true : false;\r
376 }\r
377 \r
378 PRAGMA_ALWAYS_INLINE\r
379 static inline void Endpoint_ResetDataToggle(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
380 \r
381 static inline void Endpoint_ResetDataToggle(uint8_t corenum)\r
382 {\r
383         EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].ToogleReset = 1;\r
384 }\r
385 \r
386                         #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))\r
387 extern uint8_t USB_Device_ControlEndpointSize;\r
388                         #else\r
389                                 #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE\r
390                         #endif\r
391 \r
392 void Endpoint_ClearStatusStage(uint8_t corenum);\r
393 \r
394 uint8_t Endpoint_WaitUntilReady(void);\r
395 \r
396                 #if defined(__cplusplus)\r
397 }\r
398                 #endif\r
399 \r
400 #endif\r
401 \r
402 /** @} */\r
403 \r