| 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.h
Go to the documentation of this file.
1 /*
2 * @brief USB Endpoint definitions for all architectures
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * Copyright(C) Dean Camera, 2011, 2012
7 * All rights reserved.
8 *
9 * @par
10 * Software that is described herein is for illustrative purposes only
11 * which provides customers with programming information regarding the
12 * LPC products. This software is supplied "AS IS" without any warranties of
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
14 * all warranties, express or implied, including all implied warranties of
15 * merchantability, fitness for a particular purpose and non-infringement of
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
17 * or liability for the use of the software, conveys no license or rights under any
18 * patent, copyright, mask work right, or any other intellectual property rights in
19 * or to any products. NXP Semiconductors reserves the right to make changes
20 * in the software without notification. NXP Semiconductors also makes no
21 * representation or warranty that such application will be suitable for the
22 * specified use without further testing or modification.
23 *
24 * @par
25 * Permission to use, copy, modify, and distribute this software and its
26 * documentation is hereby granted, under NXP Semiconductors' and its
27 * licensor's relevant copyrights in the software, without fee, provided that it
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
29 * copyright, permission, and disclaimer notice must appear in all copies of
30 * this code.
31 */
32
66 #ifndef __ENDPOINT_H__
67 #define __ENDPOINT_H__
68
69 /* Includes: */
70 #include "../../../Common/Common.h"
71 #include "USBMode.h"
72 #include "USBTask.h"
73 #include "USBInterrupt.h"
74
75 /* Enable C linkage for C++ Compilers: */
76 #if defined(__cplusplus)
77 extern "C" {
78 #endif
79
80 /* Preprocessor Checks: */
81 #if !defined(__INCLUDE_FROM_USB_DRIVER)
82 #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.
83 #endif
84
85 /* Public Interface - May be used in end-application: */
86 /* Macros: */
90 #define ENDPOINT_EPNUM_MASK 0x0F
91
95 #define ENDPOINT_CONTROLEP 0
96
97 #if defined(__LPC18XX__) || defined(__LPC43XX__)
98 #include "DCD/LPC18XX/Endpoint_LPC18xx.h"
99 #elif defined(__LPC175X_6X__) || defined(__LPC177X_8X__) || defined(__LPC407X_8X__)
100 #include "DCD/LPC17XX/Endpoint_LPC17xx.h"
101 #elif defined(__LPC11U1X__) || defined(__LPC11U2X_3X__) || defined(__LPC1347__)
102 #include "DCD/LPC11UXX/Endpoint_LPC11Uxx.h"
103 #endif
104
105
106
112 #define ENDPOINT_BANK_SINGLE (0 << 1)
113
119 #define ENDPOINT_BANK_DOUBLE (1 << 1)
120
121 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
122
125 #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 64
126 #endif
127
135 #define ENDPOINT_MAX_SIZE(EPIndex) 512
136
137 #if !defined(CONTROL_ONLY_DEVICE) || defined(__DOXYGEN__)
138
142 #define ENDPOINT_TOTAL_ENDPOINTS0 ENDPOINT_DETAILS_MAXEP0
143 #define ENDPOINT_TOTAL_ENDPOINTS1 ENDPOINT_DETAILS_MAXEP1
144 #define ENDPOINT_TOTAL_ENDPOINTS(corenum) ((corenum) ? ENDPOINT_DETAILS_MAXEP1 : ENDPOINT_DETAILS_MAXEP0)
145 #else
146 #define ENDPOINT_TOTAL_ENDPOINTS 1
147 #endif
148
149 /* Enums: */
154 enum Endpoint_WaitUntilReady_ErrorCodes_t {
155 ENDPOINT_READYWAIT_NoError = 0,
156 ENDPOINT_READYWAIT_EndpointStalled = 1,
159 ENDPOINT_READYWAIT_DeviceDisconnected = 2,
162 ENDPOINT_READYWAIT_BusSuspended = 3,
166 ENDPOINT_READYWAIT_Timeout = 4,
170 };
171
179 PRAGMA_ALWAYS_INLINE
180 static inline uint8_t Endpoint_GetCurrentEndpoint(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
181
182 static inline uint8_t Endpoint_GetCurrentEndpoint(uint8_t corenum)
183 {
184 return endpointselected[corenum];
185 }
186
199 PRAGMA_ALWAYS_INLINE
200 static inline void Endpoint_SelectEndpoint(uint8_t corenum, const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
201
202 static inline void Endpoint_SelectEndpoint(uint8_t corenum, const uint8_t EndpointNumber)
203 {
204 endpointselected[corenum] = EndpointNumber;
205 // usb_data_buffer_index = 0;
206 }
207
216 PRAGMA_ALWAYS_INLINE
217 static inline uint8_t Endpoint_Read_8(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
218
219 static inline uint8_t Endpoint_Read_8(uint8_t corenum)
220 {
221 uint8_t tem;
222 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
223 tem = usb_data_buffer[corenum][usb_data_buffer_index[corenum]];
224 usb_data_buffer_index[corenum]++;
225 usb_data_buffer_size[corenum]--;
226 }
227 else {
228 tem = usb_data_buffer_OUT[corenum][usb_data_buffer_OUT_index[corenum]];
229 usb_data_buffer_OUT_index[corenum]++;
230 usb_data_buffer_OUT_size[corenum]--;
231 }
232 return tem;
233 }
234
240 PRAGMA_ALWAYS_INLINE
241 static inline uint8_t Endpoint_GetEndpointDirection(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
242
243 static inline uint8_t Endpoint_GetEndpointDirection(uint8_t corenum)
244 {
245 return (endpointhandle(corenum)[endpointselected[corenum]] % 2) ? ENDPOINT_DIR_IN : ENDPOINT_DIR_OUT;
246 }
247
261 PRAGMA_ALWAYS_INLINE
262 static inline bool Endpoint_IsReadWriteAllowed(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
263
264 static inline bool Endpoint_IsReadWriteAllowed(uint8_t corenum)
265 {
266 return (Endpoint_GetEndpointDirection(corenum) == ENDPOINT_DIR_OUT) ? Endpoint_IsOUTReceived(corenum) : Endpoint_IsINReady(corenum);
267 }
268
278 PRAGMA_ALWAYS_INLINE
279 static inline void Endpoint_Write_8(uint8_t corenum, const uint8_t Data) ATTR_ALWAYS_INLINE;
280
281 static inline void Endpoint_Write_8(uint8_t corenum, const uint8_t Data)
282 {
283 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
284 usb_data_buffer[corenum][usb_data_buffer_index[corenum]] = Data;
285 usb_data_buffer_index[corenum]++;
286 }
287 else {
288 usb_data_buffer_IN[corenum][usb_data_buffer_IN_index[corenum]] = Data;
289 usb_data_buffer_IN_index[corenum]++;
290 }
291 }
292
300 PRAGMA_ALWAYS_INLINE
301 static inline void Endpoint_Discard_8(uint8_t corenum) ATTR_ALWAYS_INLINE;
302
303 static inline void Endpoint_Discard_8(uint8_t corenum)
304 {
305 volatile uint8_t dummy;
306 dummy = Endpoint_Read_8(corenum);
307 dummy = dummy;
308 }
309
318 PRAGMA_ALWAYS_INLINE
319 static inline uint16_t Endpoint_Read_16_LE(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
320
321 static inline uint16_t Endpoint_Read_16_LE(uint8_t corenum)
322 {
323 uint16_t tem = 0;
324 uint8_t tem1, tem2;
325
326 tem1 = Endpoint_Read_8(corenum);
327 tem2 = Endpoint_Read_8(corenum);
328 tem = (tem2 << 8) | tem1;
329 return tem;
330 }
331
341 PRAGMA_ALWAYS_INLINE
342 static inline uint16_t Endpoint_Read_16_BE(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
343
344 static inline uint16_t Endpoint_Read_16_BE(uint8_t corenum)
345 {
346 uint16_t tem = 0;
347 uint8_t tem1, tem2;
348
349 tem1 = Endpoint_Read_8(corenum);
350 tem2 = Endpoint_Read_8(corenum);
351 tem = (tem1 << 8) | tem2;
352 return tem;
353 }
354
365 PRAGMA_ALWAYS_INLINE
366 static inline void Endpoint_Write_16_LE(uint8_t corenum, const uint16_t Data) ATTR_ALWAYS_INLINE;
367
368 static inline void Endpoint_Write_16_LE(uint8_t corenum, const uint16_t Data)
369 {
370 Endpoint_Write_8(corenum, Data & 0xFF);
371 Endpoint_Write_8(corenum, (Data >> 8) & 0xFF);
372 }
373
384 PRAGMA_ALWAYS_INLINE
385 static inline void Endpoint_Write_16_BE(uint8_t corenum, const uint16_t Data) ATTR_ALWAYS_INLINE;
386
387 static inline void Endpoint_Write_16_BE(uint8_t corenum, const uint16_t Data)
388 {
389 Endpoint_Write_8(corenum, (Data >> 8) & 0xFF);
390 Endpoint_Write_8(corenum, Data & 0xFF);
391 }
392
400 PRAGMA_ALWAYS_INLINE
401 static inline void Endpoint_Discard_16(uint8_t corenum) ATTR_ALWAYS_INLINE;
402
403 static inline void Endpoint_Discard_16(uint8_t corenum)
404 {
405 uint8_t tem;
406 tem = Endpoint_Read_8(corenum);
407 tem = Endpoint_Read_8(corenum);
408 tem = tem;
409 }
410
420 PRAGMA_ALWAYS_INLINE
421 static inline uint32_t Endpoint_Read_32_LE(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
422
423 static inline uint32_t Endpoint_Read_32_LE(uint8_t corenum)
424 {
425 uint32_t tem = 0;
426 uint8_t tem1, tem2, tem3, tem4;
427
428 tem1 = Endpoint_Read_8(corenum);
429 tem2 = Endpoint_Read_8(corenum);
430 tem3 = Endpoint_Read_8(corenum);
431 tem4 = Endpoint_Read_8(corenum);
432 tem = (tem4 << 24) | (tem3 << 16) | (tem2 << 8) | tem1;
433 return tem;
434 }
435
445 PRAGMA_ALWAYS_INLINE
446 static inline uint32_t Endpoint_Read_32_BE(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
447
448 static inline uint32_t Endpoint_Read_32_BE(uint8_t corenum)
449 {
450 uint32_t tem = 0;
451 uint8_t tem1, tem2, tem3, tem4;
452
453 tem1 = Endpoint_Read_8(corenum);
454 tem2 = Endpoint_Read_8(corenum);
455 tem3 = Endpoint_Read_8(corenum);
456 tem4 = Endpoint_Read_8(corenum);
457 tem = (tem1 << 24) | (tem2 << 16) | (tem3 << 8) | tem4;
458 return tem;
459 }
460
471 PRAGMA_ALWAYS_INLINE
472 static inline void Endpoint_Write_32_LE(uint8_t corenum, const uint32_t Data) ATTR_ALWAYS_INLINE;
473
474 static inline void Endpoint_Write_32_LE(uint8_t corenum, const uint32_t Data)
475 {
476 Endpoint_Write_8(corenum, Data & 0xFF);
477 Endpoint_Write_8(corenum, (Data >> 8) & 0xFF);
478 Endpoint_Write_8(corenum, (Data >> 16) & 0xFF);
479 Endpoint_Write_8(corenum, (Data >> 24) & 0xFF);
480 }
481
492 PRAGMA_ALWAYS_INLINE
493 static inline void Endpoint_Write_32_BE(uint8_t corenum, const uint32_t Data) ATTR_ALWAYS_INLINE;
494
495 static inline void Endpoint_Write_32_BE(uint8_t corenum, const uint32_t Data)
496 {
497 Endpoint_Write_8(corenum, (Data >> 24) & 0xFF);
498 Endpoint_Write_8(corenum, (Data >> 16) & 0xFF);
499 Endpoint_Write_8(corenum, (Data >> 8) & 0xFF);
500 Endpoint_Write_8(corenum, Data & 0xFF);
501 }
502
510 PRAGMA_ALWAYS_INLINE
511 static inline void Endpoint_Discard_32(uint8_t corenum) ATTR_ALWAYS_INLINE;
512
513 static inline void Endpoint_Discard_32(uint8_t corenum)
514 {
515 uint8_t tem;
516 tem = Endpoint_Read_8(corenum);
517 tem = Endpoint_Read_8(corenum);
518 tem = Endpoint_Read_8(corenum);
519 tem = Endpoint_Read_8(corenum);
520 tem = tem;
521 }
522
523 void Endpoint_GetSetupPackage(uint8_t corenum, uint8_t *pData);
524
525
526 /* Disable C linkage for C++ Compilers: */
527 #if defined(__cplusplus)
528 }
529 #endif
530
531 #endif
532