A set of classes that mimic the behaviour of Mbed Ticker class but using TIMER0, TIMER1, TIMER2 and the RIT.

Revision:
0:5c7fd96cf29a
Child:
1:e60d949ec09a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tickers.h	Fri Feb 11 10:42:52 2011 +0000
@@ -0,0 +1,138 @@
+/*
+    Copyright (c) 2011 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#ifndef AJK_TICKERS_H
+#define AJK_TICKERS_H
+
+#include "mbed.h"
+#include "TickersSys.h"
+#include <list>
+
+namespace AjK {
+
+// Mimic Mbed's Ticker class but using TIMER1 
+// (note, only goes to milliseconds level not microseconds!)
+
+class Ticker1Sys;
+extern Ticker1Sys _ticker1Sys;
+
+class TickerA {
+protected:
+    FunctionPointer callback;
+    uint32_t counter;
+    uint32_t reload;
+public:
+    TickerA();
+    ~TickerA();
+    void tick(void);
+    
+    void detach(void) {        
+        callback.attach();
+    }
+    void attach(void (*fptr)(void), double d) {
+        counter = reload = (uint32_t)( d * 1000.0 );
+        callback.attach(fptr);
+    }
+    template<typename T>
+    void attach(T* tptr, void (T::*mptr)(void), double d) {  
+        if((mptr != NULL) && (tptr != NULL)) {
+            counter = reload = (uint32_t)( d * 1000.0 );
+            callback.attach(tptr, mptr);         
+        }        
+    }
+};
+
+// Mimic Mbed's Ticker class but using TIMER2
+// (note, only goes to milliseconds level not microseconds!)
+
+class Ticker2Sys;
+extern Ticker2Sys _ticker2Sys;
+
+class TickerB {
+protected:
+    FunctionPointer callback;
+    uint32_t counter;
+    uint32_t reload;
+public:
+    TickerB();
+    ~TickerB();
+    void tick(void);
+    
+    void detach(void) {        
+        callback.attach();
+    }
+    void attach(void (*fptr)(void), double d) {
+        counter = reload = (uint32_t)( d * 1000.0 );
+        callback.attach(fptr);
+    }
+    template<typename T>
+    void attach(T* tptr, void (T::*mptr)(void), double d) {  
+        if((mptr != NULL) && (tptr != NULL)) {
+            counter = reload = (uint32_t)( d * 1000.0 );
+            callback.attach(tptr, mptr);         
+        }        
+    }
+};
+
+// Mimic Mbed's Ticker class but using RIT
+// (note, only goes to milliseconds level not microseconds!)
+
+class TickerRSys;
+extern TickerRSys _tickerRSys;
+
+class TickerC {
+protected:
+    FunctionPointer callback;
+    uint32_t counter;
+    uint32_t reload;
+public:
+    TickerC();
+    ~TickerC();
+    void tick(void);
+    
+    void detach(void) {        
+        callback.attach();
+    }
+    void attach(void (*fptr)(void), double d) {
+        counter = reload = (uint32_t)( d * 1000.0 );
+        callback.attach(fptr);
+    }
+    template<typename T>
+    void attach(T* tptr, void (T::*mptr)(void), double d) {  
+        if((mptr != NULL) && (tptr != NULL)) {
+            counter = reload = (uint32_t)( d * 1000.0 );
+            callback.attach(tptr, mptr);         
+        }        
+    }
+};
+
+// Mimic Mbed's Ticker class but using actual Ticker by inheriting.
+// This just basically "renames" Ticker to TickerD for consistancy.
+
+class TickerD : public Ticker {
+public:
+    TickerD() : Ticker() {};
+};
+
+}; // namespace AjK ends.
+
+#endif