Remove volatile from next_step_time as it can be easily managed using

memory barriers since it is only touched inside a single interrupt
handler or while interrupts are disabled in setTimer().

This saves about 90 bytes since it no longer needs to be reloaded multiple
times.
This commit is contained in:
Jim McGee 2011-05-08 23:01:03 -07:00 committed by Michael Moon
parent 8378aa04fc
commit 8241549276
1 changed files with 7 additions and 2 deletions

View File

@ -19,13 +19,15 @@
#include "dda_queue.h" #include "dda_queue.h"
#endif #endif
#include "memory_barrier.h"
/// how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535) /// how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535)
#define TICK_TIME 2 MS #define TICK_TIME 2 MS
/// convert back to ms from cpu ticks so our system clock runs properly if you change TICK_TIME /// convert back to ms from cpu ticks so our system clock runs properly if you change TICK_TIME
#define TICK_TIME_MS (TICK_TIME / (F_CPU / 1000)) #define TICK_TIME_MS (TICK_TIME / (F_CPU / 1000))
/// time until next step, as output compare register is too small for long step times /// time until next step, as output compare register is too small for long step times
volatile uint32_t next_step_time; uint32_t next_step_time;
/// every time our clock fires, we increment this so we know when 10ms has elapsed /// every time our clock fires, we increment this so we know when 10ms has elapsed
uint8_t clock_counter_10ms = 0; uint8_t clock_counter_10ms = 0;
@ -125,8 +127,10 @@ void setTimer(uint32_t delay)
// save interrupt flag // save interrupt flag
uint8_t sreg = SREG; uint8_t sreg = SREG;
uint16_t step_start = 0; uint16_t step_start = 0;
// disable interrupts // disable interrupts
cli(); cli();
CLI_SEI_BUG_MEMORY_BARRIER();
// re-enable clock interrupt in case we're recovering from emergency stop // re-enable clock interrupt in case we're recovering from emergency stop
TIMSK1 |= MASK(OCIE1B); TIMSK1 |= MASK(OCIE1B);
@ -173,6 +177,7 @@ void setTimer(uint32_t delay)
} }
// restore interrupt flag // restore interrupt flag
MEMORY_BARRIER();
SREG = sreg; SREG = sreg;
} }