System Timing

Functionality related to the RAIL timer and general system time.

Data Structures

struct  RAIL_MultiTimer_t
 RAIL timer state structure.
 
struct  RAIL_PacketTimeStamp_t
 Information needed to calculate and represent a packet timestamp.

Typedefs

typedef uint32_t RAIL_Time_t
 Time in microseconds.
 
typedef void(* RAIL_TimerCallback_t) (RAIL_Handle_t cbArg)
 A pointer to the callback called when the RAIL timer expires.
 
typedef void(* RAIL_MultiTimerCallback_t) (struct RAIL_MultiTimer *tmr, RAIL_Time_t expectedTimeOfEvent, void *cbArg)
 Callback fired when timer expires.

Enumerations

enum  RAIL_TimeMode_t {
  RAIL_TIME_ABSOLUTE,
  RAIL_TIME_DELAY,
  RAIL_TIME_DISABLED
}
 Specifies a time offset in RAIL APIs.
 
enum  RAIL_SleepConfig_t {
  RAIL_SLEEP_CONFIG_TIMERSYNC_DISABLED,
  RAIL_SLEEP_CONFIG_TIMERSYNC_ENABLED
}
 The configuration.
 
enum  RAIL_PacketTimePosition_t {
  RAIL_PACKET_TIME_INVALID = 0,
  RAIL_PACKET_TIME_DEFAULT = 1,
  RAIL_PACKET_TIME_AT_PREAMBLE_START = 2,
  RAIL_PACKET_TIME_AT_PREAMBLE_START_USED_TOTAL = 3,
  RAIL_PACKET_TIME_AT_SYNC_END = 4,
  RAIL_PACKET_TIME_AT_SYNC_END_USED_TOTAL = 5,
  RAIL_PACKET_TIME_AT_PACKET_END = 6,
  RAIL_PACKET_TIME_AT_PACKET_END_USED_TOTAL = 7,
  RAIL_PACKET_TIME_COUNT
}
 The available packet timestamp position choices.

Functions

RAIL_Time_t RAIL_GetTime (void)
 Gets the current RAIL time.
 
RAIL_Status_t RAIL_SetTime (RAIL_Time_t time)
 Sets the current RAIL time.
 
RAIL_Status_t RAIL_SetTimer (RAIL_Handle_t railHandle, RAIL_Time_t time, RAIL_TimeMode_t mode, RAIL_TimerCallback_t cb)
 Schedules a timer to expire using the RAIL timebase.
 
RAIL_Time_t RAIL_GetTimer (RAIL_Handle_t railHandle)
 Returns the absolute time that the RAIL timer was configured to expire.
 
void RAIL_CancelTimer (RAIL_Handle_t railHandle)
 Stops the currently scheduled RAIL timer.
 
bool RAIL_IsTimerExpired (RAIL_Handle_t railHandle)
 Checks whether the RAIL timer has expired.
 
bool RAIL_IsTimerRunning (RAIL_Handle_t railHandle)
 Checks whether the RAIL timer is currently running.
 
bool RAIL_ConfigMultiTimer (bool enable)
 Configures the RAIL software timer feature.
 
RAIL_Status_t RAIL_SetMultiTimer (RAIL_MultiTimer_t *tmr, RAIL_Time_t expirationTime, RAIL_TimeMode_t expirationMode, RAIL_MultiTimerCallback_t callback, void *cbArg)
 Starts a multitimer instance.
 
bool RAIL_CancelMultiTimer (RAIL_MultiTimer_t *tmr)
 Stops the currently scheduled RAIL multi timer.
 
bool RAIL_IsMultiTimerRunning (RAIL_MultiTimer_t *tmr)
 Checks if a given timer is running.
 
bool RAIL_IsMultiTimerExpired (RAIL_MultiTimer_t *tmr)
 Checks if a given timer has expired.
 
RAIL_Time_t RAIL_GetMultiTimer (RAIL_MultiTimer_t *tmr, RAIL_TimeMode_t timeMode)
 Gets time left before a given timer instance expires.
 
RAIL_Status_t RAIL_ConfigSleep (RAIL_Handle_t railHandle, RAIL_SleepConfig_t sleepConfig)
 Initializes RAIL timer synchronization.
 
RAIL_Status_t RAIL_Sleep (uint16_t wakeupProcessTime, bool *deepSleepAllowed)
 Stops the RAIL timer and prepares RAIL for sleep.
 
