1 /*
2  * @brief Common types used in LPC functions
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 
32 #ifndef __LPC_TYPES_H_
33 #define __LPC_TYPES_H_
34 
35 #include <stdint.h>
36 #include <stdbool.h>
37 
38 /** @defgroup LPC_Types CHIP: LPC Common Types
39  * @ingroup CHIP_Common
40  * @{
41  */
42 
43 /** @defgroup LPC_Types_Public_Types LPC Public Types
44  * @{
45  */
46 
47 /**
48  * @brief Boolean Type definition
49  */
50 typedef enum {FALSE = 0, TRUE = !FALSE} Bool;
51 
52 /**
53  * @brief Boolean Type definition
54  */
55 #if !defined(__cplusplus)
56 // typedef enum {false = 0, true = !false} bool;
57 #endif
58 
59 /**
60  * @brief Flag Status and Interrupt Flag Status type definition
61  */
62 typedef enum {RESET = 0, SET = !RESET} FlagStatus, IntStatus, SetState;
63 #define PARAM_SETSTATE(State) ((State == RESET) || (State == SET))
64 
65 /**
66  * @brief Functional State Definition
67  */
68 typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
69 #define PARAM_FUNCTIONALSTATE(State) ((State == DISABLE) || (State == ENABLE))
70 
71 /**
72  * @ Status type definition
73  */
74 typedef enum {ERROR = 0, SUCCESS = !ERROR} Status;
75 
76 /**
77  * Read/Write transfer type mode (Block or non-block)
78  */
79 typedef enum {
80 	NONE_BLOCKING = 0,		/**< None Blocking type */
81 	BLOCKING,				/**< Blocking type */
82 } TRANSFER_BLOCK_T;
83 
84 /** Pointer to Function returning Void (any number of parameters) */
85 //typedef void (*PFV)();
86 
87 /** Pointer to Function returning int32_t (any number of parameters) */
88 //typedef int32_t (*PFI)();
89 
90 /**
91  * @}
92  */
93 
94 /** @defgroup LPC_Types_Public_Macros  LPC Public Macros
95  * @{
96  */
97 
98 /* _BIT(n) sets the bit at position "n"
99  * _BIT(n) is intended to be used in "OR" and "AND" expressions:
100  * e.g., "(_BIT(3) | _BIT(7))".
101  */
102 #undef _BIT
103 /* Set bit macro */
104 #define _BIT(n) (1 << (n))
105 
106 /* _SBF(f,v) sets the bit field starting at position "f" to value "v".
107  * _SBF(f,v) is intended to be used in "OR" and "AND" expressions:
108  * e.g., "((_SBF(5,7) | _SBF(12,0xF)) & 0xFFFF)"
109  */
110 #undef _SBF
111 /* Set bit field macro */
112 #define _SBF(f, v) ((v) << (f))
113 
114 /* _BITMASK constructs a symbol with 'field_width' least significant
115  * bits set.
116  * e.g., _BITMASK(5) constructs '0x1F', _BITMASK(16) == 0xFFFF
117  * The symbol is intended to be used to limit the bit field width
118  * thusly:
119  * <a_register> = (any_expression) & _BITMASK(x), where 0 < x <= 32.
120  * If "any_expression" results in a value that is larger than can be
121  * contained in 'x' bits, the bits above 'x - 1' are masked off.  When
122  * used with the _SBF example above, the example would be written:
123  * a_reg = ((_SBF(5,7) | _SBF(12,0xF)) & _BITMASK(16))
124  * This ensures that the value written to a_reg is no wider than
125  * 16 bits, and makes the code easier to read and understand.
126  */
127 #undef _BITMASK
128 /* Bitmask creation macro */
129 #define _BITMASK(field_width) ( _BIT(field_width) - 1)
130 
131 /* NULL pointer */
132 #ifndef NULL
133 #define NULL ((void *) 0)
134 #endif
135 
136 /* Number of elements in an array */
137 #define NELEMENTS(array)  (sizeof(array) / sizeof(array[0]))
138 
139 /* Static data/function define */
140 #define STATIC static
141 /* External data/function define */
142 #define EXTERN extern
143 
144 #if !defined(MAX)
145 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
146 #endif
147 #if !defined(MIN)
148 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
149 #endif
150 
151 /**
152  * @}
153  */
154 
155 /* Old Type Definition compatibility */
156 /** @addtogroup LPC_Types_Public_Types
157  * @{
158  */
159 
160 /** LPC type for character type */
161 typedef char CHAR;
162 
163 /** LPC type for 8 bit unsigned value */
164 typedef uint8_t UNS_8;
165 
166 /** LPC type for 8 bit signed value */
167 typedef int8_t INT_8;
168 
169 /** LPC type for 16 bit unsigned value */
170 typedef uint16_t UNS_16;
171 
172 /** LPC type for 16 bit signed value */
173 typedef int16_t INT_16;
174 
175 /** LPC type for 32 bit unsigned value */
176 typedef uint32_t UNS_32;
177 
178 /** LPC type for 32 bit signed value */
179 typedef int32_t INT_32;
180 
181 /** LPC type for 64 bit signed value */
182 typedef int64_t INT_64;
183 
184 /** LPC type for 64 bit unsigned value */
185 typedef uint64_t UNS_64;
186 
187 #ifdef __CODE_RED
188 #define BOOL_32 bool
189 #define BOOL_16 bool
190 #define BOOL_8  bool
191 #else
192 /** 32 bit boolean type */
193 typedef bool BOOL_32;
194 
195 /** 16 bit boolean type */
196 typedef bool BOOL_16;
197 
198 /** 8 bit boolean type */
199 typedef bool BOOL_8;
200 #endif
201 
202 #ifdef __CC_ARM
203 #define INLINE  __inline
204 #else
205 #define INLINE inline
206 #endif
207 
208 /**
209  * @}
210  */
211 
212 /**
213  * @}
214  */
215 
216 #endif /* __LPC_TYPES_H_ */
217