1 /** Operations with 1-bit sized bitfields
6 #pragma disable_warning 88
17 #define PRE_BITS ({preBits})
22 unsigned int preBits
: PRE_BITS
;
24 unsigned int bit0
: 1;
25 unsigned int bit1
: 1;
26 unsigned int bit2
: 1;
27 unsigned int bit3
: 1;
28 unsigned int bit4
: 1;
29 unsigned int bit5
: 1;
30 unsigned int bit6
: 1;
31 unsigned int bit7
: 1;
33 unsigned int postBits
: 8;
38 #define PRE_BIT_VALUE 0
39 #define POST_BIT_VALUE 0
41 #define PRE_BIT_VALUE ((1UL << PRE_BITS) - 1)
42 #define POST_BIT_VALUE 0xFF
46 bits_check_value_no_cast(const struct_8bits
* var
, const uint8_t value
)
48 if((var
->bit0
> 0) != ((value
& 0x01) > 0)) return false;
49 if((var
->bit1
> 0) != ((value
& 0x02) > 0)) return false;
50 if((var
->bit2
> 0) != ((value
& 0x04) > 0)) return false;
51 if((var
->bit3
> 0) != ((value
& 0x08) > 0)) return false;
53 if((var
->bit4
> 0) != ((value
& 0x10) > 0)) return false;
54 if((var
->bit5
> 0) != ((value
& 0x20) > 0)) return false;
55 if((var
->bit6
> 0) != ((value
& 0x40) > 0)) return false;
56 if((var
->bit7
> 0) != ((value
& 0x80) > 0)) return false;
62 #define CAST_TO_UINT8(x) ((uint8_t)(x))
65 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15)
68 bits_check_value(const struct_8bits
* const var
, const uint8_t value
)
71 if(var
->preBits
!= PRE_BIT_VALUE
) return false;
74 if(var
->postBits
!= POST_BIT_VALUE
) return false;
76 if((var
->bit0
> 0) != (CAST_TO_UINT8(value
& 0x01) > 0)) return false;
77 if((var
->bit1
> 0) != (CAST_TO_UINT8(value
& 0x02) > 0)) return false;
78 if((var
->bit2
> 0) != (CAST_TO_UINT8(value
& 0x04) > 0)) return false;
79 if((var
->bit3
> 0) != (CAST_TO_UINT8(value
& 0x08) > 0)) return false;
81 if((var
->bit4
> 0) != (CAST_TO_UINT8(value
& 0x10) > 0)) return false;
82 if((var
->bit5
> 0) != (CAST_TO_UINT8(value
& 0x20) > 0)) return false;
83 if((var
->bit6
> 0) != (CAST_TO_UINT8(value
& 0x40) > 0)) return false;
84 if((var
->bit7
> 0) != (CAST_TO_UINT8(value
& 0x80) > 0)) return false;
86 return bits_check_value_no_cast(var
, value
);
90 bits_set_value(struct_8bits
* const var
, const uint8_t value
)
93 var
->preBits
= PRE_BIT_VALUE
;
96 var
->postBits
= POST_BIT_VALUE
;
98 var
->bit0
= CAST_TO_UINT8(value
& 0x01) > 0;
99 var
->bit1
= CAST_TO_UINT8(value
& 0x02) > 0;
100 var
->bit2
= CAST_TO_UINT8(value
& 0x04) > 0;
101 var
->bit3
= CAST_TO_UINT8(value
& 0x08) > 0;
103 var
->bit4
= CAST_TO_UINT8(value
& 0x10) > 0;
104 var
->bit5
= CAST_TO_UINT8(value
& 0x20) > 0;
105 var
->bit6
= CAST_TO_UINT8(value
& 0x40) > 0;
106 var
->bit7
= CAST_TO_UINT8(value
& 0x80) > 0;
110 #define BITS_SET_AND_CHECK(value) bits_set_value(&volatileBits, value); ASSERT(bits_check_value(&volatileBits, value))
116 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15)
117 volatile struct_8bits volatileBits
;
119 BITS_SET_AND_CHECK(0x00);
120 BITS_SET_AND_CHECK(0xFF);
122 BITS_SET_AND_CHECK(0x0F);
123 BITS_SET_AND_CHECK(0xF0);
125 BITS_SET_AND_CHECK(0x01);
126 BITS_SET_AND_CHECK(0x02);
127 BITS_SET_AND_CHECK(0x04);
128 BITS_SET_AND_CHECK(0x08);
130 BITS_SET_AND_CHECK(0x10);
131 BITS_SET_AND_CHECK(0x20);
132 BITS_SET_AND_CHECK(0x40);
133 BITS_SET_AND_CHECK(0x80);