LAT Hologramm-Software 2.0
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1/*
2 main.c - An embedded CNC Controller with rs274/ngc (g-code) support
3 Part of Grbl
4
5 Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
6 Copyright (c) 2009-2011 Simen Svale Skogsrud
7
8 Grbl is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 Grbl is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Grbl. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "grbl.h"
23
24
25// Declare system global variable structure
27int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps.
28int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
29volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
30volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
31volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms.
32volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
33volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
34#ifdef DEBUG
35 volatile uint8_t sys_rt_exec_debug;
36#endif
37
38
39int main(void)
40{
41 // Initialize system upon power-up.
42 serial_init(); // Setup serial baud rate and interrupts
43 settings_init(); // Load Grbl settings from EEPROM
44 stepper_init(); // Configure stepper pins and interrupt timers
45 system_init(); // Configure pinout pins and pin-change interrupt
46
47 memset(sys_position,0,sizeof(sys_position)); // Clear machine position.
48 sei(); // Enable interrupts
49
50 // Initialize system state.
51 #ifdef FORCE_INITIALIZATION_ALARM
52 // Force Grbl into an ALARM state upon a power-cycle or hard reset.
54 #else
56 #endif
57
58 // Check for power-up and set system alarm if homing is enabled to force homing cycle
59 // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
60 // startup scripts, but allows access to settings and internal commands. Only a homing
61 // cycle '$H' or kill alarm locks '$X' will disable the alarm.
62 // NOTE: The startup script will run after successful completion of the homing cycle, but
63 // not after disabling the alarm locks. Prevents motion startup blocks from crashing into
64 // things uncontrollably. Very bad.
65 #ifdef HOMING_INIT_LOCK
67 #endif
68
69 // Grbl initialization loop upon power-up or a system abort. For the latter, all processes
70 // will return to this loop to be cleanly re-initialized.
71 for(;;) {
72
73 // Reset system variables.
74 uint8_t prior_state = sys.state;
75 memset(&sys, 0, sizeof(system_t)); // Clear system struct variable.
76 sys.state = prior_state;
77 sys.f_override = DEFAULT_FEED_OVERRIDE; // Set to 100%
78 sys.r_override = DEFAULT_RAPID_OVERRIDE; // Set to 100%
80 memset(sys_probe_position,0,sizeof(sys_probe_position)); // Clear probe position.
86
87 // Reset Grbl primary systems.
88 serial_reset_read_buffer(); // Clear serial read buffer
89 gc_init(); // Set g-code parser to default state
93 probe_init();
94 plan_reset(); // Clear block buffer and planner variables
95 st_reset(); // Clear stepper subsystem variables.
96
97 // Sync cleared gcode and planner positions to current system position.
100
101 // Print welcome message. Indicates an initialization has occured at power-up or with a reset.
103
104 // Start Grbl main loop. Processes program inputs and executes them.
106
107 }
108 return 0; /* Never reached */
109}
#define DEFAULT_RAPID_OVERRIDE
Definition: config.h:247
#define DEFAULT_FEED_OVERRIDE
Definition: config.h:241
#define DEFAULT_SPINDLE_SPEED_OVERRIDE
Definition: config.h:252
void coolant_init()
void gc_sync_position()
Definition: gcode.c:55
void gc_init()
Definition: gcode.c:42
void limits_init()
Definition: limits.c:41
int32_t sys_position[N_AXIS]
Definition: main.c:27
int32_t sys_probe_position[N_AXIS]
Definition: main.c:28
volatile uint8_t sys_probe_state
Definition: main.c:29
volatile uint8_t sys_rt_exec_alarm
Definition: main.c:31
system_t sys
Definition: main.c:26
int main(void)
Definition: main.c:39
volatile uint8_t sys_rt_exec_accessory_override
Definition: main.c:33
volatile uint8_t sys_rt_exec_motion_override
Definition: main.c:32
volatile uint8_t sys_rt_exec_state
Definition: main.c:30
#define bit_istrue(x, mask)
Definition: nuts_bolts.h:64
#define N_AXIS
Definition: nuts_bolts.h:31
void plan_sync_position()
Definition: planner.c:476
void plan_reset()
Definition: planner.c:199
void probe_init()
Definition: probe.c:29
void protocol_main_loop()
Definition: protocol.c:38
void report_init_message()
Definition: report.c:170
void serial_reset_read_buffer()
Definition: serial.c:201
void serial_init()
Definition: serial.c:65
settings_t settings
Definition: settings.c:24
void settings_init()
Definition: settings.c:307
#define BITFLAG_HOMING_ENABLE
Definition: settings.h:46
void spindle_init()
void st_reset()
Definition: stepper.c:535
void stepper_init()
Definition: stepper.c:566
uint8_t flags
Definition: settings.h:106
uint8_t r_override
Definition: system.h:139
uint8_t spindle_speed_ovr
Definition: system.h:140
uint8_t f_override
Definition: system.h:138
uint8_t state
Definition: system.h:128
void system_init()
Definition: system.c:24
#define STATE_ALARM
Definition: system.h:77
#define STATE_IDLE
Definition: system.h:76