struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-3556.c
blob736691cf182a48d78bd36060cba6ffe04423b2bd
1 /* bug-3556.c
3 */
5 #include <testfwk.h>
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <setjmp.h>
11 jmp_buf buf;
13 uint8_t pa_odr, pb_idr, dummy;
15 #define PA_ODR pa_odr
16 #define PA_DDR dummy
17 #define PA_CR1 dummy
18 #define PA_CR2 dummy
19 #define PB_IDR pb_idr
21 void setBit(uint8_t* port, uint8_t bit){
22 (*(port)) |= (1 << bit);
25 void clearBit(uint8_t* port, uint8_t bit){
26 (*(port)) &= ~(1 << bit);
29 void toggleBit(uint8_t* port, uint8_t bit){
30 (*(port)) ^= (1 << bit);
33 uint8_t extractBit(uint8_t port, uint8_t bit){
34 return ((port & (1 << bit)) >> bit);
37 void writeBit(uint8_t* port, uint8_t bit, uint8_t value){
38 if(value){
39 setBit(port, bit);
41 else{
42 clearBit(port, bit);
44 longjmp (buf, 1);
47 void m(){
48 setBit(&PA_DDR, 1); // configure PA1 as output
49 setBit(&PA_CR1, 1); // push-pull mode
50 setBit(&PA_CR2, 1); // high speed
52 while (1)
54 writeBit(&PA_ODR, 1, extractBit(PB_IDR, 2));
58 void writeBit2(uint8_t* port, uint8_t bit, uint8_t value){
59 if(value){
60 setBit(port, bit);
62 else{
63 clearBit(port, bit);
67 void m2(){
68 int i = 1;
69 setBit(&PA_DDR, 1); // configure PA1 as output
70 setBit(&PA_CR1, 1); // push-pull mode
71 setBit(&PA_CR2, 1); // high speed
73 while (i--)
75 writeBit2(&PA_ODR, 1, extractBit(PB_IDR, 2));
79 void
80 testBug (void) {
81 PB_IDR = 1 << 2;
82 PA_ODR = 0;
83 if (!setjmp (buf))
84 m ();
85 ASSERT (PA_ODR == 1 << 1);
87 PB_IDR = 0 << 2;
88 PA_ODR = 0;
89 if (!setjmp (buf))
90 m ();
91 ASSERT (PA_ODR == 0 << 1);
93 PB_IDR = 1 << 2;
94 PA_ODR= 0;
95 m2 ();
96 ASSERT (PA_ODR == 1 << 1);
98 PB_IDR = 0 << 2;
99 PA_ODR = 0;
100 m2 ();
101 ASSERT (PA_ODR == 0 << 1);