From 51f450f927453ef189bedfefc35546778ad7e3b4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 8 Oct 2023 11:48:42 +0200 Subject: [PATCH] Combine planner busy flag with other flags --- Firmware/planner.cpp | 8 +++----- Firmware/planner.h | 6 ++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index a0a5c103a..1411d731b 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -295,7 +295,7 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit // which corresponds to a maximum repeat frequency of 228.57 kHz. // This blocking is safe in the context of a 10kHz stepper driver interrupt // or a 115200 Bd serial line receive interrupt, which will not trigger faster than 12kHz. - if (! block->busy) { // Don't update variables if block is busy. + if (!(block->flag & BLOCK_FLAG_BUSY)) { // Don't update variables if block is busy. block->accelerate_until = accelerate_steps; block->decelerate_after = accelerate_steps+plateau_steps; block->initial_rate = initial_rate; @@ -726,7 +726,8 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate block_t *block = &block_buffer[block_buffer_head]; // Mark block as not busy (Not executed by the stepper interrupt, could be still tinkered with.) - block->busy = false; + // Also reset the block flag. + block->flag = 0; // Set sdlen for calculating sd position block->sdlen = 0; @@ -1101,9 +1102,6 @@ Having the real displacement of the head, we can calculate the total movement le } } - // Reset the block flag. - block->flag = 0; - if (plan_reset_next_e_sched) { // finally propagate a pending reset diff --git a/Firmware/planner.h b/Firmware/planner.h index aae4a4b21..bec0031ce 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -46,6 +46,9 @@ enum BlockFlag { BLOCK_FLAG_DDA_LOWRES = 8, // Block starts with Zeroed E counter BLOCK_FLAG_E_RESET = 16, + // Block is being executed by the stepper ISR + BLOCK_FLAG_BUSY = 32, + }; union dda_isteps_t @@ -104,7 +107,6 @@ typedef struct { uint32_t final_rate; // The minimal rate at exit uint32_t acceleration_steps_per_s2; // acceleration steps/sec^2 uint8_t fan_speed; // Print fan speed, ranges from 0 to 255 - volatile char busy; // Pre-calculated division for the calculate_trapezoid_for_block() routine to run faster. @@ -233,7 +235,7 @@ FORCE_INLINE block_t *plan_get_current_block() return(NULL); } block_t *block = &block_buffer[block_buffer_tail]; - block->busy = true; + block->flag |= BLOCK_FLAG_BUSY; return(block); }