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
|
|
|
|
Copyright (c) 2011 Jens Geisler
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/sleep.h>
|
2011-05-31 13:08:42 +02:00
|
|
|
#include <avr/interrupt.h>
|
2011-12-09 02:47:48 +01:00
|
|
|
#include <avr/pgmspace.h>
|
2009-02-03 09:56:45 +01:00
|
|
|
#include <util/delay.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"
|
2009-01-25 00:48:56 +01:00
|
|
|
|
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
|
|
|
|
2011-12-09 02:47:48 +01:00
|
|
|
#include "print.h"
|
|
|
|
|
|
|
|
// Declare system global variables
|
|
|
|
uint8_t sys_abort; // Global system abort flag
|
|
|
|
volatile uint8_t sys_state; // Global system state variable
|
|
|
|
|
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
|
|
|
|
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) {
|
|
|
|
|
|
|
|
// Upon a system abort, the main program will return to this loop. Once here, it is safe to
|
|
|
|
// re-initialize the system. Upon startup, the system will automatically reset to finish the
|
|
|
|
// initialization process.
|
|
|
|
if (sys_abort) {
|
|
|
|
// Execute system reset
|
|
|
|
sys_state = 0; // Reset system state
|
|
|
|
sys_abort = false; // Release system abort
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// TODO: For now, the stepper subsystem tracks the absolute stepper position from the point
|
|
|
|
// of power up or hard reset. This reset is a soft reset, where the information of the current
|
|
|
|
// position is not lost after a system abort. This is not guaranteed to be correct, since
|
|
|
|
// during an abort, the steppers can lose steps in the immediate stop. However, if a feed
|
|
|
|
// hold is performed before a system abort, this position should be correct. In the next few
|
|
|
|
// updates, this soft reset feature will be fleshed out along with the status reporting and
|
|
|
|
// jogging features.
|
|
|
|
st_reset(); // Clear stepper subsystem variables. Machine position variable is not reset.
|
|
|
|
|
|
|
|
// Print grbl initialization message
|
|
|
|
printPgmString(PSTR("\r\nGrbl " GRBL_VERSION));
|
|
|
|
printPgmString(PSTR("\r\n'$' to dump current settings\r\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
|
|
|
}
|