Commit | Line | Data |
---|---|---|
4cff3ded AW |
1 | /* |
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/>. | |
6 | */ | |
7 | ||
8 | using namespace std; | |
9 | #include <vector> | |
10 | #include "libs/Kernel.h" | |
11 | #include "libs/Module.h" | |
12 | #include "libs/Config.h" | |
4cff3ded | 13 | #include "libs/nuts_bolts.h" |
ded56b35 | 14 | #include "libs/SlowTicker.h" |
3c132bd0 | 15 | #include "libs/Adc.h" |
0e8b102e | 16 | #include "libs/Digipot.h" |
81b547a1 | 17 | #include "libs/Pauser.h" |
38d375e7 | 18 | #include "libs/StreamOutputPool.h" |
4cff3ded AW |
19 | |
20 | #include "modules/communication/SerialConsole.h" | |
21 | #include "modules/communication/GcodeDispatch.h" | |
22 | #include "modules/robot/Planner.h" | |
23 | #include "modules/robot/Robot.h" | |
24 | #include "modules/robot/Stepper.h" | |
3a4fa0c1 | 25 | #include "modules/robot/Player.h" |
4cff3ded | 26 | |
ded56b35 | 27 | |
4cff3ded AW |
28 | // List of callback functions, ordered as their corresponding events |
29 | const ModuleCallback kernel_callback_functions[NUMBER_OF_DEFINED_EVENTS] = { | |
30 | &Module::on_main_loop, | |
31 | &Module::on_console_line_received, | |
32 | &Module::on_gcode_received, | |
33 | &Module::on_stepper_wake_up, | |
34 | &Module::on_gcode_execute, | |
35 | &Module::on_speed_change, | |
36 | &Module::on_block_begin, | |
da24d6ae | 37 | &Module::on_block_end, |
befcf5cc AW |
38 | &Module::on_config_reload, |
39 | &Module::on_play, | |
70c25627 L |
40 | &Module::on_pause, |
41 | &Module::on_idle | |
4cff3ded AW |
42 | }; |
43 | ||
8c309ca9 | 44 | #define baud_rate_setting_checksum 10922 |
3c132bd0 | 45 | #define uart0_checksum 16877 |
4cff3ded AW |
46 | |
47 | // The kernel is the central point in Smoothie : it stores modules, and handles event calls | |
48 | Kernel::Kernel(){ | |
ded56b35 | 49 | |
4cff3ded AW |
50 | // Config first, because we need the baud_rate setting before we start serial |
51 | this->config = new Config(); | |
52 | // Serial second, because the other modules might want to say something | |
38d375e7 | 53 | this->streams = new StreamOutputPool(); |
4cff3ded | 54 | |
7790a7c4 AW |
55 | //this->serial = new SerialConsole(USBTX, USBRX, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number()); |
56 | ||
4cff3ded | 57 | this->add_module( this->config ); |
7790a7c4 | 58 | //this->add_module( this->serial ); |
38d375e7 | 59 | |
3c132bd0 AW |
60 | // HAL stuff |
61 | this->slow_ticker = new SlowTicker(); | |
3c132bd0 AW |
62 | this->step_ticker = new StepTicker(); |
63 | this->adc = new Adc(); | |
0e8b102e | 64 | this->digipot = new Digipot(); |
3c132bd0 | 65 | |
cd011f58 | 66 | // LPC17xx-specific |
3b1e82d2 AW |
67 | NVIC_SetPriority(TIMER0_IRQn, 1); |
68 | NVIC_SetPriority(TIMER2_IRQn, 2); | |
b6c86164 | 69 | |
4cff3ded | 70 | // Core modules |
81b547a1 AW |
71 | this->add_module( this->gcode_dispatch = new GcodeDispatch() ); |
72 | this->add_module( this->robot = new Robot() ); | |
73 | this->add_module( this->stepper = new Stepper() ); | |
74 | this->add_module( this->planner = new Planner() ); | |
75 | this->add_module( this->player = new Player() ); | |
76 | this->add_module( this->pauser = new Pauser() ); | |
4cff3ded AW |
77 | } |
78 | ||
79 | void Kernel::add_module(Module* module){ | |
80 | module->kernel = this; | |
81 | module->on_module_loaded(); | |
b66fb830 | 82 | module->register_for_event(ON_CONFIG_RELOAD); |
4cff3ded AW |
83 | } |
84 | ||
85 | void Kernel::register_for_event(unsigned int id_event, Module* module){ | |
86 | this->hooks[id_event].push_back(module); | |
87 | } | |
88 | ||
89 | void Kernel::call_event(unsigned int id_event){ | |
90 | for(unsigned int i=0; i < this->hooks[id_event].size(); i++){ | |
91 | (this->hooks[id_event][i]->*kernel_callback_functions[id_event])(this); | |
92 | } | |
93 | } | |
94 | ||
95 | void Kernel::call_event(unsigned int id_event, void * argument){ | |
96 | for(unsigned int i=0; i < this->hooks[id_event].size(); i++){ | |
97 | (this->hooks[id_event][i]->*kernel_callback_functions[id_event])(argument); | |
98 | } | |
99 | } |