diff --git a/clock.c b/clock.c index d0868c2..db62ae4 100644 --- a/clock.c +++ b/clock.c @@ -35,7 +35,7 @@ void clock_250ms() { SREG = save_reg; } - ifclock(CLOCK_FLAG_1S) { + ifclock(clock_flag_1s) { if (debug_flags & DEBUG_POSITION) { // current position sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F); @@ -68,7 +68,7 @@ void clock_10ms() { temp_tick(); - ifclock(CLOCK_FLAG_250MS) { + ifclock(clock_flag_250ms) { clock_250ms(); } diff --git a/dda_queue.c b/dda_queue.c index 8a37ae1..0d649a6 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -168,7 +168,7 @@ void queue_flush() { /// waits for a space in the queue to become available void queue_wait() { for (;queue_empty() == 0;) { - ifclock(CLOCK_FLAG_10MS) { + ifclock(clock_flag_10ms) { clock_10ms(); } } diff --git a/gcode_process.c b/gcode_process.c index 098a978..4c69f47 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -158,7 +158,7 @@ void process_gcode_command() { queue_wait(); // delay for (;next_target.P > 0;next_target.P--) { - ifclock(CLOCK_FLAG_10MS) { + ifclock(clock_flag_10ms) { clock_10ms(); } delay_ms(1); diff --git a/mendel.c b/mendel.c index 2dab42b..8249b68 100644 --- a/mendel.c +++ b/mendel.c @@ -262,7 +262,7 @@ int main (void) gcode_parse_char(c); } - ifclock(CLOCK_FLAG_10MS) { + ifclock(clock_flag_10ms) { clock_10ms(); } } diff --git a/timer.c b/timer.c index 390b082..1c1244a 100644 --- a/timer.c +++ b/timer.c @@ -33,8 +33,11 @@ uint8_t clock_counter_10ms = 0; uint8_t clock_counter_250ms = 0; /// keep track of when 1s has elapsed uint8_t clock_counter_1s = 0; + /// flags to tell main loop when above have elapsed -volatile uint8_t clock_flag = 0; +volatile uint8_t clock_flag_10ms = 0; +volatile uint8_t clock_flag_250ms = 0; +volatile uint8_t clock_flag_1s = 0; /// comparator B is the system clock, happens every TICK_TIME ISR(TIMER1_COMPB_vect) { @@ -47,17 +50,17 @@ ISR(TIMER1_COMPB_vect) { clock_counter_10ms += TICK_TIME_MS; if (clock_counter_10ms >= 10) { clock_counter_10ms -= 10; - clock_flag |= CLOCK_FLAG_10MS; + clock_flag_10ms = 1; clock_counter_250ms += 1; if (clock_counter_250ms >= 25) { clock_counter_250ms -= 25; - clock_flag |= CLOCK_FLAG_250MS; + clock_flag_250ms = 1; clock_counter_1s += 1; if (clock_counter_1s >= 4) { clock_counter_1s -= 4; - clock_flag |= CLOCK_FLAG_1S; + clock_flag_1s = 1; } } } diff --git a/timer.h b/timer.h index dd6b6be..9edc71b 100644 --- a/timer.h +++ b/timer.h @@ -11,12 +11,13 @@ /* clock stuff */ -extern volatile uint8_t clock_flag; +extern volatile uint8_t clock_flag_10ms; +extern volatile uint8_t clock_flag_250ms; +extern volatile uint8_t clock_flag_1s; -#define CLOCK_FLAG_10MS 1 -#define CLOCK_FLAG_250MS 2 -#define CLOCK_FLAG_1S 4 -#define ifclock(F) for (;clock_flag & (F);clock_flag &= ~(F)) +// If the specific bit is set, execute the following block exactly once +// and then clear the flag. +#define ifclock(F) for (;F;F=0 ) /* timer stuff