Skip to content

Commit

Permalink
Merge pull request #633 from Paciente8159/allow-main-loop-event-with-…
Browse files Browse the repository at this point in the history
…hold

Allow main loop event with hold
  • Loading branch information
Paciente8159 committed Feb 19, 2024
2 parents 5ae97b9 + 8d2cca0 commit 901f32b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
7 changes: 7 additions & 0 deletions makefiles/virtual/mcu_virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,13 @@ extern "C"
}
return 0;
}

uint8_t itp_set_step_mode(uint8_t mode) {return 0;}

uint32_t mcu_free_micros(void)
{
return (uint32_t)(mcu_free_micros() % 1000);
}
#ifdef __cplusplus
}
#endif
Expand Down
35 changes: 16 additions & 19 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,23 +958,6 @@ bool cnc_check_interlocking(void)
return false;
}

// an hold condition is active and motion as stopped
if (cnc_get_exec_state(EXEC_HOLD) && !cnc_get_exec_state(EXEC_RUN))
{
itp_stop(); // stop motion

if (cnc_get_exec_state(EXEC_HOMING | EXEC_JOG)) // flushes the buffers if motions was homing or jog
{
itp_clear();
planner_clear();
mc_sync_position();
// homing will be cleared inside homing cycle
cnc_clear_exec_state(EXEC_JOG | EXEC_HOLD);
}

return false;
}

#if ASSERT_PIN(SAFETY_DOOR)
// the safety door condition is active
if (cnc_get_exec_state(EXEC_DOOR))
Expand All @@ -983,6 +966,7 @@ bool cnc_check_interlocking(void)
if (cnc_get_exec_state(EXEC_HOMING))
{
cnc_alarm(EXEC_ALARM_HOMING_FAIL_DOOR);
return false;
}
else if (cnc_get_exec_state(EXEC_RUN)) // if the machined is running
{
Expand All @@ -993,11 +977,24 @@ bool cnc_check_interlocking(void)
{
cnc_stop();
}

return false;
}
#endif

// an hold condition is active and motion as stopped
if (cnc_get_exec_state(EXEC_HOLD) && !cnc_get_exec_state(EXEC_RUN))
{
itp_stop(); // stop motion

if (cnc_get_exec_state(EXEC_HOMING | EXEC_JOG)) // flushes the buffers if motions was homing or jog
{
itp_clear();
planner_clear();
mc_sync_position();
// homing will be cleared inside homing cycle
cnc_clear_exec_state(EXEC_JOG | EXEC_HOLD);
}
}

