fix when slow ticker gets started
authorJim Morris <morris@wolfman.com>
Sun, 21 Feb 2016 20:50:10 +0000 (12:50 -0800)
committerJim Morris <morris@wolfman.com>
Sun, 21 Feb 2016 20:50:10 +0000 (12:50 -0800)
refactor the slowticker setup
Fixes PR  #853

src/libs/SlowTicker.cpp
src/libs/SlowTicker.h
src/libs/StepTicker.cpp
src/main.cpp

index a2d516d..42893c0 100644 (file)
@@ -24,21 +24,23 @@ using namespace std;
 SlowTicker* global_slow_ticker;
 
 SlowTicker::SlowTicker(){
-    max_frequency = 0;
     global_slow_ticker = this;
 
-
     // ISP button FIXME: WHy is this here?
     ispbtn.from_string("2.10")->as_input()->pull_up();
 
-    // TODO: What is this ??
-    flag_1s_flag = 0;
-    flag_1s_count = SystemCoreClock>>2;
-
-    // Configure the actual timer after setup to avoid race conditions
     LPC_SC->PCONP |= (1 << 22);     // Power Ticker ON
-    LPC_TIM2->MR0 = 10000;          // Initial dummy value for Match Register
     LPC_TIM2->MCR = 3;              // Match on MR0, reset on MR0
+    // do not enable interrupt until setup is complete
+    LPC_TIM2->TCR = 0;              // Disable interrupt
+
+    max_frequency = 5;  // initial max frequency is set to 5Hz
+    set_frequency(max_frequency);
+    flag_1s_flag = 0;
+}
+
+void SlowTicker::start()
+{
     LPC_TIM2->TCR = 1;              // Enable interrupt
     NVIC_EnableIRQ(TIMER2_IRQn);    // Enable interrupt handler
 }
index 091f931..a0f6ce3 100644 (file)
@@ -27,7 +27,7 @@ class SlowTicker : public Module{
 
         void on_module_loaded(void);
         void on_idle(void*);
-
+        void start();
         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
index 87e0822..1849dad 100644 (file)
@@ -69,7 +69,7 @@ StepTicker::StepTicker(){
 StepTicker::~StepTicker() {
 }
 
-//called when everythinf is setup and interrupts can start
+//called when everything is setup and interrupts can start
 void StepTicker::start() {
     NVIC_EnableIRQ(TIMER0_IRQn);     // Enable interrupt handler
     NVIC_EnableIRQ(TIMER1_IRQn);     // Enable interrupt handler
index 4e4dc68..2ff6337 100644 (file)
@@ -33,6 +33,7 @@
 #include "checksumm.h"
 #include "ConfigValue.h"
 #include "StepTicker.h"
+#include "SlowTicker.h"
 
 // #include "libs/ChaNFSSD/SDFileSystem.h"
 #include "libs/nuts_bolts.h"
@@ -254,7 +255,9 @@ void init() {
         }
     }
 
+    // start the timers and interrupts
     THEKERNEL->step_ticker->start();
+    THEKERNEL->slow_ticker->start();
 }
 
 int main()