From 808f5dcfca7b71b44ac35f3baa4d7c81c4673020 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Tue, 17 Jun 2014 22:13:25 +0200 Subject: [PATCH] DDA: Move axis calculations into loops, part 6b. Clean up code to reduce duplication by consolidating code into loops for per-axis actions. Part 6b moves do_step() from the "tidiest" place into where it's currently used, dda.c. Binary size goes down another 34 bytes, to a total savings of 408 bytes and performance is much better, but still 16% lower than without using loops: SIZES ATmega... '168 '328(P) '644(P) '1280 FLASH : 19874 bytes 139% 65% 32% 16% RAM : 2302 bytes 225% 113% 57% 29% EEPROM: 32 bytes 4% 2% 2% 1% short-moves.gcode Statistics (assuming a 20 MHz clock): LED on occurences: 888. Sum of all LED on time: 320000 clock cycles. LED on time minimum: 351 clock cycles. LED on time maximum: 772 clock cycles. LED on time average: 360.36 clock cycles. smooth-curves.gcode Statistics (assuming a 20 MHz clock): LED on occurences: 9124. Sum of all LED on time: 3875874 clock cycles. LED on time minimum: 356 clock cycles. LED on time maximum: 773 clock cycles. LED on time average: 424.8 clock cycles. triangle-odd.gcode Statistics (assuming a 20 MHz clock): LED on occurences: 1636. Sum of all LED on time: 640357 clock cycles. LED on time minimum: 351 clock cycles. LED on time maximum: 773 clock cycles. LED on time average: 391.416 clock cycles. --- dda.c | 12 ++++++++++++ pinio.c | 13 ------------- pinio.h | 3 --- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/dda.c b/dda.c index a7ec783..7fc6fbd 100644 --- a/dda.c +++ b/dda.c @@ -471,6 +471,18 @@ void dda_start(DDA *dda) { current_position.F = dda->endpoint.F; } +// step the 'n' axis +static void do_step(enum axis_e n) { + if (n == X) + x_step(); + else if (n == Y) + y_step(); + else if (n == Z) + z_step(); + else if (n == E) + e_step(); +} + /*! STEP \param *dda the current move diff --git a/pinio.c b/pinio.c index 7f22062..e27222b 100644 --- a/pinio.c +++ b/pinio.c @@ -42,16 +42,3 @@ void power_off() { ps_is_on = 0; } - -// step the 'n' axis -void do_step(enum axis_e n) { - if (n == X) - x_step(); - else if (n == Y) - y_step(); - else if (n == Z) - z_step(); - else if (n == E) - e_step(); -} - diff --git a/pinio.h b/pinio.h index 60b5daa..028fe80 100644 --- a/pinio.h +++ b/pinio.h @@ -6,7 +6,6 @@ #define _PINIO_H #include "config_wrapper.h" -#include "dda.h" #ifdef SIMULATOR #include "simulator.h" @@ -34,8 +33,6 @@ inline void power_init(void) { void power_on(void); void power_off(void); -void do_step(enum axis_e n); - /* X Stepper */