diff --git a/src/open9x.cpp b/src/open9x.cpp index 6d627e7d2..d177dc02e 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -3010,7 +3010,7 @@ uint16_t getTmr16KHz() #if defined (PCBGRUVIN9X) -/**** SCHDULED MIXER INTERRUPT ****/ +/**** SCHEDULED MIXER INTERRUPT ****/ // On G9X board, we use TIMER5 to schedule mixer execution, to achieve // minimal system latency between reading sticks and outputting data. @@ -3246,11 +3246,7 @@ FORCEINLINE void DSM2_USART0_vect() pulses2MHzRPtr += sizeof(uint16_t); -#if defined (DSM2_SERIAL) - heartbeat |= HEART_TIMER_PULSES; // G: WDT will time out before 22ms (no bit-banging int. to flag heartbeat) -#endif - - if (pulses2MHzRPtr == pulses2MHzWPtr) { // if at end of read buffer ... + if (pulses2MHzRPtr == pulses2MHzWPtr) { // if reached end of DSM2 data buffer ... UCSR0B &= ~(1 << UDRIE0); // disable UDRE0 interrupt } } diff --git a/src/pulses_avr.cpp b/src/pulses_avr.cpp index cce8db60d..99671b1cf 100644 --- a/src/pulses_avr.cpp +++ b/src/pulses_avr.cpp @@ -104,11 +104,10 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation (BLOCKING ISR) #ifdef DSM2_SERIAL if (s_current_protocol == PROTO_DSM2) { - OCR1A = 44000; // next frame in 22ms - // sei will be called inside setupPulses() - setupPulses(); // will call sei() - cli(); // this blocking ISR will automatically issue sei at exit - UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt + setupPulses(); // includes scheduling of next COMPA int. vector (this ISR). + // also re-enables interrupts at and for a safe time. (G: Only if in DSM2_SERIAL mode. Why?) + cli(); // re-disable interrupts to prevent reentrance here. (This ISR will automatically issue sei upon exit.) + UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt to start transmitting DSM2 data bytes from buffer } else #endif @@ -865,8 +864,9 @@ void setupPulses() default: // PPM and DSM2=SERIAL modes set_timer3_capture(); TCCR1B = 0; // Stop counter - OCR1A = 40000; // Next frame starts in 20 mS - TCNT1 = 0; + TCNT1 = 0; // Must reset counter frist, to prevent possible immediate COMPA int. (sometimes). + OCR1A = 44000; // Next frame starts in 22ms -- DSM mode. PPM mode will adjust to the frame rate + // set in model SETUP menu, when setupPulsesPPM() is called, below. #if defined(PCBGRUVIN9X) TIMSK1 &= ~0x2F; // All Timer1 interrupts off TIFR1 = 0x2F;