sous avr-gcc.
conditions, et pas pour d'autres.
Principe de fonctionnement :
typedef volatile struct { volatile uint8_t *port; volatile uint8_t *pin; volatile uint8_t bitNo; volatile int8_t timer; } gpio_t;
volatile uint8_t interrupt_counter;
enum { i_work = 0, i_wait, i_meas_in_progress, i_meas_ready, i_send_data, i_watchdog_reset, i_comm_rx, i_comm_tx, i_comm_ok, i_irq, i_max};
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 } };
static inline void gpio_on(gpio_t *g, int8_t d) { // d = 5 => 1/5th s // d = -1 => no timer *(g->port) |= ((uint8_t) 1) bitNo; g->timer = d; return; }
static inline void gpio_off(gpio_t *g) { *(g->port) &= ~(((uint8_t) 1) bitNo); g->timer = 0; return; }
static inline void gpio_toggle(gpio_t *g) { if (*(g->pin) & ((uint8_t) 1) bitNo) { gpio_off(g); } else { gpio_on(g, -1); }
return; }
ISR(TIMER1_COMPA_vect, ISR_BLOCK) { uint8_t i;
interrupt_counter = (interrupt_counter + 1) % 25;
if (interrupt_counter == 0) // 1 s { gpio_toggle(&i_led[i_work]); }
// Switch debug leds off for(i = 0; i < i_max; i++) { if (i_led[i].timer > 0) { i_led[i].timer--;
if (i_led[i].timer == 0) { gpio_off(&i_led[i]); } } }
return; }
Je SAIS que ce timer fonctionne correctement et que l'interruption
autres (i_comm_ok) pour 5 ticks (donc 200ms). Cette led reste
if (command < cmd_max) { gpio_on(&i_led[i_comm_ok], 5); serial_send_byte(i_led[i_comm_ok].timer); _delay_ms(200); serial_send_byte(i_led[i_comm_ok].timer); } ... serial_send_byte(0x06);
Je ne vais pas expliciter serial_send_byte(), cette routine
j'obtiens :
+++RPL/2 (R) version 4.1.32 (Mardi 17/03/2020, 16:39:58 CET)3: { "\x05" }