Some useful stuff

Dependents:   FtEncoder FtControlSet

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TimeoutTweaked.h Source File

TimeoutTweaked.h

00001 #ifndef TIMEOUTTWEAKED_H
00002 #define TIMEOUTTWEAKED_H
00003 
00004 #include "Timeout.h"
00005 
00006 using namespace mbed; 
00007 
00008 /// Tweaked Timeout class, that publishes the protected TimerEvent methods
00009 /// remove() and insert(unsigned int), which are a bit faster than detach() and attach(...).
00010 /// Useful when you just want to restart a timeout in a short ISR, without hooking 
00011 /// in a "new" callback function. Saves ~1.5µs. 
00012 class  TimeoutTweaked : public Timeout {
00013 public:
00014     /// calls protected TimerEvent::remove()that
00015     /// just removes the timer event from the schedule but keeps the handler that has been attached before
00016     inline void remove() {
00017         TimerEvent::remove();
00018     }
00019     /// calls proteccted TimerEvent::insert() that inserts a new timeout event to the schedule at the given timestamp.
00020     /// e.g. insert(us_ticker_read()+timeout_us)
00021     inline void insert(unsigned int timestamp) {
00022         TimerEvent::insert(timestamp);
00023     }
00024     /// Attach a function to be called by the tweaked Timeout
00025     void attach(void (*fptr)(void)) {
00026         attach_us(fptr, 1e9);
00027         remove();
00028     }
00029     /// Attach a member function to be called by the tweaked Timeout
00030     template<typename T>
00031     void attach(T* tptr, void (T::*mptr)(void)) {
00032         attach_us(tptr, mptr, 1e9);
00033         remove();
00034     }
00035 };
00036 
00037 #endif