Added new core event triggered during looping when executing a millisecond delay.

Added `ISR_FUNC` macro for placing time critical functions in RAM.
This commit is contained in:
Terje Io
2022-01-11 19:13:18 +01:00
parent 22e0fcba1c
commit fb61a7f4ae
17 changed files with 69 additions and 38 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ It has been written to complement grblHAL and has features such as proper keyboa
---
Latest build date is 20220105, see the [changelog](changelog.md) for details.
Latest build date is 20220111, see the [changelog](changelog.md) for details.
__NOTE:__ A settings reset will be performed on an update for versions earlier than 20211122. Backup and restore of settings is recommended.
__IMPORTANT!__ A new setting has been introduced for ganged axes motors in version 20211121.
I have only bench tested this for a couple of drivers, correct function should be verified after updating by those who have more than three motors configured.
@@ -83,4 +83,4 @@ List of Supported G-Codes:
Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes.
---
2021-12-18
2022-01-11
+20
View File
@@ -1,5 +1,25 @@
## grblHAL changelog
Build 20220111:
Core:
* Added new core event triggered during looping when executing a millisecond delay.
* Added `ISR_FUNC` macro for placing time critical functions in RAM.
Drivers:
* RP2040: Limited max time between step pulses to avoid jog movements taking too long to complete. Moved time critical code run in interrupt context to RAM.
* iMXRT1062: Fixed memory leak in ioports code.
* Many: Forced ioports numbers \(_Aux \<n\>_\) to be contiguous regardless of how they are defined in the map file.
Plugins:
* Spindle \(Modbus\): Added subscription to new core event to poll for responses during delays, fixes issue with spindle at speed check for some drivers.
* Some: Moved time critical code run in interrupt context to RAM \(for RP2040 driver\).
---
Build 20220109:
Core:
+1
View File
@@ -94,6 +94,7 @@ typedef struct {
on_probe_completed_ptr on_probe_completed;
on_program_completed_ptr on_program_completed;
on_execute_realtime_ptr on_execute_realtime;
on_execute_realtime_ptr on_execute_delay;
on_unknown_accessory_override_ptr on_unknown_accessory_override;
on_report_options_ptr on_report_options;
on_report_command_help_ptr on_report_command_help;
+8 -1
View File
@@ -34,7 +34,7 @@
#else
#define GRBL_VERSION "1.1f"
#endif
#define GRBL_BUILD 20220109
#define GRBL_BUILD 20220111
// The following symbols are set here if not already set by the compiler or in config.h
// Do NOT change here!
@@ -49,6 +49,13 @@
#define ISR_CODE //!< Used by some drivers to force a function to always stay in RAM to improve performance.
#endif
#ifdef RP2040
#include "pico.h"
#define ISR_FUNC(fn) __not_in_flash_func(fn)
#else
#define ISR_FUNC(fn) fn
#endif
#ifdef ARDUINO
#include <Arduino.h>
#endif
+1 -1
View File
@@ -122,7 +122,7 @@ int grbl_enter (void)
// Clear all and set some core function pointers
memset(&grbl, 0, sizeof(grbl_t));
grbl.on_execute_realtime = protocol_execute_noop;
grbl.on_execute_realtime = grbl.on_execute_delay = protocol_execute_noop;
grbl.enqueue_gcode = protocol_enqueue_gcode;
grbl.enqueue_realtime_command = stream_enqueue_realtime_command;
grbl.on_report_options = dummy_bool_handler;
+3 -3
View File
@@ -59,7 +59,7 @@
// your e-stop switch to the microcontroller reset pin, since it is the most correct way to do this.
// Merge (bitwise or) all limit switch inputs.
ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals)
ISR_CODE axes_signals_t ISR_FUNC(limit_signals_merge)(limit_signals_t signals)
{
axes_signals_t state;
@@ -69,7 +69,7 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals)
}
// Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2).
ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode)
ISR_CODE static axes_signals_t ISR_FUNC(homing_signals_select)(limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode)
{
axes_signals_t state;
@@ -92,7 +92,7 @@ ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, a
return state;
}
ISR_CODE void limit_interrupt_handler (limit_signals_t state) // DEFAULT: Limit pin change interrupt process.
ISR_CODE void ISR_FUNC(limit_interrupt_handler)(limit_signals_t state) // DEFAULT: Limit pin change interrupt process.
{
// Ignore limit switches if already in an alarm state or in-process of executing an alarm.
// When in the alarm state, Grbl should have been reset or will force a reset, so any pending
+1 -1
View File
@@ -969,7 +969,7 @@ void mc_override_ctrl_update (gc_override_flags_t override_state)
// is in a motion state. If so, kills the steppers and sets the system alarm to flag position
// lost, since there was an abrupt uncontrolled deceleration. Called at an interrupt level by
// realtime abort command and hard limits. So, keep to a minimum.
ISR_CODE void mc_reset ()
ISR_CODE void ISR_FUNC(mc_reset)(void)
{
// Only this function can set the system reset. Helps prevent multiple kill calls.
if (bit_isfalse(sys.rt_exec_state, EXEC_RESET)) {
+1 -1
View File
@@ -72,7 +72,7 @@ bool mc_parking_motion(float *parking_target, plan_line_data_t *pl_data);
void mc_cubic_b_spline(float *target, plan_line_data_t *pl_data, float *position, float *offset1, float *offset2);
// Performs system reset. If in motion state, kills all motion and sets system alarm.
void mc_reset();
void mc_reset (void);
#ifdef ENABLE_BACKLASH_COMPENSATION
void mc_backlash_init (void);
+2 -2
View File
@@ -32,7 +32,7 @@ typedef struct {
static override_queue_t feed = {0}, accessory = {0};
ISR_CODE void enqueue_feed_override (uint8_t cmd)
ISR_CODE void ISR_FUNC(enqueue_feed_override)(uint8_t cmd)
{
uint_fast8_t bptr = (feed.head + 1) & (OVERRIDE_BUFSIZE - 1); // Get next head pointer
@@ -56,7 +56,7 @@ uint8_t get_feed_override (void)
return data;
}
ISR_CODE void enqueue_accessory_override (uint8_t cmd)
ISR_CODE void ISR_FUNC(enqueue_accessory_override)(uint8_t cmd)
{
uint_fast8_t bptr = (accessory.head + 1) & (OVERRIDE_BUFSIZE - 1); // Get next head pointer
+2 -2
View File
@@ -726,7 +726,7 @@ static void protocol_exec_rt_suspend (void)
// These characters are not passed into the main buffer,
// but rather sets system state flag bits for later execution by protocol_exec_rt_system().
// Called from input stream interrupt handler.
ISR_CODE bool protocol_enqueue_realtime_command (char c)
ISR_CODE bool ISR_FUNC(protocol_enqueue_realtime_command)(char c)
{
static bool esc = false;
@@ -914,7 +914,7 @@ ISR_CODE bool protocol_enqueue_realtime_command (char c)
// Enqueue a function to be called once by the
// foreground process, typically enqueued from an interrupt handler.
ISR_CODE bool protocol_enqueue_rt_command (on_execute_realtime_ptr fn)
ISR_CODE bool ISR_FUNC(protocol_enqueue_rt_command)(on_execute_realtime_ptr fn)
{
bool ok;
uint_fast8_t bptr = (realtime_queue.head + 1) & (RT_QUEUE_SIZE - 1); // Get next head pointer
+3
View File
@@ -1556,6 +1556,9 @@ bool read_global_settings ()
if(settings.mode == Mode_Laser && !hal.driver_cap.variable_spindle)
settings.mode = Mode_Standard;
if(!(hal.driver_cap.spindle_sync || hal.driver_cap.spindle_pid))
settings.spindle.ppr = 0;
#if COMPATIBILITY_LEVEL > 1 && DISABLE_G92_PERSISTENCE
settings.flags.g92_is_volatile = On;
#endif
+1 -1
View File
@@ -145,7 +145,7 @@ void state_update (rt_exec_t rt_exec)
stateHandler(rt_exec);
}
ISR_CODE sys_state_t state_get (void)
ISR_CODE sys_state_t ISR_FUNC(state_get)(void)
{
return sys_state;
}
+10 -10
View File
@@ -188,7 +188,7 @@ static void output_message (sys_state_t state)
}
// Callback from delay to deenergize steppers after movement, might been cancelled
void st_deenergize ()
void st_deenergize (void)
{
if(sys.steppers_deenergize) {
hal.stepper.enable(settings.steppers.deenergize);
@@ -199,7 +199,7 @@ void st_deenergize ()
// Stepper state initialization. Cycle should only start if the st.cycle_start flag is
// enabled. Startup init and limits call this function but shouldn't start the cycle.
void st_wake_up ()
void st_wake_up (void)
{
if(sys.steppers_deenergize) {
sys.steppers_deenergize = false;
@@ -215,7 +215,7 @@ void st_wake_up ()
// Stepper shutdown
ISR_CODE void st_go_idle ()
ISR_CODE void ISR_FUNC(st_go_idle)(void)
{
// Disable Stepper Driver Interrupt. Allow Stepper Port Reset Interrupt to finish, if active.
@@ -282,7 +282,7 @@ ISR_CODE void st_go_idle ()
//! \cond
ISR_CODE void stepper_driver_interrupt_handler (void)
ISR_CODE void ISR_FUNC(stepper_driver_interrupt_handler)(void)
{
#ifdef ENABLE_BACKLASH_COMPENSATION
static bool backlash_motion;
@@ -539,7 +539,7 @@ ISR_CODE void stepper_driver_interrupt_handler (void)
//! \endcond
// Reset and clear stepper subsystem variables
void st_reset ()
void st_reset (void)
{
if(hal.probe.configure)
hal.probe.configure(false, false);
@@ -600,7 +600,7 @@ void st_rpm_changed (float rpm)
}
// Called by planner_recalculate() when the executing block is updated by the new plan.
void st_update_plan_block_parameters ()
void st_update_plan_block_parameters (void)
{
if (pl_block != NULL) { // Ignore if at start of a new block.
prep.recalculate.velocity_profile = On;
@@ -610,7 +610,7 @@ void st_update_plan_block_parameters ()
}
// Changes the run state of the step segment buffer to execute the special parking motion.
void st_parking_setup_buffer()
void st_parking_setup_buffer (void)
{
// Store step execution data of partially completed block, if necessary.
if (prep.recalculate.hold_partial_block && !prep.recalculate.parking) {
@@ -628,7 +628,7 @@ void st_parking_setup_buffer()
// Restores the step segment buffer to the normal run state after a parking motion.
void st_parking_restore_buffer()
void st_parking_restore_buffer (void)
{
// Restore step execution data and flags of partially completed block, if necessary.
if (prep.recalculate.hold_partial_block) {
@@ -659,7 +659,7 @@ void st_parking_restore_buffer()
Currently, the segment buffer conservatively holds roughly up to 40-50 msec of steps.
NOTE: Computation units are in steps, millimeters, and minutes.
*/
void st_prep_buffer()
void st_prep_buffer (void)
{
// Block step prep buffer, while in a suspend state and there is no suspend motion to execute.
if (sys.step_control.end_motion)
@@ -1087,7 +1087,7 @@ void st_prep_buffer()
// however is not exactly the current speed, but the speed computed in the last step segment
// in the segment buffer. It will always be behind by up to the number of segment blocks (-1)
// divided by the ACCELERATION TICKS PER SECOND in seconds.
float st_get_realtime_rate()
float st_get_realtime_rate (void)
{
return state_get() & (STATE_CYCLE|STATE_HOMING|STATE_HOLD|STATE_JOG|STATE_SAFETY_DOOR) ? prep.current_speed : 0.0f;
}
+8 -8
View File
@@ -111,16 +111,16 @@ typedef struct stepper {
} stepper_t;
// Initialize and setup the stepper motor subsystem
void stepper_init();
void stepper_init (void);
// Enable steppers, but cycle does not start unless called by motion control or realtime command.
void st_wake_up();
void st_wake_up (void);
// Immediately disables steppers
void st_go_idle();
void st_go_idle (void);
// Reset the stepper subsystem variables
void st_reset();
void st_reset (void);
// Called by spindle_set_state() to inform about RPM changes.
void st_rpm_changed(float rpm);
@@ -129,16 +129,16 @@ void st_rpm_changed(float rpm);
void st_parking_setup_buffer();
// Restores the step segment buffer to the normal run state after a parking motion.
void st_parking_restore_buffer();
void st_parking_restore_buffer (void);
// Reloads step segment buffer. Called continuously by realtime execution system.
void st_prep_buffer();
void st_prep_buffer (void);
// Called by planner_recalculate() when the executing block is updated by the new plan.
void st_update_plan_block_parameters();
void st_update_plan_block_parameters (void);
// Called by realtime status reporting if realtime rate reporting is enabled in config.h.
float st_get_realtime_rate();
float st_get_realtime_rate (void);
void stepper_driver_interrupt_handler (void);
+3 -3
View File
@@ -112,7 +112,7 @@ int16_t stream_get_null (void)
return SERIAL_NO_DATA;
}
ISR_CODE static bool await_toolchange_ack (char c)
ISR_CODE static bool ISR_FUNC(await_toolchange_ack)(char c)
{
if(c == CMD_TOOL_ACK && !stream.rxbuffer->backup) {
memcpy(&rxbackup, stream.rxbuffer, sizeof(stream_rx_buffer_t));
@@ -147,12 +147,12 @@ bool stream_rx_suspend (stream_rx_buffer_t *rxbuffer, bool suspend)
return rxbuffer->tail != rxbuffer->head;
}
ISR_CODE bool stream_buffer_all (char c)
ISR_CODE bool ISR_FUNC(stream_buffer_all)(char c)
{
return false;
}
ISR_CODE bool stream_enqueue_realtime_command (char c)
ISR_CODE bool ISR_FUNC(stream_enqueue_realtime_command)(char c)
{
return hal.stream.enqueue_rt_command ? hal.stream.enqueue_rt_command(c) : protocol_enqueue_realtime_command(c);
}
+1 -1
View File
@@ -93,7 +93,7 @@ inline static float hypot_f (float x, float y)
// only the realtime command execute variable to have the main program execute these when
// its ready. This works exactly like the character-based realtime commands when picked off
// directly from the incoming data stream.
ISR_CODE void control_interrupt_handler (control_signals_t signals)
ISR_CODE void ISR_FUNC(control_interrupt_handler)(control_signals_t signals)
{
if(signals.deasserted)
return; // for now...
+2 -2
View File
@@ -231,7 +231,7 @@ static void execute_probe (sys_state_t state)
// Trap cycle start commands and redirect to foreground process
// by adding the function to be called to the realtime execution queue.
ISR_CODE static void trap_control_cycle_start (control_signals_t signals)
ISR_CODE static void ISR_FUNC(trap_control_cycle_start)(control_signals_t signals)
{
spin_lock++;
@@ -249,7 +249,7 @@ ISR_CODE static void trap_control_cycle_start (control_signals_t signals)
spin_lock--;
}
ISR_CODE static bool trap_stream_cycle_start (char c)
ISR_CODE static bool ISR_FUNC(trap_stream_cycle_start)(char c)
{
bool drop = false;