2 * @brief USB Endpoint definitions for the LPC11Uxx 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_LPC11Uxx Endpoint Data Reading and Writing (LPC11Uxx, LPC1347)
\r
34 * @brief Endpoint data read/write definitions for the LPC11Uxx and LPC1347 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_LPC11Uxx Read/Write of Primitive Data Types (LPC11Uxx, LPC1347)
\r
41 * @brief Endpoint primitive read/write definitions for the LPC11Uxx and LPC1347 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_LPC11Uxx Endpoint Packet Management (LPC11Uxx, LPC1347)
\r
49 * @brief Endpoint packet management definitions for the NXP LPC11Uxx and LPC1347 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_LPC11Uxx Endpoint Management (LPC11Uxx, LPC1347)
\r
56 * @brief Endpoint management definitions for the NXP LPC11Uxx and LPC1347 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_LPC11UXX_H__
\r
66 #define __ENDPOINT_LPC11UXX_H__
\r
68 #include "../EndpointCommon.h"
\r
70 #if defined(__cplusplus)
\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
78 #if !defined(__DOXYGEN__)
\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
84 #if defined(USB_DEVICE_ROM_DRIVER)
\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
93 const unsigned p_pwrd;
\r
94 #endif /* PWRROMD_PRESENT */
\r
95 #ifdef DIVROMD_PRESENT
\r
96 const LPC_ROM_DIV_STRUCT *pROMDiv;
\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
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
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
113 #define ROMDRIVER_MSC_MEM_SIZE 0x100
\r
114 extern uint8_t usb_RomDriver_MSC_buffer[ROMDRIVER_MSC_MEM_SIZE];
\r
116 #define ROMDRIVER_CDC_MEM_SIZE 0x8
\r
117 extern uint8_t usb_RomDriver_CDC_buffer[ROMDRIVER_CDC_MEM_SIZE];
\r
119 #if (USB_FORCED_FULLSPEED)
\r
120 #define CDC_MAX_BULK_EP_SIZE 64
\r
122 #define CDC_MAX_BULK_EP_SIZE 512
\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
127 #define ROMDRIVER_HID_MEM_SIZE 0x8
\r
128 extern uint8_t usb_RomDriver_HID_buffer[ROMDRIVER_HID_MEM_SIZE];
\r
132 void Endpoint_ClearEndpoints(uint8_t corenum);
\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
140 #define USED_PHYSICAL_ENDPOINTS (ENDPOINT_DETAILS_MAXEP * 2)/* This macro effect memory size of the DCD */
\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
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
172 #define PKT_LNGTH_MASK 0x000003FF
\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
192 extern void WrCmd (uint32_t cmd);
\r
194 void HAL11UXX_WriteEndPoint(uint8_t EPNum, uint8_t *pData, uint32_t cnt);
\r
196 void DcdDataTransfer(uint8_t EPNum, uint8_t *pData, uint32_t length);
\r
198 void Endpoint_Streaming(uint8_t corenum, uint8_t *buffer, uint16_t packetsize,
\r
199 uint16_t totalpackets, uint16_t dummypackets);
\r
201 extern USB_CMD_STAT EndPointCmdStsList[10][2];
\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
210 PRAGMA_ALWAYS_INLINE
\r
211 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
\r
213 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)
\r
216 PRAGMA_ALWAYS_INLINE
\r
217 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
\r
219 static inline void Endpoint_EnableEndpoint(void)
\r
222 PRAGMA_ALWAYS_INLINE
\r
223 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
\r
225 static inline void Endpoint_DisableEndpoint(void)
\r
228 PRAGMA_ALWAYS_INLINE
\r
229 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
231 static inline bool Endpoint_IsEnabled(void)
\r
236 PRAGMA_ALWAYS_INLINE
\r
237 static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
\r
239 static inline uint8_t Endpoint_GetBusyBanks(void)
\r
244 static inline void Endpoint_AbortPendingIN(void)
\r
247 PRAGMA_ALWAYS_INLINE
\r
248 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
250 static inline bool Endpoint_IsConfigured(void)
\r
252 // return ((UESTA0X & (1 << CFGOK)) ? true : false);
\r
256 PRAGMA_ALWAYS_INLINE
\r
257 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
259 static inline uint8_t Endpoint_GetEndpointInterrupts(void)
\r
261 return 0; // TODO not yet implemented
\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
268 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
\r
270 return (Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false;
\r
273 PRAGMA_ALWAYS_INLINE
\r
274 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
276 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum)
\r
278 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
\r
279 return usb_data_buffer_size[corenum];
\r
282 return usb_data_buffer_OUT_size[corenum];
\r
286 PRAGMA_ALWAYS_INLINE
\r
287 static inline bool Endpoint_IsINReady(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
289 static inline bool Endpoint_IsINReady(uint8_t corenum)
\r
292 (endpointselected[corenum] == ENDPOINT_CONTROLEP) ? (ENDPOINT_CONTROLEP + 1) : endpointhandle(corenum)[endpointselected[corenum]];
\r
293 return EndPointCmdStsList[PhyEP][0].Active ? false : true;
\r
296 PRAGMA_ALWAYS_INLINE
\r
297 static inline bool Endpoint_IsOUTReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
299 static inline bool Endpoint_IsOUTReceived(uint8_t corenum)
\r
301 return /*EndPointCmdStsList[ endpointhandle(corenum)[endpointselected] ][0].Active == 0 &&*/
\r
302 EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].NBytes != 0x200;
\r
305 PRAGMA_ALWAYS_INLINE
\r
306 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
308 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum)
\r
310 return LPC_USB->DEVCMDSTAT & USB_SETUP_RCVD ? true : false;
\r
313 PRAGMA_ALWAYS_INLINE
\r
314 static inline void Endpoint_ClearSETUP(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
316 static inline void Endpoint_ClearSETUP(uint8_t corenum)
\r
318 LPC_USB->DEVCMDSTAT |= USB_SETUP_RCVD;
\r
319 usb_data_buffer_index[corenum] = 0;
\r
322 PRAGMA_ALWAYS_INLINE
\r
323 static inline void Endpoint_ClearIN(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
325 static inline void Endpoint_ClearIN(uint8_t corenum)
\r
327 uint8_t PhyEP = (endpointselected[corenum] == ENDPOINT_CONTROLEP ? 1 : endpointhandle(corenum)[endpointselected[corenum]]);
\r
329 DcdDataTransfer(PhyEP, usb_data_buffer[corenum], usb_data_buffer_index[corenum]);
\r
330 usb_data_buffer_index[corenum] = 0;
\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
338 PRAGMA_ALWAYS_INLINE
\r
339 static inline void Endpoint_ClearOUT(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
341 static inline void Endpoint_ClearOUT(uint8_t corenum)
\r
343 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
\r
344 usb_data_buffer_index[corenum] = 0;
\r
346 else {usb_data_buffer_OUT_index[corenum] = 0; }
\r
348 EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].NBytes = 0x200;
\r
351 PRAGMA_ALWAYS_INLINE
\r
352 static inline void Endpoint_StallTransaction(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
354 static inline void Endpoint_StallTransaction(uint8_t corenum)
\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
362 PRAGMA_ALWAYS_INLINE
\r
363 static inline void Endpoint_ClearStall(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
365 static inline void Endpoint_ClearStall(uint8_t corenum)
\r
367 EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].Stall = 0;
\r
370 PRAGMA_ALWAYS_INLINE
\r
371 static inline bool Endpoint_IsStalled(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
373 static inline bool Endpoint_IsStalled(uint8_t corenum)
\r
375 return EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].Stall ? true : false;
\r
378 PRAGMA_ALWAYS_INLINE
\r
379 static inline void Endpoint_ResetDataToggle(uint8_t corenum) ATTR_ALWAYS_INLINE;
\r
381 static inline void Endpoint_ResetDataToggle(uint8_t corenum)
\r
383 EndPointCmdStsList[endpointhandle(corenum)[endpointselected[corenum]]][0].ToogleReset = 1;
\r
386 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
\r
387 extern uint8_t USB_Device_ControlEndpointSize;
\r
389 #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
\r
392 void Endpoint_ClearStatusStage(uint8_t corenum);
\r
394 uint8_t Endpoint_WaitUntilReady(void);
\r
396 #if defined(__cplusplus)
\r