Convert the clock_flag variable into 3 separate varables.
This costs 2 bytes of ram, but saves 60 bytes of flash. Doing so also eliminates the need to disable interrupts while clearing flags in the ifclock macro. Conflicts: clock.c timer.c timer.h
This commit is contained in:
parent
1e198e16ea
commit
f22e691fee
4
clock.c
4
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
2
mendel.c
2
mendel.c
|
|
@ -262,7 +262,7 @@ int main (void)
|
|||
gcode_parse_char(c);
|
||||
}
|
||||
|
||||
ifclock(CLOCK_FLAG_10MS) {
|
||||
ifclock(clock_flag_10ms) {
|
||||
clock_10ms();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
timer.c
11
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
timer.h
11
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue