Loading...
Searching...
No Matches

Low-level RTT (Real Time Timer) peripheral driver. More...

Detailed Description

Low-level RTT (Real Time Timer) peripheral driver.

(Low-) Power Implications

After the RTT has been initialized (i.e. after calling rtt_init()), the RTT should be powered on and running. The RTT can then be powered off manually at a later point in time by calling the rtt_poweroff() function. When the RTT is powered back on using the rtt_poweron() function, it should transparently continue its previously configured operation.

On many CPUs, certain power states might need to be blocked in rtt_init(), so that it is ensured that the RTT will function properly while it is enabled.

Warning
This module will be automatically be used as a backend for ZTIMER_SEC and ZTIMER_MSEC. If direct access to RTT is needed then include ztimer_no_periph_rtt to avoid auto-selection, i.e.: USEMODULE += ztimer_no_periph_rtt.

Files

file  rtt.h
 Low-level RTT (Real Time Timer) peripheral driver interface definitions.
 

Macros

#define RTT_FREQUENCY
 The desired frequency for the RTT.
 
#define RTT_MAX_VALUE
 The maximum value for the RTT counter, must be (2^n - 1)
 
#define RTT_MIN_OFFSET   (2U)
 The minimum offset to correctly set an rtt callback.
 
#define RTT_US_TO_TICKS(us)   (RTT_SEC_TO_TICKS(us) / 1000000UL)
 Convert microseconds to rtt ticks.
 
#define RTT_MS_TO_TICKS(ms)   (RTT_SEC_TO_TICKS(ms) / 1000UL)
 Convert milliseconds to rtt ticks.
 
#define RTT_SEC_TO_TICKS(sec)   (sec * RTT_FREQUENCY)
 Convert seconds to rtt ticks.
 
#define RTT_MIN_TO_TICKS(min)   (RTT_SEC_TO_TICKS((min) * 60))
 Convert minutes to rtt ticks.
 
#define RTT_TICKS_TO_US(ticks)   ((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY)
 Convert rtt ticks to microseconds.
 
#define RTT_TICKS_TO_MS(ticks)   (RTT_TICKS_TO_US(ticks) / 1000)
 Convert rtt ticks to milliseconds.
 
#define RTT_TICKS_TO_SEC(ticks)   (RTT_TICKS_TO_MS(ticks) / 1000)
 Convert rtt ticks to seconds.
 
#define RTT_TICKS_TO_MIN(ticks)   (RTT_TICKS_TO_SEC(ticks) / 60)
 Convert rtt ticks to minutes.
 

Typedefs

typedef void(* rtt_cb_t) (void *arg)
 Signature for the alarm callback.
 

Functions

void rtt_init (void)
 Initialize RTT module.
 
void rtt_set_overflow_cb (rtt_cb_t cb, void *arg)
 Set a callback for the counter overflow event.
 
void rtt_clear_overflow_cb (void)
 Clear the overflow callback.
 
uint32_t rtt_get_counter (void)
 Get the current RTT counter.
 
void rtt_set_counter (uint32_t counter)
 Set the RTT counter to a specified value.
 
void rtt_set_alarm (uint32_t alarm, rtt_cb_t cb, void *arg)
 Set an alarm for RTT to the specified absolute target time.
 
uint32_t rtt_get_alarm (void)
 Get the value of a set alarm.
 
void rtt_clear_alarm (void)
 Clear any set alarm, do nothing if nothing set.
 
void rtt_poweron (void)
 Turn the RTT hardware module on.
 
void rtt_poweroff (void)
 Turn the RTT hardware module off.
 

Macro Definition Documentation

◆ RTT_FREQUENCY

#define RTT_FREQUENCY

The desired frequency for the RTT.

Definition at line 55 of file rtt.h.

◆ RTT_MAX_VALUE

#define RTT_MAX_VALUE

The maximum value for the RTT counter, must be (2^n - 1)

Definition at line 65 of file rtt.h.

◆ RTT_MIN_OFFSET

#define RTT_MIN_OFFSET   (2U)

The minimum offset to correctly set an rtt callback.

