| 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_LPC17xx.h
Go to the documentation of this file.
1 /*
2 * @brief USB Endpoint definitions for the LPC17xx 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_LPC17XX_H__
66 #define __ENDPOINT_LPC17XX_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 6 /* Maximum of supported endpoint */
81 #define USED_PHYSICAL_ENDPOINTS (ENDPOINT_DETAILS_MAXEP * 2) /* This macro effect memory size of the DCD */
82 #define ENDPOINT_DETAILS_MAXEP0 ENDPOINT_DETAILS_MAXEP
83 #define ENDPOINT_DETAILS_MAXEP1 ENDPOINT_DETAILS_MAXEP
84
85 extern volatile bool SETUPReceived;
86 extern DMADescriptor dmaDescriptor[USED_PHYSICAL_ENDPOINTS];
87
88 void SIE_WriteCommandData (uint32_t cmd, uint32_t val);
89
90 void SIE_WriteCommand (uint32_t cmd);
91
92 extern volatile bool isOutReceived;
93 extern volatile bool isInReady;
94
95 void WriteControlEndpoint(uint8_t *pData, uint32_t cnt);
96
97 void ReadControlEndpoint(uint8_t *pData);
98
99 void DcdDataTransfer(uint8_t PhyEP, uint8_t *pData, uint32_t cnt);
100
101 void Endpoint_Streaming(uint8_t corenum, uint8_t *buffer, uint16_t packetsize,
102 uint16_t totalpackets, uint16_t dummypackets);
103
104 void Endpoint_ClearEndpoints(uint8_t corenum);
105
106 bool Endpoint_ConfigureEndpoint_Prv(uint8_t corenum,
107 const uint8_t Number,
108 const uint8_t UECFG0XData,
109 const uint8_t UECFG1XData);
110
111 #endif
112
138 /*static inline */ bool Endpoint_ConfigureEndpoint(uint8_t corenum,
139 const uint8_t Number,
140 const uint8_t Type,
141 const uint8_t Direction,
142 const uint16_t Size,
143 const uint8_t Banks) /*ATTR_ALWAYS_INLINE*/;
144
145 static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
146
147 static inline uint16_t USB_Device_GetFrameNumber(void)
148 {
149 uint32_t val;
150
151 SIE_WriteCommand(CMD_RD_FRAME);
152 val = SIE_ReadCommandData(DAT_RD_FRAME);
153 val = val | (SIE_ReadCommandData(DAT_RD_FRAME) << 8);
154
155 return val;
156 }
157
158 static inline void USB_Device_SetDeviceAddress(uint8_t corenum, const uint8_t Address) ATTR_ALWAYS_INLINE;
159
160 static inline void USB_Device_SetDeviceAddress(uint8_t corenum, const uint8_t Address)
161 {
162 SIE_WriteCommandData(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | Address));
163 SIE_WriteCommandData(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | Address));
164 }
165
173 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
174
175 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)
176 {}
177
185 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
186
187 static inline void Endpoint_EnableEndpoint(void)
188 {}
189
195 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
196
197 static inline void Endpoint_DisableEndpoint(void)
198 {}
199
204 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
205
206 static inline bool Endpoint_IsEnabled(void)
207 {
208 return true;
209 }
210
220 static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
221
222 static inline uint8_t Endpoint_GetBusyBanks(void)
223 {
224 return 0;
225 }
226
235 static inline void Endpoint_AbortPendingIN(void)
236 {}
237
243 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
244
245 static inline bool Endpoint_IsConfigured(void)
246 {
247 return true;
248 }
249
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;
262 }
263
270 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT
271 ATTR_ALWAYS_INLINE;
272
273 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
274 {
275 return (Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false;
276 }
277
287 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
288
289 static inline uint16_t Endpoint_BytesInEndpoint(uint8_t corenum)
290 {
291 if (endpointselected == ENDPOINT_CONTROLEP) {
292 return usb_data_buffer_size[corenum];
293 }
294 else {
295 // return (dmaDescriptor[ endpointhandle[endpointselected] ].PresentCount);
296 return usb_data_buffer_OUT_size[corenum];
297 }
298 }
299
308 static inline bool Endpoint_IsINReady(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
309
310 static inline bool Endpoint_IsINReady(uint8_t corenum)
311 {
312 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
313
314 return isInReady;
315 }
316 else {
317 uint8_t SelEP_Data;
318 if (dmaDescriptor[endpointhandle(corenum)[endpointselected[corenum]]].Retired == true) {
319 SIE_WriteCommand(CMD_SEL_EP(endpointhandle(corenum)[endpointselected[corenum]]) );
320 SelEP_Data = SIE_ReadCommandData(DAT_SEL_EP(endpointhandle(corenum)[endpointselected[corenum]]) );
321 if ((SelEP_Data & 1) == 0) {
322 return true;
323 }
324 }
325 return false;
326 }
327
328 }
329
338 static inline bool Endpoint_IsOUTReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
339
340 static inline bool Endpoint_IsOUTReceived(uint8_t corenum)
341 {
342 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
343
344 return isOutReceived;
345 }
346 else {
347 return (dmaDescriptor[endpointhandle(corenum)[endpointselected[corenum]]].Retired &&
348 (dmaDescriptor[endpointhandle(corenum)[endpointselected[corenum]]].Status == 2 ||
349 dmaDescriptor[endpointhandle(corenum)[endpointselected[corenum]]].Status == 3)
350 ) ? true : false;
351 }
352 }
353
362 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
363
364 static inline bool Endpoint_IsSETUPReceived(uint8_t corenum)
365 {
366 return SETUPReceived;
367 }
368
379 static inline void Endpoint_ClearSETUP(uint8_t corenum) ATTR_ALWAYS_INLINE;
380
381 static inline void Endpoint_ClearSETUP(uint8_t corenum)
382 {
383 SETUPReceived = FALSE;
384 usb_data_buffer_index[corenum] = 0;
385 usb_data_buffer_size[corenum] = 0;
386 SIE_WriteCommand(CMD_SEL_EP(ENDPOINT_CONTROLEP));
387 SIE_WriteCommand(CMD_CLR_BUF);
388 }
389
398 static inline void Endpoint_ClearIN(uint8_t corenum) ATTR_ALWAYS_INLINE;
399
400 static inline void Endpoint_ClearIN(uint8_t corenum)
401 {
402 uint8_t PhyEP = (endpointselected[corenum] == ENDPOINT_CONTROLEP ? 1 : endpointhandle(corenum)[endpointselected[corenum]]);
403
404 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
405 WriteControlEndpoint(usb_data_buffer[corenum], usb_data_buffer_index[corenum]);
406 usb_data_buffer_index[corenum] = 0;
407 usb_data_buffer_size[corenum] = 0;
408 }
409 else {
410 DcdDataTransfer(PhyEP, usb_data_buffer_IN[corenum], usb_data_buffer_IN_index[corenum]);
411 LPC_USB->DMARSet = _BIT(PhyEP);
412 usb_data_buffer_IN_index[corenum] = 0;
413 }
414 }
415
424 static inline void Endpoint_ClearOUT(uint8_t corenum) ATTR_ALWAYS_INLINE;
425
426 static inline void Endpoint_ClearOUT(uint8_t corenum)
427 {
428 usb_data_buffer_index[corenum] = 0;
429 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) { /* Control only */
430 SIE_WriteCommand(CMD_SEL_EP(ENDPOINT_CONTROLEP));
431 SIE_WriteCommand(CMD_CLR_BUF);
432 isOutReceived = false;
433 }
434 else {
435 usb_data_buffer_OUT_index[corenum] = 0;
436 usb_data_buffer_OUT_size[corenum] = 0;
437 dmaDescriptor[endpointhandle(corenum)[endpointselected[corenum]]].Status = 0;
438 LPC_USB->DMAIntEn |= (1 << 1);
439 }
440 }
441
456 // static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
457 void Endpoint_StallTransaction(uint8_t corenum);
458
466 static inline void Endpoint_ClearStall(uint8_t corenum) ATTR_ALWAYS_INLINE;
467
468 static inline void Endpoint_ClearStall(uint8_t corenum)
469 {
470 uint8_t PhysicalEp = endpointhandle(corenum)[endpointselected[corenum]] + (endpointselected[corenum] == ENDPOINT_CONTROLEP ? 1 : 0);
471
472 HAL_DisableUSBInterrupt(corenum);
473 SIE_WriteCommandData(CMD_SET_EP_STAT(PhysicalEp), DAT_WR_BYTE(0));
474 HAL_EnableUSBInterrupt(corenum);
475 }
476
485 static inline bool Endpoint_IsStalled(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
486
487 static inline bool Endpoint_IsStalled(uint8_t corenum)
488 {
489 bool isStalled;
490
491 HAL_DisableUSBInterrupt(corenum);
492 SIE_WriteCommand(CMD_SEL_EP(endpointhandle(corenum)[endpointselected[corenum]]) );
493 isStalled = SIE_ReadCommandData(DAT_SEL_EP(endpointhandle(corenum)[endpointselected[corenum]]) ) & EP_SEL_ST ? true : false;
494 HAL_EnableUSBInterrupt(corenum);
495
496 return isStalled; /* Device Status */
497 }
498
500 static inline void Endpoint_ResetDataToggle(uint8_t corenum) ATTR_ALWAYS_INLINE;
501
502 static inline void Endpoint_ResetDataToggle(uint8_t corenum)
503 {}
504
505 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
506 extern uint8_t USB_Device_ControlEndpointSize;
507 #else
508 #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
509 #endif
510
518 void Endpoint_ClearStatusStage(uint8_t corenum);
519
520 uint8_t Endpoint_WaitUntilReady(void);
521
522 #if defined(__cplusplus)
523 }
524 #endif
525
526 #endif
527