2 * @brief USB Endpoint definitions for the LPC18xx microcontrollers
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\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
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
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
36 * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
\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
43 * Functions, macros, variables, enums and types related to data reading and writing of primitive data types
\r
44 * from and to endpoints.
\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
51 * Functions, macros, variables, enums and types related to packet management of endpoints.
\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
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
65 #ifndef __ENDPOINT_LPC18XX_H__
\r
66 #define __ENDPOINT_LPC18XX_H__
\r
68 #include "../EndpointCommon.h"
\r
70 /* Enable C linkage for C++ Compilers: */
\r
71 #if defined(__cplusplus)
\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
80 /* Private Interface - For use in library only: */
\r
81 #if !defined(__DOXYGEN__)
\r
83 #define ENDPOINT_DETAILS_MAXEP0 6
\r
84 #define ENDPOINT_DETAILS_MAXEP1 4
\r
86 #if defined(USB_DEVICE_ROM_DRIVER)
\r
87 /*==========================================================================*/
\r
88 /* USB ROM DRIVER DEFINITIONS */
\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
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
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
112 #define ROMDRIVER_MSC_MEM_SIZE 0x1000
\r
113 extern uint8_t usb_RomDriver_MSC_buffer[ROMDRIVER_MSC_MEM_SIZE];
\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
121 #define CDC_MAX_BULK_EP_SIZE 512
\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
126 #define ROMDRIVER_HID_MEM_SIZE 0x800
\r
127 extern uint8_t usb_RomDriver_HID_buffer[ROMDRIVER_HID_MEM_SIZE];
\r
128 /*==========================================================================*/
\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
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
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
159 /*---------- DEVICEADDR ----------*/
\r
160 #define DEVICEADDR_AddressAdvance (1 << 24)
\r
161 #define DEVICEADDR_DeviceAddr (0xff << 25)
\r
163 /*---------- ENDPTNAK ----------*/
\r
164 #define ENDPTNAK_RX (0x3f)
\r
165 #define ENDPTNAK_TX (0x3f << 16)
\r
167 /*---------- ENDPTNAKEN ----------*/
\r
168 #define ENDPTNAKEN_RX (0x3f)
\r
169 #define ENDPTNAKEN_TX (0x3f << 16)
\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
183 /*---------- USBMODE_D ----------*/
\r
184 /*---------- ENDPSETUPSTAT ----------*/
\r
186 /*---------- ENDPTPRIME ----------*/
\r
187 #define ENDPTPRIME_RX (0x3f)
\r
188 #define ENDPTPRIME_TX (0x3f << 16)
\r
190 /*---------- ENDPTFLUSH ----------*/
\r
191 #define ENDPTFLUSH_RX (0x3f)
\r
192 #define ENDPTFLUSH_TX (0x3f << 16)
\r
194 /*---------- ENDPTSTAT ----------*/
\r
195 #define ENDPTSTAT_RX (0x3f)
\r
196 #define ENDPTSTAT_TX (0x3f << 16)
\r
198 /*---------- ENDPTCOMPLETE ----------*/
\r
199 #define ENDPTCOMPLETE_RX (0x3f)
\r
200 #define ENDPTCOMPLETE_TX (0x3f << 16)
\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
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
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
224 /*---------- Device TD ----------*/
\r
226 /*---------- Word 1 ----------*/
\r
229 /*---------- Word 2 ----------*/
\r
231 __IO uint32_t TransactionErr : 1;
\r
233 __IO uint32_t BufferErr : 1;
\r
234 __IO uint32_t Halted : 1;
\r
235 __IO uint32_t Active : 1;
\r
237 uint32_t MultiplierOverride : 2;
\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
243 /*---------- Word 3 - 7 ----------*/
\r
244 uint32_t BufferPage[5];
\r
247 } DeviceTransferDescriptor, *PDeviceTransferDescriptor;
\r
249 /*---------- Device Qhd ----------*/
\r
251 /*---------- Word 1: Capability/Characteristics ----------*/
\r
253 __IO uint32_t IntOnSetup : 1;
\r
254 uint32_t MaxPacketSize : 11;
\r
256 __IO uint32_t ZeroLengthTermination : 1;
\r
260 /*---------- Word 2 ----------*/
\r
261 uint32_t currentTD;
\r
263 /*---------- Word 3 - 10 ----------*/
\r
264 __IO DeviceTransferDescriptor overlay;
\r
266 /*---------- Word 11-12 ----------*/
\r
267 __IO uint8_t SetupPackage[8];
\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
274 extern volatile DeviceQueueHead * const dQueueHead[];
\r
275 extern DeviceTransferDescriptor * const dTransferDescriptor[];
\r
277 void DcdDataTransfer(uint8_t corenum, uint8_t EPNum, uint8_t *pData, uint32_t cnt);
\r
279 void Endpoint_Streaming(uint8_t corenum, uint8_t *buffer, uint16_t packetsize,
\r
280 uint16_t totalpackets, uint16_t dummypackets);
\r
282 /* Inline Functions: */
\r
284 /* Function Prototypes: */
\r
285 void Endpoint_ClearEndpoints(uint8_t corenum);
\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
294 /* Inline Functions: */
\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
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
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
328 // endpointhandle[Number] = HAL17XX_ConfigureEndpoint(Number,Type,Direction,Size,Banks);
\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
336 * @param EndpointNumber : Endpoint number whose FIFO buffers are to be reset.
\r
339 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
\r
341 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)
\r
345 * @brief Enables the currently selected endpoint so that data can be sent and received through it to
\r
348 * @note Endpoints must first be configured properly via @ref Endpoint_ConfigureEndpoint().
\r
351 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
\r
353 static inline void Endpoint_EnableEndpoint(void)
\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
361 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
\r
363 static inline void Endpoint_DisableEndpoint(void)
\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
370 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
372 static inline bool Endpoint_IsEnabled(void)
\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
382 * @ingroup Group_EndpointPacketManagement_LPC18xx
\r
384 * @return Total number of busy banks in the selected endpoint.
\r
386 static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
\r
388 static inline uint8_t Endpoint_GetBusyBanks(void)
\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
398 * @ingroup Group_EndpointPacketManagement_LPC18xx
\r
401 static inline void Endpoint_AbortPendingIN(void)
\r
405 * @brief Determines if the currently selected endpoint is configured.
\r
407 * @return Boolean \c true if the currently selected endpoint has been configured, \c false otherwise.
\r
409 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
411 static inline bool Endpoint_IsConfigured(void)
\r
413 // return ((UESTA0X & (1 << CFGOK)) ? true : false);
\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
422 * @return Mask whose bits indicate which endpoints have interrupted.
\r
424 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
426 static inline uint8_t Endpoint_GetEndpointInterrupts(void)
\r
428 return 0; // TODO not yet implemented
\r
432 * @brief Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
\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
437 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT
\r
438 ATTR_ALWAYS_INLINE;
\r
440 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
\r
442 return (Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false;
\r
446 * @brief Indicates the number of bytes currently stored in the current endpoint's selected bank.
\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
451 * @ingroup Group_EndpointRW_LPC18xx
\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
456 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
458 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum)
\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
466 return usb_data_buffer_OUT_size[corenum];
\r
471 * @brief Determines if the selected IN endpoint is ready for a new packet to be sent to the host.
\r
473 * @ingroup Group_EndpointPacketManagement_LPC18xx
\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
478 static inline bool Endpoint_IsINReady(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
480 static inline bool Endpoint_IsINReady(uint8_t corenum)
\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
488 * @brief Determines if the selected OUT endpoint has received new packet from the host.
\r
490 * @ingroup Group_EndpointPacketManagement_LPC18xx
\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
495 static inline bool Endpoint_IsOUTReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
497 static inline bool Endpoint_IsOUTReceived(uint8_t corenum)
\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
505 * @brief Determines if the current CONTROL type endpoint has received a SETUP packet.
\r
507 * @ingroup Group_EndpointPacketManagement_LPC18xx
\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
512 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
514 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum)
\r
516 return USB_REG(corenum)->ENDPTSETUPSTAT ? true : false;
\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
523 * @ingroup Group_EndpointPacketManagement_LPC18xx
\r
525 * @param corenum : ID Number of USB Core to be processed.
\r
527 * @note This is not applicable for non CONTROL type endpoints.
\r
529 static inline void Endpoint_ClearSETUP(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
531 static inline void Endpoint_ClearSETUP(uint8_t corenum)
\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
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
543 * @ingroup Group_EndpointPacketManagement_LPC18xx
\r
544 * @param corenum : ID Number of USB Core to be processed.
\r
547 static inline void Endpoint_ClearIN(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
549 static inline void Endpoint_ClearIN(uint8_t corenum)
\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
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
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
566 * @ingroup Group_EndpointPacketManagement_LPC18xx
\r
567 * @param corenum : ID Number of USB Core to be processed.
\r
570 static inline void Endpoint_ClearOUT(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
572 static inline void Endpoint_ClearOUT(uint8_t corenum)
\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
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
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
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
596 * @ingroup Group_EndpointPacketManagement_LPC18xx
\r
597 * @param corenum : ID Number of USB Core to be processed.
\r
600 static inline void Endpoint_StallTransaction(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
602 static inline void Endpoint_StallTransaction(uint8_t corenum)
\r
604 ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) |= ENDPTCTRL_RxStall | ENDPTCTRL_TxStall;
\r
608 * @brief Clears the STALL condition on the currently selected endpoint.
\r
610 * @ingroup Group_EndpointPacketManagement_LPC18xx
\r
611 * @param corenum : ID Number of USB Core to be processed.
\r
614 static inline void Endpoint_ClearStall(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
616 static inline void Endpoint_ClearStall(uint8_t corenum)
\r
618 // === TODO: Only clear stall correct endpoint ===
\r
619 ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) &= ~(ENDPTCTRL_RxStall | ENDPTCTRL_TxStall);
\r
623 * @brief Determines if the currently selected endpoint is stalled, false otherwise.
\r
625 * @ingroup Group_EndpointPacketManagement_LPC18xx
\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
630 static inline bool Endpoint_IsStalled(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
632 static inline bool Endpoint_IsStalled(uint8_t corenum)
\r
634 return ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) &
\r
635 (ENDPTCTRL_RxStall | ENDPTCTRL_TxStall);
\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
641 static inline void Endpoint_ResetDataToggle(uint8_t corenum)
\r
643 ENDPTCTRL_REG(corenum, EP_Physical2Logical(endpointhandle(corenum)[endpointselected[corenum]]) ) |= ENDPTCTRL_RxToggleReset |
\r
644 ENDPTCTRL_TxToggleReset;
\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
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
660 * @note This variable should be treated as read-only in the user application, and never manually
\r
661 * changed in value.
\r
663 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
\r
664 extern uint8_t USB_Device_ControlEndpointSize;
\r
666 #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
\r
669 /* Function Prototypes: */
\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
677 void Endpoint_ClearStatusStage(uint8_t corenum);
\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
683 * @note This routine should not be called on CONTROL type endpoints.
\r
685 * @ingroup Group_EndpointRW_LPC18xx
\r
687 * @return A value from the @ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
\r
689 uint8_t Endpoint_WaitUntilReady(void);
\r
691 /* Disable C linkage for C++ Compilers: */
\r
692 #if defined(__cplusplus)
\r