2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie 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.
4 Smoothie 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.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
8 #include "libs/Kernel.h"
10 #include "modules/tools/laser/Laser.h"
11 #include "modules/tools/extruder/ExtruderMaker.h"
12 #include "modules/tools/temperaturecontrol/TemperatureControlPool.h"
13 #include "modules/tools/endstops/Endstops.h"
14 #include "modules/tools/touchprobe/Touchprobe.h"
15 #include "modules/tools/zprobe/ZProbe.h"
16 #include "modules/tools/scaracal/SCARAcal.h"
17 #include "modules/tools/switch/SwitchPool.h"
18 #include "modules/tools/temperatureswitch/TemperatureSwitch.h"
20 #include "modules/robot/Conveyor.h"
21 #include "modules/utils/simpleshell/SimpleShell.h"
22 #include "modules/utils/configurator/Configurator.h"
23 #include "modules/utils/currentcontrol/CurrentControl.h"
24 #include "modules/utils/player/Player.h"
25 #include "modules/utils/pausebutton/PauseButton.h"
26 #include "modules/utils/PlayLed/PlayLed.h"
27 #include "modules/utils/panel/Panel.h"
28 #include "libs/Network/uip/Network.h"
30 #include "checksumm.h"
31 #include "ConfigValue.h"
33 // #include "libs/ChaNFSSD/SDFileSystem.h"
34 #include "libs/nuts_bolts.h"
35 #include "libs/utils.h"
38 #include "libs/SerialMessage.h"
40 #include "libs/USBDevice/USB.h"
41 #include "libs/USBDevice/USBMSD/USBMSD.h"
42 #include "libs/USBDevice/USBMSD/SDCard.h"
43 #include "libs/USBDevice/USBSerial/USBSerial.h"
44 #include "libs/USBDevice/DFU.h"
45 #include "libs/SDFAT.h"
46 #include "StreamOutputPool.h"
47 #include "ToolManager.h"
49 #include "libs/Watchdog.h"
52 #include "system_LPC17xx.h"
56 #define second_usb_serial_enable_checksum CHECKSUM("second_usb_serial_enable")
57 #define disable_msd_checksum CHECKSUM("msd_disable")
58 #define disable_leds_checksum CHECKSUM("leds_disable")
60 // Watchdog wd(5000000, WDT_MRI);
63 SDCard sd
__attribute__ ((section ("AHBSRAM0"))) (P0_9
, P0_8
, P0_7
, P0_6
); // this selects SPI1 as the sdcard as it is on Smoothieboard
64 //SDCard sd(P0_18, P0_17, P0_15, P0_16); // this selects SPI0 as the sdcard
66 USB u
__attribute__ ((section ("AHBSRAM0")));
67 USBSerial usbserial
__attribute__ ((section ("AHBSRAM0"))) (&u
);
68 USBMSD msc
__attribute__ ((section ("AHBSRAM0"))) (&u
, &sd
);
70 DFU dfu
__attribute__ ((section ("AHBSRAM0"))) (&u
);
72 SDFAT mounter
__attribute__ ((section ("AHBSRAM0"))) ("sd", &sd
);
84 // Default pins to low status
85 for (int i
= 0; i
< 5; i
++){
90 Kernel
* kernel
= new Kernel();
92 kernel
->streams
->printf("Smoothie Running @%ldMHz\r\n", SystemCoreClock
/ 1000000);
94 kernel
->streams
->printf(" Build version %s, Build date %s\r\n", version
.get_build(), version
.get_build_date());
96 //some boards don't have leds.. TOO BAD!
97 kernel
->use_leds
= !kernel
->config
->value( disable_leds_checksum
)->by_default(false)->as_bool();
99 // attempt to be able to disable msd in config
100 // if(!kernel->config->value( disable_msd_checksum )->by_default(false)->as_bool()){
101 // msc= new USBMSD(&u, &sd);
104 // kernel->streams->printf("MSD is disabled\r\n");
107 bool sdok
= (sd
.disk_initialize() == 0);
109 // Create and add main modules
110 kernel
->add_module( new SimpleShell() );
111 kernel
->add_module( new Configurator() );
112 kernel
->add_module( new CurrentControl() );
113 kernel
->add_module( new PauseButton() );
114 kernel
->add_module( new PlayLed() );
115 kernel
->add_module( new Endstops() );
116 kernel
->add_module( new Player() );
119 // these modules can be completely disabled in the Makefile by adding to EXCLUDE_MODULES
120 #ifndef NO_TOOLS_SWITCH
121 SwitchPool
*sp
= new SwitchPool();
125 #ifndef NO_TOOLS_EXTRUDER
126 // NOTE this must be done first before Temperature control so ToolManager can handle Tn before temperaturecontrol module does
127 ExtruderMaker
*em
= new ExtruderMaker();
131 #ifndef NO_TOOLS_TEMPERATURECONTROL
132 // Note order is important here must be after extruder so Tn as a parameter will get executed first
133 TemperatureControlPool
*tp
= new TemperatureControlPool();
137 #ifndef NO_TOOLS_LASER
138 kernel
->add_module( new Laser() );
140 #ifndef NO_UTILS_PANEL
141 kernel
->add_module( new Panel() );
143 #ifndef NO_TOOLS_TOUCHPROBE
144 kernel
->add_module( new Touchprobe() );
146 #ifndef NO_TOOLS_ZPROBE
147 kernel
->add_module( new ZProbe() );
149 #ifndef NO_TOOLS_SCARACAL
150 kernel
->add_module( new SCARAcal() );
153 kernel
->add_module( new Network() );
155 #ifndef NO_TOOLS_TEMPERATURESWITCH
156 kernel
->add_module( new TemperatureSwitch() );
159 // Create and initialize USB stuff
161 //if(sdok) { // only do this if there is an sd disk
162 // msc= new USBMSD(&u, &sd);
163 // kernel->add_module( msc );
167 // kernel->add_module( msc );
170 kernel
->add_module( &msc
);
171 kernel
->add_module( &usbserial
);
172 if( kernel
->config
->value( second_usb_serial_enable_checksum
)->by_default(false)->as_bool() ){
173 kernel
->add_module( new USBSerial(&u
) );
175 kernel
->add_module( &dfu
);
176 kernel
->add_module( &u
);
178 // clear up the config cache to save some memory
179 kernel
->config
->config_cache_clear();
181 if(kernel
->use_leds
) {
182 // set some leds to indicate status... led0 init doe, led1 mainloop running, led2 idle loop running, led3 sdcard ok
183 leds
[0]= 1; // indicate we are done with init
184 leds
[3]= sdok
?1:0; // 4th led inidicates sdcard is available (TODO maye should indicate config was found)
188 // load config override file if present
189 // NOTE only Mxxx commands that set values should be put in this file. The file is generated by M500
190 FILE *fp
= fopen(kernel
->config_override_filename(), "r");
193 kernel
->streams
->printf("Loading config override file: %s...\n", kernel
->config_override_filename());
194 while(fgets(buf
, sizeof buf
, fp
) != NULL
) {
195 kernel
->streams
->printf(" %s", buf
);
196 if(buf
[0] == ';') continue; // skip the comments
197 struct SerialMessage message
= {&(StreamOutput::NullStream
), buf
};
198 kernel
->call_event(ON_CONSOLE_LINE_RECEIVED
, &message
);
200 kernel
->streams
->printf("config override file executed\n");
213 if(THEKERNEL
->use_leds
) {
214 // flash led 2 to show we are alive
215 leds
[1]= (cnt
++ & 0x1000) ? 1 : 0;
217 THEKERNEL
->call_event(ON_MAIN_LOOP
);
218 THEKERNEL
->call_event(ON_IDLE
);