Fix and improve G-code queue (#21122)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
37
Marlin/src/core/bug_on.h
Normal file
37
Marlin/src/core/bug_on.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Copyright (c) 2021 X-Ryl669 [https://blog.cyril.by]
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// We need SERIAL_ECHOPAIR and macros.h
|
||||
#include "serial.h"
|
||||
|
||||
#if ENABLED(POSTMORTEM_DEBUGGING)
|
||||
// Useful macro for stopping the CPU on an unexpected condition
|
||||
// This is used like SERIAL_ECHOPAIR, that is: a key-value call of the local variables you want
|
||||
// to dump to the serial port before stopping the CPU.
|
||||
#define BUG_ON(V...) do { SERIAL_ECHOPAIR(ONLY_FILENAME, __LINE__, ": "); SERIAL_ECHOLNPAIR(V); SERIAL_FLUSHTX(); *(char*)0 = 42; } while(0)
|
||||
#elif ENABLED(MARLIN_DEV_MODE)
|
||||
// Don't stop the CPU here, but at least dump the bug on the serial port
|
||||
#define BUG_ON(V...) do { SERIAL_ECHOPAIR(ONLY_FILENAME, __LINE__, ": BUG!\n"); SERIAL_ECHOLNPAIR(V); SERIAL_FLUSHTX(); } while(0)
|
||||
#else
|
||||
// Release mode, let's ignore the bug
|
||||
#define BUG_ON(V...) NOOP
|
||||
#endif
|
@@ -131,6 +131,7 @@
|
||||
#define STR_WATCHDOG_FIRED "Watchdog timeout. Reset required."
|
||||
#define STR_ERR_KILLED "Printer halted. kill() called!"
|
||||
#define STR_ERR_STOPPED "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)"
|
||||
#define STR_ERR_SERIAL_MISMATCH "Serial status mismatch"
|
||||
#define STR_BUSY_PROCESSING "busy: processing"
|
||||
#define STR_BUSY_PAUSED_FOR_USER "busy: paused for user"
|
||||
#define STR_BUSY_PAUSED_FOR_INPUT "busy: paused for input"
|
||||
|
@@ -349,6 +349,31 @@
|
||||
#define CALL_IF_EXISTS(Return, That, Method, ...) \
|
||||
static_cast<Return>(Private::Call_ ## Method(That, ##__VA_ARGS__))
|
||||
|
||||
// Compile-time string manipulation
|
||||
namespace CompileTimeString {
|
||||
// Simple compile-time parser to find the position of the end of a string
|
||||
constexpr const char* findStringEnd(const char *str) {
|
||||
return *str ? findStringEnd(str + 1) : str;
|
||||
}
|
||||
|
||||
// Check whether a string contains a slash
|
||||
constexpr bool containsSlash(const char *str) {
|
||||
return *str == '/' ? true : (*str ? containsSlash(str + 1) : false);
|
||||
}
|
||||
// Find the last position of the slash
|
||||
constexpr const char* findLastSlashPos(const char* str) {
|
||||
return *str == '/' ? (str + 1) : findLastSlashPos(str - 1);
|
||||
}
|
||||
// Compile-time evaluation of the last part of a file path
|
||||
// Typically used to shorten the path to file in compiled strings
|
||||
// CompileTimeString::baseName(__FILE__) returns "macros.h" and not /path/to/Marlin/src/core/macros.h
|
||||
constexpr const char* baseName(const char* str) {
|
||||
return containsSlash(str) ? findLastSlashPos(findStringEnd(str)) : str;
|
||||
}
|
||||
}
|
||||
|
||||
#define ONLY_FILENAME CompileTimeString::baseName(__FILE__)
|
||||
|
||||
#else
|
||||
|
||||
#define MIN_2(a,b) ((a)<(b)?(a):(b))
|
||||
|
@@ -52,6 +52,10 @@ PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMST
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENABLED(MEATPACK)
|
||||
MeatpackSerial<decltype(_SERIAL_IMPL)> mpSerial(false, _SERIAL_IMPL);
|
||||
#endif
|
||||
|
||||
void serialprintPGM(PGM_P str) {
|
||||
while (const char c = pgm_read_byte(str++)) SERIAL_CHAR(c);
|
||||
}
|
||||
|
@@ -24,6 +24,10 @@
|
||||
#include "../inc/MarlinConfig.h"
|
||||
#include "serial_hook.h"
|
||||
|
||||
#if ENABLED(MEATPACK)
|
||||
#include "../feature/meatpack.h"
|
||||
#endif
|
||||
|
||||
// Commonly-used strings in serial output
|
||||
extern const char NUL_STR[], SP_P_STR[], SP_T_STR[],
|
||||
X_STR[], Y_STR[], Z_STR[], E_STR[],
|
||||
@@ -69,12 +73,19 @@ extern uint8_t marlin_debug_flags;
|
||||
typedef MultiSerial<decltype(MYSERIAL0), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL1)>, decltype(MYSERIAL1)), 0> SerialOutputT;
|
||||
#endif
|
||||
extern SerialOutputT multiSerial;
|
||||
#define SERIAL_IMPL multiSerial
|
||||
#define _SERIAL_IMPL multiSerial
|
||||
#else
|
||||
#define _PORT_REDIRECT(n,p) NOOP
|
||||
#define _PORT_RESTORE(n) NOOP
|
||||
#define SERIAL_ASSERT(P) NOOP
|
||||
#define SERIAL_IMPL MYSERIAL0
|
||||
#define _SERIAL_IMPL MYSERIAL0
|
||||
#endif
|
||||
|
||||
#if ENABLED(MEATPACK)
|
||||
extern MeatpackSerial<decltype(_SERIAL_IMPL)> mpSerial;
|
||||
#define SERIAL_IMPL mpSerial
|
||||
#else
|
||||
#define SERIAL_IMPL _SERIAL_IMPL
|
||||
#endif
|
||||
|
||||
#define SERIAL_OUT(WHAT, V...) (void)SERIAL_IMPL.WHAT(V)
|
||||
@@ -294,7 +305,7 @@ void serialprintPGM(PGM_P str);
|
||||
#endif
|
||||
|
||||
#define SERIAL_ECHOPGM_P(P) (serialprintPGM(P))
|
||||
#define SERIAL_ECHOLNPGM_P(P) (serialprintPGM(P "\n"))
|
||||
#define SERIAL_ECHOLNPGM_P(P) do{ serialprintPGM(P); SERIAL_EOL(); }while(0)
|
||||
|
||||
#define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S)))
|
||||
#define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n")))
|
||||
|
Reference in New Issue
Block a user