From 110e0d782f50082819101ca39ad4e38300046467 Mon Sep 17 00:00:00 2001 From: FanDjango <51046875+FanDjango@users.noreply.github.com> Date: Mon, 16 Nov 2020 21:56:05 +0100 Subject: [PATCH] Guards for large BLOCK_BUFFER_SIZE (>=128) (#20130) Co-authored-by: Scott Lahteine --- Marlin/src/inc/SanityCheck.h | 2 ++ Marlin/src/module/planner.cpp | 18 ++++++++---------- Marlin/src/module/planner.h | 6 +++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 22930a7621..18506163f5 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2759,6 +2759,8 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #if !BLOCK_BUFFER_SIZE || !IS_POWER_OF_2(BLOCK_BUFFER_SIZE) #error "BLOCK_BUFFER_SIZE must be a power of 2." +#elif BLOCK_BUFFER_SIZE > 64 + #error "A very large BLOCK_BUFFER_SIZE is not needed and takes longer to drain the buffer on pause / cancel." #endif #if ENABLED(LED_CONTROL_MENU) && !IS_ULTIPANEL diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 74535df1f9..147adb12e3 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -213,7 +213,7 @@ xyze_float_t Planner::previous_speed; float Planner::previous_nominal_speed_sqr; #if ENABLED(DISABLE_INACTIVE_EXTRUDER) - uint8_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 }; + last_move_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 }; #endif #ifdef XY_FREQUENCY_LIMIT @@ -2037,22 +2037,20 @@ bool Planner::_populate_block(block_t * const block, bool split_move, #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder LOOP_L_N(i, EXTRUDERS) - if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--; - - #if HAS_DUPLICATION_MODE - if (extruder_duplication_enabled && extruder == 0) { - ENABLE_AXIS_E1(); - g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2; - } - #endif + if (g_uc_extruder_last_move[i]) g_uc_extruder_last_move[i]--; #define ENABLE_ONE_E(N) do{ \ if (extruder == N) { \ ENABLE_AXIS_E##N(); \ g_uc_extruder_last_move[N] = (BLOCK_BUFFER_SIZE) * 2; \ + if ((N) == 0 && TERN0(HAS_DUPLICATION_MODE, extruder_duplication_enabled)) \ + ENABLE_AXIS_E1(); \ } \ - else if (!g_uc_extruder_last_move[N]) \ + else if (!g_uc_extruder_last_move[N]) { \ DISABLE_AXIS_E##N(); \ + if ((N) == 0 && TERN0(HAS_DUPLICATION_MODE, extruder_duplication_enabled)) \ + DISABLE_AXIS_E1(); \ + } \ }while(0); #else diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index c4e11490b1..ac30938f2a 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -287,6 +287,10 @@ typedef struct { #endif } skew_factor_t; +#if ENABLED(DISABLE_INACTIVE_EXTRUDER) + typedef IF<(BLOCK_BUFFER_SIZE > 64), uint16_t, uint8_t>::type last_move_t; +#endif + class Planner { public: @@ -435,7 +439,7 @@ class Planner { #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Counters to manage disabling inactive extruders - static uint8_t g_uc_extruder_last_move[EXTRUDERS]; + static last_move_t g_uc_extruder_last_move[EXTRUDERS]; #endif #if HAS_WIRED_LCD