diff --git a/src/pulses_avr.cpp b/src/pulses_avr.cpp index e174071f7..6d48eacb4 100644 --- a/src/pulses_avr.cpp +++ b/src/pulses_avr.cpp @@ -104,33 +104,27 @@ uint8_t *pulses2MHzWPtr = pulses2MHz; #ifndef SIMU -ISR(TIMER1_COMPA_vect) //2MHz pulse generation +ISR(TIMER1_COMPA_vect) //2MHz pulse generation (BLOCKING ISR) { - static uint8_t pulsePol; /* TODO strange, it's always 0 at first, shouldn't it be initialized properly in setupPulses? - - gruvin: Good point. But not quite. pulsePol should be set when we reset to the start of - the pulse buffer, just as is done below. BUT, it seems to me that this entire function - is upsidedown. That check should be done FIRST, before the pulse toggling code. - So the present situation would have (only) the first frame sent NOT inverted, if inverted - polarity had been selected. Not critical, but shoul dbe addressed. */ + static uint8_t pulsePol = 0; /* The very first call to this handler will toggle PPM_out high, then + call setupPulses() and initialise pulsePol. This is allowed in favour + of minimal ongoing PPM toggle latency. */ - // Latency -- how far further on from interrupt trigger has the timer counted? - // (or -- how long did it take to get to this function) - uint8_t dt = TCNT1L; + uint8_t dt = TCNT1L; // record Timer1 latency for DEBUG stats display #ifdef DSM2_SERIAL if (g_model.protocol == PROTO_DSM2) { OCR1A = 40000; // sei will be called inside setupPulses() - setupPulses(); - cli(); + setupPulses(); // will call sei() + cli(); // this blocking ISR will autmoatically issue sei at exit UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt } else #endif { - // Original bitbang for PPM #if !defined(PCBV4) + // Original bitbang for PPM if (s_current_protocol != PROTO_NONE) { if (pulsePol) { PORTB |= (1<