From 82415492762b802bf8f9037d2229b5ad2bd56133 Mon Sep 17 00:00:00 2001 From: Jim McGee Date: Sun, 8 May 2011 23:01:03 -0700 Subject: [PATCH] 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. --- timer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/timer.c b/timer.c index 1c1244a..838fcc7 100644 --- a/timer.c +++ b/timer.c @@ -19,13 +19,15 @@ #include "dda_queue.h" #endif +#include "memory_barrier.h" + /// how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535) #define TICK_TIME 2 MS /// 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)) /// 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 uint8_t clock_counter_10ms = 0; @@ -125,9 +127,11 @@ void setTimer(uint32_t delay) // save interrupt flag uint8_t sreg = SREG; uint16_t step_start = 0; + // disable interrupts cli(); - + CLI_SEI_BUG_MEMORY_BARRIER(); + // re-enable clock interrupt in case we're recovering from emergency stop TIMSK1 |= MASK(OCIE1B); @@ -173,6 +177,7 @@ void setTimer(uint32_t delay) } // restore interrupt flag + MEMORY_BARRIER(); SREG = sreg; }