Mistake on this page?
Report an issue in GitHub or email us
TimerEvent.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may 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,
13  * WITHOUT 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_TIMEREVENT_H
18 #define MBED_TIMEREVENT_H
19 
20 #include "hal/ticker_api.h"
21 #include "platform/mbed_toolchain.h"
22 #include "platform/NonCopyable.h"
23 #include "drivers/TickerDataClock.h"
24 
25 namespace mbed {
26 
27 /**
28  * \defgroup drivers_TimerEvent TimerEvent class
29  * \ingroup drivers-public-api-ticker
30  * @{
31  */
32 
33 /** Base abstraction for timer interrupts
34  *
35  * @note Synchronization level: Interrupt safe
36  */
37 class TimerEvent : private NonCopyable<TimerEvent> {
38 #if !defined(DOXYGEN_ONLY)
39 protected:
40  TimerEvent(const ticker_data_t *data);
41 
42  /** The handler registered with the underlying timer interrupt
43  *
44  * @param id Timer Event ID
45  */
46  static void irq(uint32_t id);
47 
48  /** Destruction removes it...
49  */
50  ~TimerEvent();
51 
52  // The handler called to service the timer event of the derived class
53  virtual void handler() = 0;
54 
55  /** Set absolute timestamp of the internal event.
56  * @param timestamp event's 32-bit us timestamp
57  *
58  * @warning
59  * Do not insert more than one timestamp.
60  * The same @a event object is used for every @a insert/insert_absolute call.
61  *
62  * @warning
63  * Ticker's present time is used for reference. The wrapping of the 32-bit
64  * timestamp is handled by assuming that the time specified is always in the
65  * future. For reference @see convert_timestamp. This could cause problems
66  * under load, as if the requested time is missed, the event will be scheduled
67  * one whole 32-bit wrap (over an hour) in the future.
68  *
69  * @warning
70  * Despite previous documentation, this sets an absolute time, based on
71  * a wrapping 32-bit timestamp, not a time relative to now. The replacement
72  * Chrono-based call is `insert_absolute(TickerDataClock::time_point timestamp)`,
73  * not `insert(std::chrono::microseconds rel_time)`. However
74  * `insert(5ms)` can be used instead of `insert_absolute(_ticker_data.now() + 5ms)`.
75  * Due to unclear documentation, it's possible some users may have been
76  * doing `insert(5000)` without adding the current time, and they could be
77  * corrected to `insert(5ms)`.
78  *
79  * @deprecated use `insert_absolute(TickerDataClock::time_point timestamp)`
80  */
81  MBED_DEPRECATED_SINCE("mbed-os-6.0.0", "Pass a chrono time_point, not an integer microsecond count. For example use `last_chrono_time + 5ms` rather than `last_us_time + 5000`.")
82  void insert(timestamp_t timestamp);
83 
84  /** Set relative timestamp of the internal event.
85  * @param rel_time relative time for event's us timestamp
86  *
87  * @warning
88  * Do not insert more than one timestamp.
89  * The same @a event object is used for every @a insert/insert_absolute call.
90  *
91  * @note
92  * Ticker's present timestamp is used for reference. If the relative time is
93  * non-positive, the event will be run immediately.
94  */
95  void insert(std::chrono::microseconds rel_time);
96 
97  /** Set absolute timestamp of the internal event.
98  * @param timestamp event's us timestamp
99  *
100  * @warning
101  * Do not insert more than one timestamp.
102  * The same @a event object is used for every @a insert/insert_absolute call.
103  *
104  * @deprecated use `insert_absolute(TickerDataClock::time_point timestamp)`
105  */
106  MBED_DEPRECATED_SINCE("mbed-os-6.0.0", "Pass a chrono time_point, not an integer microsecond count. For example use `last_chrono_time + 5ms` rather than `last_us_time + 5000`.")
107  void insert_absolute(us_timestamp_t timestamp);
108 
109  /** Set absolute timestamp of the internal event.
110  * @param timestamp event's us timestamp
111  *
112  * @warning
113  * Do not insert more than one timestamp.
114  * The same @a event object is used for every @a insert/insert_absolute call.
115  *
116  * @note
117  * If the timestamp is in the past, the event will be run immediately.
118  */
119  void insert_absolute(TickerDataClock::time_point timestamp);
120 
121  /** Remove timestamp.
122  */
123  void remove();
124 
125  ticker_event_t event;
126 
127  TickerDataClock _ticker_data;
128 #endif
129 };
130 
131 /** @}*/
132 
133 } // namespace mbed
134 
135 #endif
uint64_t us_timestamp_t
A us timestamp stored in a 64 bit integer.
Definition: ticker_api.h:39
Ticker&#39;s data structure.
Definition: ticker_api.h:144
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:162
Base abstraction for timer interrupts.
Definition: TimerEvent.h:37
A partial implementation of a C++11 Clock representing a HAL ticker.
Ticker&#39;s event structure.
Definition: ticker_api.h:43
uint32_t timestamp_t
Legacy format representing a timestamp in us.
Definition: ticker_api.h:33
Definition: ATHandler.h:46
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.