Rename setTimer() to timer_set() for more consistency.

Pure cosmetical change.

Performance check:

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
[...]
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20518 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 302 clock cycles.
LED on time maximum: 713 clock cycles.
LED on time average: 308.72 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 307 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 358.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 302 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 330.322 clock cycles.
This commit is contained in:
Markus Hitter 2015-03-01 14:00:09 +01:00
parent d29737699f
commit 8b88334b06
8 changed files with 22 additions and 26 deletions

6
dda.c
View File

@ -322,7 +322,7 @@ void dda_create(DDA *dda, TARGET *target) {
// 2^32/6000 is about 715mm which should be plenty // 2^32/6000 is about 715mm which should be plenty
// changed * 10 to * (F_CPU / 100000) so we can work in cpu_ticks rather than microseconds. // changed * 10 to * (F_CPU / 100000) so we can work in cpu_ticks rather than microseconds.
// timer.c setTimer() routine altered for same reason // timer.c timer_set() routine altered for same reason
// changed distance * 6000 .. * F_CPU / 100000 to // changed distance * 6000 .. * F_CPU / 100000 to
// distance * 2400 .. * F_CPU / 40000 so we can move a distance of up to 1800mm without overflowing // distance * 2400 .. * F_CPU / 40000 so we can move a distance of up to 1800mm without overflowing
@ -527,7 +527,7 @@ void dda_start(DDA *dda) {
dda->live = 1; dda->live = 1;
// set timeout for first step // set timeout for first step
setTimer(dda->c); timer_set(dda->c);
} }
// else just a speed change, keep dda->live = 0 // else just a speed change, keep dda->live = 0
@ -721,7 +721,7 @@ void dda_step(DDA *dda) {
} }
else { else {
psu_timeout = 0; psu_timeout = 0;
setTimer(dda->c); timer_set(dda->c);
} }
// turn off step outputs, hopefully they've been on long enough by now to register with the drivers // turn off step outputs, hopefully they've been on long enough by now to register with the drivers

View File

