R_RTOS  0.1
DistributedRealTimeOperatingSystemfortheARMCortexMArchitecture
R_RTOS_BitMagic.h
Go to the documentation of this file.
1 
9 #ifndef HEADERS_R_RTOS_BITMAGIC_H_
10 #define HEADERS_R_RTOS_BITMAGIC_H_
11 
12 #include "R_RTOS_inc.h"
13 
14 // Manipulating rightmost Bits
15 // Turn off rightmost 1 bit
16 // 1100 1010 -> 1010 1000
17 #define BITM_RMB_TURN_BIT_OFF(x) (((uint32_t)x)&(((uint32_t)x)-(uint32_t)1u))
18 // Turn on rightmost 0 bit
19 // 1010 0101 -> 1010 0111
20 #define BITM_RMB_TURN_BIT_ON(x) (((uint32_t)x)|(((uint32_t)x)+(uint32_t)1u))
21 // Turn off trailing 1's
22 // 1010 1111 -> 1010 0000
23 #define BITM_RMB_TURN_TRAIL_OFF(x) (((uint32_t)x)&(((uint32_t)x)+(uint32_t)1u))
24 // Turn on trailing 0's
25 // 1010 0000 -> 1011 1111
26 #define BITM_RMB_TURN_TRAIL_ON(x) (((uint32_t)x)|(((uint32_t)x)-(uint32_t)1u))
27 // Single 1 bit at position of rightmost 0 bit; zero if none
28 // 1010 1011 -> 0000 0100
29 #define BITM_RMB_EXTRCT_SNGL_OFF(x) ((~((uint32_t)x))&(((uint32_t)x)+(uint32_t)1u))
30 // Single 0 bit at position of rightmost 1 bit; all 1's if none
31 // 1010 0100 -> 1111 1011
32 #define BITM_RMB_EXTRCT_SNGL_ON(x) ((~((uint32_t)x))|(((uint32_t)x)-(uint32_t)1u))
33 // 1 bits instead of trailing 0 bits, 0 bits elsewhere; zero if none
34 // 1010 1000 -> 0000 0111
35 #define BITM_RMB_EXTRCT_TRAIL_OFF(x) (~(((uint32_t)x)|(-((uint32_t)x))))
36 // 0 bits instead of trailing 1 bits, 1 bits elsewhere; all 1's if none
37 // 1010 0111 -> 1111 1000
38 #define BITM_RMB_EXTRCT_TRAIL_ON(x) ((~((uint32_t)x))|(((uint32_t)x)+(uint32_t)1u))
39 // 1 bits instead of trailing 0 bits, 0 bits elsewhere; zero if none
40 // 1010 1000 -> 0000 0111
41 #define BITM_RMB_TURN_LEAD_OFF(x) (((uint32_t)x)|(-((uint32_t)x)))
42 // 0 bits instead of trailing 1 bits, 1 bits elsewhere; all 1's if none
43 // 1010 0111 -> 1111 1000
44 #define BITM_RMB_EXTRCT_LEAD_ON(x) ((~((uint32_t)x))|(((uint32_t)x)+(uint32_t)1u))
45 // isolate rightmost 1 bit; zero if none
46 // 1010 1100 -> 0000 0100
47 #define BITM_RMB_ISOLT_ON(x) (((uint32_t)x)&(-((uint32_t)x)))
48 
56 uint8_t bitM_bitPos(uint32_t bits);
57 
58 #endif /* HEADERS_R_RTOS_BITMAGIC_H_ */
uint8_t bitM_bitPos(uint32_t bits)
Definition: R_RTOS_BitMagic.c:16
Defines, Typedefs and Macros for the whole system.