2009-01-25 00:48:56 +01:00
|
|
|
/*
|
|
|
|
main.c - An embedded CNC Controller with rs274/ngc (g-code) support
|
|
|
|
Part of Grbl
|
|
|
|
|
2011-01-14 16:45:18 +01:00
|
|
|
Copyright (c) 2009-2011 Simen Svale Skogsrud
|
2011-12-09 02:47:48 +01:00
|
|
|
Copyright (c) 2011 Sungeun K. Jeon
|
2012-01-06 18:10:41 +01:00
|
|
|
|
2009-01-25 00:48:56 +01:00
|
|
|
Grbl is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Grbl is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-05-31 13:08:42 +02:00
|
|
|
#include <avr/interrupt.h>
|
2011-12-09 02:47:48 +01:00
|
|
|
#include <avr/pgmspace.h>
|
2011-06-03 15:28:14 +02:00
|
|
|
#include "config.h"
|
2011-02-11 00:34:53 +01:00
|
|
|
#include "planner.h"
|
2011-12-09 02:47:48 +01:00
|
|
|
#include "nuts_bolts.h"
|
2009-01-28 23:48:21 +01:00
|
|
|
#include "stepper.h"
|
|
|
|
#include "spindle_control.h"
|
2009-01-25 00:48:56 +01:00
|
|
|
#include "motion_control.h"
|
|
|
|
#include "gcode.h"
|
2011-02-18 22:11:53 +01:00
|
|
|
#include "protocol.h"
|
2011-02-20 00:29:56 +01:00
|
|
|
#include "limits.h"
|
2011-02-05 00:45:41 +01:00
|
|
|
#include "settings.h"
|
2011-05-31 22:45:38 +02:00
|
|
|
#include "serial.h"
|
2009-02-03 09:56:45 +01:00
|
|
|
|
2012-01-06 18:10:41 +01:00
|
|
|
// Declare system global variable structure
|
|
|
|
system_t sys;
|
2011-12-09 02:47:48 +01:00
|
|
|
|
2009-01-25 00:48:56 +01:00
|
|
|
int main(void)
|
|
|
|
{
|
2011-12-09 02:47:48 +01:00
|
|
|
// Initialize system
|
|
|
|
sei(); // Enable interrupts
|
|
|
|
serial_init(BAUD_RATE); // Setup serial baud rate and interrupts
|
|
|
|
st_init(); // Setup stepper pins and interrupt timers
|
2012-01-06 18:10:41 +01:00
|
|
|
|
|
|
|
sys.abort = true; // Set abort to complete initialization
|
2011-02-12 00:03:58 +01:00
|
|
|
|
2011-12-09 02:47:48 +01:00
|
|
|
while(1) {
|
|
|
|
|
2012-01-06 18:10:41 +01:00
|
|
|
// Execute system reset upon a system abort, where the main program will return to this loop.
|
|
|
|
// Once here, it is safe to re-initialize the system. At startup, the system will automatically
|
|
|
|
// reset to finish the initialization process.
|
|
|
|
if (sys.abort) {
|
|
|
|
|
|
|
|
// Clear all system variables
|
|
|
|
memset(&sys, 0, sizeof(sys));
|
2011-12-09 02:47:48 +01:00
|
|
|
|
|
|
|
// Reset system.
|
|
|
|
serial_reset_read_buffer(); // Clear serial read buffer
|
|
|
|
settings_init(); // Load grbl settings from EEPROM
|
|
|
|
protocol_init(); // Clear incoming line data
|
|
|
|
plan_init(); // Clear block buffer and planner variables
|
|
|
|
gc_init(); // Set g-code parser to default state
|
|
|
|
spindle_init();
|
|
|
|
limits_init();
|
2012-01-06 18:10:41 +01:00
|
|
|
st_reset(); // Clear stepper subsystem variables.
|
|
|
|
|
|
|
|
// Set system runtime defaults
|
|
|
|
// TODO: Eventual move to EEPROM from config.h when all of the new settings are worked out.
|
|
|
|
// Mainly to avoid having to maintain several different versions.
|
|
|
|
#ifdef CYCLE_AUTO_START
|
|
|
|
sys.auto_start = true;
|
|
|
|
#endif
|
2011-12-09 02:47:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protocol_execute_runtime();
|
2011-02-18 22:19:01 +01:00
|
|
|
protocol_process(); // ... process the serial protocol
|
2011-12-09 02:47:48 +01:00
|
|
|
|
2009-01-25 00:48:56 +01:00
|
|
|
}
|
|
|
|
return 0; /* never reached */
|
|
|
|
}
|