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:
Jim McGee 2011-05-08 22:03:14 -07:00 committed by Michael Moon
parent b6b5ced7be
commit 1e198e16ea
3 changed files with 11 additions and 3 deletions

View File

@ -16,6 +16,7 @@
#ifdef TEMP_INTERCOM #ifdef TEMP_INTERCOM
#include "intercom.h" #include "intercom.h"
#endif #endif
#include "memory_barrier.h"
/*! do stuff every 1/4 second /*! do stuff every 1/4 second
@ -25,8 +26,14 @@ void clock_250ms() {
if (steptimeout > (30 * 4)) { if (steptimeout > (30 * 4)) {
power_off(); power_off();
} }
else if (heaters_all_off()) else if (heaters_all_off()) {
uint8_t save_reg = SREG;
cli();
CLI_SEI_BUG_MEMORY_BARRIER();
steptimeout++; steptimeout++;
MEMORY_BARRIER();
SREG = save_reg;
}
ifclock(CLOCK_FLAG_1S) { ifclock(CLOCK_FLAG_1S) {
if (debug_flags & DEBUG_POSITION) { if (debug_flags & DEBUG_POSITION) {

2
dda.c
View File

@ -23,7 +23,7 @@
#endif #endif
/// step timeout /// step timeout
uint8_t steptimeout = 0; volatile uint8_t steptimeout = 0;
/* /*
position tracking position tracking

3
dda.h
View File

@ -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 /// 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 /// 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; extern TARGET startpoint;