Permalink
Browse files

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.
  • Loading branch information...
1 parent 8378aa0 commit 82415492762b802bf8f9037d2229b5ad2bd56133 @madscifi madscifi committed with triffid May 9, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 timer.c
View
@@ -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;
}

0 comments on commit 8241549

Please sign in to comment.