Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
SysTimer< US_IN_TICK, IRQ > Class Template Reference
[SysTimer class]
The SysTimer class is used to provide timing for system suspension, and the idle loop in TICKLESS mode. More...
#include <SysTimer.h>
Inherits mbed::TimerEvent, and NonCopyable< SysTimer< US_IN_TICK, IRQ > >.
Public Member Functions | |
| SysTimer () | |
| Default constructor uses LPTICKER if available (so the timer will continue to run in deep sleep), else USTICKER. | |
| void | set_wake_time (uint64_t at) |
| Set the wake time. | |
| bool | wake_time_passed () const |
| Check whether the wake time has passed. | |
| bool | wake_time_set () const |
| Check whether wake timer is active. | |
| void | cancel_wake () |
| Cancel any pending wake. | |
| void | start_tick () |
| Schedule an os tick to fire. | |
| void | acknowledge_tick () |
| Acknowledge an os tick. | |
| void | cancel_tick () |
| Prevent any more scheduled ticks from triggering. | |
| bool | ticking () const |
| Check whether ticker is active. | |
| int | unacknowledged_ticks () const |
| Check unacknowledged ticks. | |
| uint64_t | get_tick () const |
| Get the current tick count. | |
| uint64_t | update_and_get_tick () |
| Update and get the current tick count. | |
| us_timestamp_t | get_time_since_tick () const |
| Returns time since last tick. | |
| us_timestamp_t | get_time () const |
| Get the time. | |
Static Public Member Functions | |
| static IRQn_ID_t | get_irq_number () |
| Get the interrupt number for the tick. | |
Private Member Functions | |
| void | insert (timestamp_t timestamp) |
| Set relative timestamp of the internal event. | |
| void | insert_absolute (us_timestamp_t timestamp) |
| Set absolute timestamp of the internal event. | |
| void | remove () |
| Remove timestamp. | |
| MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &) | |
| NonCopyable copy constructor. | |
| MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator | |
| NonCopyable copy assignment operator. | |
Static Private Member Functions | |
| static void | irq (uint32_t id) |
| The handler registered with the underlying timer interrupt. | |
Detailed Description
template<uint32_t US_IN_TICK, bool IRQ = true>
class mbed::internal::SysTimer< US_IN_TICK, IRQ >
The SysTimer class is used to provide timing for system suspension, and the idle loop in TICKLESS mode.
Template for speed for testing - only one instance will be used normally.
- Note:
- SysTimer is not the part of Mbed API.
Definition at line 49 of file SysTimer.h.
Constructor & Destructor Documentation
| SysTimer | ( | ) |
Default constructor uses LPTICKER if available (so the timer will continue to run in deep sleep), else USTICKER.
Definition at line 49 of file SysTimer.cpp.
Member Function Documentation
| void acknowledge_tick | ( | ) |
Acknowledge an os tick.
This will queue another os tick immediately if the os is running slow
Definition at line 191 of file SysTimer.cpp.
| void cancel_tick | ( | ) |
Prevent any more scheduled ticks from triggering.
If called from OS tick context, there may be remaining unacknowledged ticks.
Definition at line 204 of file SysTimer.cpp.
| void cancel_wake | ( | ) |
Cancel any pending wake.
Definition at line 143 of file SysTimer.cpp.
| IRQn_ID_t get_irq_number | ( | ) | [static] |
Get the interrupt number for the tick.
- Returns:
- interrupt number
Definition at line 254 of file SysTimer.cpp.
| uint64_t get_tick | ( | ) | const |
Get the current tick count.
This count is updated by the ticker interrupt, if the ticker interrupt is running. It the ticker interrupt is not running, update_and_get_tick() should be used instead.
This indicates how many ticks have been generated by the tick interrupt. The os_timer should equal this number minus the number of unacknowledged ticks.
- Returns:
- The number of ticks since timer creation.
Definition at line 215 of file SysTimer.cpp.
| us_timestamp_t get_time | ( | ) | const |
Get the time.
Returns the instantaneous precision time from underlying timer. This is a slow operation so should not be called from critical sections.
- Returns:
- Current time in microseconds
Definition at line 237 of file SysTimer.cpp.
| us_timestamp_t get_time_since_tick | ( | ) | const |
Returns time since last tick.
- Returns:
- Relative time in microseconds
Definition at line 245 of file SysTimer.cpp.
| void set_wake_time | ( | uint64_t | at ) |
Set the wake time.
Schedules an interrupt to cause wake-up in time for the event. Interrupt may be arranged early to account for latency. If the time has already passed, no interrupt will be scheduled.
This is called from outside a critical section, as it is known to be a slow operation.
If the wake time is already set, this is a no-op. But that check is racy, which means wake_time_set() should be rechecked after taking a critical section.
As a side-effect, this clears the unacknowledged tick count - the caller is expected to use update_and_get_tick() after the suspend operation.
- Parameters:
-
at Wake up tick
- Warning:
- If the ticker tick is already scheduled it needs to be cancelled first!
Definition at line 88 of file SysTimer.cpp.
| void start_tick | ( | ) |
Schedule an os tick to fire.
Ticks will be rescheduled automatically every tick until cancel_tick is called.
A tick will be fired immediately if there are any unacknowledged ticks.
- Warning:
- If a tick is already scheduled it needs to be cancelled first!
Definition at line 175 of file SysTimer.cpp.
| bool ticking | ( | ) | const |
Check whether ticker is active.
Each time the tick interrupt fires, it is automatically rescheduled, so this will remain true once the tick is started, except during processing.
- Returns:
- true if the ticker is active.
Definition at line 157 of file SysTimer.h.
| int unacknowledged_ticks | ( | ) | const |
Check unacknowledged ticks.
Returns the count of how many times the OS timer has been queued minus the number of times is has been acknowledged.
get_tick() - unacknowledged_ticks() should equal the OS's tick count, although such a calculation is not atomic if the ticker is currently running.
- Returns:
- number of unacknowledged ticks
Definition at line 173 of file SysTimer.h.
| uint64_t update_and_get_tick | ( | ) |
Update and get the current tick count.
This is a slow operation that reads the timer and adjusts for elapsed time. Can only be used when the ticker is not running, as there is no IRQ synchronization.
This clears the unacknowledged tick counter - the caller is assumed to update their timer based on this return.
- Returns:
- The number of ticks since timer creation.
Definition at line 223 of file SysTimer.cpp.
| bool wake_time_passed | ( | ) | const |
Check whether the wake time has passed.
This is a fast operation, based on checking whether the wake interrupt has run.
- Returns:
- true if the specified wake tick has passed
Definition at line 103 of file SysTimer.h.
| bool wake_time_set | ( | ) | const |
Check whether wake timer is active.
- Returns:
- true if the wake timer is active.
Definition at line 113 of file SysTimer.h.
Generated on Tue Jul 12 2022 13:55:44 by
1.7.2