]> rtime.felk.cvut.cz Git - arc.git/blob - include/bit.h
Merge branch 'mikulka' of git@rtime.felk.cvut.cz:arc into mikulka
[arc.git] / include / bit.h
1 \r
2 /* -------------------------------- Arctic Core ------------------------------\r
3  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
4  *\r
5  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
6  *\r
7  * This source code is free software; you can redistribute it and/or modify it\r
8  * under the terms of the GNU General Public License version 2 as published by the\r
9  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
10  *\r
11  * This program is distributed in the hope that it will be useful, but\r
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
13  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
14  * for more details.\r
15  * -------------------------------- Arctic Core ------------------------------*/\r
16 \r
17 /*\r
18  * Bit manipulation functions, NOT tested..\r
19  */\r
20 \r
21 #ifndef BIT_H_\r
22 #define BIT_H_\r
23 \r
24 #include <stdint.h>\r
25 /**\r
26  * @param aPtr  Ptr to an array of unsigned chars.\r
27  * @param num   The bit number to get.\r
28  * @return\r
29  */\r
30 static inline int Bit_Get(uint8_t *aPtr, int num ) {\r
31         return (aPtr[num / 8] >> (num % 8)) & 1;\r
32 }\r
33 \r
34 /**\r
35  *\r
36  * @param aPtr\r
37  * @param num\r
38  * @return\r
39  */\r
40 static inline void Bit_Set(uint8_t *aPtr, int num ) {\r
41         aPtr[num / 8] |=  (1<<(num % 8));\r
42 }\r
43 \r
44 /**\r
45  *\r
46  * @param aPtr\r
47  * @param num\r
48  * @return\r
49  */\r
50 static inline void Bit_Clear(uint8_t *aPtr, int num ) {\r
51         aPtr[num / 8] &=  ~(1<<(num % 8));\r
52 }\r
53 \r
54 \r
55 #endif /* BIT_H_ */\r