AnHardt / Marlin

Reprap FW with look ahead. SDcard and LCD support. It works on Gen6, Ultimaker, RAMPS and Sanguinololu
GNU General Public License v3.0
1 stars 1 forks source link

Fix temp-interrupt with LIN_ADVANCE #74

Closed AnHardt closed 6 years ago

AnHardt commented 7 years ago

Error mechanism: Let's suppose we are in 'Temperature::isr()'.

  CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
  sei();

The temperature-interrupt is disabled, but all others are enabled.

Now the temp-isr is interrupted by the Stepper::advance_isr_scheduler()

    // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
    CBI(TIMSK0, OCIE0B); // Temperature ISR
    DISABLE_STEPPER_DRIVER_INTERRUPT();
    sei();

temp-isr and stepper-isr are disabled. When we leave the Stepper::advance_isr_scheduler() we execute

    // Restore original ISR settings
    cli();
    SBI(TIMSK0, OCIE0B);
    ENABLE_STEPPER_DRIVER_INTERRUPT();

Enable temp-isr and stepper-isr. In case we interrupted the temp-isr this does not restore the ISR settings, but enables the temp-isr falsely. If its time for a fresh temp-isr now, this is entered before the still on the stack temp-isr ended - the temp-isr bites its tail.

Problems: Is temp-isr is entered multiple times the stack may overflow. temp-isr is not made for reentering.

Symptoms: Sampling OVERSAMPLENR+1 (or more) instead of OVERSAMPLENR samples.

Even worse and unpredictable things when the stack overfolowes