[Drivers] Let ticker support long us timestamp.

pull/4094/head
Vincent Coubard 2017-03-31 14:36:55 +01:00
parent c90a3a007a
commit abb0a65ac5
2 changed files with 8 additions and 8 deletions

View File

@ -29,16 +29,16 @@ void Ticker::detach() {
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
void Ticker::setup(timestamp_t t) { void Ticker::setup(us_timestamp_t t) {
core_util_critical_section_enter(); core_util_critical_section_enter();
remove(); remove();
_delay = t; _delay = t;
insert(_delay + ticker_read(_ticker_data)); insert_absolute(_delay + ticker_read_us(_ticker_data));
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
void Ticker::handler() { void Ticker::handler() {
insert(event.timestamp + _delay); insert_absolute(event.timestamp + _delay);
_function(); _function();
} }

View File

@ -100,7 +100,7 @@ public:
* @param func pointer to the function to be called * @param func pointer to the function to be called
* @param t the time between calls in micro-seconds * @param t the time between calls in micro-seconds
*/ */
void attach_us(Callback<void()> func, timestamp_t t) { void attach_us(Callback<void()> func, us_timestamp_t t) {
_function = func; _function = func;
setup(t); setup(t);
} }
@ -118,7 +118,7 @@ public:
MBED_DEPRECATED_SINCE("mbed-os-5.1", MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The attach_us function does not support cv-qualifiers. Replaced by " "The attach_us function does not support cv-qualifiers. Replaced by "
"attach_us(callback(obj, method), t).") "attach_us(callback(obj, method), t).")
void attach_us(T *obj, M method, timestamp_t t) { void attach_us(T *obj, M method, us_timestamp_t t) {
attach_us(Callback<void()>(obj, method), t); attach_us(Callback<void()>(obj, method), t);
} }
@ -131,12 +131,12 @@ public:
void detach(); void detach();
protected: protected:
void setup(timestamp_t t); void setup(us_timestamp_t t);
virtual void handler(); virtual void handler();
protected: protected:
timestamp_t _delay; /* Time delay (in microseconds) for re-setting the multi-shot callback. */ us_timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
Callback<void()> _function; /* Callback. */ Callback<void()> _function; /**< Callback. */
}; };
} // namespace mbed } // namespace mbed