RAIL_Status_t RAIL_Wake (RAIL_Time_t elapsedTime)
 Wakes RAIL from sleep and restarts the RAIL timer.

Detailed Description

Functionality related to the RAIL timer and general system time.

These functions can be used to get information about the current system time or to manipulate the RAIL timer.

The system time returned by RAIL_GetTime() is in the same timebase that is used throughout RAIL. Any callbacks that return a timestamp, such as rxPacketReceived(), will use the same timebase as will any APIs that accept an absolute time for scheduling their action. Throughout the documentation, the timebase is referred to as the RAIL timebase. The timebase is currently a value in microseconds from chip boot time, which means that it will wrap every 1.19 hours. ((2^32 - 1) / (3600 sec/hr * 1000000 us/sec)).

The provided timer is hardware-backed and interrupt-driven. It can be used for timing any event in the system, but is especially helpful for timing protocol-based state machines and other systems that interact with the radio. To avoid processing the expiration in interrupt context, leave the timerExpired() callback empty and poll for expiration with the RAIL_IsTimerExpired() function.

Typedef Documentation

RAIL_MultiTimerCallback_t

Callback fired when timer expires.

Parameters
[in]tmrA pointer to an expired timer.
[in]expectedTimeOfEventAn absolute time event fired.
[in]cbArgA user-supplied callback argument.

Definition at line 204 of file rail_types.h.

typedef void(* RAIL_TimerCallback_t) (RAIL_Handle_t cbArg)

A pointer to the callback called when the RAIL timer expires.

Parameters
[in]cbArgThe argument passed to the callback.
Returns
void.

Definition at line 147 of file rail_types.h.

Enumeration Type Documentation

The available packet timestamp position choices.

Enumerator
RAIL_PACKET_TIME_INVALID 

Indicates that a timestamp is not to be or was not provided.

It is useful if the application doesn't care about packet timestamps and doesn't want RAIL to spend time calculating one.

RAIL_PACKET_TIME_DEFAULT 

Requests the choice most expedient for RAIL to calculate, which may depend on the radio and/or its configuration.

The actual choice would always be reflected in the timePosition field of RAIL_RxPacketDetails_t or RAIL_TxPacketDetails_t returned and would never be one of the _USED_TOTAL values.

RAIL_PACKET_TIME_AT_PREAMBLE_START 

Requests the timestamp corresponding to the first preamble bit sent or received.

Indicates that timestamp did not require using totalPacketBytes.

RAIL_PACKET_TIME_AT_PREAMBLE_START_USED_TOTAL 

Requests the timestamp corresponding to the first preamble bit sent or received.

Indicates that timestamp did require using totalPacketBytes.

RAIL_PACKET_TIME_AT_SYNC_END 

Requests the timestamp corresponding to right after its last SYNC word bit has been sent or received.

Indicates that timestamp did not require using totalPacketBytes.

RAIL_PACKET_TIME_AT_SYNC_END_USED_TOTAL 

Requests the timestamp corresponding to right after its last SYNC word bit has been sent or received.

Indicates that timestamp did require using totalPacketBytes.

RAIL_PACKET_TIME_AT_PACKET_END 

Requests the timestamp corresponding to right after its last bit has been sent or received.

Indicates that timestamp did not require using totalPacketBytes.

RAIL_PACKET_TIME_AT_PACKET_END_USED_TOTAL 

Requests the timestamp corresponding to right after its last bit has been sent or received.

Indicates that timestamp did require using totalPacketBytes.

RAIL_PACKET_TIME_COUNT 

A count of the choices in this enumeration.

Definition at line 245 of file rail_types.h.

The configuration.

Enumerator
RAIL_SLEEP_CONFIG_TIMERSYNC_DISABLED 

Disable timer sync before and after sleep.

RAIL_SLEEP_CONFIG_TIMERSYNC_ENABLED 

Enable timer sync before and after sleep.

Definition at line 230 of file rail_types.h.

Specifies a time offset in RAIL APIs.

Different APIs use the same constants and may provide more specifics about how they're used but the general use for each is described below.

Enumerator
RAIL_TIME_ABSOLUTE 

The time specified is an exact time in the RAIL timebase.

The given event should happen at exactly that time. If this time is already in the past, an error is returned. Because the RAIL timebase wraps at 32 bits, there is no real 'past'. Instead, any event greater than 3/4 of the way into the future is considered to be in the past.

