RKH
rkhdef.h
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
49 /* -------------------------- Development history -------------------------- */
50 /*
51  * 2015.10.24 LeFr v2.4.05 Initial version
52  */
53 
54 /* -------------------------------- Authors -------------------------------- */
55 /*
56  * LeFr Leandro Francucci francuccilea@gmail.com
57  */
58 
59 /* --------------------------------- Notes --------------------------------- */
60 /* --------------------------------- Module -------------------------------- */
61 #ifndef __RKHDEF_H__
62 #define __RKHDEF_H__
63 
64 /* ----------------------------- Include files ----------------------------- */
65 /* ---------------------- External C language linkage ---------------------- */
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 /* --------------------------------- Macros -------------------------------- */
71 /*
72  * Bit's macros.
73  */
74 
86 #define RKH_BIT(bit) (1u << (bit))
87 
99 #define RKH_BIT08(bit) ((rui8_t)((rui8_t) 1u << (bit)))
100 #define RKH_BIT16(bit) ((rui16_t)((rui16_t) 1u << (bit)))
101 #define RKH_BIT32(bit) ((rui32_t)((rui32_t) 1u << (bit)))
102 
116 #define RKH_BIT_MASK(bit_mask, bit_shift) \
117  ((bit_mask) << (bit_shift))
118 
131 #define RKH_BIT_MASK_08(bit_mask, bit_shift) \
132  ((rui8_t)((rui8_t)(bit_mask) << (bit_shift)))
133 #define RKH_BIT_MASK_16(bit_mask, bit_shift) \
134  ((rui16_t)((rui16_t)(bit_mask) << (bit_shift)))
135 #define RKH_BIT_MASK_32(bit_mask, bit_shift) \
136  ((rui32_t)((rui32_t)(bit_mask) << (bit_shift)))
137 
151 #define RKH_BIT_SET_08(val, mask) \
152  ((val) = (rui8_t)(((rui8_t)(val)) | ((rui8_t)(mask))))
153 #define RKH_BIT_SET_16(val, mask) \
154  ((val) = (rui16_t)(((rui16_t)(val)) | ((rui16_t)(mask))))
155 #define RKH_BIT_SET_32(val, mask) \
156  ((val) = (rui32_t)(((rui32_t)(val)) | ((rui32_t)(mask))))
157 
171 #define RKH_BIT_CLR_08(val, mask) \
172  ((val) = (rui8_t)(((rui8_t)(val)) & ((rui8_t) ~(mask))))
173 #define RKH_BIT_CLR_16(val, mask) \
174  ((val) = (rui16_t)(((rui16_t)(val)) & ((rui16_t) ~(mask))))
175 #define RKH_BIT_CLR_32(val, mask) \
176  ((val) = (rui32_t)(((rui32_t)(val)) & ((rui32_t) ~(mask))))
177 
192 #define RKH_BIT_IS_SET(val, mask) \
193  ((((mask) != 0u) && \
194  (((val) & (mask)) == (mask))) ? (RKH_YES) : (RKH_NO))
195 
209 #define RKH_BIT_IS_CLR(val, mask) \
210  ((((mask) != 0u) && \
211  (((val) & (mask)) == 0u)) ? (RKH_YES) : (RKH_NO))
212 
226 #define RKH_BIT_IS_SET_ANY(val, mask) \
227  ((((val) & (mask)) == 0u) ? (RKH_NO) : (RKH_YES))
228 
242 #define RKH_BIT_IS_CLR_ANY(val, mask) \
243  ((((val) & (mask)) == (mask)) ? (RKH_NO) : (RKH_YES))
244 
245 /* -------------------------------- Constants ------------------------------ */
246 #define RKH_NULL ((void *) 0)
247 
254 #define RKH_FALSE 0u
255 #define RKH_TRUE 1u
256 
257 #define RKH_NO 0u
258 #define RKH_YES 1u
259 
260 #define RKH_DISABLED 0u
261 #define RKH_ENABLED 1u
262 
263 #define RKH_INACTIVE 0u
264 #define RKH_ACTIVE 1u
265 
266 #define RKH_INVALID 0u
267 #define RKH_VALID 1u
268 
269 #define RKH_OFF 0u
270 #define RKH_ON 1u
271 
272 #define RKH_CLR 0u
273 #define RKH_SET 1u
274 
275 #define RKH_FAIL 0u
276 #define RKH_OK 1u
277 
279 /* ------------------------------- Data types ------------------------------ */
280 /* -------------------------- External variables --------------------------- */
281 /* -------------------------- Function prototypes -------------------------- */
282 /* -------------------- External C language linkage end -------------------- */
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 /* ------------------------------ Module end ------------------------------- */
288 #endif
289 
290 /* ------------------------------ End of file ------------------------------ */