]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/LPCUSBLib/Drivers/USB/Core/DCD/LPC18XX/Endpoint_LPC18xx.h
Update LPC18xx FreeRTOS+UDP demo to use LPCOpen USB and Ethernet drivers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / LPCUSBLib / Drivers / USB / Core / DCD / LPC18XX / Endpoint_LPC18xx.h
1 /*\r
2  * @brief USB Endpoint definitions for the LPC18xx 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_LPC18xx Endpoint Data Reading and Writing (LPC18xx)\r
34  *  @brief Endpoint data read/write definitions for the LPC 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_LPC18xx Read/Write of Primitive Data Types (LPC18xx)\r
41  *  @brief Endpoint primitive read/write definitions for the LPC18xx 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_LPC18xx Endpoint Packet Management (LPC18xx)\r
49  *  @brief Endpoint packet management definitions for the LPC18xx 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_LPC18xx Endpoint Management (LPC18xx)\r
56  *  @brief Endpoint management definitions for the LPC18xx 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_LPC18XX_H__\r
66 #define __ENDPOINT_LPC18XX_H__\r
67 \r
68         #include "../EndpointCommon.h"\r
69 \r
70 /* Enable C linkage for C++ Compilers: */\r
71                 #if defined(__cplusplus)\r
72 extern "C" {\r
73                 #endif\r
74 \r
75 /* Preprocessor Checks: */\r
76                 #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
77                         #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.\r
78                 #endif\r
79 \r
80 /* Private Interface - For use in library only: */\r
81         #if !defined(__DOXYGEN__)\r
82 /* Macros: */\r
83                                 #define ENDPOINT_DETAILS_MAXEP0             6\r
84                                 #define ENDPOINT_DETAILS_MAXEP1             4\r
85 \r
86                         #if defined(USB_DEVICE_ROM_DRIVER)\r
87 /*==========================================================================*/\r
88 /* USB ROM DRIVER DEFINITIONS */\r
89 \r
90 /* A table of pointers to the chip's main ROM functions contained in ROM is located at the\r
91    address contained at this location */\r
92 typedef struct _ROM {\r
93         const unsigned p_otp;\r
94         const unsigned p_aes;\r
95         const unsigned p_pwd;\r
96         const unsigned p_clk;\r
97         const unsigned p_ipc;\r
98         const unsigned p_spifi;\r
99         const unsigned p_usbd;\r
100 }  ROM_FUNCTION_TABLE;\r
101 \r
102 /* A table of pointers to the USBD functions contained in ROM is located at the\r
103    address contained at this location */\r
104                                 #define ROM_FUNCTION_TABLE_PTR_ADDR         (0x10400104UL)\r
105                                 #define ROM_USBD_PTR (((ROM_FUNCTION_TABLE *) (ROM_FUNCTION_TABLE_PTR_ADDR))->p_usbd)\r
106 \r
107                                 #define ROMDRIVER_USB0_BASE LPC_USB0_BASE\r
108                                 #define ROMDRIVER_USB1_BASE LPC_USB1_BASE\r
109                                 #define ROMDRIVER_MEM_SIZE  0x1000\r
110 extern uint8_t usb_RomDriver_buffer[ROMDRIVER_MEM_SIZE];\r
111 \r
112                                 #define ROMDRIVER_MSC_MEM_SIZE  0x1000\r
113 extern uint8_t usb_RomDriver_MSC_buffer[ROMDRIVER_MSC_MEM_SIZE];\r
114 \r
115                                 #define ROMDRIVER_CDC_MEM_SIZE  0x800\r
116 extern uint8_t usb_RomDriver_CDC_buffer[ROMDRIVER_CDC_MEM_SIZE];\r
117                                 #define ROMDRIVER_CDC_DATA_BUFFER_SIZE  640\r
118                                 #if (USB_FORCED_FULLSPEED)\r
119                                         #define CDC_MAX_BULK_EP_SIZE            64\r
120                                 #else\r
121                                         #define CDC_MAX_BULK_EP_SIZE            512\r
122                                 #endif\r
123 extern uint8_t UsbdCdc_EPIN_buffer[CDC_MAX_BULK_EP_SIZE];\r
124 extern uint8_t UsbdCdc_EPOUT_buffer[CDC_MAX_BULK_EP_SIZE];\r
125 \r
126                                 #define ROMDRIVER_HID_MEM_SIZE  0x800\r
127 extern uint8_t usb_RomDriver_HID_buffer[ROMDRIVER_HID_MEM_SIZE];\r
128 /*==========================================================================*/\r
129                         #endif\r
130 \r
131 /*==========================================================================*/\r
132 /* DEVICE REGISTER DEFINITIONS                                                                  */\r
133 /*==========================================================================*/\r
134 /*---------- USBCMD ----------*/\r
135                                 #define USBCMD_D_RunStop                (1 << 0)                /* Run or Stop */\r
136                                 #define USBCMD_D_Reset                  (1 << 1)                /* Host Controller Reset */\r
137                                 #define USBCMD_D_SetupTripWire          (1 << 13)\r
138                                 #define USBCMD_D_AddTDTripWire          (1 << 14)\r
139                                 #define USBCMD_D_IntThreshold           (0xff << 16)\r
140 \r
141 /*---------- USBSTS ----------*/\r
142                                 #define USBSTS_D_UsbInt                     0x00000001UL                /* USB Interrupt */\r
143                                 #define USBSTS_D_UsbErrorInt                0x00000002UL                /* USB Error Interrupt */\r
144                                 #define USBSTS_D_PortChangeDetect           0x00000004UL                /* Port Change Detect */\r
145                                 #define USBSTS_D_ResetReceived              (1 << 6)\r
146                                 #define USBSTS_D_SofReceived                (1 << 7)\r
147                                 #define USBSTS_D_SuspendInt                 (1 << 8)\r
148                                 #define USBSTS_D_NAK                        (1 << 16)\r
149 \r
150 /*---------- USBINTR ----------*/\r
151                                 #define USBINTR_D_UsbIntEnable              (1 << 0)\r
152                                 #define USBINTR_D_UsbErrorIntEnable         (1 << 1)\r
153                                 #define USBINTR_D_PortChangeIntEnable       (1 << 2)\r
154                                 #define USBINTR_D_UsbResetEnable            (1 << 6)\r
155                                 #define USBINTR_D_SofReceivedEnable         (1 << 7)\r
156                                 #define USBINTR_D_SuspendEnable             (1 << 8)\r
157                                 #define USBINTR_D_NAKEnable                 (1 << 16)\r
158 \r
159 /*---------- DEVICEADDR ----------*/\r
160                                 #define DEVICEADDR_AddressAdvance           (1 << 24)\r
161                                 #define DEVICEADDR_DeviceAddr               (0xff << 25)\r
162 \r
163 /*---------- ENDPTNAK ----------*/\r
164                                 #define ENDPTNAK_RX                         (0x3f)\r
165                                 #define ENDPTNAK_TX                         (0x3f << 16)\r
166 \r
167 /*---------- ENDPTNAKEN ----------*/\r
168                                 #define ENDPTNAKEN_RX                       (0x3f)\r
169                                 #define ENDPTNAKEN_TX                       (0x3f << 16)\r
170 \r
171 /*---------- PORTSC ----------*/\r
172                                 #define PORTSC_D_CurrentConnectStatus           0x00000001UL            /* Current Connect Status */\r
173                                 #define PORTSC_D_ForcePortResume                0x00000040UL            /* Force Port Resume */\r
174                                 #define PORTSC_D_PortSuspend                    0x00000080UL            /* Port Suspend */\r
175                                 #define PORTSC_D_PortReset                  0x00000100UL                /* Port Reset */\r
176                                 #define PORTSC_D_HighSpeedStatus                0x00000200UL            /* Line Status */\r
177                                 #define PORTSC_D_PortIndicatorControl           0x0000C000UL            /* Port Indicator Control */\r
178                                 #define PORTSC_D_PortTestControl                0x000F0000UL            /* Port Test Control */\r
179                                 #define PORTSC_D_PhyClockDisable                0x00800000UL            /* PHY Clock Disable - EHCI derivation */\r
180                                 #define PORTSC_D_PortForceFullspeedConnect  0x01000000UL                /* Force Device on Fullspeed mode (disable chirp sequences) - EHCI derivation */\r
181                                 #define PORTSC_D_PortSpeed                  0x0C000000UL                /* Device Speed - EHCI derivation */\r
182 \r
183 /*---------- USBMODE_D ----------*/\r
184 /*---------- ENDPSETUPSTAT ----------*/\r
185 \r
186 /*---------- ENDPTPRIME ----------*/\r
187                                 #define ENDPTPRIME_RX                       (0x3f)\r
188                                 #define ENDPTPRIME_TX                       (0x3f << 16)\r
189 \r
190 /*---------- ENDPTFLUSH ----------*/\r
191                                 #define ENDPTFLUSH_RX                       (0x3f)\r
192                                 #define ENDPTFLUSH_TX                       (0x3f << 16)\r
193 \r
194 /*---------- ENDPTSTAT ----------*/\r
195                                 #define ENDPTSTAT_RX                        (0x3f)\r
196                                 #define ENDPTSTAT_TX                        (0x3f << 16)\r
197 \r
198 /*---------- ENDPTCOMPLETE ----------*/\r
199                                 #define ENDPTCOMPLETE_RX                        (0x3f)\r
200                                 #define ENDPTCOMPLETE_TX                        (0x3f << 16)\r
201 \r
202 /*---------- ENDPTCTRL ----------*/\r
203                                 #define ENDPTCTRL_RxStall                   (1)\r
204                                 #define ENDPTCTRL_RxType                    (3 << 2)\r
205                                 #define ENDPTCTRL_RxToggleInhibit           (1 << 5)\r
206                                 #define ENDPTCTRL_RxToggleReset             (1 << 6)\r
207                                 #define ENDPTCTRL_RxEnable                  (1 << 7)\r
208 \r
209                                 #define ENDPTCTRL_TxStall                   (1 << 16)\r
210                                 #define ENDPTCTRL_TxType                    (3 << 18)\r
211                                 #define ENDPTCTRL_TxToggleInhibit           (1 << 21)\r
212                                 #define ENDPTCTRL_TxToggleReset             (1 << 22)\r
213                                 #define ENDPTCTRL_TxEnable                  (1 << 23)\r
214                                 #define ENDPTCTRL_REG(corenum, LogicalAddr)  ( ((__IO uint32_t *) &(USB_REG(corenum)->ENDPTCTRL[0]))[   \\r
215                                                                                                                   LogicalAddr] )\r
216                                 #define EP_Physical2Logical(n)      ((n) / 2)\r
217 /* Total physical endpoints*/\r
218                                 #define USED_PHYSICAL_ENDPOINTS0                                                ENDPOINT_DETAILS_MAXEP0 * 2 /* This macro effect memory size of the DCD */\r
219                                 #define USED_PHYSICAL_ENDPOINTS1                                                ENDPOINT_DETAILS_MAXEP1 * 2 /* This macro effect memory size of the DCD */\r
220                                 #define USED_PHYSICAL_ENDPOINTS(corenum)                ((corenum) ? USED_PHYSICAL_ENDPOINTS1 : USED_PHYSICAL_ENDPOINTS0) /* This macro effect memory size of the DCD */\r
221                                 #define EP_Physical2BitPosition(n) ( EP_Physical2Logical(n) + ((n) % 2 ? 16 : 0 ) )\r
222 //                              #define LINK_TERMINATE      1\r
223 \r
224 /*---------- Device TD ----------*/\r
225 typedef struct {\r
226         /*---------- Word 1 ----------*/\r
227         uint32_t NextTD;\r
228 \r
229         /*---------- Word 2 ----------*/\r
230         uint32_t : 3;\r
231         __IO uint32_t TransactionErr : 1;\r
232         uint32_t : 1;\r
233         __IO uint32_t BufferErr : 1;\r
234         __IO uint32_t Halted : 1;\r
235         __IO uint32_t Active : 1;\r
236         uint32_t : 2;\r
237         uint32_t MultiplierOverride : 2;\r
238         uint32_t : 3;\r
239         __IO uint32_t IntOnComplete : 1;\r
240         __IO uint32_t TotalBytes : 15;\r
241         uint32_t : 0;                                   /* force next member alinged on the next word */\r
242 \r
243         /*---------- Word 3 - 7 ----------*/\r
244         uint32_t BufferPage[5];\r
245 \r
246         uint32_t reserved;\r
247 } DeviceTransferDescriptor, *PDeviceTransferDescriptor;\r
248 \r
249 /*---------- Device Qhd ----------*/\r
250 typedef struct {\r
251         /*---------- Word 1: Capability/Characteristics ----------*/\r
252         uint32_t : 15;\r
253         __IO uint32_t IntOnSetup : 1;\r
254         uint32_t MaxPacketSize : 11;\r
255         uint32_t : 2;\r
256         __IO uint32_t ZeroLengthTermination : 1;\r
257         uint32_t Mult : 2;\r
258         uint32_t : 0;\r
259 \r
260         /*---------- Word 2 ----------*/\r
261         uint32_t currentTD;\r
262 \r
263         /*---------- Word 3 - 10 ----------*/\r
264         __IO DeviceTransferDescriptor overlay;\r
265 \r
266         /*---------- Word 11-12 ----------*/\r
267         __IO uint8_t SetupPackage[8];\r
268 \r
269         uint16_t TransferCount;\r
270         __IO uint16_t IsOutReceived;                            // === TODO: IsOutReceived should be refractor to QueueHead Status ===\r
271         uint16_t reserved[6];\r
272 } DeviceQueueHead, *PDeviceQueueHead;\r
273 \r
274 extern volatile DeviceQueueHead * const dQueueHead[];\r
275 extern DeviceTransferDescriptor * const dTransferDescriptor[];\r
276 \r
277 void DcdDataTransfer(uint8_t corenum, uint8_t EPNum, uint8_t *pData, uint32_t cnt);\r
278 \r
279 void Endpoint_Streaming(uint8_t corenum, uint8_t *buffer, uint16_t packetsize,\r
280                                                 uint16_t totalpackets, uint16_t dummypackets);\r
281 \r
282 /* Inline Functions: */\r
283 \r
284 /* Function Prototypes: */\r
285 void Endpoint_ClearEndpoints(uint8_t corenum);\r
286 \r
287 bool Endpoint_ConfigureEndpoint_Prv(uint8_t corenum,\r
288                                                                         const uint8_t Number,\r
289                                                                         const uint8_t UECFG0XData,\r
290                                                                         const uint8_t UECFG1XData);\r
291 \r
292         #endif\r
293 \r
294 /* Inline Functions: */\r
295 /**\r
296  * @brief  Configures the specified endpoint number with the given endpoint type, direction, bank size\r
297  *  and banking mode. Once configured, the endpoint may be read from or written to, depending\r
298  *  on its direction.\r
299  * @param  corenum        : ID Number of USB Core to be processed.\r
300  * @param  Number         : Endpoint number to configure. This must be more than 0 and less than @ref ENDPOINT_TOTAL_ENDPOINTS\r
301  * @param  Type           : Type of endpoint to configure, a \c EP_TYPE_* mask. Not all endpoint types\r
302  *                          are available on Low Speed USB devices - refer to the USB 2.0 specification.\r
303  * @param  Direction      : Endpoint data direction, either @ref ENDPOINT_DIR_OUT or @ref ENDPOINT_DIR_IN.\r
304  *                          All endpoints (except Control type) are unidirectional - data may only be read\r
305  *                          from or written to the endpoint bank based on its direction, not both.\r
306  * @param  Size           : Size of the endpoint's bank, where packets are stored before they are transmitted\r
307  *                          to the USB host, or after they have been received from the USB host (depending on\r
308  *                          the endpoint's data direction). The bank size must indicate the maximum packet size\r
309  *                          that the endpoint can handle.\r
310  * @param  Banks          : Number of banks to use for the endpoint being configured, an \c ENDPOINT_BANK_* mask.\r
311  *                          More banks uses more USB DPRAM, but offers better performance. Isochronous type\r
312  *                          endpoints <b>must</b> have at least two banks.\r
313  * @return Boolean \c true if the configuration succeeded, \c false otherwise.\r
314  */\r
315 /*static inline */ bool Endpoint_ConfigureEndpoint(uint8_t corenum,\r
316                                                                                                          const uint8_t Number,\r
317                                                                                                    const uint8_t Type,\r
318                                                                                                    const uint8_t Direction,\r
319                                                                                                    const uint16_t Size,\r
320                                                                                                    const uint8_t Banks) /*ATTR_ALWAYS_INLINE*/;\r
321 \r
322 //          static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,\r
323 //                                                        const uint8_t Type,\r
324 //                                                        const uint8_t Direction,\r
325 //                                                        const uint16_t Size,\r
326 //                                                        const uint8_t Banks)\r
327 //          {\r
328 //              endpointhandle[Number] = HAL17XX_ConfigureEndpoint(Number,Type,Direction,Size,Banks);\r
329 //              return true;\r
330 //          }\r
331 \r
332 /**\r
333  * @brief  Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's\r
334  *  data In and Out pointers to the bank's contents.\r
335  *\r
336  * @param  EndpointNumber : Endpoint number whose FIFO buffers are to be reset.\r
337  * @return Nothing.\r
338  */\r
339 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;\r
340 \r
341 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)\r
342 {}\r
343 \r
344 /**\r
345  *  @brief  Enables the currently selected endpoint so that data can be sent and received through it to\r
346  *  and from a host.\r
347  *\r
348  *  @note Endpoints must first be configured properly via @ref Endpoint_ConfigureEndpoint().\r
349  *  @return Nothing.\r
350  */\r
351 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;\r
352 \r
353 static inline void Endpoint_EnableEndpoint(void)\r
354 {}\r
355 \r
356 /**\r
357  *  @brief  Disables the currently selected endpoint so that data cannot be sent and received through it\r
358  *  to and from a host.\r
359  *  @return Nothing.\r
360  */\r
361 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;\r
362 \r
363 static inline void Endpoint_DisableEndpoint(void)\r
364 {}\r
365 \r
366 /**\r
367  * @brief  Determines if the currently selected endpoint is enabled, but not necessarily configured\r
368  * @return Boolean \c true if the currently selected endpoint is enabled, \c false otherwise.\r
369  */\r
370 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
371 \r
372 static inline bool Endpoint_IsEnabled(void)\r
373 {\r
374         return true;\r
375 }\r
376 \r
377 /**\r
378  *  @brief  Retrieves the number of busy banks in the currently selected endpoint, which have been queued for\r
379  *  transmission via the @ref Endpoint_ClearIN() command, or are awaiting acknowledgement via the\r
380  *  @ref Endpoint_ClearOUT() command.\r
381  *\r
382  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
383  *\r
384  *  @return Total number of busy banks in the selected endpoint.\r
385  */\r
386 static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;\r
387 \r
388 static inline uint8_t Endpoint_GetBusyBanks(void)\r
389 {\r
390         return 0;\r
391 }\r
392 \r
393 /** @brief Aborts all pending IN transactions on the currently selected endpoint, once the bank\r
394  *  has been queued for transmission to the host via @ref Endpoint_ClearIN(). This function\r
395  *  will terminate all queued transactions, resetting the endpoint banks ready for a new\r
396  *  packet.\r
397  *\r
398  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
399  *  @return Nothing.\r
400  */\r
401 static inline void Endpoint_AbortPendingIN(void)\r
402 {}\r
403 \r
404 /**\r
405  * @brief  Determines if the currently selected endpoint is configured.\r
406  *\r
407  *  @return Boolean \c true if the currently selected endpoint has been configured, \c false otherwise.\r
408  */\r
409 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
410 \r
411 static inline bool Endpoint_IsConfigured(void)\r
412 {\r
413         //                              return ((UESTA0X & (1 << CFGOK)) ? true : false);\r
414         return true;\r
415 }\r
416 \r
417 /**\r
418  *  @brief  Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their\r
419  *  interrupt duration has elapsed. Which endpoints have interrupted can be determined by\r
420  *  masking the return value against <tt>(1 << <i>{Endpoint Number}</i>)</tt>.\r
421  *\r
422  *  @return Mask whose bits indicate which endpoints have interrupted.\r
423  */\r
424 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
425 \r
426 static inline uint8_t Endpoint_GetEndpointInterrupts(void)\r
427 {\r
428         return 0;                               // TODO not yet implemented\r
429 }\r
430 \r
431 /**\r
432  * @brief  Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type\r
433  *                 endpoints).\r
434  * @param  EndpointNumber : Index of the endpoint whose interrupt flag should be tested\r
435  * @return Boolean \c true if the specified endpoint has interrupted, \c false otherwise.\r
436  */\r
437 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT\r
438 ATTR_ALWAYS_INLINE;\r
439 \r
440 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)\r
441 {\r
442         return (Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false;\r
443 }\r
444 \r
445 /**\r
446  * @brief  Indicates the number of bytes currently stored in the current endpoint's selected bank.\r
447  *\r
448  *  @note The return width of this function may differ, depending on the maximum endpoint bank size\r
449  *        of the selected LPC model.\r
450  *\r
451  *  @ingroup Group_EndpointRW_LPC18xx\r
452  *\r
453  * @param  corenum :        ID Number of USB Core to be processed.\r
454  * @return Total number of bytes in the currently selected Endpoint's FIFO buffer\r
455  */\r
456 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
457 \r
458 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum)\r
459 {\r
460         // return usb_data_buffer_index;                        // TODO not implemented yet\r
461         // uint8_t PhyEP = (endpointselected==ENDPOINT_CONTROLEP ? 1: endpointhandle[endpointselected]);\r
462         if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {\r
463                 return usb_data_buffer_size[corenum];\r
464         }\r
465         else {\r
466                 return usb_data_buffer_OUT_size[corenum];\r
467         }\r
468 }\r
469 \r
470 /**\r
471  * @brief  Determines if the selected IN endpoint is ready for a new packet to be sent to the host.\r
472  *\r
473  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
474  *\r
475  * @param  corenum :        ID Number of USB Core to be processed.\r
476  *  @return Boolean \c true if the current endpoint is ready for an IN packet, \c false otherwise.\r
477  */\r
478 static inline bool Endpoint_IsINReady(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
479 \r
480 static inline bool Endpoint_IsINReady(uint8_t corenum)\r
481 {\r
482         uint8_t PhyEP = (endpointselected[corenum] == ENDPOINT_CONTROLEP ? 1 : endpointhandle(corenum)[endpointselected[corenum]]);\r
483         return (dQueueHead[corenum][PhyEP].overlay.NextTD & LINK_TERMINATE) &&\r
484                    (dQueueHead[corenum][PhyEP].overlay.Active == 0);\r
485 }\r
486 \r
487 /**\r
488  * @brief  Determines if the selected OUT endpoint has received new packet from the host.\r
489  *\r
490  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
491  *\r
492  * @param  corenum :        ID Number of USB Core to be processed.\r
493  *  @return Boolean \c true if current endpoint is has received an OUT packet, \c false otherwise.\r
494  */\r
495 static inline bool Endpoint_IsOUTReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
496 \r
497 static inline bool Endpoint_IsOUTReceived(uint8_t corenum)\r
498 {\r
499         //              return  (dQueueHead[ endpointhandle[endpointselected] ].overlay.NextTD == LINK_TERMINATE &&\r
500         //                      dQueueHead[ endpointhandle[endpointselected] ].overlay.Active == 0 );\r
501         return dQueueHead[corenum][endpointhandle(corenum)[endpointselected[corenum]]].IsOutReceived ? true : false;                            // TODO refractor IsOutReceived\r
502 }\r
503 \r
504 /**\r
505  * @brief  Determines if the current CONTROL type endpoint has received a SETUP packet.\r
506  *\r
507  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
508  *\r
509  * @param  corenum :        ID Number of USB Core to be processed.\r
510  *  @return Boolean \c true if the selected endpoint has received a SETUP packet, \c false otherwise.\r
511  */\r
512 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
513 \r
514 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum)\r
515 {\r
516         return USB_REG(corenum)->ENDPTSETUPSTAT ? true : false;\r
517 }\r
518 \r
519 /**\r
520  *  @brief  Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the\r
521  *  endpoint for the next packet.\r
522  *\r
523  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
524  *\r
525  *  @param  corenum :        ID Number of USB Core to be processed.\r
526  *  @return Nothing.\r
527  *  @note This is not applicable for non CONTROL type endpoints.\r
528  */\r
529 static inline void Endpoint_ClearSETUP(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
530 \r
531 static inline void Endpoint_ClearSETUP(uint8_t corenum)\r
532 {\r
533         IP_USBHS_001_T * USB_Reg = USB_REG(corenum);\r
534         USB_Reg->ENDPTSETUPSTAT = USB_Reg->ENDPTSETUPSTAT;\r
535         usb_data_buffer_index[corenum] = 0;\r
536         USB_Reg->ENDPTNAKEN |= (1 << 0);\r
537 }\r
538 \r
539 /**\r
540  *  @brief  Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the\r
541  *  next packet and switching to the alternative endpoint bank if double banked.\r
542  *\r
543  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
544  *  @param  corenum :        ID Number of USB Core to be processed.\r
545  *  @return Nothing.\r
546  */\r
547 static inline void Endpoint_ClearIN(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
548 \r
549 static inline void Endpoint_ClearIN(uint8_t corenum)\r
550 {\r
551         uint8_t PhyEP = endpointselected[corenum] == ENDPOINT_CONTROLEP ? 1 : (endpointhandle(corenum)[endpointselected[corenum]]);\r
552         if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {\r
553                 DcdDataTransfer(corenum, PhyEP, (uint8_t *)usb_data_buffer[corenum], usb_data_buffer_index[corenum]);\r
554                 usb_data_buffer_index[corenum] = 0;\r
555         }\r
556         else {\r
557                 DcdDataTransfer(corenum, PhyEP, usb_data_buffer_IN[corenum], usb_data_buffer_IN_index[corenum]);\r
558                 usb_data_buffer_IN_index[corenum] = 0;\r
559         }\r
560 }\r
561 \r
562 /**\r
563  *  @brief  Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint\r
564  *  for the next packet and switching to the alternative endpoint bank if double banked.\r
565  *\r
566  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
567  * @param  corenum :        ID Number of USB Core to be processed.\r
568  * @return Nothing.\r
569  */\r
570 static inline void Endpoint_ClearOUT(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
571 \r
572 static inline void Endpoint_ClearOUT(uint8_t corenum)\r
573 {\r
574         if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {\r
575                 usb_data_buffer_index[corenum] = 0;\r
576                 dQueueHead[corenum][endpointhandle(corenum)[endpointselected[corenum]]].IsOutReceived = 0;\r
577         }\r
578         else {\r
579                 usb_data_buffer_OUT_index[corenum] = 0;\r
580                 dQueueHead[corenum][endpointhandle(corenum)[endpointselected[corenum]]].IsOutReceived = 0;\r
581                 USB_REG(corenum)->ENDPTNAKEN |= (1 << endpointselected[corenum]);\r
582         }\r
583 \r
584 }\r
585 \r
586 /**\r
587  *  @brief  Stalls the current endpoint, indicating to the host that a logical problem occurred with the\r
588  *  indicated endpoint and that the current transfer sequence should be aborted. This provides a\r
589  *  way for devices to indicate invalid commands to the host so that the current transfer can be\r
590  *  aborted and the host can begin its own recovery sequence.\r
591  *\r
592  *  The currently selected endpoint remains stalled until either the @ref Endpoint_ClearStall() macro\r
593  *  is called, or the host issues a CLEAR FEATURE request to the device for the currently selected\r
594  *  endpoint.\r
595  *\r
596  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
597  *  @param  corenum :        ID Number of USB Core to be processed.\r
598  *  @return Nothing.\r
599  */\r
600 static inline void Endpoint_StallTransaction(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
601 \r
602 static inline void Endpoint_StallTransaction(uint8_t corenum)\r
603 {\r
604         ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) |= ENDPTCTRL_RxStall | ENDPTCTRL_TxStall;\r
605 }\r
606 \r
607 /**\r
608  *  @brief  Clears the STALL condition on the currently selected endpoint.\r
609  *\r
610  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
611  *  @param  corenum :        ID Number of USB Core to be processed.\r
612  *  @return Nothing.\r
613  */\r
614 static inline void Endpoint_ClearStall(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
615 \r
616 static inline void Endpoint_ClearStall(uint8_t corenum)\r
617 {\r
618         // === TODO: Only clear stall correct endpoint ===\r
619         ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) &= ~(ENDPTCTRL_RxStall | ENDPTCTRL_TxStall);\r
620 }\r
621 \r
622 /**\r
623  * @brief  Determines if the currently selected endpoint is stalled, false otherwise.\r
624  *\r
625  *  @ingroup Group_EndpointPacketManagement_LPC18xx\r
626  *\r
627  *  @param  corenum :        ID Number of USB Core to be processed.\r
628  *  @return Boolean \c true if the currently selected endpoint is stalled, \c false otherwise.\r
629  */\r
630 static inline bool Endpoint_IsStalled(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
631 \r
632 static inline bool Endpoint_IsStalled(uint8_t corenum)\r
633 {\r
634         return ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) &\r
635                    (ENDPTCTRL_RxStall | ENDPTCTRL_TxStall);\r
636 }\r
637 \r
638 /** Resets the data toggle of the currently selected endpoint. */\r
639 static inline void Endpoint_ResetDataToggle(uint8_t corenum) ATTR_ALWAYS_INLINE;\r
640 \r
641 static inline void Endpoint_ResetDataToggle(uint8_t corenum)\r
642 {\r
643         ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) |= ENDPTCTRL_RxToggleReset |\r
644                                                                                                                                                          ENDPTCTRL_TxToggleReset;\r
645 }\r
646 \r
647 /* External Variables: */\r
648 /** Global indicating the maximum packet size of the default control endpoint located at address\r
649  *  0 in the device. This value is set to the value indicated in the device descriptor in the user\r
650  *  project once the USB interface is initialized into device mode.\r
651  *\r
652  *  If space is an issue, it is possible to fix this to a static value by defining the control\r
653  *  endpoint size in the \c FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile\r
654  *  via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically\r
655  *  read from the descriptors at runtime and instead fixed to the given value. When used, it is\r
656  *  important that the descriptor control endpoint size value matches the size given as the\r
657  *  \c FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the \c FIXED_CONTROL_ENDPOINT_SIZE token\r
658  *  be used in the device descriptors to ensure this.\r
659  *\r
660  *  @note This variable should be treated as read-only in the user application, and never manually\r
661  *        changed in value.\r
662  */\r
663                         #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))\r
664 extern uint8_t USB_Device_ControlEndpointSize;\r
665                         #else\r
666                                 #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE\r
667                         #endif\r
668 \r
669 /* Function Prototypes: */\r
670 /**\r
671  * @brief Completes the status stage of a control transfer on a CONTROL type endpoint automatically,\r
672  *  with respect to the data direction. This is a convenience function which can be used to\r
673  *  simplify user control request handling.\r
674  *   @param  corenum :        ID Number of USB Core to be processed.\r
675  *   @return Nothing.\r
676  */\r
677 void Endpoint_ClearStatusStage(uint8_t corenum);\r
678 \r
679 /**\r
680  * @brief  Spin-loops until the currently selected non-control endpoint is ready for the next packet of data\r
681  *  to be read or written to it.\r
682  *\r
683  *  @note This routine should not be called on CONTROL type endpoints.\r
684  *\r
685  *  @ingroup Group_EndpointRW_LPC18xx\r
686  *\r
687  *  @return A value from the @ref Endpoint_WaitUntilReady_ErrorCodes_t enum.\r
688  */\r
689 uint8_t Endpoint_WaitUntilReady(void);\r
690 \r
691 /* Disable C linkage for C++ Compilers: */\r
692                 #if defined(__cplusplus)\r
693 }\r
694                 #endif\r
695 \r
696 #endif\r
697 \r
698 /** @} */\r