Skip to content

Commit 5eee108

Browse files
committed
Pin state reporting of all pins. Flash optimization.
- New pin state realtime reporting feature. Instead of `Lim:000` for limit state reports, the new feature shows `Pin:000|0|0000`, or something similar. The `|` delimited fields indicate xyz limits, probe, and control pin states, where 0 is always not triggered, and 1 is triggered. Invert masks ARE accounted for. Each field may be enabled or disabled via the `$10` status report setting. The probe and control pin flags are bits 5 and 6, respectively. - Remove the now deprecated `REPORT_CONTROL_PIN_STATE` option in config.h - The old limit pin reports `Lim:000` may be re-enabled by commenting out `REPORT_ALL_PIN_STATES` in config.h. - Incremented the version letter (v1.0c) to indicate the change in reporting style. - Replaced all bit_true_atomic and bit_false_atomic macros with function calls. This saved a couple hundred bytes of flash.
1 parent b9c3461 commit 5eee108

16 files changed

Lines changed: 182 additions & 63 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ Grbl includes full acceleration management with look ahead. That means the contr
3131

3232
***
3333

34-
##Update Summary for v1.0b
34+
##Update Summary for v1.0c
3535
- **IMPORTANT:** Your EEPROM will be wiped and restored with new settings. This is due to the addition of two new spindle speed '$' settings.
3636

37+
- Altered limit pin status reports from `Lim:000` to `Pin:000|0|0000`, where the `|` delimiters separate the new probe state and control pin states. Each new field may be disabled by the `$10` Grbl setting. NOTE: Commenting `REPORT_ALL_PIN_STATES` in config.h reverts to old `Lim:` reports, if needed.
38+
3739
- New safety door parking motion as a compile-option. Grbl will retract, disable the spindle/coolant, and park near Z max. When resumed, it will perform these task in reverse order and continue the program. Highly configurable. See config.h for details.
3840

3941
- New '$' Grbl settings for max and min spindle rpm. Allows for tweaking the PWM output to more closely match true spindle rpm. When max rpm is set to zero or less than min rpm, the PWM pin D11 will act like a simple enable on/off output.

doc/log/commit_log_v1.0b.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
----------------
2+
Date: 2015-09-30
3+
Author: Sonny Jeon
4+
Subject: Bug fixes.
5+
6+
- G38.x was not printing correctly in the $G g-code state reports. Now
7+
fixed.
8+
9+
- When investigating the above issue, it was noticed that G38.x
10+
wouldn’t show at all, but instead a G0 would be printed. This was
11+
unlike the v0.9j master build. It turned out volatile variables do not
12+
like to be defined inside a C struct. These are undefined on how to be
13+
handled. Once pulled out, all weird issues went away.
14+
15+
- Also changed two ‘sizeof()’ statements in the mc_probe() and
16+
probe_state_monitor() functions to be more robust later on.
17+
18+
- Updated the commit logs to individual files for each minor release.
19+
Forgot to update the generating script to account for this.
20+
21+
22+
----------------
23+
Date: 2015-09-30
24+
Author: Sonny Jeon
25+
Subject: Minor bug fixes.
26+
27+
- G38.x was not printing correctly in the $G g-code state reports. Now
28+
fixed.
29+
30+
- Potential bug regarding volatile variables inside a struct. It has
31+
never been a problem in v0.9, but ran into this during v1.0
32+
development. Just to be safe, the fixes are applied here.
33+
34+
- Updated pre-built firmwares with these two bug fixes.
35+
36+
137
----------------
238
Date: 2015-09-24
339
Author: Sonny Jeon

grbl/config.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@
164164
// uncomment the config option USE_SPINDLE_DIR_AS_ENABLE_PIN below.
165165
// #define INVERT_SPINDLE_ENABLE_PIN // Default disabled. Uncomment to enable.
166166

