Skip to content

Commit 3d7cb52

Browse files
committed
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.
1 parent 7edc03b commit 3d7cb52

10 files changed

+132
-79
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ target_sources(grbl INTERFACE
3838
${CMAKE_CURRENT_LIST_DIR}/ioports.c
3939
${CMAKE_CURRENT_LIST_DIR}/vfs.c
4040
${CMAKE_CURRENT_LIST_DIR}/canbus.c
41+
${CMAKE_CURRENT_LIST_DIR}/pid.c
4142
${CMAKE_CURRENT_LIST_DIR}/kinematics/corexy.c
4243
${CMAKE_CURRENT_LIST_DIR}/kinematics/wall_plotter.c
4344
${CMAKE_CURRENT_LIST_DIR}/kinematics/delta.c

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## grblHAL ##
22

3-
Latest build date is 20250311, see the [changelog](changelog.md) for details.
3+
Latest build date is 20250320, see the [changelog](changelog.md) for details.
44

55
> [!NOTE]
66
> 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
8989
Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes.
9090

9191
---
92-
20250311
92+
20250320

changelog.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
## grblHAL changelog
22

3+
<a name="20250320">Build 20250320
4+
5+
Core:
6+
7+
* "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.
8+
9+
Drivers:
10+
11+
* ESP32: added tentative support for fourth motor for MKS DLC32 MAX board. Untested.
12+
13+
* RP2040: moved support code for MCP3221 ADC, fixed bug affecting RP2450 IRQ handling for gpio numbers > 31 and added plasma plugin.
14+
15+
* STM32F4xx: expanded check for I2C peripheral beeing ready to accept new commands.
16+
17+
* STM32Fxxxx: updated _my_machine.h_ for display enable change.
18+
19+
Plugins:
20+
21+
* 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.
22+
23+
* Some: removed Arduino specific include paths.
24+
25+
---
26+
327
<a name="20250313">Build 20250313
428

529
Core:
@@ -12,7 +36,7 @@ Drivers:
1236

1337
Plugins:
1438

15-
* Spindle: fixed issues with stepper spindle enable/disable via S-commands. Related to issue [#30](https://github.com/grblHAL/Plugins_spindle/issues/30).
39+
* 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).
1640

1741
---
1842

core_handlers.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ typedef message_code_t (*feedback_message_ptr)(message_code_t message_code);
6565
typedef alarm_code_t (*alarm_message_ptr)(alarm_code_t alarm_code);
6666

6767
typedef struct {
68-
init_message_ptr init_message; //<! Prints system welcome message.
69-
help_message_ptr help_message; //<! Prints system help message.
70-
status_message_ptr status_message; //<! Prints system status messages.
71-
feedback_message_ptr feedback_message; //<! Prints miscellaneous feedback messages.
72-
alarm_message_ptr alarm_message; //<! Prints alarm message.
68+
init_message_ptr init_message; //!< Prints system welcome message.
69+
help_message_ptr help_message; //!< Prints system help message.
70+
status_message_ptr status_message; //!< Prints system status messages.
71+
feedback_message_ptr feedback_message; //!< Prints miscellaneous feedback messages.
72+
alarm_message_ptr alarm_message; //!< Prints alarm message.
7373
setting_output_ptr setting;
7474
} report_t;
7575

gcode.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ parser_state_t *gc_get_state (void)
166166
return &gc_state;
167167
}
168168