RAIL_TIME_DELAY 

The time specified is relative to the current time.

The event should occur that many ticks in the future. Delays are only guaranteed at least as long as the value specified. An overhead may occur between the time when the API is called and when the delay starts. As a result, using this for operations that must happen at an exact given time is not recommended. For that, you must use RAIL_TIME_ABSOLUTE delays.

Note that, if you specify a delay 0, that event is triggered as soon as possible. This is different than specifying an absolute time of now which would return an error unless it was possible.

RAIL_TIME_DISABLED 

The specified time is invalid and should be ignored.

For some APIs this can also indicate that any previously stored delay should be invalidated and disabled.

Definition at line 156 of file rail_types.h.

Function Documentation

bool RAIL_CancelMultiTimer ( RAIL_MultiTimer_t tmr)

Stops the currently scheduled RAIL multi timer.

Parameters
[in,out]tmrA RAIL timer instance handle.
Returns
true if the timer was successfully canceled. false if the timer was not running.

Cancels the timer. If this function is called before the timer expires, the cb callback specified in the earlier RAIL_SetTimer() call will never be called.

void RAIL_CancelTimer ( RAIL_Handle_t  railHandle)

Stops the currently scheduled RAIL timer.

Parameters
[in]railHandleA RAIL instance handle.
Returns
void.

Cancels the timer. If this function is called before the timer expires, the cb callback specified in the earlier RAIL_SetTimer() call will never be called.

bool RAIL_ConfigMultiTimer ( bool  enable)

Configures the RAIL software timer feature.

Parameters
[in]enableEnables/disables the RAIL multitimer.
Returns
True if the multitimer was successfully enabled/disabled, false otherwise.

Turning this on will add a software timer layer above the physical RAIL timer so that the user can have as many timers as desired. It is not necessary to call this function if the MultiTimer APIs are not used.

Note
This function must be called before calling RAIL_SetMultiTimer. This function is a no-op on multiprotocol as this layer is already used under the hood. It should not be called while the RAIL timer is running. Call RAIL_IsTimerRunning before enabling/disabling the multitimer. If the multitimer is not needed, do not call this function to allow the multitimer code to be dead stripped. If the multiTimer is enabled for use, the multiTimer and timer APIs

can both be used; however, no timer can be in use while this function

is being called.

RAIL_Status_t RAIL_ConfigSleep ( RAIL_Handle_t  railHandle,
RAIL_SleepConfig_t  sleepConfig 
)

Initializes RAIL timer synchronization.

Parameters
[in]railHandleA RAIL instance handle.
[in]sleepConfigA sleep configuration.
Returns
Status code indicating success of the function call.
RAIL_Time_t RAIL_GetMultiTimer ( RAIL_MultiTimer_t tmr,
RAIL_TimeMode_t  timeMode 
)

Gets time left before a given timer instance expires.

Parameters
[in]tmrA pointer to the timer structure to query.
[in]timeModeIndicates how the function provides the time remaining. By choosing RAIL_TimeMode_t::RAIL_TIME_ABSOLUTE, the function returns the absolute expiration time, and by choosing RAIL_TimeMode_t::RAIL_TIME_DELAY, the function returns the amount of time remaining before the timer's expiration.
Returns
Time left expressed in RAIL's time units. 0 if the soft timer is not running or has already expired.
RAIL_Time_t RAIL_GetTime ( void  )

Gets the current RAIL time.

Returns
Returns the RAIL timebase in microseconds. Note that this wraps after about 1.19 hours since it's stored in a 32bit value.

Returns the current time in the RAIL timebase (microseconds). It can be used to compare with packet timestamps or to schedule transmits.

RAIL_Time_t RAIL_GetTimer ( RAIL_Handle_t  railHandle)

Returns the absolute time that the RAIL timer was configured to expire.

Parameters
[in]railHandleA RAIL instance handle.
Returns
The absolute time that this timer was set to expire.

Provides the absolute time regardless of the RAIL_TimeMode_t that was passed into RAIL_SetTimer. Note that the time might be in the past if the timer has already expired. The return value is undefined if the timer was never set.

bool RAIL_IsMultiTimerExpired ( RAIL_MultiTimer_t tmr)

Checks if a given timer has expired.

