]> git.sur5r.net Git - armstart-ibdap/blob - inc/lpc_types.h
Fix build
[armstart-ibdap] / inc / lpc_types.h
1 /*\r
2  * @brief Common types used in LPC functions\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\r
9  * Software that is described herein is for illustrative purposes only\r
10  * which provides customers with programming information regarding the\r
11  * LPC products.  This software is supplied "AS IS" without any warranties of\r
12  * any kind, and NXP Semiconductors and its licensor disclaim any and\r
13  * all warranties, express or implied, including all implied warranties of\r
14  * merchantability, fitness for a particular purpose and non-infringement of\r
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility\r
16  * or liability for the use of the software, conveys no license or rights under any\r
17  * patent, copyright, mask work right, or any other intellectual property rights in\r
18  * or to any products. NXP Semiconductors reserves the right to make changes\r
19  * in the software without notification. NXP Semiconductors also makes no\r
20  * representation or warranty that such application will be suitable for the\r
21  * specified use without further testing or modification.\r
22  *\r
23  * @par\r
24  * Permission to use, copy, modify, and distribute this software and its\r
25  * documentation is hereby granted, under NXP Semiconductors' and its\r
26  * licensor's relevant copyrights in the software, without fee, provided that it\r
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This\r
28  * copyright, permission, and disclaimer notice must appear in all copies of\r
29  * this code.\r
30  */\r
31 \r
32 #ifndef __LPC_TYPES_H_\r
33 #define __LPC_TYPES_H_\r
34 \r
35 #include <stdint.h>\r
36 #include <stdbool.h>\r
37 \r
38 /** @defgroup LPC_Types CHIP: LPC Common Types\r
39  * @ingroup CHIP_Common\r
40  * @{\r
41  */\r
42 \r
43 /** @defgroup LPC_Types_Public_Types LPC Public Types\r
44  * @{\r
45  */\r
46 \r
47 /**\r
48  * @brief Boolean Type definition\r
49  */\r
50 typedef enum {FALSE = 0, TRUE = !FALSE} Bool;\r
51 \r
52 /**\r
53  * @brief Boolean Type definition\r
54  */\r
55 #if !defined(__cplusplus)\r
56 // typedef enum {false = 0, true = !false} bool;\r
57 #endif\r
58 \r
59 /**\r
60  * @brief Flag Status and Interrupt Flag Status type definition\r
61  */\r
62 typedef enum {RESET = 0, SET = !RESET} FlagStatus, IntStatus, SetState;\r
63 #define PARAM_SETSTATE(State) ((State == RESET) || (State == SET))\r
64 \r
65 /**\r
66  * @brief Functional State Definition\r
67  */\r
68 typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;\r
69 #define PARAM_FUNCTIONALSTATE(State) ((State == DISABLE) || (State == ENABLE))\r
70 \r
71 /**\r
72  * @ Status type definition\r
73  */\r
74 typedef enum {ERROR = 0, SUCCESS = !ERROR} Status;\r
75 \r
76 /**\r
77  * Read/Write transfer type mode (Block or non-block)\r
78  */\r
79 typedef enum {\r
80         NONE_BLOCKING = 0,              /**< None Blocking type */\r
81         BLOCKING,                               /**< Blocking type */\r
82 } TRANSFER_BLOCK_T;\r
83 \r
84 /** Pointer to Function returning Void (any number of parameters) */\r
85 typedef void (*PFV)();\r
86 \r
87 /** Pointer to Function returning int32_t (any number of parameters) */\r
88 typedef int32_t (*PFI)();\r
89 \r
90 /**\r
91  * @}\r
92  */\r
93 \r
94 /** @defgroup LPC_Types_Public_Macros  LPC Public Macros\r
95  * @{\r
96  */\r
97 \r
98 /* _BIT(n) sets the bit at position "n"\r
99  * _BIT(n) is intended to be used in "OR" and "AND" expressions:\r
100  * e.g., "(_BIT(3) | _BIT(7))".\r
101  */\r
102 #undef _BIT\r
103 /* Set bit macro */\r
104 #define _BIT(n) (1 << (n))\r
105 \r
106 /* _SBF(f,v) sets the bit field starting at position "f" to value "v".\r
107  * _SBF(f,v) is intended to be used in "OR" and "AND" expressions:\r
108  * e.g., "((_SBF(5,7) | _SBF(12,0xF)) & 0xFFFF)"\r
109  */\r
110 #undef _SBF\r
111 /* Set bit field macro */\r
112 #define _SBF(f, v) ((v) << (f))\r
113 \r
114 /* _BITMASK constructs a symbol with 'field_width' least significant\r
115  * bits set.\r
116  * e.g., _BITMASK(5) constructs '0x1F', _BITMASK(16) == 0xFFFF\r
117  * The symbol is intended to be used to limit the bit field width\r
118  * thusly:\r
119  * <a_register> = (any_expression) & _BITMASK(x), where 0 < x <= 32.\r
120  * If "any_expression" results in a value that is larger than can be\r
121  * contained in 'x' bits, the bits above 'x - 1' are masked off.  When\r
122  * used with the _SBF example above, the example would be written:\r
123  * a_reg = ((_SBF(5,7) | _SBF(12,0xF)) & _BITMASK(16))\r
124  * This ensures that the value written to a_reg is no wider than\r
125  * 16 bits, and makes the code easier to read and understand.\r
126  */\r
127 #undef _BITMASK\r
128 /* Bitmask creation macro */\r
129 #define _BITMASK(field_width) ( _BIT(field_width) - 1)\r
130 \r
131 /* NULL pointer */\r
132 #ifndef NULL\r
133 #define NULL ((void *) 0)\r
134 #endif\r
135 \r
136 /* Number of elements in an array */\r
137 #define NELEMENTS(array)  (sizeof(array) / sizeof(array[0]))\r
138 \r
139 /* Static data/function define */\r
140 #define STATIC static\r
141 /* External data/function define */\r
142 #define EXTERN extern\r
143 \r
144 #if !defined(MAX)\r
145 #define MAX(a, b) (((a) > (b)) ? (a) : (b))\r
146 #endif\r
147 #if !defined(MIN)\r
148 #define MIN(a, b) (((a) < (b)) ? (a) : (b))\r
149 #endif\r
150 \r
151 /**\r
152  * @}\r
153  */\r
154 \r
155 /* Old Type Definition compatibility */\r
156 /** @addtogroup LPC_Types_Public_Types\r
157  * @{\r
158  */\r
159 \r
160 /** LPC type for character type */\r
161 typedef char CHAR;\r
162 \r
163 /** LPC type for 8 bit unsigned value */\r
164 typedef uint8_t UNS_8;\r
165 \r
166 /** LPC type for 8 bit signed value */\r
167 typedef int8_t INT_8;\r
168 \r
169 /** LPC type for 16 bit unsigned value */\r
170 typedef uint16_t UNS_16;\r
171 \r
172 /** LPC type for 16 bit signed value */\r
173 typedef int16_t INT_16;\r
174 \r
175 /** LPC type for 32 bit unsigned value */\r
176 typedef uint32_t UNS_32;\r
177 \r
178 /** LPC type for 32 bit signed value */\r
179 typedef int32_t INT_32;\r
180 \r
181 /** LPC type for 64 bit signed value */\r
182 typedef int64_t INT_64;\r
183 \r
184 /** LPC type for 64 bit unsigned value */\r
185 typedef uint64_t UNS_64;\r
186 \r
187 #ifdef __CODE_RED\r
188 #define BOOL_32 bool\r
189 #define BOOL_16 bool\r
190 #define BOOL_8  bool\r
191 #else\r
192 /** 32 bit boolean type */\r
193 typedef bool BOOL_32;\r
194 \r
195 /** 16 bit boolean type */\r
196 typedef bool BOOL_16;\r
197 \r
198 /** 8 bit boolean type */\r
199 typedef bool BOOL_8;\r
200 #endif\r
201 \r
202 #ifdef __CC_ARM\r
203 #define INLINE  __inline\r
204 #else\r
205 #define INLINE inline\r
206 #endif\r
207 \r
208 /**\r
209  * @}\r
210  */\r
211 \r
212 /**\r
213  * @}\r
214  */\r
215 \r
216 #endif /* __LPC_TYPES_H_ */\r