169+
char *gc_coord_system_to_str (coord_system_id_t id)
170+
{
171+
static char buf[6];
172+
173+
uint8_t g5x = id + 54;
174+
175+
strcat(strcpy(buf, "G"), uitoa((uint32_t)(g5x > 59 ? 59 : g5x)));
176+
if(g5x > 59) {
177+
strcat(buf, ".");
178+
strcat(buf, uitoa((uint32_t)(g5x - 59)));
179+
}
180+
181+
return buf;
182+
}
183+
169184
static void set_spindle_override (spindle_t *spindle, bool disable)
170185
{
171186
if(spindle->hal && spindle->hal->param->state.override_disable != disable) {

gcode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ float *gc_get_scaling (void);
702702
// Get current axis offset.
703703
float gc_get_offset (uint_fast8_t idx, bool real_time);
704704

705+
char *gc_coord_system_to_str (coord_system_id_t id);
706+
705707
void gc_clear_output_commands (output_command_t *cmd);
706708

707709
spindle_t *gc_spindle_get (spindle_num_t spindle);

grbl.h

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#else
4343
#define GRBL_VERSION "1.1f"
4444
#endif
45-
#define GRBL_BUILD 20250313
45+
#define GRBL_BUILD 20250317
4646

4747
#define GRBL_URL "https://github.com/grblHAL"
4848

@@ -84,52 +84,61 @@
8484
// g-code programs, maybe selected for interface programs.
8585
// NOTE: If changed, manually update help message in report.c.
8686

87-
#define CMD_EXIT 0x03 // ctrl-C (ETX)
88-
#define CMD_REBOOT 0x14 // ctrl-T (DC4) - only acted upon if preceded by 0x1B (ESC)
89-
#define CMD_RESET 0x18 // ctrl-X (CAN)
90-
#define CMD_STOP 0x19 // ctrl-Y (EM)
91-
#define CMD_STATUS_REPORT_LEGACY '?'
92-
#define CMD_CYCLE_START_LEGACY '~'
93-
#define CMD_FEED_HOLD_LEGACY '!'
94-
#define CMD_PROGRAM_DEMARCATION '%'
87+
#define CMD_EXIT 0x03 //!< ctrl-C (ETX)
88+
#define CMD_REBOOT 0x14 //!< ctrl-T (DC4) - only acted upon if preceded by 0x1B (ESC)
89+
#define CMD_RESET 0x18 //!< ctrl-X (CAN)
90+
#define CMD_STOP 0x19 //!< ctrl-Y (EM)
91+
#define CMD_STATUS_REPORT_LEGACY '?'
92+
#define CMD_CYCLE_START_LEGACY '~'
93+
#define CMD_FEED_HOLD_LEGACY '!'
94+
#define CMD_PROGRAM_DEMARCATION '%'
9595

9696
// NOTE: All override realtime commands must be in the extended ASCII character set, starting
9797
// at character value 128 (0x80) and up to 255 (0xFF). If the normal set of realtime commands,
9898
// such as status reports, feed hold, reset, and cycle start, are moved to the extended set
9999
// space, protocol.c's protocol_process_realtime() will need to be modified to accommodate the change.
100-
#define CMD_STATUS_REPORT 0x80 // TODO: use 0x05 ctrl-E ENQ instead?
101-
#define CMD_CYCLE_START 0x81 // TODO: use 0x06 ctrl-F ACK instead? or SYN/DC2/DC3?
102-
#define CMD_FEED_HOLD 0x82 // TODO: use 0x15 ctrl-U NAK instead?
103-
#define CMD_GCODE_REPORT 0x83
104-
#define CMD_SAFETY_DOOR 0x84
105-
#define CMD_JOG_CANCEL 0x85
100+
#define CMD_STATUS_REPORT 0x80 // TODO: use 0x05 ctrl-E ENQ instead?
101+
#define CMD_CYCLE_START 0x81 // TODO: use 0x06 ctrl-F ACK instead? or SYN/DC2/DC3?
102+
#define CMD_FEED_HOLD 0x82 // TODO: use 0x15 ctrl-U NAK instead?
103+
#define CMD_GCODE_REPORT 0x83
104+
#define CMD_SAFETY_DOOR 0x84
105+
#define CMD_JOG_CANCEL 0x85
106106
//#define CMD_DEBUG_REPORT 0x86 // Only when DEBUG enabled, sends debug report in '{}' braces.
107-
#define CMD_STATUS_REPORT_ALL 0x87
108-
#define CMD_OPTIONAL_STOP_TOGGLE 0x88
109-
#define CMD_SINGLE_BLOCK_TOGGLE 0x89
110-
#define CMD_OVERRIDE_FAN0_TOGGLE 0x8A // Toggle Fan 0 on/off, not implemented by the core.
111-
#define CMD_MPG_MODE_TOGGLE 0x8B // Toggle MPG mode on/off, not implemented by the core.
112-
#define CMD_AUTO_REPORTING_TOGGLE 0x8C // Toggle auto real time reporting if configured.
113-
#define CMD_OVERRIDE_FEED_RESET 0x90 // Restores feed override value to 100%.
114-
#define CMD_OVERRIDE_FEED_COARSE_PLUS 0x91
115-
#define CMD_OVERRIDE_FEED_COARSE_MINUS 0x92
116-
#define CMD_OVERRIDE_FEED_FINE_PLUS 0x93
117-
#define CMD_OVERRIDE_FEED_FINE_MINUS 0x94
118-
#define CMD_OVERRIDE_RAPID_RESET 0x95 // Restores rapid override value to 100%.
119-
#define CMD_OVERRIDE_RAPID_MEDIUM 0x96
120-
#define CMD_OVERRIDE_RAPID_LOW 0x97
107+
#define CMD_STATUS_REPORT_ALL 0x87
108+
#define CMD_OPTIONAL_STOP_TOGGLE 0x88
109+
#define CMD_SINGLE_BLOCK_TOGGLE 0x89
110+
#define CMD_OVERRIDE_FAN0_TOGGLE 0x8A //!< Toggle Fan 0 on/off, not implemented by the core.
111+
#define CMD_MPG_MODE_TOGGLE 0x8B //!< Toggle MPG mode on/off, not implemented by the core.
112+
#define CMD_AUTO_REPORTING_TOGGLE 0x8C //!< Toggle auto real time reporting if configured.
113+
#define CMD_OVERRIDE_FEED_RESET 0x90 //!< Restores feed override value to 100%.
114+
#define CMD_OVERRIDE_FEED_COARSE_PLUS 0x91
115+
#define CMD_OVERRIDE_FEED_COARSE_MINUS 0x92
116+
#define CMD_OVERRIDE_FEED_FINE_PLUS 0x93
117+
#define CMD_OVERRIDE_FEED_FINE_MINUS 0x94
118+
#define CMD_OVERRIDE_RAPID_RESET 0x95 //!< Restores rapid override value to 100%.
119+
#define CMD_OVERRIDE_RAPID_MEDIUM 0x96
120+
#define CMD_OVERRIDE_RAPID_LOW 0x97
121121
// #define CMD_OVERRIDE_RAPID_EXTRA_LOW 0x98 // *NOT SUPPORTED*
122122
#define CMD_OVERRIDE_SPINDLE_RESET 0x99 // Restores spindle override value to 100%.
123-
#define CMD_OVERRIDE_SPINDLE_COARSE_PLUS 0x9A
124-
#define CMD_OVERRIDE_SPINDLE_COARSE_MINUS 0x9B
125-
#define CMD_OVERRIDE_SPINDLE_FINE_PLUS 0x9C
126-
#define CMD_OVERRIDE_SPINDLE_FINE_MINUS 0x9D
127-
#define CMD_OVERRIDE_SPINDLE_STOP 0x9E
128-
#define CMD_OVERRIDE_COOLANT_FLOOD_TOGGLE 0xA0
129-
#define CMD_OVERRIDE_COOLANT_MIST_TOGGLE 0xA1
130-
#define CMD_PID_REPORT 0xA2
131-
#define CMD_TOOL_ACK 0xA3
132-
#define CMD_PROBE_CONNECTED_TOGGLE 0xA4
123+
#define CMD_OVERRIDE_SPINDLE_COARSE_PLUS 0x9A
124+
#define CMD_OVERRIDE_SPINDLE_COARSE_MINUS 0x9B
125+
#define CMD_OVERRIDE_SPINDLE_FINE_PLUS 0x9C
126+
#define CMD_OVERRIDE_SPINDLE_FINE_MINUS 0x9D
127+
#define CMD_OVERRIDE_SPINDLE_STOP 0x9E
128+
#define CMD_OVERRIDE_COOLANT_FLOOD_TOGGLE 0xA0
129+
#define CMD_OVERRIDE_COOLANT_MIST_TOGGLE 0xA1
130+
#define CMD_PID_REPORT 0xA2
131+
#define CMD_TOOL_ACK 0xA3
132+
#define CMD_PROBE_CONNECTED_TOGGLE 0xA4
133+
// The following character codes are reserved for plugin use
134+
#define CMD_MACRO_0 0xB0
135+
#define CMD_MACRO_1 0xB1
136+
#define CMD_MACRO_2 0xB2
137+
#define CMD_MACRO_3 0xB3
138+
#define CMD_MACRO_4 0xB4
139+
#define CMD_MACRO_5 0xB5
140+
#define CMD_MACRO_6 0xB6
141+
#define CMD_MACRO_7 0xB7
133142

134143
// System motion line numbers must be zero.
135144
#define JOG_LINE_NUMBER 0

grbllib.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,11 @@ static void task_execute (sys_state_t state)
452452
if(immediate_task && sys.driver_started) {
453453

454454
hal.irq_disable();
455-
task = immediate_task;
456-
immediate_task = NULL;
455+
if((task = immediate_task))
456+
immediate_task = NULL;
457457
hal.irq_enable();
458458

459-
do {
459+
if(task) do {
460460
void *data = task->data;
461461
foreground_task_ptr fn = task->fn;
462462
task_free(task);
@@ -474,12 +474,27 @@ static void task_execute (sys_state_t state)
474474
task->fn(task->data);
475475
} while((task = task->next));
476476

477-
while(next_task && (int32_t)(next_task->time - now) <= 0) {
477+
while((task = next_task) && (int32_t)(task->time - now) <= 0) {
478+
479+
hal.irq_disable();
480+
481+
if(task == next_task)
482+
next_task = task->next;
483+
else {
484+
core_task_t *t;
485+
if((t = next_task)) {
486+
while(t->next && t->next != task)
487+
t = t->next;
488+
if(t->next && t->next == task)
489+
t->next = task->next;
490+
}
491+
}
492+
493+
hal.irq_enable();
478494

479-
void *data = next_task->data;
480-
foreground_task_ptr fn = next_task->fn;
481-
task_free(next_task);
482-
next_task = next_task->next;
495+
void *data = task->data;
496+
foreground_task_ptr fn = task->fn;
497+
task_free(task);
483498

484499
fn(data);
485500
}

probe.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ typedef enum {
3232
typedef union {
3333
uint8_t value;
3434
struct {
35-
uint8_t triggered :1, //<! Set to true when probe or toolsetter is triggered.
36-
connected :1, //<! Set to true when probe is connected. Always set to true if the driver does not have a probe connected input.
37-
inverted :1, //<! For driver use
38-
is_probing :1, //<! For driver use
39-
irq_enabled :1, //<! For driver use
40-
tls_triggered :1, //<! Set to true when toolsetter is triggered.
35+
uint8_t triggered :1, //!< Set to true when probe or toolsetter is triggered.
36+
connected :1, //!< Set to true when probe is connected. Always set to true if the driver does not have a probe connected input.
37+
inverted :1, //!< For driver use
38+
is_probing :1, //!< For driver use
39+
irq_enabled :1, //!< For driver use
40+
tls_triggered :1, //!< Set to true when toolsetter is triggered.
4141
unassigned :2;
4242
};
4343
} probe_state_t;

report.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,6 @@ static char *appendbuf (int argc, ...)
7575
return buf;
7676
}
7777

78-
static char *map_coord_system (coord_system_id_t id)
79-
{
80-
uint8_t g5x = id + 54;
81-
82-
strcpy(buf, uitoa((uint32_t)(g5x > 59 ? 59 : g5x)));
83-
if(g5x > 59) {
84-
strcat(buf, ".");
85-
strcat(buf, uitoa((uint32_t)(g5x - 59)));
86-
}
87-
88-
return buf;
89-
}
90-
9178
// Convert axis position values to null terminated string (mm).
9279
static char *get_axis_values_mm (float *axis_values)
9380
{
@@ -642,7 +629,7 @@ void report_ngc_parameters (void)
642629
break;
643630

644631
default: // G54-G59
645-
hal.stream.write(map_coord_system((coord_system_id_t)idx));
632+
hal.stream.write(gc_coord_system_to_str((coord_system_id_t)idx) + 1);
646633
break;
647634
}
648635

@@ -710,8 +697,8 @@ void report_gcode_modes (void)
710697
} else
711698
hal.stream.write(uitoa((uint32_t)gc_state.modal.motion));
712699

713-
hal.stream.write(" G");
714-
hal.stream.write(map_coord_system(gc_state.modal.coord_system.id));
700+
hal.stream.write(" ");
701+
hal.stream.write(gc_coord_system_to_str(gc_state.modal.coord_system.id));
715702

716703
#if COMPATIBILITY_LEVEL < 10
717704

@@ -1375,8 +1362,8 @@ void report_realtime_status (void)
13751362
}
13761363

13771364
if(report.gwco) {
1378-
hal.stream.write_all("|WCS:G");
1379-
hal.stream.write_all(map_coord_system(gc_state.modal.coord_system.id));
1365+
hal.stream.write_all("|WCS:");
1366+
hal.stream.write_all(gc_coord_system_to_str(gc_state.modal.coord_system.id));
13801367
}
13811368

13821369
if(report.overrides) {

0 commit comments

Comments
 (0)