If the callback is taking into account rtt_get_counter() then the rtt might advance right between the call to rtt_get_counter() and rtt_set_alarm(). If that happens with val==1, the alarm would be set to the current time, which would then underflow. To avoid this, the alarm should be set at least two ticks in the future.

This value can vary depending on the platform.

Definition at line 83 of file rtt.h.

◆ RTT_MIN_TO_TICKS

#define RTT_MIN_TO_TICKS (   min)    (RTT_SEC_TO_TICKS((min) * 60))

Convert minutes to rtt ticks.

Parameters
[in]minnumber of minutes
Returns
rtt ticks

Definition at line 134 of file rtt.h.

◆ RTT_MS_TO_TICKS

#define RTT_MS_TO_TICKS (   ms)    (RTT_SEC_TO_TICKS(ms) / 1000UL)

Convert milliseconds to rtt ticks.

Parameters
[in]msnumber of milliseconds
Returns
rtt ticks

Definition at line 120 of file rtt.h.

◆ RTT_SEC_TO_TICKS

#define RTT_SEC_TO_TICKS (   sec)    (sec * RTT_FREQUENCY)

Convert seconds to rtt ticks.

Parameters
[in]secnumber of seconds
Returns
rtt ticks

Definition at line 127 of file rtt.h.

◆ RTT_TICKS_TO_MIN

#define RTT_TICKS_TO_MIN (   ticks)    (RTT_TICKS_TO_SEC(ticks) / 60)

Convert rtt ticks to minutes.

Parameters
[in]ticksrtt ticks
Returns
number of minutes

Definition at line 162 of file rtt.h.

◆ RTT_TICKS_TO_MS

#define RTT_TICKS_TO_MS (   ticks)    (RTT_TICKS_TO_US(ticks) / 1000)

Convert rtt ticks to milliseconds.

Parameters
[in]ticksrtt ticks
Returns
number of milliseconds

Definition at line 148 of file rtt.h.

◆ RTT_TICKS_TO_SEC

#define RTT_TICKS_TO_SEC (   ticks)    (RTT_TICKS_TO_MS(ticks) / 1000)

Convert rtt ticks to seconds.

Parameters
[in]ticksrtt ticks
Returns
number of seconds

Definition at line 155 of file rtt.h.

◆ RTT_TICKS_TO_US

#define RTT_TICKS_TO_US (   ticks)    ((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY)

Convert rtt ticks to microseconds.

Parameters
[in]ticksrtt ticks
Returns
number of microseconds

Definition at line 141 of file rtt.h.

◆ RTT_US_TO_TICKS

#define RTT_US_TO_TICKS (   us)    (RTT_SEC_TO_TICKS(us) / 1000000UL)

Convert microseconds to rtt ticks.

Parameters
[in]usnumber of microseconds
Returns
rtt ticks

Definition at line 113 of file rtt.h.

Typedef Documentation

◆ rtt_cb_t

typedef void(* rtt_cb_t) (void *arg)

Signature for the alarm callback.

Parameters
[in]argOptional argument which is passed to the callback

Definition at line 170 of file rtt.h.

Function Documentation

◆ rtt_get_alarm()

uint32_t rtt_get_alarm ( void  )

Get the value of a set alarm.

If no alarm is set, the return value is arbitrary.

Returns
Value the alarm is set to

◆ rtt_get_counter()

uint32_t rtt_get_counter ( void  )

Get the current RTT counter.

Returns
Current value of the RTT counter

◆ rtt_set_alarm()

void rtt_set_alarm ( uint32_t  alarm,
rtt_cb_t  cb,
void *  arg 
)

Set an alarm for RTT to the specified absolute target time.

Parameters
[in]alarmThe value to trigger an alarm when hit
[in]cbCallback executed when alarm is hit
[in]argArgument passed to callback when alarm is hit

◆ rtt_set_counter()

void rtt_set_counter ( uint32_t  counter)

Set the RTT counter to a specified value.

Parameters
[in]counterThe value to set the RTT to.
Note
This function is only provided when the feature periph_rtt_set_counter is provided

◆ rtt_set_overflow_cb()

void rtt_set_overflow_cb ( rtt_cb_t  cb,
void *  arg 
)

Set a callback for the counter overflow event.

Parameters
[in]cbCallback to execute on overflow
[in]argArgument passed to the callback