LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
USBController.h
Go to the documentation of this file.
1 /*
2  * @brief Common USB Controller 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 
42 #ifndef __USBCONTROLLER_H__
43 #define __USBCONTROLLER_H__
44 
45  /* Includes: */
46  #include "../../../Common/Common.h"
47  #include "USBMode.h"
48 
49  /* Enable C linkage for C++ Compilers: */
50  #if defined(__cplusplus)
51  extern "C" {
52  #endif
53 
54  /* Preprocessor Checks and Defines: */
55  #if !defined(__INCLUDE_FROM_USB_DRIVER)
56  #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.
57  #endif
58 
59  /* Defines: */
65  #define ENDPOINT_DIR_MASK 0x80
66 
70  #define ENDPOINT_DIR_OUT 0x00
71 
75  #define ENDPOINT_DIR_IN 0x80
76 
77 
83  #define EP_TYPE_MASK 0x03
84 
89  #define EP_TYPE_CONTROL 0x00
90 
95  #define EP_TYPE_ISOCHRONOUS 0x01
96 
101  #define EP_TYPE_BULK 0x02
102 
107  #define EP_TYPE_INTERRUPT 0x03
108 
109 
110  #include "Events.h"
111  #include "USBTask.h"
112  #include "USBInterrupt.h"
113 
114  #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
115  #include "Host.h"
116  #include "OTG.h"
117  #include "Pipe.h"
118  #include "HostStandardReq.h"
119  #include "PipeStream.h"
120  #endif
121 
122  #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
123  #include "Device.h"
124  #include "Endpoint.h"
125  #include "DeviceStandardReq.h"
126  #include "EndpointStream.h"
127  #endif
128 
129  /* Public Interface - May be used in end-application: */
130  /* Macros: */
138  #define USB_OPT_REG_DISABLED (1 << 1)
139 
146  #define USB_OPT_REG_ENABLED (0 << 1)
147 
152  #define USB_OPT_MANUAL_PLL (1 << 2)
153 
158  #define USB_OPT_AUTO_PLL (0 << 2)
159 
160 
161  #if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
162 
169  #define USB_STREAM_TIMEOUT_MS 100
170  #endif
171 
172  /* Inline Functions: */
173  #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || \
174  defined(__DOXYGEN__)
175 
184 
185  static inline bool USB_VBUS_GetStatus(void)
186  {
187  return (USBSTA & (1 << VBUS)) ? true : false;
188  }
189 
190  #endif
191 
197  static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;
198 
199  static inline void USB_Detach(void)
200  {}
201 
211  static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;
212 
213  static inline void USB_Attach(void)
214  {}
215 
216  /* Function Prototypes: */
233  void USB_Init(uint8_t corenum, uint8_t mode);
234 
239  void USB_Disable(uint8_t corenum, uint8_t mode);
240 
244  void USB_ResetInterface(uint8_t corenum, uint8_t mode);
245 
246  /* Global Variables: */
247  extern volatile uint8_t USB_CurrentMode[];
248  // #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)
262  // extern volatile uint8_t USB_CurrentMode[];
263  // #elif defined(USB_HOST_ONLY)
264  // #define USB_CurrentMode[0] USB_MODE_Host
265  // #elif defined(USB_DEVICE_ONLY)
266  // #define USB_CurrentMode[0] USB_MODE_Device
267  // #endif
268 
269  #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
270 
276  extern volatile uint8_t USB_Options;
277  #elif defined(USE_STATIC_OPTIONS)
278  #define USB_Options USE_STATIC_OPTIONS
279  #endif
280 
281  /* Enums: */
285  enum USB_Modes_t {
292  };
293 
294  /* Private Interface - For use in library only: */
295  #if !defined(__DOXYGEN__)
296  /* Function Prototypes: */
297  #if defined(__INCLUDE_FROM_USB_CONTROLLER_C)
298  #if defined(USB_CAN_BE_DEVICE)
299  static void USB_Init_Device(uint8_t corenum);
300 
301  #endif
302 
303  #if defined(USB_CAN_BE_HOST)
304  static void USB_Init_Host(uint8_t corenum);
305 
306  #endif
307  #endif
308 
309  /* Inline Functions: */
311  static inline void USB_PLL_On(void) ATTR_ALWAYS_INLINE;
312 
313  static inline void USB_PLL_On(void)
314  {}
315 
317  static inline void USB_PLL_Off(void) ATTR_ALWAYS_INLINE;
318 
319  static inline void USB_PLL_Off(void)
320  {}
321 
323  static inline bool USB_PLL_IsReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
324 
325  static inline bool USB_PLL_IsReady(void)
326  {
327  return true; // implement later if needed
328  }
329 
331  static inline void USB_REG_On(void) ATTR_ALWAYS_INLINE;
332 
333  static inline void USB_REG_On(void)
334  {}
335 
337  static inline void USB_REG_Off(void) ATTR_ALWAYS_INLINE;
338 
339  static inline void USB_REG_Off(void)
340  {}
341 
343  static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE;
344 
345  static inline void USB_OTGPAD_On(void)
346  {}
347 
349  static inline void USB_OTGPAD_Off(void) ATTR_ALWAYS_INLINE;
350 
351  static inline void USB_OTGPAD_Off(void)
352  {}
353 
355  static inline void USB_CLK_Freeze(void) ATTR_ALWAYS_INLINE;
356 
357  static inline void USB_CLK_Freeze(void)
358  {}
359 
361  static inline void USB_CLK_Unfreeze(void) ATTR_ALWAYS_INLINE;
362 
363  static inline void USB_CLK_Unfreeze(void)
364  {}
365 
367  static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
368 
369  static inline void USB_Controller_Enable(void)
370  {}
371 
373  static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
374 
375  static inline void USB_Controller_Disable(void)
376  {}
377 
379  static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;
380 
381  static inline void USB_Controller_Reset(void)
382  {}
383 
384  #if defined(USB_CAN_BE_BOTH)
386  static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
387 
388  static inline uint8_t USB_GetUSBModeFromUID(void)
389  {
390  // if (USBSTA & (1 << ID))
391  // return USB_MODE_Device;
392  // else
393  // return USB_MODE_Host;
394  return 0;
395  }
396 
397  #endif
398 
399  #endif
400 
401 
402  /* Disable C linkage for C++ Compilers: */
403  #if defined(__cplusplus)
404  }
405  #endif
406 
407 #endif
408