Fix handling of the steptimeout variable.
Steptimeout is used both inside and outside of interrupts, and as such it needs special attention. Specifically, the increment outside of the interrupt context needs to occur when interrupts are disabled, or a clear of the variable can be missed. The variable was also made volatile. This is not strictly necessary given the current code, but it is the more conservative approach to dealing with the variable (and costs nothing in the current code).
This commit is contained in:
parent
b6b5ced7be
commit
1e198e16ea
9
clock.c
9
clock.c
|
|
@ -16,6 +16,7 @@
|
|||
#ifdef TEMP_INTERCOM
|
||||
#include "intercom.h"
|
||||
#endif
|
||||
#include "memory_barrier.h"
|
||||
|
||||
/*! do stuff every 1/4 second
|
||||
|
||||
|
|
@ -25,8 +26,14 @@ void clock_250ms() {
|
|||
if (steptimeout > (30 * 4)) {
|
||||
power_off();
|
||||
}
|
||||
else if (heaters_all_off())
|
||||
else if (heaters_all_off()) {
|
||||
uint8_t save_reg = SREG;
|
||||
cli();
|
||||
CLI_SEI_BUG_MEMORY_BARRIER();
|
||||
steptimeout++;
|
||||
MEMORY_BARRIER();
|
||||
SREG = save_reg;
|
||||
}
|
||||
|
||||
ifclock(CLOCK_FLAG_1S) {
|
||||
if (debug_flags & DEBUG_POSITION) {
|
||||
|
|
|
|||
2
dda.c
2
dda.c
|
|
@ -23,7 +23,7 @@
|
|||
#endif
|
||||
|
||||
/// step timeout
|
||||
uint8_t steptimeout = 0;
|
||||
volatile uint8_t steptimeout = 0;
|
||||
|
||||
/*
|
||||
position tracking
|
||||
|
|
|
|||
3
dda.h
3
dda.h
|
|
@ -122,7 +122,8 @@ typedef struct {
|
|||
*/
|
||||
|
||||
/// steptimeout is set to zero when we step, and increases over time so we can turn the motors off when they've been idle for a while
|
||||
extern uint8_t steptimeout;
|
||||
/// It is also used inside and outside of interrupts, which is why it has been made volatile
|
||||
extern volatile uint8_t steptimeout;
|
||||
|
||||
/// startpoint holds the endpoint of the most recently created DDA, so we know where the next one created starts. could also be called last_endpoint
|
||||
extern TARGET startpoint;
|
||||
|
|
|
|||
Loading…
Reference in New Issue