Wrapper around the nRF5 TIMER peripheral.
More...
#include <nrfcxx/periph.hpp>
|
int | configure (unsigned int freq_Hz, unsigned int bitmode=TIMER_BITMODE_BITMODE_16Bit, bool use_constlat=true) |
| Configure the TIMER to run as a timer. More...
|
|
void | deconfigure () |
| Deconfigure the TIMER.
|
|
unsigned int | frequency_Hz () const |
| Get the configured clock frequency in Hz.
|
|
void | start () |
| Invoke TASKS_START.
|
|
void | clear () |
| Invoke TASKS_CLEAR.
|
|
void | stop () |
| Invoke TASKS_STOP.
|
|
void | shutdown () |
| Invoke TASKS_SHUTDOWN.
|
|
void | capture (unsigned int ccidx) const |
| Capture the current counter using CC ccidx . More...
|
|
unsigned int | captured (unsigned int ccidx) const |
| Return the captured counter in CC ccidx .
|
|
unsigned int | counter (unsigned int ccidx=0) const |
| Read the current timer value. More...
|
|
unsigned int | delta (unsigned int a, unsigned int b) const |
| Calculate the count distance from a to b . More...
|
|
timestamp_type | timestamp (unsigned int ccidx=0) const |
| Create a timestamp instance using this timer. More...
|
|
const nrf5::TIMER_Type & | peripheral () const |
| Reference the nRF5 TIMER peripheral instance used by the abstraction.
|
|
const unsigned int | ccr_count () const |
| The number of capture/compare registers on the device.
|
|
|
constexpr static unsigned int | cc_mask = 7 |
| Mask to create a valid CC index from a non-negative integer. More...
|
|
|
constexpr | TIMER (const nrf5::TIMER_Type &timer) |
|
void | capture_ (unsigned int ccidx) const |
| Capture the current counter into CC ccidx (unvalidated).
|
|
unsigned int | captured_ (unsigned int ccidx) const |
| Return the captured value in CC ccidx (unvalidated).
|
|
unsigned int | counter_ (unsigned int ccidx) const |
| Capture and return the current counter using ccidx (unvalidated).
|
|
Wrapper around the nRF5 TIMER peripheral.
This abstraction supports using specific timers in timer mode. Timer IRQ handler definitions and interrupt configuration, if necessary, are the responsibility of the application, as is allocation of capture/compare registers to specific roles.
- Note
- When a soft device is used TIMER0 is restricted to the soft device. Other TIMER instances are available to applications.
◆ bitmode_supported()
constexpr static bool nrfcxx::periph::TIMER::bitmode_supported |
( |
const nrf5::TIMER_Type & |
timer, |
|
|
unsigned int |
bitmode |
|
) |
| |
|
inlinestaticconstexpr |
Verify a specific timer can support the requested bitmode.
- Note
- The user is responsible for ensuring that
timer
references an existing nRF5x TIMER peripheral and that bitmode
is a valid setting for the timer BITMODE
register.
◆ capture()
void nrfcxx::periph::TIMER::capture |
( |
unsigned int |
ccidx | ) |
const |
|
inline |
Capture the current counter using CC ccidx
.
- Note
- This function intentionally does not return the captured value, as reading it from the peripheral takes a couple clock cycles which can negatively impact instrumentation accuracy. If the overhead impact on subsequent operations is not a concern, use counter() to capture and return the current timer value.
◆ configure()
int nrfcxx::periph::TIMER::configure |
( |
unsigned int |
freq_Hz, |
|
|
unsigned int |
bitmode = TIMER_BITMODE_BITMODE_16Bit , |
|
|
bool |
use_constlat = true |
|
) |
| |
Configure the TIMER to run as a timer.
All interrupts are cleared and disabled, and the timer counter is cleared. Configuration is performed as specified by the parameters.
- Parameters
-
freq_Hz | the desired frequency of the timer. The value is limited by clock::hfclk::Frequency_Hz, and the actual value is the largest power-of-2 divisor of that frequency that does not exceed freq_Hz . Zero may be passed to deconfigure the TIMER. |
bitmode | the NRF_TIMER_Type::BITMODE.BITMODE setting controlling the range for timer counter values. |
use_constlat | pass true to ensure that NRF_POWER->TASKS_CONSTLAT is in force as long as the timer is configured; pass false if the timer can tolerate running in NRF_POWER->TASKS_LOWPWR mode. If freq_Hz is zero any previously-specified constant latency dependency is removed. |
- Returns
- 0 if configuration is successful, or -1 if a parameter is invalid.
- Note
- The timer must be started before it is useful. Startup time may be reduced if
use_constlat
is true
.
◆ counter()
unsigned int nrfcxx::periph::TIMER::counter |
( |
unsigned int |
ccidx = 0 | ) |
const |
|
inline |
Read the current timer value.
Since the timer counter is not exposed a capture/compare index must be provided. The caller is responsible for ensuring that ccidx
is not used for other purposes that would be disrupted by invocations of counter().
- Returns
- the full-precision counter value.
◆ delta()
unsigned int nrfcxx::periph::TIMER::delta |
( |
unsigned int |
a, |
|
|
unsigned int |
b |
|
) |
| const |
|
inline |
Calculate the count distance from a
to b
.
The value is truncated based on the bitmode
passed to configure().
◆ instance()
static TIMER& nrfcxx::periph::TIMER::instance |
( |
int |
idx | ) |
|
|
static |
Reference the abstraction instance for a specific peripheral instance.
- Parameters
-
idx | the peripheral instance desired. |
- Warning
- If
idx
specifies a peripheral instance that does not exist on the device the system will reset into failsafe mode.
◆ timestamp()
timestamp_type nrfcxx::periph::TIMER::timestamp |
( |
unsigned int |
ccidx = 0 | ) |
const |
|
inline |
Create a timestamp instance using this timer.
- Parameters
-
ccidx | the capture/compare index to be used for counter captures. |
- Returns
- a #timestamp_type object initialized to time activity relative to the current counter value.
◆ cc_mask
constexpr static unsigned int nrfcxx::periph::TIMER::cc_mask = 7 |
|
staticconstexpr |
Mask to create a valid CC index from a non-negative integer.
This allows up to 8 capture/compare registers. Not all registers are available on all timers.
The documentation for this class was generated from the following file: