MCPcopy Create free account
hub / github.com/bdring/FluidNC / protocol_main_loop

Function protocol_main_loop

FluidNC/src/Protocol.cpp:240–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238int32_t heapLowWaterReportTime = 0;
239
240void protocol_main_loop() {
241 add_watchdog_to_task();
242 start_polling();
243
244 // ---------------------------------------------------------------------------------
245 // Primary loop! Upon a system abort, this exits back to main() to reset the system.
246 // This is also where the system idles while waiting for something to do.
247 // ---------------------------------------------------------------------------------
248 for (;; vTaskDelay(1)) {
249 if (activeChannel) {
250 // The input polling task has collected a line of input
251 if (gcode_echo->get()) {
252 report_echo_line_received(activeLine, allChannels);
253 }
254
255 Channel* out_channel = Job::leader ? Job::leader : activeChannel;
256
257 Error status_code = execute_line(activeLine, *out_channel, AuthenticationLevel::LEVEL_GUEST);
258
259 // Tell the channel that the line has been processed.
260 // If the line was aborted, the channel could be invalid
261 if (!sys.abort()) {
262 activeChannel->ack(status_code);
263 }
264
265 // Tell the input polling task that the line has been processed,
266 // so it can give us another one when available
267 activeChannel = nullptr;
268 }
269
270 // Auto-cycle start any queued moves.
271 protocol_auto_cycle_start();
272 protocol_execute_realtime(); // Runtime command check point.
273 sys.process_changes();
274
275 if (sys.abort()) {
276 sys.set_abort(false);
277 }
278
279 // check to see if we should disable the stepper drivers
280 // If idleEndTime is 0, no disable is pending.
281
282 // "(ticks() - EndTime) > 0" is a twos-complement arithmetic trick
283 // for avoiding problems when the number space wraps around from
284 // negative to positive or vice-versa. It always works if EndTime
285 // is set to "timer() + N" where N is less than half the number
286 // space. Using "timer() > EndTime" fails across the positive to
287 // negative transition using signed comparison, and across the
288 // negative to positive transition using unsigned.
289
290 if (idleEndTime && (getCpuTicks() - idleEndTime) > 0) {
291 idleEndTime = 0; //
292 Axes::set_disable(true, false);
293 }
294 uint32_t newHeapSize = xPortGetFreeHeapSize();
295 if (newHeapSize < heapLowWater) {
296 heapLowWater = newHeapSize;
297 }

Callers 1

loopFunction · 0.85

Calls 15

start_pollingFunction · 0.85
vTaskDelayFunction · 0.85
execute_lineFunction · 0.85
xPortGetFreeHeapSizeFunction · 0.85
process_changesMethod · 0.80
set_abortMethod · 0.80
add_watchdog_to_taskFunction · 0.50
getCpuTicksFunction · 0.50
usToCpuTicksFunction · 0.50

Tested by

no test coverage detected