Mistake on this page?
Report an issue in GitHub or email us
SysTimer.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2012 ARM Limited
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 #ifndef MBED_SYS_TIMER_H
23 #define MBED_SYS_TIMER_H
24 
25 #if MBED_TICKLESS || defined(DOXYGEN_ONLY)
26 
27 #include "platform/NonCopyable.h"
28 #include "drivers/TimerEvent.h"
29 
30 namespace rtos {
31 namespace internal {
32 
33 /**
34  * @cond RTOS_INTERNAL
35  *
36  * @addtogroup rtos
37  * @{
38  *
39  * @defgroup rtos_SysTimer SysTimer class
40  * @{
41  */
42 
43 /**
44  * The SysTimer class is used exclusively by RTX idle loop in TICKLESS mode.
45  *
46  * @note SysTimer is not the part of Mbed RTOS API.
47  */
48 class SysTimer: private mbed::TimerEvent, private mbed::NonCopyable<SysTimer> {
49 public:
50 
51  SysTimer();
52  SysTimer(const ticker_data_t *data);
53  virtual ~SysTimer();
54 
55  /**
56  * Enable an IRQ/SysTick with the correct priority.
57  */
58  static void setup_irq();
59 
60  /**
61  * Set wakeup time and schedule a wakeup event after delta ticks
62  *
63  * After suspend has been called the function suspend_time_passed
64  * can be used to determine if the suspend time has passed.
65  *
66  * @param delta Ticks to remain suspended
67  */
68  void suspend(uint32_t delta);
69 
70  /**
71  * Check if the suspend time has passed
72  *
73  * @return true if the specified number of ticks has passed otherwise false
74  */
75  bool suspend_time_passed();
76 
77  /**
78  * Exit suspend mode and return elapsed ticks
79  *
80  * Due to a scheduling issue, the number of ticks returned is decremented
81  * by 1 so that a handler can be called and update to the current value.
82  * This allows scheduling restart successfully after the OS is resumed.
83  *
84  * @return the number of elapsed ticks minus 1
85  */
86  uint32_t resume();
87 
88  /**
89  * Schedule an os tick to fire
90  *
91  * @param delta Tick to fire at relative to current tick
92  *
93  * @warning If a tick is already scheduled it needs to be cancelled first!
94  */
95  void schedule_tick(uint32_t delta = 1);
96 
97  /**
98  * Prevent any scheduled ticks from triggering
99  */
100  void cancel_tick();
101 
102  /** Get the current tick count
103  *
104  * @return The number of ticks since timer creation. For the os_timer this
105  * should match RTX's tick count (the number of ticks since boot).
106  */
107  uint32_t get_tick();
108 
109  /**
110  * Get the time
111  *
112  * @return Current time in microseconds
113  */
114  us_timestamp_t get_time();
115 
116 protected:
117  virtual void handler();
118  void _increment_tick();
119  static void _set_irq_pending();
120  us_timestamp_t _time_us;
121  uint64_t _tick;
122  bool _suspend_time_passed;
123  bool _suspended;
124 };
125 
126 /**
127  * @}
128  * @}
129  * @endcond
130  */
131 
132 }
133 }
134 
135 #endif
136 
137 #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:93
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:168
Base abstraction for timer interrupts.
Definition: TimerEvent.h:32
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.