Fork of Smoothie to port to mbed non-LPC targets.
Fork of Smoothie by
libs/Kernel.cpp@3:f151d08d335c, 2014-03-02 (annotated)
- Committer:
- Bigcheese
- Date:
- Sun Mar 02 06:33:08 2014 +0000
- Revision:
- 3:f151d08d335c
- Parent:
- 2:1df0b61d3b5a
Bunch of stuff. Need to locally merge in updated USB changes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Michael J. Spencer |
2:1df0b61d3b5a | 1 | /* |
scachat | 0:31e91bb0ef3c | 2 | This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). |
scachat | 0:31e91bb0ef3c | 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. |
scachat | 0:31e91bb0ef3c | 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. |
Michael J. Spencer |
2:1df0b61d3b5a | 5 | You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. |
scachat | 0:31e91bb0ef3c | 6 | */ |
scachat | 0:31e91bb0ef3c | 7 | |
scachat | 0:31e91bb0ef3c | 8 | #include "libs/Kernel.h" |
scachat | 0:31e91bb0ef3c | 9 | #include "libs/Module.h" |
scachat | 0:31e91bb0ef3c | 10 | #include "libs/Config.h" |
scachat | 0:31e91bb0ef3c | 11 | #include "libs/nuts_bolts.h" |
scachat | 0:31e91bb0ef3c | 12 | #include "libs/SlowTicker.h" |
scachat | 0:31e91bb0ef3c | 13 | #include "libs/Pauser.h" |
Michael J. Spencer |
2:1df0b61d3b5a | 14 | #include "libs/StreamOutputPool.h" |
scachat | 0:31e91bb0ef3c | 15 | |
scachat | 0:31e91bb0ef3c | 16 | #include "modules/communication/SerialConsole.h" |
scachat | 0:31e91bb0ef3c | 17 | #include "modules/communication/GcodeDispatch.h" |
scachat | 0:31e91bb0ef3c | 18 | #include "modules/robot/Planner.h" |
scachat | 0:31e91bb0ef3c | 19 | #include "modules/robot/Robot.h" |
scachat | 0:31e91bb0ef3c | 20 | #include "modules/robot/Stepper.h" |
Michael J. Spencer |
2:1df0b61d3b5a | 21 | #include "modules/robot/Conveyor.h" |
Michael J. Spencer |
2:1df0b61d3b5a | 22 | #include "modules/tools/endstops/Endstops.h" |
scachat | 0:31e91bb0ef3c | 23 | |
Michael J. Spencer |
2:1df0b61d3b5a | 24 | #define baud_rate_setting_checksum CHECKSUM("baud_rate") |
Michael J. Spencer |
2:1df0b61d3b5a | 25 | #define uart0_checksum CHECKSUM("uart0") |
scachat | 0:31e91bb0ef3c | 26 | |
Michael J. Spencer |
2:1df0b61d3b5a | 27 | Kernel* Kernel::instance; |
scachat | 0:31e91bb0ef3c | 28 | |
Michael J. Spencer |
2:1df0b61d3b5a | 29 | // The kernel is the central point in Smoothie : it stores modules, and handles event calls |
Michael J. Spencer |
2:1df0b61d3b5a | 30 | Kernel::Kernel(){ |
Michael J. Spencer |
2:1df0b61d3b5a | 31 | instance= this; // setup the Singleton instance of the kernel |
scachat | 0:31e91bb0ef3c | 32 | |
Michael J. Spencer |
2:1df0b61d3b5a | 33 | // Config first, because we need the baud_rate setting before we start serial |
scachat | 0:31e91bb0ef3c | 34 | this->config = new Config(); |
scachat | 0:31e91bb0ef3c | 35 | |
scachat | 0:31e91bb0ef3c | 36 | // Serial second, because the other modules might want to say something |
Michael J. Spencer |
2:1df0b61d3b5a | 37 | this->streams = new StreamOutputPool(); |
Michael J. Spencer |
2:1df0b61d3b5a | 38 | |
Michael J. Spencer |
2:1df0b61d3b5a | 39 | this->current_path = "/"; |
Michael J. Spencer |
2:1df0b61d3b5a | 40 | |
scachat | 0:31e91bb0ef3c | 41 | this->add_module( this->config ); |
scachat | 0:31e91bb0ef3c | 42 | this->add_module( this->serial ); |
Michael J. Spencer |
2:1df0b61d3b5a | 43 | |
Michael J. Spencer |
2:1df0b61d3b5a | 44 | // HAL stuff |
Michael J. Spencer |
2:1df0b61d3b5a | 45 | add_module( this->slow_ticker = new SlowTicker()); |
scachat | 0:31e91bb0ef3c | 46 | this->step_ticker = new StepTicker(); |
Bigcheese | 3:f151d08d335c | 47 | // this->adc = new Adc(); |
scachat | 0:31e91bb0ef3c | 48 | |
Michael J. Spencer |
2:1df0b61d3b5a | 49 | // Configure the step ticker |
Michael J. Spencer |
2:1df0b61d3b5a | 50 | int base_stepping_frequency = this->config->value(base_stepping_frequency_checksum )->by_default(100000)->as_number(); |
Michael J. Spencer |
2:1df0b61d3b5a | 51 | float microseconds_per_step_pulse = this->config->value(microseconds_per_step_pulse_checksum )->by_default(5 )->as_number(); |
Michael J. Spencer |
2:1df0b61d3b5a | 52 | |
Michael J. Spencer |
2:1df0b61d3b5a | 53 | // Configure the step ticker ( TODO : shouldnt this go into stepticker's code ? ) |
Michael J. Spencer |
2:1df0b61d3b5a | 54 | this->step_ticker->set_reset_delay( microseconds_per_step_pulse / 1000000L ); |
Michael J. Spencer |
2:1df0b61d3b5a | 55 | this->step_ticker->set_frequency( base_stepping_frequency ); |
Michael J. Spencer |
2:1df0b61d3b5a | 56 | |
Michael J. Spencer |
2:1df0b61d3b5a | 57 | // Core modules |
scachat | 0:31e91bb0ef3c | 58 | this->add_module( this->gcode_dispatch = new GcodeDispatch() ); |
scachat | 0:31e91bb0ef3c | 59 | this->add_module( this->robot = new Robot() ); |
scachat | 0:31e91bb0ef3c | 60 | this->add_module( this->stepper = new Stepper() ); |
scachat | 0:31e91bb0ef3c | 61 | this->add_module( this->planner = new Planner() ); |
Michael J. Spencer |
2:1df0b61d3b5a | 62 | this->add_module( this->conveyor = new Conveyor() ); |
scachat | 0:31e91bb0ef3c | 63 | this->add_module( this->pauser = new Pauser() ); |
Michael J. Spencer |
2:1df0b61d3b5a | 64 | this->add_module( this->public_data = new PublicData() ); |
Michael J. Spencer |
2:1df0b61d3b5a | 65 | this->add_module( this->toolsmanager = new ToolsManager() ); |
Michael J. Spencer |
2:1df0b61d3b5a | 66 | |
scachat | 0:31e91bb0ef3c | 67 | } |
scachat | 0:31e91bb0ef3c | 68 | |
Michael J. Spencer |
2:1df0b61d3b5a | 69 | // Add a module to Kernel. We don't actually hold a list of modules, we just tell it where Kernel is |
scachat | 0:31e91bb0ef3c | 70 | void Kernel::add_module(Module* module){ |
scachat | 0:31e91bb0ef3c | 71 | module->on_module_loaded(); |
scachat | 0:31e91bb0ef3c | 72 | } |
scachat | 0:31e91bb0ef3c | 73 | |
Michael J. Spencer |
2:1df0b61d3b5a | 74 | // Adds a hook for a given module and event |
Michael J. Spencer |
2:1df0b61d3b5a | 75 | void Kernel::register_for_event(_EVENT_ENUM id_event, Module* module){ |
scachat | 0:31e91bb0ef3c | 76 | this->hooks[id_event].push_back(module); |
scachat | 0:31e91bb0ef3c | 77 | } |
scachat | 0:31e91bb0ef3c | 78 | |
Michael J. Spencer |
2:1df0b61d3b5a | 79 | // Call a specific event without arguments |
Michael J. Spencer |
2:1df0b61d3b5a | 80 | void Kernel::call_event(_EVENT_ENUM id_event){ |
Michael J. Spencer |
2:1df0b61d3b5a | 81 | for (Module* current : hooks[id_event]) { |
Michael J. Spencer |
2:1df0b61d3b5a | 82 | (current->*kernel_callback_functions[id_event])(this); |
scachat | 0:31e91bb0ef3c | 83 | } |
scachat | 0:31e91bb0ef3c | 84 | } |
scachat | 0:31e91bb0ef3c | 85 | |
Michael J. Spencer |
2:1df0b61d3b5a | 86 | // Call a specific event with an argument |
Michael J. Spencer |
2:1df0b61d3b5a | 87 | void Kernel::call_event(_EVENT_ENUM id_event, void * argument){ |
Michael J. Spencer |
2:1df0b61d3b5a | 88 | for (Module* current : hooks[id_event]) { |
Michael J. Spencer |
2:1df0b61d3b5a | 89 | (current->*kernel_callback_functions[id_event])(argument); |
scachat | 0:31e91bb0ef3c | 90 | } |
scachat | 0:31e91bb0ef3c | 91 | } |