Protect pulse generation timing by disabling interrupts for longer.
This commit is contained in:
committed by
InsanityAutomation
parent
e09672edac
commit
62008024cd
@@ -1526,6 +1526,12 @@ void Stepper::apply_directions() {
|
||||
*/
|
||||
|
||||
HAL_STEP_TIMER_ISR() {
|
||||
#ifndef __AVR__
|
||||
// Disable interrupts, to avoid ISR preemption while we reprogram the period
|
||||
// (AVR enters the ISR with global interrupts disabled, so no need to do it here)
|
||||
hal.isr_off();
|
||||
#endif
|
||||
|
||||
HAL_timer_isr_prologue(MF_TIMER_STEP);
|
||||
|
||||
Stepper::isr();
|
||||
@@ -1543,12 +1549,6 @@ void Stepper::isr() {
|
||||
|
||||
static hal_timer_t nextMainISR = 0; // Interval until the next main Stepper Pulse phase (0 = Now)
|
||||
|
||||
#ifndef __AVR__
|
||||
// Disable interrupts, to avoid ISR preemption while we reprogram the period
|
||||
// (AVR enters the ISR with global interrupts disabled, so no need to do it here)
|
||||
hal.isr_off();
|
||||
#endif
|
||||
|
||||
// Program timer compare for the maximum period, so it does NOT
|
||||
// flag an interrupt while this ISR is running - So changes from small
|
||||
// periods to big periods are respected and the timer does not reset to 0
|
||||
@@ -1569,8 +1569,6 @@ void Stepper::isr() {
|
||||
// We need this variable here to be able to use it in the following loop
|
||||
hal_timer_t min_ticks;
|
||||
do {
|
||||
// Enable ISRs to reduce USART processing latency
|
||||
hal.isr_on();
|
||||
|
||||
hal_timer_t interval = 0;
|
||||
|
||||
@@ -1591,6 +1589,9 @@ void Stepper::isr() {
|
||||
NOLESS(nextBabystepISR, nextMainISR / 2); // TODO: Only look at axes enabled for baby-stepping
|
||||
#endif
|
||||
|
||||
// Enable ISRs to reduce latency for higher priority ISRs, or all ISRs if no prioritization.
|
||||
hal.isr_on();
|
||||
|
||||
interval = nextMainISR; // Interval is either some old nextMainISR or FTM_MIN_TICKS
|
||||
TERN_(BABYSTEPPING, NOMORE(interval, nextBabystepISR)); // Come back early for Babystepping?
|
||||
|
||||
@@ -1619,6 +1620,9 @@ void Stepper::isr() {
|
||||
if (is_babystep) nextBabystepISR = babystepping_isr();
|
||||
#endif
|
||||
|
||||
// Enable ISRs to reduce latency for higher priority ISRs, or all ISRs if no prioritization.
|
||||
hal.isr_on();
|
||||
|
||||
// ^== Time critical. NOTHING besides pulse generation should be above here!!!
|
||||
|
||||
if (!nextMainISR) nextMainISR = block_phase_isr(); // Manage acc/deceleration, get next block
|
||||
|
||||
Reference in New Issue
Block a user