167-
// Enable control pin states feedback in status reports. The data is presented as simple binary of
168-
// the control pin port (0 (low) or 1(high)), masked to show only the input pins. Non-control pins on the
169-
// port will always show a 0 value. See cpu_map.h for the pin bitmap. As with the limit pin reporting,
170-
// we do not recommend keeping this option enabled. Try to only use this for setting up a new CNC.
171-
// #define REPORT_CONTROL_PIN_STATE // Default disabled. Uncomment to enable.
167+
// Enable all pin states feedback in status reports. Configurable with Grbl settings to print only
168+
// the desired data, which is presented as simple binary reading of each pin as (0 (low) or 1(high)).
169+
// The fields are printed in a particular order and settings groups are separated by '|' characters.
170+
// NOTE: This option is here for backward compatibility of the old style of pin state reports, i.e.
171+
// `Lim:000`. This new `Pin:` report will be the standard going forward.
172+
#define REPORT_ALL_PIN_STATES // Default enabled. Comment to disable.
172173

173174
// When Grbl powers-cycles or is hard reset with the Arduino reset button, Grbl boots up with no ALARM
174175
// by default. This is to make it as simple as possible for new users to start using Grbl. When homing

grbl/gcode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ uint8_t gc_execute_line(char *line)
10441044
protocol_buffer_synchronize(); // Sync and finish all remaining buffered motions before moving on.
10451045
if (gc_state.modal.program_flow == PROGRAM_FLOW_PAUSED) {
10461046
if (sys.state != STATE_CHECK_MODE) {
1047-
bit_true_atomic(sys_rt_exec_state, EXEC_FEED_HOLD); // Use feed hold for program pause.
1047+
system_set_exec_state_flag(EXEC_FEED_HOLD); // Use feed hold for program pause.
10481048
protocol_execute_realtime(); // Execute suspend.
10491049
}
10501050
} else { // == PROGRAM_FLOW_COMPLETED

grbl/grbl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#define grbl_h
2323

2424
// Grbl versioning system
25-
#define GRBL_VERSION "1.0b"
26-
#define GRBL_VERSION_BUILD "20150930"
25+
#define GRBL_VERSION "1.0c"
26+
#define GRBL_VERSION_BUILD "20151109"
2727

2828
// Define standard libraries used by Grbl.
2929
#include <avr/io.h>

grbl/limits.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ uint8_t limits_get_state()
106106
// Check limit pin state.
107107
if (limits_get_state()) {
108108
mc_reset(); // Initiate system kill.
109-
bit_true_atomic(sys_rt_exec_alarm, (EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate hard limit critical event
109+
system_set_exec_alarm_flag((EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate hard limit critical event
110110
}
111111
#else
112112
mc_reset(); // Initiate system kill.
113-
bit_true_atomic(sys_rt_exec_alarm, (EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate hard limit critical event
113+
system_set_exec_alarm_flag((EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate hard limit critical event
114114
#endif
115115
}
116116
}
@@ -126,7 +126,7 @@ uint8_t limits_get_state()
126126
// Check limit pin state.
127127
if (limits_get_state()) {
128128
mc_reset(); // Initiate system kill.
129-
bit_true_atomic(sys_rt_exec_alarm, (EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate hard limit critical event
129+
system_set_exec_alarm_flag((EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate hard limit critical event
130130
}
131131
}
132132
}
@@ -235,7 +235,7 @@ void limits_go_home(uint8_t cycle_mask)
235235
return;
236236
} else {
237237
// Pull-off motion complete. Disable CYCLE_STOP from executing.
238-
bit_false_atomic(sys_rt_exec_state,EXEC_CYCLE_STOP);
238+
system_clear_exec_state_flag(EXEC_CYCLE_STOP);
239239
break;
240240
}
241241
}
@@ -335,15 +335,15 @@ void limits_soft_check(float *target)
335335
// workspace volume so just come to a controlled stop so position is not lost. When complete
336336
// enter alarm mode.
337337
if (sys.state == STATE_CYCLE) {
338-
bit_true_atomic(sys_rt_exec_state, EXEC_FEED_HOLD);
338+
system_set_exec_state_flag(EXEC_FEED_HOLD);
339339
do {
340340
protocol_execute_realtime();
341341
if (sys.abort) { return; }
342342
} while ( sys.state != STATE_IDLE );
343343
}
344344

345345
mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown.
346-
bit_true_atomic(sys_rt_exec_alarm, (EXEC_ALARM_SOFT_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate soft limit critical event
346+
system_set_exec_alarm_flag((EXEC_ALARM_SOFT_LIMIT|EXEC_CRITICAL_EVENT)); // Indicate soft limit critical event
347347
protocol_execute_realtime(); // Execute to enter critical event loop and system abort
348348
return;
349349
}

grbl/motion_control.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void mc_homing_cycle()
220220
#ifdef LIMITS_TWO_SWITCHES_ON_AXES
221221
if (limits_get_state()) {
222222
mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown.
223-
bit_true_atomic(sys_rt_exec_alarm, (EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT));
223+
system_set_exec_alarm_flag((EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT));
224224
return;
225225
}
226226
#endif
@@ -276,7 +276,7 @@ void mc_homing_cycle()
276276
// After syncing, check if probe is already triggered. If so, halt and issue alarm.
277277
// NOTE: This probe initialization error applies to all probing cycles.
278278
if ( probe_get_state() ) { // Check probe pin state.
279-
bit_true_atomic(sys_rt_exec_alarm, EXEC_ALARM_PROBE_FAIL);
279+
system_set_exec_alarm_flag(EXEC_ALARM_PROBE_FAIL);
280280
protocol_execute_realtime();
281281
}
282282
if (sys.abort) { return; } // Return if system reset has been issued.
@@ -292,7 +292,7 @@ void mc_homing_cycle()
292292
sys_probe_state = PROBE_ACTIVE;
293293

294294
// Perform probing cycle. Wait here until probe is triggered or motion completes.
295-
bit_true_atomic(sys_rt_exec_state, EXEC_CYCLE_START);
295+
system_set_exec_state_flag(EXEC_CYCLE_START);
296296
do {
297297
protocol_execute_realtime();
298298
if (sys.abort) { return; } // Check for system abort
@@ -303,7 +303,7 @@ void mc_homing_cycle()
303303
// Set state variables and error out, if the probe failed and cycle with error is enabled.
304304
if (sys_probe_state == PROBE_ACTIVE) {
305305
if (is_no_error) { memcpy(sys.probe_position, sys.position, sizeof(sys.position)); }
306-
else { bit_true_atomic(sys_rt_exec_alarm, EXEC_ALARM_PROBE_FAIL); }
306+
else { system_set_exec_alarm_flag(EXEC_ALARM_PROBE_FAIL); }
307307
} else {
308308
sys.probe_succeeded = true; // Indicate to system the probing cycle completed successfully.
309309
}
@@ -366,7 +366,7 @@ void mc_reset()
366366
{
367367
// Only this function can set the system reset. Helps prevent multiple kill calls.
368368
if (bit_isfalse(sys_rt_exec_state, EXEC_RESET)) {
369-
bit_true_atomic(sys_rt_exec_state, EXEC_RESET);
369+
system_set_exec_state_flag(EXEC_RESET);
370370

371371
// Kill spindle and coolant.
372372
spindle_stop();
@@ -378,8 +378,8 @@ void mc_reset()
378378
// violated, by which, all bets are off.
379379
if ((sys.state & (STATE_CYCLE | STATE_HOMING)) ||
380380
(sys.step_control & (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_PARK))) {
381-
if (sys.state == STATE_HOMING) { bit_true_atomic(sys_rt_exec_alarm, EXEC_ALARM_HOMING_FAIL); }
382-
else { bit_true_atomic(sys_rt_exec_alarm, EXEC_ALARM_ABORT_CYCLE); }
381+
if (sys.state == STATE_HOMING) { system_set_exec_alarm_flag(EXEC_ALARM_HOMING_FAIL); }
382+
else { system_set_exec_alarm_flag(EXEC_ALARM_ABORT_CYCLE); }
383383
st_go_idle(); // Force kill steppers. Position has likely been lost.
384384
}
385385
}

grbl/nuts_bolts.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@
5656

5757
// Bit field and masking macros
5858
#define bit(n) (1 << n)
59-
#define bit_true_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) |= (mask); SREG = sreg; }
60-
#define bit_false_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) &= ~(mask); SREG = sreg; }
61-
#define bit_toggle_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) ^= (mask); SREG = sreg; }
6259
#define bit_true(x,mask) (x) |= (mask)
6360
#define bit_false(x,mask) (x) &= ~(mask)
6461
#define bit_istrue(x,mask) ((x & mask) != 0)

grbl/probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void probe_init()
3434
#else
3535
PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation.
3636
#endif
37-
// probe_configure_invert_mask(false); // Initialize invert mask. Not required. Updated when in-use.
37+
probe_configure_invert_mask(false); // Initialize invert mask. Re-updated during use.
3838
}
3939

4040

grbl/protocol.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void protocol_buffer_synchronize()
190190
// when one of these conditions exist respectively: There are no more blocks sent (i.e. streaming
191191
// is finished, single commands), a command that needs to wait for the motions in the buffer to
192192
// execute calls a buffer sync, or the planner buffer is full and ready to go.
193-
void protocol_auto_cycle_start() { bit_true_atomic(sys_rt_exec_state, EXEC_CYCLE_START); }
193+
void protocol_auto_cycle_start() { system_set_exec_state_flag(EXEC_CYCLE_START); }
194194

195195

196196
// This function is the general interface to Grbl's real-time command execution system. It is called
@@ -237,7 +237,7 @@ void protocol_exec_rt_system()
237237
// Halt everything upon a critical event flag. Currently hard and soft limits flag this.
238238
if (rt_exec & EXEC_CRITICAL_EVENT) {
239239
report_feedback_message(MESSAGE_CRITICAL_EVENT);
240-
bit_false_atomic(sys_rt_exec_state,EXEC_RESET); // Disable any existing reset
240+
system_clear_exec_state_flag(EXEC_RESET); // Disable any existing reset
241241
do {
242242
// Block everything, except reset and status reports, until user issues reset or power
243243
// cycles. Hard limits typically occur while unattended or not paying attention. Gives
@@ -248,12 +248,12 @@ void protocol_exec_rt_system()
248248
// TODO: Allow status reports during a critical alarm. Still need to think about implications of this.
249249
// if (sys_rt_exec_state & EXEC_STATUS_REPORT) {
250250
// report_realtime_status();
251-
// bit_false_atomic(sys_rt_exec_state,EXEC_STATUS_REPORT);
251+
// system_clear_exec_state_flag(EXEC_STATUS_REPORT);
252252
// }
253253

254254
} while (bit_isfalse(sys_rt_exec_state,EXEC_RESET));
255255
}
256-
bit_false_atomic(sys_rt_exec_alarm,0xFF); // Clear all alarm flags
256+
system_clear_exec_alarm_flag(0xFF); // Clear all alarm flags
257257
}
258258

259259
rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state.
@@ -268,7 +268,7 @@ void protocol_exec_rt_system()
268268
// Execute and serial print status
269269
if (rt_exec & EXEC_STATUS_REPORT) {
270270
report_realtime_status();
271-
bit_false_atomic(sys_rt_exec_state,EXEC_STATUS_REPORT);
271+
system_clear_exec_state_flag(EXEC_STATUS_REPORT);
272272
}
273273

274274
// NOTE: The math involved to calculate the hold should be low enough for most, if not all,
@@ -340,7 +340,7 @@ void protocol_exec_rt_system()
340340

341341
}
342342

343-
bit_false_atomic(sys_rt_exec_state,(EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR));
343+
system_clear_exec_state_flag((EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR));
344344
}
345345

346346
// Execute a cycle start by starting the stepper interrupt to begin executing the blocks in queue.
@@ -380,7 +380,7 @@ void protocol_exec_rt_system()
380380
}
381381
}
382382
}
383-
bit_false_atomic(sys_rt_exec_state,EXEC_CYCLE_START);
383+
system_clear_exec_state_flag(EXEC_CYCLE_START);
384384
}
385385

386386
if (rt_exec & EXEC_CYCLE_STOP) {
@@ -399,7 +399,7 @@ void protocol_exec_rt_system()
399399
sys.suspend = SUSPEND_DISABLE;
400400
sys.state = STATE_IDLE;
401401
}
402-
bit_false_atomic(sys_rt_exec_state,EXEC_CYCLE_STOP);
402+
system_clear_exec_state_flag(EXEC_CYCLE_STOP);
403403
}
404404
}
405405

@@ -544,7 +544,7 @@ static void protocol_exec_rt_suspend()
544544

545545
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
546546
sys.suspend |= SUSPEND_RESTORE_COMPLETE;
547-
bit_true_atomic(sys_rt_exec_state,EXEC_CYCLE_START); // Set to resume program.
547+
system_set_exec_state_flag(EXEC_CYCLE_START); // Set to resume program.
548548
}
549549
}
550550

0 commit comments

Comments
 (0)