| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

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