123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #ifndef MBED_TICKER_H
- #define MBED_TICKER_H
- #include "drivers/TimerEvent.h"
- #include "platform/Callback.h"
- #include "platform/mbed_toolchain.h"
- #include "platform/NonCopyable.h"
- #include "platform/mbed_power_mgmt.h"
- #include "hal/lp_ticker_api.h"
- #include "platform/mbed_critical.h"
- namespace mbed {
- class Ticker : public TimerEvent, private NonCopyable<Ticker> {
- public:
- Ticker() : TimerEvent(), _function(0), _lock_deepsleep(true)
- {
- }
-
- Ticker(const ticker_data_t *data) : TimerEvent(data), _function(0), _lock_deepsleep(true)
- {
- #if DEVICE_LPTICKER
- _lock_deepsleep = (data != get_lp_ticker_data());
- #endif
- }
-
- void attach(Callback<void()> func, float t)
- {
- attach_us(func, t * 1000000.0f);
- }
-
- template<typename T, typename M>
- MBED_DEPRECATED_SINCE("mbed-os-5.1",
- "The attach function does not support cv-qualifiers. Replaced by "
- "attach(callback(obj, method), t).")
- void attach(T *obj, M method, float t)
- {
- attach(callback(obj, method), t);
- }
-
- void attach_us(Callback<void()> func, us_timestamp_t t)
- {
- core_util_critical_section_enter();
-
- if (!_function && _lock_deepsleep) {
- sleep_manager_lock_deep_sleep();
- }
- _function = func;
- setup(t);
- core_util_critical_section_exit();
- }
-
- template<typename T, typename M>
- MBED_DEPRECATED_SINCE("mbed-os-5.1",
- "The attach_us function does not support cv-qualifiers. Replaced by "
- "attach_us(callback(obj, method), t).")
- void attach_us(T *obj, M method, us_timestamp_t t)
- {
- attach_us(Callback<void()>(obj, method), t);
- }
- virtual ~Ticker()
- {
- detach();
- }
-
- void detach();
- protected:
- void setup(us_timestamp_t t);
- virtual void handler();
- protected:
- us_timestamp_t _delay;
- Callback<void()> _function;
- bool _lock_deepsleep;
- };
- }
- #endif
|