Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crashes in LimitPin ISRs due to calling it's calling mc_reset() #84

Open
wants to merge 2 commits into
base: Devt
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions FluidNC/src/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ void protocol_reset() {
// rtAlarm = ExecAlarm::None;
}


bool protocol_abort() {
if (rtReset && config->_sdCard->get_state() == SDState::BusyPrinting) {
//Report print stopped
_notifyf("SD print canceled", "Reset during SD file at line: %d", config->_sdCard->lineNumber());
// log_info() does not work well in this case because the message gets broken in half
// by report_init_message(). The flow of control that causes it is obscure.
config->_sdCard->getClient() << "[MSG:"
<< "Reset during SD file at line: " << config->_sdCard->lineNumber();

config->_sdCard->closeFile();
}
if (sys.abort) {
log_debug("protocol_abort()");
return true;
}
return false;
}


static int32_t idleEndTime = 0;

/*
Expand Down Expand Up @@ -166,7 +186,7 @@ void protocol_main_loop() {
char line[Channel::maxLine];
while (true) {
protocol_execute_realtime(); // Runtime command check point.
if (sys.abort) {
if (protocol_abort()) {
return; // Bail to calling function upon system abort
}

Expand Down Expand Up @@ -209,7 +229,7 @@ void protocol_main_loop() {
// auto-cycle start, if enabled, any queued moves.
protocol_auto_cycle_start();
protocol_execute_realtime(); // Runtime command check point.
if (sys.abort) {
if (protocol_abort()) {
return; // Bail to main() program loop to reset system.
}

Expand Down Expand Up @@ -240,7 +260,7 @@ void protocol_buffer_synchronize() {
do {
pollChannels();
protocol_execute_realtime(); // Check and execute run-time commands
if (sys.abort) {
if (protocol_abort()) {
return; // Check for system abort
}
} while (plan_get_current_block() || (sys.state == State::Cycle));
Expand Down Expand Up @@ -291,6 +311,7 @@ static void protocol_do_alarm() {
// System alarm. Everything has shutdown by something that has gone severely wrong. Report
case ExecAlarm::HardLimit:
case ExecAlarm::SoftLimit:
protocol_abort();
sys.state = State::Alarm; // Set system alarm state
alarm_msg(rtAlarm);
report_feedback_message(Message::CriticalEvent);
Expand Down Expand Up @@ -853,7 +874,7 @@ static void protocol_exec_rt_suspend() {
}

while (sys.suspend.value) {
if (sys.abort) {
if (protocol_abort()) {
return;
}
// if a jogCancel comes in and we have a jog "in-flight" (parsed and handed over to mc_move_motors()),
Expand Down Expand Up @@ -926,7 +947,7 @@ static void protocol_exec_rt_suspend() {
config->_coolant->off();
report_ovr_counter = 0; // Set to report change immediately
Stepper::go_idle(); // Stop stepping and maybe disable steppers
while (!(sys.abort)) {
while (!(protocol_abort())) {
protocol_exec_rt_system(); // Do nothing until reset.
}
return; // Abort received. Return to re-initialize.
Expand Down