LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 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 
83 extern volatile bool SETUPReceived;
84 extern DMADescriptor dmaDescriptor[USED_PHYSICAL_ENDPOINTS];
85 
86 extern void SIE_WriteCommandData (uint32_t cmd, uint32_t val);
87 
88 extern void SIE_WriteCommamd (uint32_t cmd);
89 
90 extern volatile bool isOutReceived;
91 extern volatile bool isInReady;
92 
93 void WriteControlEndpoint(uint8_t *pData, uint32_t cnt);
94 
95 void ReadControlEndpoint(uint8_t *pData);
96 
97 void DcdDataTransfer(uint8_t PhyEP, uint8_t *pData, uint32_t cnt);
98 
99 void Endpoint_Streaming(uint8_t *buffer, uint16_t packetsize,
100  uint16_t totalpackets, uint16_t dummypackets);
101 
102 void Endpoint_ClearEndpoints(void);
103 
104 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
105  const uint8_t UECFG0XData,
106  const uint8_t UECFG1XData);
107 
108  #endif
109 
110 /*static inline */ bool Endpoint_ConfigureEndpoint(const uint8_t Number,
111  const uint8_t Type,
112  const uint8_t Direction,
113  const uint16_t Size,
114  const uint8_t Banks) /*ATTR_ALWAYS_INLINE*/;
115 
116 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
117 
118 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)
119 {}
120 
121 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
122 
123 static inline void Endpoint_EnableEndpoint(void)
124 {}
125 
126 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
127 
128 static inline void Endpoint_DisableEndpoint(void)
129 {}
130 
131 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
132 
133 static inline bool Endpoint_IsEnabled(void)
134 {
135  return true;
136 }
137 
138 static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
139 
140 static inline uint8_t Endpoint_GetBusyBanks(void)
141 {
142  return 0;
143 }
144 
145 static inline void Endpoint_AbortPendingIN(void)
146 {}
147 
148 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
149 
150 static inline bool Endpoint_IsConfigured(void)
151 {
152  return true;
153 }
154 
155 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
156 
157 static inline uint8_t Endpoint_GetEndpointInterrupts(void)
158 {
159  return 0;
160 }
161 
164 
165 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
166 {
167  return (Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false;
168 }
169 
170 static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
171 
172 static inline uint16_t Endpoint_BytesInEndpoint(void)
173 {
175  return usb_data_buffer_size;
176  }
177  else {
178  // return (dmaDescriptor[ endpointhandle[endpointselected] ].PresentCount);
180  }
181 }
182 
183 static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
184 
185 static inline bool Endpoint_IsINReady(void)
186 {
188 
189  return isInReady;
190  }
191  else {
192  uint8_t SelEP_Data;
193  if (dmaDescriptor[endpointhandle[endpointselected]].Retired == true) {
194  SIE_WriteCommamd(CMD_SEL_EP(endpointhandle[endpointselected]) );
195  SelEP_Data = SIE_ReadCommandData(DAT_SEL_EP(endpointhandle[endpointselected]) );
196  if ((SelEP_Data & 1) == 0) {
197  return true;
198  }
199  }
200  return false;
201  }
202 
203 }
204 
205 static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
206 
207 static inline bool Endpoint_IsOUTReceived(void)
208 {
210 
211  return isOutReceived;
212  }
213  else {
214  return (dmaDescriptor[endpointhandle[endpointselected]].Retired &&
215  (dmaDescriptor[endpointhandle[endpointselected]].Status == 2 ||
216  dmaDescriptor[endpointhandle[endpointselected]].Status == 3)
217  ) ? true : false;
218  }
219 }
220 
221 static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
222 
223 static inline bool Endpoint_IsSETUPReceived(void)
224 {
225  return SETUPReceived;
226 }
227 
228 static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE;
229 
230 static inline void Endpoint_ClearSETUP(void)
231 {
232  SETUPReceived = FALSE;
235  SIE_WriteCommamd(CMD_SEL_EP(ENDPOINT_CONTROLEP));
236  SIE_WriteCommamd(CMD_CLR_BUF);
237 }
238 
239 static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE;
240 
241 static inline void Endpoint_ClearIN(void)
242 {
244 
246  WriteControlEndpoint(usb_data_buffer, usb_data_buffer_index);
249  }
250  else {
252  LPC_USB->USBDMARSet = _BIT(PhyEP);
254  }
255 }
256 
257 static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE;
258 
259 static inline void Endpoint_ClearOUT(void)
260 {
262  if (endpointselected == ENDPOINT_CONTROLEP) { /* Control only */
263  SIE_WriteCommamd(CMD_SEL_EP(ENDPOINT_CONTROLEP));
264  SIE_WriteCommamd(CMD_CLR_BUF);
265  isOutReceived = false;
266  }
267  else {
270  dmaDescriptor[endpointhandle[endpointselected]].Status = 0;
271  LPC_USB->USBDMAIntEn |= (1 << 1);
272  }
273 }
274 
275 // static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
276 void Endpoint_StallTransaction(void);
277 
278 static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;
279 
280 static inline void Endpoint_ClearStall(void)
281 {
282  uint8_t PhysicalEp = endpointhandle[endpointselected] + (endpointselected == ENDPOINT_CONTROLEP ? 1 : 0);
283 
285  SIE_WriteCommandData(CMD_SET_EP_STAT(PhysicalEp), DAT_WR_BYTE(0));
287 }
288 
289 static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
290 
291 static inline bool Endpoint_IsStalled(void)
292 {
293  bool isStalled;
294 
296  SIE_WriteCommamd(CMD_SEL_EP(endpointhandle[endpointselected]) );
297  isStalled = SIE_ReadCommandData(DAT_SEL_EP(endpointhandle[endpointselected]) ) & EP_SEL_ST ? true : false;
299 
300  return isStalled; /* Device Status */
301 }
302 
303 static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;
304 
305 static inline void Endpoint_ResetDataToggle(void)
306 {}
307 
308  #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
309 extern uint8_t USB_Device_ControlEndpointSize;
310  #else
311  #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
312  #endif
313 
314 void Endpoint_ClearStatusStage(void);
315 
316 uint8_t Endpoint_WaitUntilReady(void);
317 
318  #if defined(__cplusplus)
319 }
320  #endif
321 
322 #endif
323