From f0fa5f9f3e5cc9f6596544812dab7251d3bbc3ef Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Wed, 16 Nov 2016 10:42:04 -0800 Subject: [PATCH] dda_lookahead.c: reduce size of ATOMIC section. We calculate a safe join speed in dda_join_moves using data from two source DDA movements. We ensure the DDA values we use are sane by atomically copying them to local variables before beginning our calculation. But later we discard all our results if the DDA went live in the meantime, as evidenced by changes in `DDA->live` or `DDA->id`. Since we will not use the results of our calculations if either of these change, we can safely reference all the other DDA values non-atomically. Change the ATOMIC section to protect only the `DDA->id` values at the start. Added by Traumflug: this costs a negligible 4 bytes binary size: ATmega sizes '168 '328(P) '644(P) '1280 Program: 18082 bytes 127% 59% 29% 15% Data: 2176 bytes 213% 107% 54% 27% EEPROM: 32 bytes 4% 2% 2% 1% --- dda_lookahead.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dda_lookahead.c b/dda_lookahead.c index 1ad3253..64fc1ba 100644 --- a/dda_lookahead.c +++ b/dda_lookahead.c @@ -190,18 +190,19 @@ void dda_join_moves(DDA *prev, DDA *current) { // Make sure we have 2 moves and the previous move is not already active if (prev->live == 0) { - // Perform an atomic copy to preserve volatile parameters during the calculations + // Copy DDA ids to verify later that nothing changed during calculations ATOMIC_START prev_id = prev->id; - prev_F = prev->endpoint.F; - prev_F_start_in_steps = prev->start_steps; - prev_total_steps = prev->total_steps; - crossF = current->crossF; this_id = current->id; - this_total_steps = current->total_steps; - this_fast_axis = current->fast_axis; ATOMIC_END + prev_F = prev->endpoint.F; + prev_F_start_in_steps = prev->start_steps; + prev_total_steps = prev->total_steps; + crossF = current->crossF; + this_total_steps = current->total_steps; + this_fast_axis = current->fast_axis; + // Here we have to distinguish between feedrate along the movement // direction and feedrate of the fast axis. They can differ by a factor // of 2.