mbed-drivers
Ticker.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_TICKER_H
18 #define MBED_TICKER_H
19 
20 #include "TimerEvent.h"
21 #include "core-util/FunctionPointer.h"
22 
23 namespace mbed {
24 
58 class Ticker : public TimerEvent {
59 
60 public:
61  Ticker() : TimerEvent() {
62  }
63 
64  Ticker(const ticker_data_t *const data) : TimerEvent(data) {
65  }
66 
72  void attach(void (*fptr)(void), float t) {
73  attach_us(fptr, t * 1000000.0f);
74  }
75 
82  template<typename T>
83  void attach(T* tptr, void (T::*mptr)(void), float t) {
84  attach_us(tptr, mptr, t * 1000000.0f);
85  }
86 
92  void attach_us(void (*fptr)(void), timestamp_t t) {
93  _function.attach(fptr);
94  setup(t);
95  }
96 
103  template<typename T>
104  void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) {
105  _function.attach(tptr, mptr);
106  setup(t);
107  }
108 
109  virtual ~Ticker() {
110  detach();
111  }
112 
115  void detach();
116 
117 protected:
118  void setup(timestamp_t t);
119  virtual void handler();
120 
121 protected:
122  timestamp_t _delay;
123  mbed::util::FunctionPointer _function;
124 };
125 
126 } // namespace mbed
127 
128 #endif
void attach_us(void(*fptr)(void), timestamp_t t)
Definition: Ticker.h:92
void detach()
Definition: Ticker.cpp:25
void attach_us(T *tptr, void(T::*mptr)(void), timestamp_t t)
Definition: Ticker.h:104
Definition: TimerEvent.h:26
mbed::util::FunctionPointer _function
Definition: Ticker.h:123
Definition: Ticker.h:58
timestamp_t _delay
Definition: Ticker.h:122
void attach(void(*fptr)(void), float t)
Definition: Ticker.h:72
Definition: BusIn.cpp:19
void attach(T *tptr, void(T::*mptr)(void), float t)
Definition: Ticker.h:83