LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 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 
82  #if defined(USB_DEVICE_ROM_DRIVER)
83 
84 typedef struct _ROM {
85  const unsigned p_usbd;
86  const unsigned p_clib;
87  const unsigned p_cand;
88  #ifdef PWRROMD_PRESENT
89  const PWRD *pPWRD;
90  #else
91  const unsigned p_pwrd;
92  #endif /* PWRROMD_PRESENT */
93  #ifdef DIVROMD_PRESENT
94  const LPC_ROM_DIV_STRUCT *pROMDiv;
95  #else
96  const unsigned p_dev1;
97  #endif /* DIVROMD_PRESENT */
98  const unsigned p_dev2;
99  const unsigned p_dev3;
100  const unsigned p_dev4;
101 } ROM_FUNCTION_TABLE;
102 
103  #define ROM_FUNCTION_TABLE_PTR_ADDR (0x1FFF1FF8UL)
104  #define ROM_USBD_PTR ((*(ROM_FUNCTION_TABLE * *) (ROM_FUNCTION_TABLE_PTR_ADDR))->p_usbd)
105 
106  #define ROMDRIVER_USB0_BASE LPC_USB_BASE
107  #define ROMDRIVER_USB1_BASE LPC_USB_BASE
108  #define ROMDRIVER_MEM_SIZE 0x500
109 extern uint8_t usb_RomDriver_buffer[ROMDRIVER_MEM_SIZE];
110 
111  #define ROMDRIVER_MSC_MEM_SIZE 0x100
112 extern uint8_t usb_RomDriver_MSC_buffer[ROMDRIVER_MSC_MEM_SIZE];
113 
114  #define ROMDRIVER_CDC_MEM_SIZE 0x8
115 extern uint8_t usb_RomDriver_CDC_buffer[ROMDRIVER_CDC_MEM_SIZE];
116  #define ROMDRIVER_CDC_DATA_BUFFER_SIZE 64
117  #if (USB_FORCED_FULLSPEED)
118  #define CDC_MAX_BULK_EP_SIZE 64
119  #else
120  #define CDC_MAX_BULK_EP_SIZE 512
121  #endif
122 extern uint8_t UsbdCdc_EPIN_buffer[CDC_MAX_BULK_EP_SIZE];
123 extern uint8_t UsbdCdc_EPOUT_buffer[CDC_MAX_BULK_EP_SIZE];
124 
125  #define ROMDRIVER_HID_MEM_SIZE 0x8
126 extern uint8_t usb_RomDriver_HID_buffer[ROMDRIVER_HID_MEM_SIZE];
127 
128  #endif
129 
130 void Endpoint_ClearEndpoints(void);
131 
132 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
133  const uint8_t UECFG0XData,
134  const uint8_t UECFG1XData);
135 
136  #endif
137  #define USED_PHYSICAL_ENDPOINTS (ENDPOINT_DETAILS_MAXEP * 2)/* This macro effect memory size of the DCD */
138 
139  #define USB_EN (0x1 << 7) /* Device Enable */
140  #define USB_SETUP_RCVD (0x1 << 8) /* SETUP token received */
141  #define USB_PLL_ON (0x1 << 9) /* PLL is always ON */
142  #define USB_LPM (0x1 << 11) /* LPM is supported */
143  #define USB_IntOnNAK_AO (0x1 << 12) /* Device Interrupt on NAK BULK OUT */
144  #define USB_IntOnNAK_AI (0x1 << 13) /* Device Interrupt on NAK BULK IN */
145  #define USB_IntOnNAK_CO (0x1 << 14) /* Device Interrupt on NAK CTRL OUT */
146  #define USB_IntOnNAK_CI (0x1 << 15) /* Device Interrupt on NAK CTRL IN */
147  #define USB_DCON (0x1 << 16) /* Device connect */
148  #define USB_DSUS (0x1 << 17) /* Device Suspend */
149  #define USB_LPM_SUS (0x1 << 19) /* LPM suspend */
150  #define USB_REMOTE_WAKE (0x1 << 20) /* LPM Remote Wakeup */
151  #define USB_DCON_C (0x1 << 24) /* Device connection change */
152  #define USB_DSUS_C (0x1 << 25) /* Device SUSPEND change */
153  #define USB_DRESET_C (0x1 << 26) /* Device RESET */
154  #define USB_VBUS_DBOUNCE (0x1 << 28) /* Device VBUS detect */
155 
156  #define EP0_INT (0x1 << 0)
157  #define EP1_INT (0x1 << 1)
158  #define EP2_INT (0x1 << 2)
159  #define EP3_INT (0x1 << 3)
160  #define EP4_INT (0x1 << 4)
161  #define EP5_INT (0x1 << 5)
162  #define EP6_INT (0x1 << 6)
163  #define EP7_INT (0x1 << 7)
164  #define EP8_INT (0x1 << 8)
165  #define EP9_INT (0x1 << 9)
166  #define FRAME_INT (0x1 << 30)
167  #define DEV_STAT_INT (0x80000000)
168 
169  #define PKT_LNGTH_MASK 0x000003FF
170 
171  #define ERR_NOERROR 0x00
172  #define ERR_PID_ENCODE 0x01
173  #define ERR_UNKNOWN_PID 0x02
174  #define ERR_UNEXPECT_PKT 0x03
175  #define ERR_TCRC 0x04
176  #define ERR_DCRC 0x05
177  #define ERR_TIMEOUT 0x06
178  #define ERR_BABBIE 0x07
179  #define ERR_EOF_PKT 0x08
180  #define ERR_TX_RX_NAK 0x09
181  #define ERR_SENT_STALL 0x0A
182  #define ERR_BUF_OVERRUN 0x0B
183  #define ERR_SENT_EPT_PKT 0x0C
184  #define ERR_BIT_STUFF 0x0D
185  #define ERR_SYNC 0x0E
186  #define ERR_TOGGLE_BIT 0x0F
187 extern void WrCmdDat (uint32_t cmd, uint32_t val);
188 
189 extern void WrCmd (uint32_t cmd);
190 
191 void HAL11UXX_WriteEndPoint(uint8_t EPNum, uint8_t *pData, uint32_t cnt);
192 
193 void DcdDataTransfer(uint8_t EPNum, uint8_t *pData, uint32_t length);
194 
195 void Endpoint_Streaming(uint8_t *buffer, uint16_t packetsize,
196  uint16_t totalpackets, uint16_t dummypackets);
197 
198 extern USB_CMD_STAT EndPointCmdStsList[10][2];
199 
200 /*static inline */ bool Endpoint_ConfigureEndpoint(const uint8_t Number,
201  const uint8_t Type,
202  const uint8_t Direction,
203  const uint16_t Size,
204  const uint8_t Banks) /*ATTR_ALWAYS_INLINE*/;
205 
207 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
208 
209 static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)
210 {}
211 
213 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
214 
215 static inline void Endpoint_EnableEndpoint(void)
216 {}
217 
219 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
220 
221 static inline void Endpoint_DisableEndpoint(void)
222 {}
223 
225 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
226 
227 static inline bool Endpoint_IsEnabled(void)
228 {
229  return true;
230 }
231 
233 static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
234 
235 static inline uint8_t Endpoint_GetBusyBanks(void)
236 {
237  return 0;
238 }
239 
240 static inline void Endpoint_AbortPendingIN(void)
241 {}
242 
244 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
245 
246 static inline bool Endpoint_IsConfigured(void)
247 {
248  // return ((UESTA0X & (1 << CFGOK)) ? true : false);
249  return true;
250 }
251 
253 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
254 
255 static inline uint8_t Endpoint_GetEndpointInterrupts(void)
256 {
257  return 0; // TODO not yet implemented
258 }
259 
263 
264 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
265 {
266  return (Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false;
267 }
268 
270 static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
271 
272 static inline uint16_t Endpoint_BytesInEndpoint(void)
273 {
275  return usb_data_buffer_size;
276  }
277  else {
279  }
280 }
281 
283 static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
284 
285 static inline bool Endpoint_IsINReady(void)
286 {
287  uint32_t PhyEP =
289  return EndPointCmdStsList[PhyEP][0].Active ? false : true;
290 }
291 
293 static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
294 
295 static inline bool Endpoint_IsOUTReceived(void)
296 {
297  return /*EndPointCmdStsList[ endpointhandle[endpointselected] ][0].Active == 0 &&*/
298  EndPointCmdStsList[endpointhandle[endpointselected]][0].NBytes != 0x200;
299 }
300 
302 static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
303 
304 static inline bool Endpoint_IsSETUPReceived(void)
305 {
306  return LPC_USB->DEVCMDSTAT & USB_SETUP_RCVD ? true : false;
307 }
308 
310 static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE;
311 
312 static inline void Endpoint_ClearSETUP(void)
313 {
314  LPC_USB->DEVCMDSTAT |= USB_SETUP_RCVD;
316 }
317 
319 static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE;
320 
321 static inline void Endpoint_ClearIN(void)
322 {
324  if (PhyEP == 1) {
327  }
328  else {
331  }
332 }
333 
335 static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE;
336 
337 static inline void Endpoint_ClearOUT(void)
338 {
341  }
342  else {usb_data_buffer_OUT_index = 0; }
343 
344  EndPointCmdStsList[endpointhandle[endpointselected]][0].NBytes = 0x200;
345 }
346 
348 static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
349 
350 static inline void Endpoint_StallTransaction(void)
351 {
352  EndPointCmdStsList[endpointhandle[endpointselected]][0].Stall = 1;
354  EndPointCmdStsList[1][0].Stall = 1;
355  }
356 }
357 
359 static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;
360 
361 static inline void Endpoint_ClearStall(void)
362 {
363  EndPointCmdStsList[endpointhandle[endpointselected]][0].Stall = 0;
364 }
365 
367 static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
368 
369 static inline bool Endpoint_IsStalled(void)
370 {
371  return EndPointCmdStsList[endpointhandle[endpointselected]][0].Stall ? true : false;
372 }
373 
375 static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;
376 
377 static inline void Endpoint_ResetDataToggle(void)
378 {
379  EndPointCmdStsList[endpointhandle[endpointselected]][0].ToogleReset = 1;
380 }
381 
382  #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
383 extern uint8_t USB_Device_ControlEndpointSize;
384  #else
385  #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
386  #endif
387 
388 void Endpoint_ClearStatusStage(void);
389 
390 uint8_t Endpoint_WaitUntilReady(void);
391 
392  #if defined(__cplusplus)
393 }
394  #endif
395 
396 #endif
397