System Timing#
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 or structures that provide a timestamp, such as RAIL_RxPacketDetails_t::timeReceived, 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 RAIL_Init() 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 cb parameter passed to RAIL_SetTimer() as NULL and poll for expiration with the RAIL_IsTimerExpired() function. See below for an example of the interrupt driven method of interacting with the timer.
void timerCb(RAIL_Handle_t cbArg)
{
// Timer callback action
}
void main(void)
{
// Initialize RAIL ...
// Set up a timer for 1 ms from now
RAIL_SetTimer(railHandle, 1000, RAIL_TIME_RELATIVE, &timerCb);
// Run main loop
while(1);
}
If multiple software timers are needed to be run off of the one available hardware timer, enable a software multiplexing layer within RAIL using the RAIL_ConfigMultiTimer() function. This will allow you to set up as many timers as you want using the RAIL_*MultiTimer() functions. See the example below for using the multitimer functionality.
// Declare timer structures in global space or somewhere that will exist
// until the callback has fired
RAIL_MultiTimer_t tmr1, tmr2;
void timerCb(RAIL_MultiTimer_t *tmr,
RAIL_Time_t expectedTimeOfEvent,
void *cbArg)
{
if (tmr == tmr1) {
// Timer 1 action
} else {
// Timer 2 action
}
}
void main(void)
{
// Initialize RAIL ...
RAIL_ConfigMultiTimer(true);
// Set up one timer for 1 ms from now and one at time 2000000 in the RAIL
// timebase
RAIL_SetMultiTimer(&tmr1, 1000, RAIL_TIME_RELATIVE, &timerCb, NULL);
RAIL_SetMultiTimer(&tmr2, 2000000, RAIL_TIME_ABSOLUTE, &timerCb, NULL);
// Run main loop
while(1);
}
Modules#
Enumerations#
Specify a time offset in RAIL APIs.
The available packet timestamp position choices.
Typedefs#
Time in microseconds.
A pointer to the callback called when the RAIL timer expires.
Callback fired when timer expires.
Functions#
Get the current RAIL time.
Set the current RAIL time.
Blocking delay routine for a specified number of microseconds.
Schedule a timer to expire using the RAIL timebase.
Return the absolute time that the RAIL timer was configured to expire.
Stop the currently scheduled RAIL timer.
Check whether the RAIL timer has expired.
Check whether the RAIL timer is currently running.
Configure the RAIL software timer feature.
Start a multitimer instance.
Stop the currently scheduled RAIL multitimer.
Check if a given timer is running.
Check if a given timer has expired.
Get time left before a given timer instance expires.
Enumeration Documentation#
RAIL_TimeMode_t#
RAIL_TimeMode_t
Specify 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. |
RAIL_TIME_DELAY | The time specified is relative to the current time. |
RAIL_TIME_DISABLED | The specified time is invalid and should be ignored. |
228
of file common/rail_types.h
RAIL_PacketTimePosition_t#
RAIL_PacketTimePosition_t
The available packet timestamp position choices.
Enumerator | |
---|---|
RAIL_PACKET_TIME_INVALID | Indicate that a timestamp is not to be or was not provided. |
RAIL_PACKET_TIME_DEFAULT | Request the choice most expedient for RAIL to calculate, which may depend on the radio and/or its configuration. |
RAIL_PACKET_TIME_AT_PREAMBLE_START | Request the timestamp corresponding to the first preamble bit sent or received. |
RAIL_PACKET_TIME_AT_PREAMBLE_START_USED_TOTAL | Request the timestamp corresponding to the first preamble bit sent or received. |
RAIL_PACKET_TIME_AT_SYNC_END | Request the timestamp corresponding to right after its last SYNC word bit has been sent or received. |
RAIL_PACKET_TIME_AT_SYNC_END_USED_TOTAL | Request the timestamp corresponding to right after its last SYNC word bit has been sent or received. |
RAIL_PACKET_TIME_AT_PACKET_END | Request the timestamp corresponding to right after its last bit has been sent or received. |
RAIL_PACKET_TIME_AT_PACKET_END_USED_TOTAL | Request the timestamp corresponding to right after its last bit has been sent or received. |
RAIL_PACKET_TIME_COUNT | A count of the choices in this enumeration. |
302
of file common/rail_types.h
Typedef Documentation#
RAIL_TimerCallback_t#
typedef void(* RAIL_TimerCallback_t) (RAIL_Handle_t cbArg) )(RAIL_Handle_t cbArg)
A pointer to the callback called when the RAIL timer expires.
[in] | cbArg | The argument passed to the callback. |
219
of file common/rail_types.h
RAIL_MultiTimerCallback_t#
RAIL_MultiTimerCallback_t )(struct RAIL_MultiTimer *tmr, RAIL_Time_t expectedTimeOfEvent, void *cbArg)
Callback fired when timer expires.
[in] | tmr | A pointer to an expired timer. |
[in] | expectedTimeOfEvent | An absolute time event fired. |
[in] | cbArg | A user-supplied callback argument. |
276
of file common/rail_types.h
Function Documentation#
RAIL_GetTime#
RAIL_Time_t RAIL_GetTime (void )
Get the current RAIL time.
N/A |
Returns
Returns the RAIL timebase in microseconds. Note that this wraps after about 1.19 hours since it's stored in a 32 bit value.
Returns the current time in the RAIL timebase (microseconds). It can be used to compare with packet timestamps or to schedule transmits.
987
of file common/rail.h
RAIL_SetTime#
RAIL_Status_t RAIL_SetTime (RAIL_Time_t time)
Set the current RAIL time.
[in] | time | Set the RAIL timebase to this value in microseconds. |
Warnings
Use this API only for testing purposes or in very limited circumstances during RAIL Timer Synchronization. Undefined behavior can result by calling it in multiprotocol or when the radio is not idle or timed events are active. Applications using RAIL_GetTime() may not be designed for discontinuous changes to the RAIL time base.
Returns
Status code indicating the success of the function call.
Sets the current time in the RAIL timebase in microseconds.
1004
of file common/rail.h
RAIL_DelayUs#
RAIL_Status_t RAIL_DelayUs (RAIL_Time_t microseconds)
Blocking delay routine for a specified number of microseconds.
[in] | microseconds | Delay duration in microseconds. |
Returns
Status code indicating success of the function call.
Use this RAIL API only for short blocking delays because it has less overhead than calling RAIL_GetTime() in a loop. Note
Passing large delay values may give unpredictable results or trigger the Watchdog reset.
Also, this function will start the clocks required for the RAIL timebase if they are not running, except between RAIL_Sleep() and RAIL_Wake() where the timer must remain stopped.
Interrupts are not disabled during the delay, so the delay may be longer if an interrupt extends beyond the delay duration.
1023
of file common/rail.h
RAIL_SetTimer#
RAIL_Status_t RAIL_SetTimer (RAIL_Handle_t railHandle, RAIL_Time_t time, RAIL_TimeMode_t mode, RAIL_TimerCallback_t cb)
Schedule a timer to expire using the RAIL timebase.
[in] | railHandle | A RAIL instance handle. |
[in] | time | The timer's expiration time in the RAIL timebase. |
[in] | mode | Indicates 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] | cb | The 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.
Warnings
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.
1048
of file common/rail.h
RAIL_GetTimer#
RAIL_Time_t RAIL_GetTimer (RAIL_Handle_t railHandle)
Return the absolute time that the RAIL timer was configured to expire.
[in] | railHandle | A 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.
1064
of file common/rail.h
RAIL_CancelTimer#
void RAIL_CancelTimer (RAIL_Handle_t railHandle)
Stop the currently scheduled RAIL timer.
[in] | railHandle | A RAIL instance handle. 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. |
1074
of file common/rail.h
RAIL_IsTimerExpired#
bool RAIL_IsTimerExpired (RAIL_Handle_t railHandle)
Check whether the RAIL timer has expired.
[in] | railHandle | A RAIL instance handle. |
Returns
True if the previously scheduled timer has expired and false otherwise.
Polling with this function is an alternative to the callback.
1085
of file common/rail.h
RAIL_IsTimerRunning#
bool RAIL_IsTimerRunning (RAIL_Handle_t railHandle)
Check whether the RAIL timer is currently running.
[in] | railHandle | A RAIL instance handle. |
Returns
Returns true if the timer is running and false if the timer has expired or was never set.
1094
of file common/rail.h
RAIL_ConfigMultiTimer#
bool RAIL_ConfigMultiTimer (bool enable)
Configure the RAIL software timer feature.
[in] | enable | Enables/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. Do not call this function 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.
1117
of file common/rail.h
RAIL_SetMultiTimer#
RAIL_Status_t RAIL_SetMultiTimer (RAIL_MultiTimer_t * tmr, RAIL_Time_t expirationTime, RAIL_TimeMode_t expirationMode, RAIL_MultiTimerCallback_t callback, void * cbArg)
Start a multitimer instance.
[inout] | tmr | A pointer to the timer instance to start. |
[in] | expirationTime | A time when the timer is set to expire. |
[in] | expirationMode | Select mode of expirationTime. See RAIL_TimeMode_t. |
[in] | callback | A function to call on timer expiry. See RAIL_MultiTimerCallback_t. NULL is a legal value. |
[in] | cbArg | An extra callback function parameter for the user application. |
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.
Returns
RAIL_STATUS_NO_ERROR on success.
RAIL_STATUS_INVALID_PARAMETER if tmr has an illegal value or if timeout is in the past.
1141
of file common/rail.h
RAIL_CancelMultiTimer#
bool RAIL_CancelMultiTimer (RAIL_MultiTimer_t * tmr)
Stop the currently scheduled RAIL multitimer.
[inout] | tmr | A 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.
1160
of file common/rail.h
RAIL_IsMultiTimerRunning#
bool RAIL_IsMultiTimerRunning (RAIL_MultiTimer_t * tmr)
Check if a given timer is running.
[in] | tmr | A pointer to the timer structure to query. |
Returns
true if the timer is running. false if the timer is not running.
1171
of file common/rail.h
RAIL_IsMultiTimerExpired#
bool RAIL_IsMultiTimerExpired (RAIL_MultiTimer_t * tmr)
Check if a given timer has expired.
[in] | tmr | A pointer to the timer structure to query. |
Returns
true if the timer is expired. false if the timer is running.
1182
of file common/rail.h
RAIL_GetMultiTimer#
RAIL_Time_t RAIL_GetMultiTimer (RAIL_MultiTimer_t * tmr, RAIL_TimeMode_t timeMode)
Get time left before a given timer instance expires.
[in] | tmr | A pointer to the timer structure to query. |
[in] | timeMode | Indicates 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.
1199
of file common/rail.h