Switch to ATOMIC sections instead of cli/sei/CRITICAL_SECTION

This commit is contained in:
Yuri D'Elia 2022-08-21 14:27:26 +02:00
parent 8cbe69e285
commit 30dccb3252

View File

@ -1157,18 +1157,18 @@ FORCE_INLINE static void applyBabysteps() {
if(curTodo>0) if(curTodo>0)
{ {
CRITICAL_SECTION_START; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
babystep(axis,/*fwd*/true); babystep(axis,/*fwd*/true);
babystepsTodo[axis]--; //less to do next time babystepsTodo[axis]--; //less to do next time
CRITICAL_SECTION_END; }
} }
else else
if(curTodo<0) if(curTodo<0)
{ {
CRITICAL_SECTION_START; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
babystep(axis,/*fwd*/false); babystep(axis,/*fwd*/false);
babystepsTodo[axis]++; //less to do next time babystepsTodo[axis]++; //less to do next time
CRITICAL_SECTION_END; }
} }
} }
} }
@ -1537,9 +1537,9 @@ ISR(TIMER0_COMPB_vect)
#endif //SYSTEM_TIMER_2 #endif //SYSTEM_TIMER_2
{ {
DISABLE_SOFT_PWM_INTERRUPT(); DISABLE_SOFT_PWM_INTERRUPT();
sei(); NONATOMIC_BLOCK(NONATOMIC_FORCEOFF) {
soft_pwm_isr(); soft_pwm_isr();
cli(); }
ENABLE_SOFT_PWM_INTERRUPT(); ENABLE_SOFT_PWM_INTERRUPT();
} }
@ -1825,32 +1825,32 @@ void temp_mgr_init()
adc_start_cycle(); adc_start_cycle();
// initialize timer5 // initialize timer5
CRITICAL_SECTION_START; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
// CTC // CTC
TCCR5B &= ~(1<<WGM53); TCCR5B &= ~(1<<WGM53);
TCCR5B |= (1<<WGM52); TCCR5B |= (1<<WGM52);
TCCR5A &= ~(1<<WGM51); TCCR5A &= ~(1<<WGM51);
TCCR5A &= ~(1<<WGM50); TCCR5A &= ~(1<<WGM50);
// output mode = 00 (disconnected) // output mode = 00 (disconnected)
TCCR5A &= ~(3<<COM5A0); TCCR5A &= ~(3<<COM5A0);
TCCR5A &= ~(3<<COM5B0); TCCR5A &= ~(3<<COM5B0);
// x/256 prescaler // x/256 prescaler
TCCR5B |= (1<<CS52); TCCR5B |= (1<<CS52);
TCCR5B &= ~(1<<CS51); TCCR5B &= ~(1<<CS51);
TCCR5B &= ~(1<<CS50); TCCR5B &= ~(1<<CS50);
// reset counter // reset counter
TCNT5 = 0; TCNT5 = 0;
OCR5A = TIMER5_OCRA_OVF; OCR5A = TIMER5_OCRA_OVF;
// clear pending interrupts, enable COMPA // clear pending interrupts, enable COMPA
TEMP_MGR_INT_FLAG_CLEAR(); TEMP_MGR_INT_FLAG_CLEAR();
ENABLE_TEMP_MGR_INTERRUPT(); ENABLE_TEMP_MGR_INTERRUPT();
CRITICAL_SECTION_END; }
} }
static void pid_heater(uint8_t e, const float current, const int target) static void pid_heater(uint8_t e, const float current, const int target)
@ -2174,9 +2174,9 @@ ISR(TIMER5_COMPA_vect)
// run temperature management with interrupts enabled to reduce latency // run temperature management with interrupts enabled to reduce latency
DISABLE_TEMP_MGR_INTERRUPT(); DISABLE_TEMP_MGR_INTERRUPT();
sei(); NONATOMIC_BLOCK(NONATOMIC_FORCEOFF) {
temp_mgr_isr(); temp_mgr_isr();
cli(); }
ENABLE_TEMP_MGR_INTERRUPT(); ENABLE_TEMP_MGR_INTERRUPT();
} }
@ -2185,30 +2185,28 @@ void disable_heater()
setAllTargetHotends(0); setAllTargetHotends(0);
setTargetBed(0); setTargetBed(0);
CRITICAL_SECTION_START; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
// propagate all values down the chain
setIsrTargetTemperatures();
temp_mgr_pid();
// propagate all values down the chain // we can't call soft_pwm_core directly to toggle the pins as it would require removing the inline
setIsrTargetTemperatures(); // attribute, so disable each pin individually
temp_mgr_pid();
// we can't call soft_pwm_core directly to toggle the pins as it would require removing the inline
// attribute, so disable each pin individually
#if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 && EXTRUDERS > 0 #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 && EXTRUDERS > 0
WRITE(HEATER_0_PIN,LOW); WRITE(HEATER_0_PIN,LOW);
#endif #endif
#if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 && EXTRUDERS > 1 #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 && EXTRUDERS > 1
WRITE(HEATER_1_PIN,LOW); WRITE(HEATER_1_PIN,LOW);
#endif #endif
#if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 && EXTRUDERS > 2 #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 && EXTRUDERS > 2
WRITE(HEATER_2_PIN,LOW); WRITE(HEATER_2_PIN,LOW);
#endif #endif
#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
// TODO: this doesn't take immediate effect! // TODO: this doesn't take immediate effect!
timer02_set_pwm0(0); timer02_set_pwm0(0);
bedPWMDisabled = 0; bedPWMDisabled = 0;
#endif #endif
}
CRITICAL_SECTION_END;
} }
static void check_min_temp_raw() static void check_min_temp_raw()