timer.c: get rid of explicitely disabling the step timer.

This is no longer neccessary, as the step timer is not designed to
fire always exactly once.

Saves 54 bytes binary size.
This commit is contained in:
Markus Hitter 2011-11-17 13:33:31 +01:00
parent 53490bb318
commit 9c489911b6
2 changed files with 36 additions and 49 deletions

View File

@ -167,9 +167,6 @@ void next_move() {
dda_start(current_movebuffer);
}
}
if (queue_empty())
setTimer(0);
}
/// DEBUG - print queue.

82
timer.c
View File

@ -138,56 +138,46 @@ void setTimer(uint32_t delay)
// re-enable clock interrupt in case we're recovering from emergency stop
TIMSK1 |= MASK(OCIE1B);
if (delay > 0) {
// if the delay is too small use a minimum delay so that there is time
// to set everything up before the timer expires.
// if the delay is too small use a minimum delay so that there is time
// to set everything up before the timer expires.
if (delay < 17 )
delay = 17;
if (delay < 17 )
delay = 17;
// Assume all steps belong to one move. Within one move the delay is
// from one step to the next one, which should be more or less the same
// as from one step interrupt to the next one. The last step interrupt happend
// at OCR1A, so start delay from there.
step_start = OCR1A;
if (next_step_time == 0) {
// new move, take current time as start value
step_start = TCNT1;
}
next_step_time = delay;
if (next_step_time < 65536) {
// set the comparator directly to the next real step
OCR1A = (next_step_time + step_start) & 0xFFFF;
}
else if (next_step_time < 75536) {
// Next comparator interrupt would have to trigger another
// interrupt within a short time (possibly within 1 cycle).
// Avoid the impossible by firing the interrupt earlier.
OCR1A = (step_start - 10000) & 0xFFFF;
next_step_time += 10000;
}
else {
OCR1A = step_start;
}
// Enable this interrupt, but only do it after disabling
// global interrupts. This will cause push any possible
// timer1a interrupt to the far side of the return, protecting the
// stack from recursively clobbering memory.
cli();
CLI_SEI_BUG_MEMORY_BARRIER();
TIMSK1 |= MASK(OCIE1A);
} else {
// TODO: as the interrupt is designed to fire only once,
// doing a setTimer(0) should be obsolete.
// flag: move has ended
next_step_time = 0;
TIMSK1 &= ~MASK(OCIE1A);
// Assume all steps belong to one move. Within one move the delay is
// from one step to the next one, which should be more or less the same
// as from one step interrupt to the next one. The last step interrupt happend
// at OCR1A, so start delay from there.
step_start = OCR1A;
if (next_step_time == 0) {
// new move, take current time as start value
step_start = TCNT1;
}
next_step_time = delay;
if (next_step_time < 65536) {
// set the comparator directly to the next real step
OCR1A = (next_step_time + step_start) & 0xFFFF;
}
else if (next_step_time < 75536) {
// Next comparator interrupt would have to trigger another
// interrupt within a short time (possibly within 1 cycle).
// Avoid the impossible by firing the interrupt earlier.
OCR1A = (step_start - 10000) & 0xFFFF;
next_step_time += 10000;
}
else {
OCR1A = step_start;
}
// Enable this interrupt, but only do it after disabling
// global interrupts. This will cause push any possible
// timer1a interrupt to the far side of the return, protecting the
// stack from recursively clobbering memory.
cli();
CLI_SEI_BUG_MEMORY_BARRIER();
TIMSK1 |= MASK(OCIE1A);
// restore interrupt flag
MEMORY_BARRIER();
SREG = sreg;