LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Common.h
Go to the documentation of this file.
1 /*
2  * @brief LPCUSB library's common macros, definitions
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 
33 
50 #ifndef __LPCUSBlib_COMMON_H__
51 #define __LPCUSBlib_COMMON_H__
52 
53  /* Macros: */
54  #define __INCLUDE_FROM_COMMON_H
55 
56  /* Includes: */
57  #include <stdint.h>
58  #include <stdbool.h>
59  #include <string.h>
60  #include <stddef.h>
61 
62  #if defined(USE_LUFA_CONFIG_HEADER)
63  #include "LUFAConfig.h"
64  #endif
65 
66  #if 1 // TODO add control macros later
67  #include "../LPCUSBlibConfig.h"
68  #endif
69 
70  #include "CompilerSpecific.h"
71  #include "Attributes.h"
72 
73  /* Enable C linkage for C++ Compilers: */
74  #if defined(__cplusplus)
75  extern "C" {
76  #endif
77 
78  /* Architecture specific utility includes: */
79  #if defined(__DOXYGEN__)
80 
84  typedef MACHINE_REG_t uint_reg_t;
85  #else
86  typedef uint32_t uint_reg_t;
87  #define ARCH_LITTLE_ENDIAN
88  #define PROGMEM const
89  #define pgm_read_byte(x) (*x)
90  #define memcmp_P(...) memcmp(__VA_ARGS__)
91  #define memcpy_P(...) memcpy(__VA_ARGS__)
92  #include "Endianness.h"
93  #endif
94 
95  /* Public Interface - May be used in end-application: */
96  /* Macros: */
102  #define MACROS do
103 
109  #define MACROE while (0)
110 
121  #if !defined(MAX) || defined(__DOXYGEN__)
122  #define MAX(x, y) (((x) > (y)) ? (x) : (y))
123  #endif
124 
135  #if !defined(MIN) || defined(__DOXYGEN__)
136  #define MIN(x, y) (((x) < (y)) ? (x) : (y))
137  #endif
138 
139  #if !defined(STRINGIFY) || defined(__DOXYGEN__)
140 
147  #define STRINGIFY(x) #x
148 
156  #define STRINGIFY_EXPANDED(x) STRINGIFY(x)
157  #endif
158 
159  /* Inline Functions: */
165  static inline uint8_t BitReverse(uint8_t Byte) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
166  static inline uint8_t BitReverse(uint8_t Byte)
167  {
168  Byte = (((Byte & 0xF0) >> 4) | ((Byte & 0x0F) << 4));
169  Byte = (((Byte & 0xCC) >> 2) | ((Byte & 0x33) << 2));
170  Byte = (((Byte & 0xAA) >> 1) | ((Byte & 0x55) << 1));
171 
172  return Byte;
173  }
174 
182  static inline void Delay_MS(uint16_t Milliseconds) ATTR_ALWAYS_INLINE;
183  static inline void Delay_MS(uint16_t Milliseconds)
184  {
185  while (Milliseconds--)
186  {
187  volatile uint32_t i;
188 
189  for (i = 0; i < (4 * 1000); i++) { /* This logic was tested. It gives app. 1 micro sec delay */
190  ;
191  }
192  }
193  }
194 
204  static inline uint_reg_t GetGlobalInterruptMask(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
205  static inline uint_reg_t GetGlobalInterruptMask(void)
206  {
208  // TODO #warning GetGlobalInterruptMask() is not implemented under ARCH_LPC.
209  return 0;
210  //GCC_MEMORY_BARRIER();
211  }
212 
222  static inline void SetGlobalInterruptMask(const uint_reg_t GlobalIntState) ATTR_ALWAYS_INLINE;
223  static inline void SetGlobalInterruptMask(const uint_reg_t GlobalIntState)
224  {
226  // TODO #warning SetGlobalInterruptMask() is not implemented under ARCH_LPC.
228  }
229 
235  static inline void GlobalInterruptEnable(void) ATTR_ALWAYS_INLINE;
236  static inline void GlobalInterruptEnable(void)
237  {
239  // TODO #warning GlobalInterruptEnable() is not implemented under ARCH_LPC.
241  }
242 
248  static inline void GlobalInterruptDisable(void) ATTR_ALWAYS_INLINE;
249  static inline void GlobalInterruptDisable(void)
250  {
252  // TODO #warning GlobalInterruptDisable() is not implemented under ARCH_LPC.
254  }
255 
256  /* Disable C linkage for C++ Compilers: */
257  #if defined(__cplusplus)
258  }
259  #endif
260 
261 #endif
262