Parameters
[in]tmrA pointer to the timer structure to query.
Returns
true if the timer is expired. false if the timer is running.
bool RAIL_IsMultiTimerRunning ( RAIL_MultiTimer_t tmr)

Checks if a given timer is running.

Parameters
[in]tmrA pointer to the timer structure to query.
Returns
true if the timer is running. false if the timer is not running.
bool RAIL_IsTimerExpired ( RAIL_Handle_t  railHandle)

Checks whether the RAIL timer has expired.

Parameters
[in]railHandleA RAIL instance handle.
Returns
True if the previously scheduled timer has expired and false otherwise.

Polling via this function can be used as an alternative to the callback.

bool RAIL_IsTimerRunning ( RAIL_Handle_t  railHandle)

Checks whether the RAIL timer is currently running.

Parameters
[in]railHandleA RAIL instance handle.
Returns
Returns true if the timer is running and false if the timer has expired or was never set.
RAIL_Status_t RAIL_SetMultiTimer ( RAIL_MultiTimer_t tmr,
RAIL_Time_t  expirationTime,
RAIL_TimeMode_t  expirationMode,
RAIL_MultiTimerCallback_t  callback,
void *  cbArg 
)

Starts a multitimer instance.

Note
It is legal to start an already running timer. If this is done, the timer will first be stopped before the new configuration is applied. If expirationTime is 0, the callback is called immediately.
Parameters
[in,out]tmrA pointer to the timer instance to start.
[in]expirationTimeA time when the timer is set to expire.
[in]expirationModeSelect mode of expirationTime. See RAIL_TimeMode_t.
[in]callbackA function to call on timer expiry. See RAIL_MultiTimerCallback_t. NULL is a legal value.
[in]cbArgAn extra callback function parameter for the user application.
Returns
RAIL_STATUS_NO_ERROR on success.
RAIL_STATUS_INVALID_PARAMETER if tmr has an illegal value or if timeout is in the past.
RAIL_Status_t RAIL_SetTime ( RAIL_Time_t  time)

Sets the current RAIL time.

Parameters
[in]timeSet the RAIL timebase to this value in microseconds.
Returns
Status code indicating success of the function call.

Sets the current time in the RAIL timebase in microseconds.

RAIL_Status_t RAIL_SetTimer ( RAIL_Handle_t  railHandle,
RAIL_Time_t  time,
RAIL_TimeMode_t  mode,
RAIL_TimerCallback_t  cb 
)

Schedules a timer to expire using the RAIL timebase.

Parameters
[in]railHandleA RAIL instance handle.
[in]timeThe timer's expiration time in the RAIL timebase.
[in]modeIndicates whether the time argument is an absolute RAIL time or relative to the current RAIL time. Specifying mode RAIL_TIME_DISABLED is the same as calling RAIL_CancelTimer().
[in]cbThe callback for RAIL to call when the timer expires.
Returns
RAIL_STATUS_NO_ERROR on success and RAIL_STATUS_INVALID_PARAMETER if the timer can't be scheduled.

Configures a timer to expire after a period in the RAIL timebase. This timer can be used to implement low-level protocol features.

Warning
Attempting to schedule the timer when it is still running from a previous request is bad practice, unless the cb callback is identical to that used in the previous request, in which case the timer is rescheduled to the new time. Note that if the original timer expires as it is being rescheduled, the callback may or may not occur. It is generally good practice to cancel a running timer before rescheduling it to minimize ambiguity.
RAIL_Status_t RAIL_Sleep ( uint16_t  wakeupProcessTime,
bool *  deepSleepAllowed 
)

Stops the RAIL timer and prepares RAIL for sleep.

Parameters
[in]wakeupProcessTimeTime in microseconds that the application and hardware need to recover from sleep state.
[out]deepSleepAllowedtrue - system can go to deep sleep. false - system should not go to deep sleep. Deep sleep should be blocked in this case.
Returns
Status code indicating success of the function call.
Warning
The active RAIL configuration must be idle to enable sleep.
RAIL_Status_t RAIL_Wake ( RAIL_Time_t  elapsedTime)

Wakes RAIL from sleep and restarts the RAIL timer.

Parameters
[in]elapsedTimeAdd the sleep duration to the RAIL timer before restarting the RAIL timer.
Returns
Status code indicating success of the function call.

If the timer sync was enabled by RAIL_ConfigSleep, synchronize the RAIL timer using an alternate timer. Otherwise, add elapsedTime to the RAIL timer.