// end of JOG
if (cnc_get_exec_state(EXEC_JOG | EXEC_HOLD) == EXEC_JOG)
{
Expand Down
26 changes: 13 additions & 13 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,19 +698,19 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w
{
case 50:
mantissa++;
__attribute__((fallthrough));
__FALL_THROUGH__
case 40:
mantissa++;
__attribute__((fallthrough));
__FALL_THROUGH__
case 30:
mantissa++;
__attribute__((fallthrough));
__FALL_THROUGH__
case 20:
mantissa++;
__attribute__((fallthrough));
__FALL_THROUGH__
case 10:
mantissa++;
__attribute__((fallthrough));
__FALL_THROUGH__
case 0:
break;
default:
Expand Down Expand Up @@ -1471,7 +1471,7 @@ uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, pa
break;
case G92_1: // G92.1
memset(g92permanentoffset, 0, sizeof(g92permanentoffset));
__attribute__((fallthrough));
__FALL_THROUGH__
// continue
case G92_2: // G92.2
memset(parser_parameters.g92_offset, 0, sizeof(parser_parameters.g92_offset));
Expand Down Expand Up @@ -1643,7 +1643,7 @@ uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, pa
{
block_data.spindle = 0;
}
__attribute__((fallthrough));
__FALL_THROUGH__
case G1:
if (block_data.feed == 0)
{
Expand Down Expand Up @@ -2136,7 +2136,7 @@ static uint8_t parser_gcode_word(uint8_t code, uint8_t mantissa, parser_state_t
{
return STATUS_GCODE_UNSUPPORTED_COMMAND;
}
__attribute__((fallthrough));
__FALL_THROUGH__
#ifdef ENABLE_G39_H_MAPPING
case 39:
#endif
Expand Down Expand Up @@ -2220,7 +2220,7 @@ static uint8_t parser_gcode_word(uint8_t code, uint8_t mantissa, parser_state_t
{
return STATUS_GCODE_UNSUPPORTED_COMMAND;
}
__attribute__((fallthrough));
__FALL_THROUGH__
case 49:
new_state->groups.tlo_mode = ((code == 49) ? G49 : G43);
new_group |= GCODE_GROUP_TOOLLENGTH;
Expand Down Expand Up @@ -2270,7 +2270,7 @@ static uint8_t parser_gcode_word(uint8_t code, uint8_t mantissa, parser_state_t
{
return STATUS_GCODE_UNSUPPORTED_COMMAND;
}
__attribute__((fallthrough));
__FALL_THROUGH__
#ifndef DISABLE_G10_SUPPORT
case 10:
#endif
Expand All @@ -2283,7 +2283,7 @@ static uint8_t parser_gcode_word(uint8_t code, uint8_t mantissa, parser_state_t
return STATUS_GCODE_MODAL_GROUP_VIOLATION;
}
cmd->group_0_1_useaxis = 1;
__attribute__((fallthrough));
__FALL_THROUGH__
case 4:
case 53:
// convert code within 4 bits without
Expand Down Expand Up @@ -2327,10 +2327,10 @@ static uint8_t parser_mcode_word(uint8_t code, uint8_t mantissa, parser_state_t
{
case 60:
code = 5;
__attribute__((fallthrough));
__FALL_THROUGH__
case 30:
code = (code & 1) ? 5 : 3;
__attribute__((fallthrough));
__FALL_THROUGH__
case 0:
case 1:
case 2:
Expand Down
4 changes: 2 additions & 2 deletions uCNC/src/hal/mcus/avr/mcu_avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ ISR(TWI_vect, ISR_BLOCK)
case TW_SR_ARB_LOST_SLA_ACK:
case TW_SR_ARB_LOST_GCALL_ACK:
index++;
__attribute__((fallthrough));
__FALL_THROUGH__
case TW_SR_STOP: // stop or repeated start condition received
// sends the data
if (i < I2C_SLAVE_BUFFER_SIZE)
Expand All @@ -1294,7 +1294,7 @@ ISR(TWI_vect, ISR_BLOCK)
case TW_ST_SLA_ACK:
case TW_ST_ARB_LOST_SLA_ACK:
i = 0;
__attribute__((fallthrough));
__FALL_THROUGH__
case TW_ST_DATA_ACK: // byte sent, ack returned
// copy data to output register
TWDR = mcu_i2c_buffer[i++];
Expand Down
4 changes: 2 additions & 2 deletions uCNC/src/hal/mcus/lpc176x/mcu_lpc176x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ void I2C_ISR(void)
case 0x68:
case 0x78:
index++;
__attribute__((fallthrough));
__FALL_THROUGH__
case 0xA0: // stop or repeated start condition received
// sends the data
if (i < I2C_SLAVE_BUFFER_SIZE)
Expand All @@ -1258,7 +1258,7 @@ void I2C_ISR(void)
case 0xA8: // addressed, returned ack
case 0xB0: // arbitration lost, returned ack
i = 0;
__attribute__((fallthrough));
__FALL_THROUGH__
case 0xB8: // byte sent, ack returned
// copy data to output register
I2C_REG->I2DAT = mcu_i2c_buffer[i++];
Expand Down
6 changes: 6 additions & 0 deletions uCNC/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ extern "C"
#define __TIMEOUT_MS__(timeout) timeout*=1000; __TIMEOUT_US__(timeout)
#define __TIMEOUT_ASSERT__(timeout) if(timeout < 0)

#if defined(__GNUC__) && __GNUC__ >= 7
#define __FALL_THROUGH__ __attribute__ ((fallthrough));
#else
#define __FALL_THROUGH__
#endif /* __GNUC__ >= 7 */

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 901f32b

Please sign in to comment.