Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Committer:
Michael J. Spencer
Date:
Fri Feb 28 18:52:52 2014 -0800
Revision:
2:1df0b61d3b5a
Parent:
0:31e91bb0ef3c
Child:
3:f151d08d335c
Update to latest Smoothie.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael J. Spencer 2:1df0b61d3b5a 1 /*
Michael J. Spencer 2:1df0b61d3b5a 2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
Michael J. Spencer 2:1df0b61d3b5a 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.
Michael J. Spencer 2:1df0b61d3b5a 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/>.
Michael J. Spencer 2:1df0b61d3b5a 6 */
Michael J. Spencer 2:1df0b61d3b5a 7
Michael J. Spencer 2:1df0b61d3b5a 8
Michael J. Spencer 2:1df0b61d3b5a 9
Michael J. Spencer 2:1df0b61d3b5a 10 #ifndef SLOWTICKER_H
Michael J. Spencer 2:1df0b61d3b5a 11 #define SLOWTICKER_H
Michael J. Spencer 2:1df0b61d3b5a 12
Michael J. Spencer 2:1df0b61d3b5a 13 using namespace std;
Michael J. Spencer 2:1df0b61d3b5a 14 #include <vector>
Michael J. Spencer 2:1df0b61d3b5a 15 #include "libs/nuts_bolts.h"
Michael J. Spencer 2:1df0b61d3b5a 16 #include "libs/Module.h"
Michael J. Spencer 2:1df0b61d3b5a 17 #include "libs/Kernel.h"
Michael J. Spencer 2:1df0b61d3b5a 18 #include "libs/Hook.h"
Michael J. Spencer 2:1df0b61d3b5a 19
Michael J. Spencer 2:1df0b61d3b5a 20 #include "libs/Pin.h"
Michael J. Spencer 2:1df0b61d3b5a 21
Michael J. Spencer 2:1df0b61d3b5a 22 #include "system_LPC17xx.h" // for SystemCoreClock
Michael J. Spencer 2:1df0b61d3b5a 23 #include <math.h>
Michael J. Spencer 2:1df0b61d3b5a 24
Michael J. Spencer 2:1df0b61d3b5a 25 class SlowTicker : public Module{
Michael J. Spencer 2:1df0b61d3b5a 26 public:
Michael J. Spencer 2:1df0b61d3b5a 27 SlowTicker();
Michael J. Spencer 2:1df0b61d3b5a 28
Michael J. Spencer 2:1df0b61d3b5a 29 void on_module_loaded(void);
Michael J. Spencer 2:1df0b61d3b5a 30 void on_idle(void*);
Michael J. Spencer 2:1df0b61d3b5a 31 void on_gcode_received(void*);
Michael J. Spencer 2:1df0b61d3b5a 32 void on_gcode_execute(void*);
Michael J. Spencer 2:1df0b61d3b5a 33
Michael J. Spencer 2:1df0b61d3b5a 34 void set_frequency( int frequency );
Michael J. Spencer 2:1df0b61d3b5a 35 void tick();
Michael J. Spencer 2:1df0b61d3b5a 36 // For some reason this can't go in the .cpp, see : http://mbed.org/forum/mbed/topic/2774/?page=1#comment-14221
Michael J. Spencer 2:1df0b61d3b5a 37 template<typename T> Hook* attach( uint32_t frequency, T *optr, uint32_t ( T::*fptr )( uint32_t ) ){
Michael J. Spencer 2:1df0b61d3b5a 38 Hook* hook = new Hook();
Michael J. Spencer 2:1df0b61d3b5a 39 hook->interval = int(floor((SystemCoreClock/4)/frequency));
Michael J. Spencer 2:1df0b61d3b5a 40 hook->attach(optr, fptr);
Michael J. Spencer 2:1df0b61d3b5a 41 hook->countdown = hook->interval;
Michael J. Spencer 2:1df0b61d3b5a 42 if( frequency > this->max_frequency ){
Michael J. Spencer 2:1df0b61d3b5a 43 this->max_frequency = frequency;
Michael J. Spencer 2:1df0b61d3b5a 44 this->set_frequency(frequency);
Michael J. Spencer 2:1df0b61d3b5a 45 }
Michael J. Spencer 2:1df0b61d3b5a 46 this->hooks.push_back(hook);
Michael J. Spencer 2:1df0b61d3b5a 47 return hook;
Michael J. Spencer 2:1df0b61d3b5a 48 }
Michael J. Spencer 2:1df0b61d3b5a 49
Michael J. Spencer 2:1df0b61d3b5a 50 bool flag_1s();
Michael J. Spencer 2:1df0b61d3b5a 51
Michael J. Spencer 2:1df0b61d3b5a 52 vector<Hook*> hooks;
Michael J. Spencer 2:1df0b61d3b5a 53 uint32_t max_frequency;
Michael J. Spencer 2:1df0b61d3b5a 54 uint32_t interval;
Michael J. Spencer 2:1df0b61d3b5a 55
Michael J. Spencer 2:1df0b61d3b5a 56 uint32_t g4_ticks;
Michael J. Spencer 2:1df0b61d3b5a 57 bool g4_pause;
Michael J. Spencer 2:1df0b61d3b5a 58
Michael J. Spencer 2:1df0b61d3b5a 59 Pin ispbtn;
Michael J. Spencer 2:1df0b61d3b5a 60 protected:
Michael J. Spencer 2:1df0b61d3b5a 61 int flag_1s_count;
Michael J. Spencer 2:1df0b61d3b5a 62 volatile int flag_1s_flag;
Michael J. Spencer 2:1df0b61d3b5a 63 };
Michael J. Spencer 2:1df0b61d3b5a 64
Michael J. Spencer 2:1df0b61d3b5a 65
Michael J. Spencer 2:1df0b61d3b5a 66
Michael J. Spencer 2:1df0b61d3b5a 67
Michael J. Spencer 2:1df0b61d3b5a 68
Michael J. Spencer 2:1df0b61d3b5a 69 #endif