@ -82,7 +82,7 @@ void queue_step() {
DDA* current_movebuffer = &movebuffer[mb_tail]; DDA* current_movebuffer = &movebuffer[mb_tail];
if (current_movebuffer->live) { if (current_movebuffer->live) {
if (current_movebuffer->waitfor_temp) { if (current_movebuffer->waitfor_temp) {
setTimer(HEATER_WAIT_TIMEOUT); timer_set(HEATER_WAIT_TIMEOUT);
if (temp_achieved()) { if (temp_achieved()) {
current_movebuffer->live = current_movebuffer->done = 0; current_movebuffer->live = current_movebuffer->done = 0;
serial_writestr_P(PSTR("Temp achieved\n")); serial_writestr_P(PSTR("Temp achieved\n"));
@ -139,7 +139,7 @@ void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) {
if (isdead) { if (isdead) {
next_move(); next_move();
// Compensate for the cli() in setTimer(). // Compensate for the cli() in timer_set().
sei(); sei();
} }
} }
@ -158,14 +158,14 @@ void next_move() {
uint8_t t = mb_tail + 1; uint8_t t = mb_tail + 1;
t &= (MOVEBUFFER_SIZE - 1); t &= (MOVEBUFFER_SIZE - 1);
DDA* current_movebuffer = &movebuffer[t]; DDA* current_movebuffer = &movebuffer[t];
// tail must be set before setTimer call as setTimer // Tail must be set before calling timer_set(), as timer_set() reenables
// reenables the timer interrupt, potentially exposing // the timer interrupt, potentially exposing mb_tail to the timer
// mb_tail to the timer interrupt routine. // interrupt routine.
mb_tail = t; mb_tail = t;
if (current_movebuffer->waitfor_temp) { if (current_movebuffer->waitfor_temp) {
serial_writestr_P(PSTR("Waiting for target temp\n")); serial_writestr_P(PSTR("Waiting for target temp\n"));
current_movebuffer->live = 1; current_movebuffer->live = 1;
setTimer(HEATER_WAIT_TIMEOUT); timer_set(HEATER_WAIT_TIMEOUT);
} }
else { else {
dda_start(current_movebuffer); dda_start(current_movebuffer);

View File

@ -90,7 +90,7 @@ ISR(TIMER1_COMPA_vect) {
next_step_time -= 65536; next_step_time -= 65536;
// similar algorithm as described in setTimer below. // Similar algorithm as described in timer_set() below.
if (next_step_time < 65536) { if (next_step_time < 65536) {
OCR1A = (OCR1A + next_step_time) & 0xFFFF; OCR1A = (OCR1A + next_step_time) & 0xFFFF;
} else if(next_step_time < 75536){ } else if(next_step_time < 75536){
@ -103,8 +103,7 @@ ISR(TIMER1_COMPA_vect) {
/// initialise timer and enable system clock interrupt. /// initialise timer and enable system clock interrupt.
/// step interrupt is enabled later when we start using it /// step interrupt is enabled later when we start using it
void timer_init() void timer_init() {
{
// no outputs // no outputs
TCCR1A = 0; TCCR1A = 0;
// Normal Mode // Normal Mode
@ -117,8 +116,7 @@ void timer_init()
#ifdef HOST #ifdef HOST
/// specify how long until the step timer should fire /// specify how long until the step timer should fire
void setTimer(uint32_t delay) void timer_set(uint32_t delay) {
{
// save interrupt flag // save interrupt flag
uint8_t sreg = SREG; uint8_t sreg = SREG;
uint16_t step_start = 0; uint16_t step_start = 0;

View File

@ -23,7 +23,7 @@ timer stuff
*/ */
void timer_init(void) __attribute__ ((cold)); void timer_init(void) __attribute__ ((cold));
void setTimer(uint32_t delay); void timer_set(uint32_t delay);
void timer_stop(void); void timer_stop(void);

View File

@ -171,7 +171,7 @@ void sim_gcode(const char msg[]);
void sim_timer_init(uint8_t scale); void sim_timer_init(uint8_t scale);
void sim_timer_stop(void); void sim_timer_stop(void);
void sim_setTimer(void); void sim_timer_set(void);
uint16_t sim_tick_counter(void); uint16_t sim_tick_counter(void);
uint64_t sim_runtime_ns(void); ///< Simulated run-time in nanoseconds uint64_t sim_runtime_ns(void); ///< Simulated run-time in nanoseconds
void sim_time_warp(void); ///< skip ahead to next timer interrupt, when time_scale==0 void sim_time_warp(void); ///< skip ahead to next timer interrupt, when time_scale==0

View File

@ -161,10 +161,10 @@ static void timer1_isr(void) {
sei(); sei();
// Setup next timer // Setup next timer
sim_setTimer(); sim_timer_set();
} }
void sim_setTimer() { void sim_timer_set() {
// Set callbacks for COMPA and COMPB timers // Set callbacks for COMPA and COMPB timers
uint32_t nextA = 0, nextB = 0; uint32_t nextA = 0, nextB = 0;
uint16_t now = sim_tick_counter(); uint16_t now = sim_tick_counter();

12
timer.c
View File

@ -69,7 +69,7 @@ ISR(TIMER1_COMPA_vect) {
next_step_time -= 65536; next_step_time -= 65536;
// similar algorithm as described in setTimer below. // Similar algorithm as described in timer_set() below.
if (next_step_time < 65536) { if (next_step_time < 65536) {
OCR1A = (OCR1A + next_step_time) & 0xFFFF; OCR1A = (OCR1A + next_step_time) & 0xFFFF;
} else if(next_step_time < 75536){ } else if(next_step_time < 75536){
@ -82,8 +82,7 @@ ISR(TIMER1_COMPA_vect) {
/// initialise timer and enable system clock interrupt. /// initialise timer and enable system clock interrupt.
/// step interrupt is enabled later when we start using it /// step interrupt is enabled later when we start using it
void timer_init() void timer_init() {
{
// no outputs // no outputs
TCCR1A = 0; TCCR1A = 0;
// Normal Mode // Normal Mode
@ -94,7 +93,7 @@ void timer_init()
TIMSK1 = MASK(OCIE1B); TIMSK1 = MASK(OCIE1B);
#ifdef SIMULATOR #ifdef SIMULATOR
// Tell simulator // Tell simulator
sim_setTimer(); sim_timer_set();
#endif #endif
} }
@ -107,8 +106,7 @@ void timer_init()
as late as possible. If you use it from outside the step interrupt, as late as possible. If you use it from outside the step interrupt,
do a sei() after it to make the interrupt actually fire. do a sei() after it to make the interrupt actually fire.
*/ */
void setTimer(uint32_t delay) void timer_set(uint32_t delay) {
{
uint16_t step_start = 0; uint16_t step_start = 0;
#ifdef ACCELERATION_TEMPORAL #ifdef ACCELERATION_TEMPORAL
uint16_t current_time; uint16_t current_time;
@ -177,7 +175,7 @@ void setTimer(uint32_t delay)
TIMSK1 |= MASK(OCIE1A); TIMSK1 |= MASK(OCIE1A);
#ifdef SIMULATOR #ifdef SIMULATOR
// Tell simulator // Tell simulator
sim_setTimer(); sim_timer_set();
#endif #endif
} }

View File

@ -26,7 +26,7 @@ timer stuff
*/ */
void timer_init(void) __attribute__ ((cold)); void timer_init(void) __attribute__ ((cold));
void setTimer(uint32_t delay); void timer_set(uint32_t delay);
void timer_stop(void); void timer_stop(void);