From 3d7cb52d982478c2f35b8b33191f41c539804e94 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Thu, 20 Mar 2025 11:25:25 +0100 Subject: [PATCH] Hardened" task handler code, reseved some realtime control characters for macro plugins. Added missing file to CMakeLists.txt and made private function public for plugin use. --- CMakeLists.txt | 1 + README.md | 4 +-- changelog.md | 26 ++++++++++++++- core_handlers.h | 10 +++--- gcode.c | 15 +++++++++ gcode.h | 2 ++ grbl.h | 87 +++++++++++++++++++++++++++---------------------- grbllib.c | 31 +++++++++++++----- probe.h | 12 +++---- report.c | 23 +++---------- 10 files changed, 132 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 012da35..6377885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ target_sources(grbl INTERFACE ${CMAKE_CURRENT_LIST_DIR}/ioports.c ${CMAKE_CURRENT_LIST_DIR}/vfs.c ${CMAKE_CURRENT_LIST_DIR}/canbus.c + ${CMAKE_CURRENT_LIST_DIR}/pid.c ${CMAKE_CURRENT_LIST_DIR}/kinematics/corexy.c ${CMAKE_CURRENT_LIST_DIR}/kinematics/wall_plotter.c ${CMAKE_CURRENT_LIST_DIR}/kinematics/delta.c diff --git a/README.md b/README.md index 4968cac..a5bf374 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## grblHAL ## -Latest build date is 20250311, see the [changelog](changelog.md) for details. +Latest build date is 20250320, see the [changelog](changelog.md) for details. > [!NOTE] > A settings reset will be performed on an update of builds prior to 20241208. Backup and restore of settings is recommended. @@ -89,4 +89,4 @@ G/M-codes not supported by [legacy Grbl](https://github.com/gnea/grbl/wiki) are Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes. --- -20250311 +20250320 diff --git a/changelog.md b/changelog.md index 9a0b3eb..c1de3cb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,29 @@ ## grblHAL changelog +Build 20250320 + +Core: + +* "Hardened" task handler code, reseved some realtime control characters for macro plugins, added missing file to _CMakeLists.txt_ and made private function public for plugin use. + +Drivers: + +* ESP32: added tentative support for fourth motor for MKS DLC32 MAX board. Untested. + +* RP2040: moved support code for MCP3221 ADC, fixed bug affecting RP2450 IRQ handling for gpio numbers > 31 and added plasma plugin. + +* STM32F4xx: expanded check for I2C peripheral beeing ready to accept new commands. + +* STM32Fxxxx: updated _my_machine.h_ for display enable change. + +Plugins: + +* Keypad: added PR [#16](https://github.com/grblHAL/Plugin_keypad/pull/16) and keycode 'o' for cycling through coordinate systems. Changed default macro keycode bindings to new reserved realtime control characters. + +* Some: removed Arduino specific include paths. + +--- + Build 20250313 Core: @@ -12,7 +36,7 @@ Drivers: Plugins: -* Spindle: fixed issues with stepper spindle enable/disable via S-commands. Related to issue [#30](https://github.com/grblHAL/Plugins_spindle/issues/30). +* Spindle: added support for setting $677. Fixed issues with stepper spindle enable/disable via S-commands. Related to issue [#30](https://github.com/grblHAL/Plugins_spindle/issues/30). --- diff --git a/core_handlers.h b/core_handlers.h index c7140bd..22013c7 100644 --- a/core_handlers.h +++ b/core_handlers.h @@ -65,11 +65,11 @@ typedef message_code_t (*feedback_message_ptr)(message_code_t message_code); typedef alarm_code_t (*alarm_message_ptr)(alarm_code_t alarm_code); typedef struct { - init_message_ptr init_message; // 59 ? 59 : g5x))); + if(g5x > 59) { + strcat(buf, "."); + strcat(buf, uitoa((uint32_t)(g5x - 59))); + } + + return buf; +} + static void set_spindle_override (spindle_t *spindle, bool disable) { if(spindle->hal && spindle->hal->param->state.override_disable != disable) { diff --git a/gcode.h b/gcode.h index 1c0a8aa..d78d341 100644 --- a/gcode.h +++ b/gcode.h @@ -702,6 +702,8 @@ float *gc_get_scaling (void); // Get current axis offset. float gc_get_offset (uint_fast8_t idx, bool real_time); +char *gc_coord_system_to_str (coord_system_id_t id); + void gc_clear_output_commands (output_command_t *cmd); spindle_t *gc_spindle_get (spindle_num_t spindle); diff --git a/grbl.h b/grbl.h index daf5391..f8fe7c2 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20250313 +#define GRBL_BUILD 20250317 #define GRBL_URL "https://github.com/grblHAL" @@ -84,52 +84,61 @@ // g-code programs, maybe selected for interface programs. // NOTE: If changed, manually update help message in report.c. -#define CMD_EXIT 0x03 // ctrl-C (ETX) -#define CMD_REBOOT 0x14 // ctrl-T (DC4) - only acted upon if preceded by 0x1B (ESC) -#define CMD_RESET 0x18 // ctrl-X (CAN) -#define CMD_STOP 0x19 // ctrl-Y (EM) -#define CMD_STATUS_REPORT_LEGACY '?' -#define CMD_CYCLE_START_LEGACY '~' -#define CMD_FEED_HOLD_LEGACY '!' -#define CMD_PROGRAM_DEMARCATION '%' +#define CMD_EXIT 0x03 //!< ctrl-C (ETX) +#define CMD_REBOOT 0x14 //!< ctrl-T (DC4) - only acted upon if preceded by 0x1B (ESC) +#define CMD_RESET 0x18 //!< ctrl-X (CAN) +#define CMD_STOP 0x19 //!< ctrl-Y (EM) +#define CMD_STATUS_REPORT_LEGACY '?' +#define CMD_CYCLE_START_LEGACY '~' +#define CMD_FEED_HOLD_LEGACY '!' +#define CMD_PROGRAM_DEMARCATION '%' // NOTE: All override realtime commands must be in the extended ASCII character set, starting // at character value 128 (0x80) and up to 255 (0xFF). If the normal set of realtime commands, // such as status reports, feed hold, reset, and cycle start, are moved to the extended set // space, protocol.c's protocol_process_realtime() will need to be modified to accommodate the change. -#define CMD_STATUS_REPORT 0x80 // TODO: use 0x05 ctrl-E ENQ instead? -#define CMD_CYCLE_START 0x81 // TODO: use 0x06 ctrl-F ACK instead? or SYN/DC2/DC3? -#define CMD_FEED_HOLD 0x82 // TODO: use 0x15 ctrl-U NAK instead? -#define CMD_GCODE_REPORT 0x83 -#define CMD_SAFETY_DOOR 0x84 -#define CMD_JOG_CANCEL 0x85 +#define CMD_STATUS_REPORT 0x80 // TODO: use 0x05 ctrl-E ENQ instead? +#define CMD_CYCLE_START 0x81 // TODO: use 0x06 ctrl-F ACK instead? or SYN/DC2/DC3? +#define CMD_FEED_HOLD 0x82 // TODO: use 0x15 ctrl-U NAK instead? +#define CMD_GCODE_REPORT 0x83 +#define CMD_SAFETY_DOOR 0x84 +#define CMD_JOG_CANCEL 0x85 //#define CMD_DEBUG_REPORT 0x86 // Only when DEBUG enabled, sends debug report in '{}' braces. -#define CMD_STATUS_REPORT_ALL 0x87 -#define CMD_OPTIONAL_STOP_TOGGLE 0x88 -#define CMD_SINGLE_BLOCK_TOGGLE 0x89 -#define CMD_OVERRIDE_FAN0_TOGGLE 0x8A // Toggle Fan 0 on/off, not implemented by the core. -#define CMD_MPG_MODE_TOGGLE 0x8B // Toggle MPG mode on/off, not implemented by the core. -#define CMD_AUTO_REPORTING_TOGGLE 0x8C // Toggle auto real time reporting if configured. -#define CMD_OVERRIDE_FEED_RESET 0x90 // Restores feed override value to 100%. -#define CMD_OVERRIDE_FEED_COARSE_PLUS 0x91 -#define CMD_OVERRIDE_FEED_COARSE_MINUS 0x92 -#define CMD_OVERRIDE_FEED_FINE_PLUS 0x93 -#define CMD_OVERRIDE_FEED_FINE_MINUS 0x94 -#define CMD_OVERRIDE_RAPID_RESET 0x95 // Restores rapid override value to 100%. -#define CMD_OVERRIDE_RAPID_MEDIUM 0x96 -#define CMD_OVERRIDE_RAPID_LOW 0x97 +#define CMD_STATUS_REPORT_ALL 0x87 +#define CMD_OPTIONAL_STOP_TOGGLE 0x88 +#define CMD_SINGLE_BLOCK_TOGGLE 0x89 +#define CMD_OVERRIDE_FAN0_TOGGLE 0x8A //!< Toggle Fan 0 on/off, not implemented by the core. +#define CMD_MPG_MODE_TOGGLE 0x8B //!< Toggle MPG mode on/off, not implemented by the core. +#define CMD_AUTO_REPORTING_TOGGLE 0x8C //!< Toggle auto real time reporting if configured. +#define CMD_OVERRIDE_FEED_RESET 0x90 //!< Restores feed override value to 100%. +#define CMD_OVERRIDE_FEED_COARSE_PLUS 0x91 +#define CMD_OVERRIDE_FEED_COARSE_MINUS 0x92 +#define CMD_OVERRIDE_FEED_FINE_PLUS 0x93 +#define CMD_OVERRIDE_FEED_FINE_MINUS 0x94 +#define CMD_OVERRIDE_RAPID_RESET 0x95 //!< Restores rapid override value to 100%. +#define CMD_OVERRIDE_RAPID_MEDIUM 0x96 +#define CMD_OVERRIDE_RAPID_LOW 0x97 // #define CMD_OVERRIDE_RAPID_EXTRA_LOW 0x98 // *NOT SUPPORTED* #define CMD_OVERRIDE_SPINDLE_RESET 0x99 // Restores spindle override value to 100%. -#define CMD_OVERRIDE_SPINDLE_COARSE_PLUS 0x9A -#define CMD_OVERRIDE_SPINDLE_COARSE_MINUS 0x9B -#define CMD_OVERRIDE_SPINDLE_FINE_PLUS 0x9C -#define CMD_OVERRIDE_SPINDLE_FINE_MINUS 0x9D -#define CMD_OVERRIDE_SPINDLE_STOP 0x9E -#define CMD_OVERRIDE_COOLANT_FLOOD_TOGGLE 0xA0 -#define CMD_OVERRIDE_COOLANT_MIST_TOGGLE 0xA1 -#define CMD_PID_REPORT 0xA2 -#define CMD_TOOL_ACK 0xA3 -#define CMD_PROBE_CONNECTED_TOGGLE 0xA4 +#define CMD_OVERRIDE_SPINDLE_COARSE_PLUS 0x9A +#define CMD_OVERRIDE_SPINDLE_COARSE_MINUS 0x9B +#define CMD_OVERRIDE_SPINDLE_FINE_PLUS 0x9C +#define CMD_OVERRIDE_SPINDLE_FINE_MINUS 0x9D +#define CMD_OVERRIDE_SPINDLE_STOP 0x9E +#define CMD_OVERRIDE_COOLANT_FLOOD_TOGGLE 0xA0 +#define CMD_OVERRIDE_COOLANT_MIST_TOGGLE 0xA1 +#define CMD_PID_REPORT 0xA2 +#define CMD_TOOL_ACK 0xA3 +#define CMD_PROBE_CONNECTED_TOGGLE 0xA4 +// The following character codes are reserved for plugin use +#define CMD_MACRO_0 0xB0 +#define CMD_MACRO_1 0xB1 +#define CMD_MACRO_2 0xB2 +#define CMD_MACRO_3 0xB3 +#define CMD_MACRO_4 0xB4 +#define CMD_MACRO_5 0xB5 +#define CMD_MACRO_6 0xB6 +#define CMD_MACRO_7 0xB7 // System motion line numbers must be zero. #define JOG_LINE_NUMBER 0 diff --git a/grbllib.c b/grbllib.c index a9827e1..04906c6 100644 --- a/grbllib.c +++ b/grbllib.c @@ -452,11 +452,11 @@ static void task_execute (sys_state_t state) if(immediate_task && sys.driver_started) { hal.irq_disable(); - task = immediate_task; - immediate_task = NULL; + if((task = immediate_task)) + immediate_task = NULL; hal.irq_enable(); - do { + if(task) do { void *data = task->data; foreground_task_ptr fn = task->fn; task_free(task); @@ -474,12 +474,27 @@ static void task_execute (sys_state_t state) task->fn(task->data); } while((task = task->next)); - while(next_task && (int32_t)(next_task->time - now) <= 0) { + while((task = next_task) && (int32_t)(task->time - now) <= 0) { - void *data = next_task->data; - foreground_task_ptr fn = next_task->fn; - task_free(next_task); - next_task = next_task->next; + hal.irq_disable(); + + if(task == next_task) + next_task = task->next; + else { + core_task_t *t; + if((t = next_task)) { + while(t->next && t->next != task) + t = t->next; + if(t->next && t->next == task) + t->next = task->next; + } + } + + hal.irq_enable(); + + void *data = task->data; + foreground_task_ptr fn = task->fn; + task_free(task); fn(data); } diff --git a/probe.h b/probe.h index 76ab1cc..9ef62c2 100644 --- a/probe.h +++ b/probe.h @@ -32,12 +32,12 @@ typedef enum { typedef union { uint8_t value; struct { - uint8_t triggered :1, // 59 ? 59 : g5x))); - if(g5x > 59) { - strcat(buf, "."); - strcat(buf, uitoa((uint32_t)(g5x - 59))); - } - - return buf; -} - // Convert axis position values to null terminated string (mm). static char *get_axis_values_mm (float *axis_values) { @@ -642,7 +629,7 @@ void report_ngc_parameters (void) break; default: // G54-G59 - hal.stream.write(map_coord_system((coord_system_id_t)idx)); + hal.stream.write(gc_coord_system_to_str((coord_system_id_t)idx) + 1); break; } @@ -710,8 +697,8 @@ void report_gcode_modes (void) } else hal.stream.write(uitoa((uint32_t)gc_state.modal.motion)); - hal.stream.write(" G"); - hal.stream.write(map_coord_system(gc_state.modal.coord_system.id)); + hal.stream.write(" "); + hal.stream.write(gc_coord_system_to_str(gc_state.modal.coord_system.id)); #if COMPATIBILITY_LEVEL < 10 @@ -1375,8 +1362,8 @@ void report_realtime_status (void) } if(report.gwco) { - hal.stream.write_all("|WCS:G"); - hal.stream.write_all(map_coord_system(gc_state.modal.coord_system.id)); + hal.stream.write_all("|WCS:"); + hal.stream.write_all(gc_coord_system_to_str(gc_state.modal.coord_system.id)); } if(report.overrides) {