[solved] Re: Something I don't understand (loops and interrupts)

BERTRAND Joël <[email protected]> Fri, 3 Apr 2020 17:56:53 +0200
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
	I have written in a header :

static gpio_t i_led[i_max] =
            {
                    { &PORTD, &PIND, 3, 0 },
                    { &PORTD, &PIND, 4, 0 },
                    { &PORTD, &PIND, 5, 0 },
                    { &PORTD, &PIND, 6, 0 },
                    { &PORTD, &PIND, 7, 0 },
                    { &PORTB, &PINB, 0, 0 },
                    { &PORTB, &PINB, 1, 0 },
                    { &PORTB, &PINB, 2, 0 },
                    { &PORTB, &PINB, 3, 0 },
                    { &PORTB, &PINB, 4, 0 }
            };

	Note the "static" keyword. With this keyword, table is different in
each file that includes this header ! Solution is :

typedef volatile struct
{
    volatile uint8_t    *port;
    volatile uint8_t    *pin;
    volatile uint8_t    bitNo;
    volatile int8_t     timer;
} gpio_t;

#ifdef __MAIN__
    volatile gpio_t i_led[i_max] =
            {
                    { &PORTD, &PIND, 3, 0 },
                    { &PORTD, &PIND, 4, 0 },
                    { &PORTD, &PIND, 5, 0 },
                    { &PORTD, &PIND, 6, 0 },
                    { &PORTD, &PIND, 7, 0 },
                    { &PORTB, &PINB, 0, 0 },
                    { &PORTB, &PINB, 1, 0 },
                    { &PORTB, &PINB, 2, 0 },
                    { &PORTB, &PINB, 3, 0 },
                    { &PORTB, &PINB, 4, 0 }
            };
#else
    extern volatile gpio_t i_led[i_max];
#endif

	And my firmware runs as expected.

	Regards,

	JKB