this->add_module( this->serial );
// HAL stuff
- this->slow_ticker = new SlowTicker();
+ add_module( this->slow_ticker = new SlowTicker());
this->step_ticker = new StepTicker();
this->adc = new Adc();
this->digipot = new Digipot();
flag_1s_count = SystemCoreClock;
}
+void SlowTicker::on_module_loaded()
+{
+ register_for_event(ON_IDLE);
+}
+
void SlowTicker::set_frequency( int frequency ){
this->interval = int(floor((SystemCoreClock >> 2)/frequency)); // SystemCoreClock/4 = Timer increments in a second
LPC_TIM2->MR0 = this->interval;
void SlowTicker::tick()
{
+ _isr_context = true;
+
LPC_GPIO1->FIODIR |= 1<<20;
LPC_GPIO1->FIOSET = 1<<20;
if (ispbtn.get() == 0)
__debugbreak();
+
+ _isr_context = false;
}
bool SlowTicker::flag_1s(){
return false;
}
+void SlowTicker::on_idle(void*)
+{
+ if (flag_1s())
+ kernel->call_event(ON_SECOND_TICK);
+}
+
extern "C" void TIMER2_IRQHandler (void){
if((LPC_TIM2->IR >> 0) & 1){ // If interrupt register set for MR0
LPC_TIM2->IR |= 1 << 0; // Reset it
class SlowTicker : public Module{
public:
SlowTicker();
+
+ void on_module_loaded(void);
+ void on_idle(void*);
+
void set_frequency( int frequency );
void tick();
// For some reason this can't go in the .cpp, see : http://mbed.org/forum/mbed/topic/2774/?page=1#comment-14221
// Call tick() on each active motor
inline void StepTicker::tick(){
+ _isr_context = true;
+
int i;
uint32_t bm;
for (i = 0, bm = 1; i < 12; i++, bm <<= 1)
this->active_motors[i]->tick();
}
}
+
+ _isr_context = false;
}
// Call signal_mode_finished() on each active motor that asked to be signaled. We do this instead of inside of tick() so that
// all tick()s are called before we do the move finishing
void StepTicker::signal_moves_finished(){
+ _isr_context = true;
+
int i;
uint32_t bm;
for (i = 0, bm = 1; i < 12; i++, bm <<= 1)
}
}
this->moves_finished = false;
+
+ _isr_context = false;
}
// Reset step pins on all active motors
inline void StepTicker::reset_tick(){
+ _isr_context = true;
+
int i;
uint32_t bm;
for (i = 0, bm = 1; i < 12; i++, bm <<= 1)
if (this->active_motor_bm & bm)
this->active_motors[i]->step_pin->set(0);
}
+
+ _isr_context = false;
}
extern "C" void TIMER1_IRQHandler (void){
using std::string;
#include <cstring>
+volatile bool _isr_context = false;
uint16_t get_checksum(string to_check){
// From: http://en.wikipedia.org/wiki/Fletcher%27s_checksum
#include <vector>
using std::string;
+extern volatile bool _isr_context;
+
string lc(string str);
string remove_non_number( string str );
while(1){
kernel->call_event(ON_MAIN_LOOP);
kernel->call_event(ON_IDLE);
- if (kernel->slow_ticker->flag_1s())
- kernel->call_event(ON_SECOND_TICK);
}
}