SLEEPTIMER
Detailed Description
Low frequency timer utilities. Utilities (timer, delays and time keeping).
sleeptimer module
The sleeptimer.c and sleeptimer.h source files for the SLEEPTIMER device driver library are in the service/sleeptimer folder.
Introduction
The Sleeptimer driver provides software timers, delays, timekeeping and date functionalities based on the low-frequency real-time clock peripheral.
All Silicon Laboratories microcontrollers equipped with the RTC or RTCC peripheral are currently supported. Only one instance of this driver can be initialized by the application.
Functionalities overview
Software timers
This functionality allows the user to create periodic and one shot timers. A user callback can be associated with a timer. It will be called from when the timer expires.
Timer structures must be allocated by the user. The callback function is called from within an interrupt handler with interrupts enabled.
Timekeeping
A 64-bits tick counter accessible through the uint64_t sl_sleeptimer_get_tick_count64(void) API. It keeps the tick count since the initialization of the driver
The SL_SLEEPTIMER_WALLCLOCK_CONFIG configuration enables a UNIX timestamp (seconds count since January 1, 1970, 00:00:00).
This timestamp can also be accessed the following API:
- sl_sleeptimer_timestamp_t sl_sleeptimer_get_time(void) ;
- sl_status_t sl_sleeptimer_set_time(sl_sleeptimer_timestamp_t time) ;
Convenience conversion functions are provided to convert UNIX timestamp to NTP and Zigbee cluster format :
- sl_status_t sl_sleeptimer_convert_unix_time_to_ntp(sl_sleeptimer_timestamp_t time, uint32_t *ntp_time) ;
- sl_status_t sl_sleeptimer_convert_ntp_time_to_unix(uint32_t ntp_time, sl_sleeptimer_timestamp_t *time) ;
- sl_status_t sl_sleeptimer_convert_unix_time_to_zigbee(sl_sleeptimer_timestamp_t time, uint32_t *zigbee_time) ;
- sl_status_t sl_sleeptimer_convert_zigbee_time_to_unix(uint32_t zigbee_time, sl_sleeptimer_timestamp_t *time) ;
Date
The previously described internal timestamp can also be accessed through a date format sl_sleeptimer_date_t.
API :
- sl_status_t sl_sleeptimer_get_datetime(sl_sleeptimer_date_t *date) ;
- sl_status_t sl_sleeptimer_set_datetime(sl_sleeptimer_date_t *date) ;
Frequency setup and tick unit
This driver works with a configurable time unit called tick.
The value of a tick is based on the clock source and the internal frequency divider.
One of the following clock sources must be enabled before initializing the sleeptimer:
- LFXO: external crystal oscillator. Typically running at 32.768 kHz.
- LFRCO: internal oscillator running at 32.768 kHz
- ULFRCO: Ultra low-frequency oscillator running at 1.000 kHz
The frequency divider is selected with the SL_SLEEPTIMER_FREQ_DIVIDER configuration. Its value must be a power of two within the range 1 to 32.
Tick (seconds) = 1 / (clock_frequency / frequency_divider)
The highest resolution is 30.5 us. It is achieved with a 32.768 kHz clock and a divider of 1.
Configuration Options
SL_SLEEPTIMER_PERIPHERAL can be set to one of the three following values :
SL_SLEEPTIMER_WALLCLOCK_CONFIG must be defined to 1 to enable the following functionalities :
- Timekeeping through UNIX timestamp
- Date
- Timestamp Conversion functions
SL_SLEEPTIMER_FREQ_DIVIDER value must be a power of 2 within the range 1 to 32.
The API
This section contains brief descriptions of the API functions. For more information about input and output parameters and return values, click on the hyperlinked function names. Most functions return an error code,
SL_STATUS_OK
is returned on success, see
sl_status.h
for other error codes.
The application code must include the
sl_sleeptimer.h
header file.
All API functions can be called from within interrupt handlers.
sl_sleeptimer_init()
These functions initialize the sleeptimer driver. Typically, sl_sleeptimer_init() is called once in the startup code.
sl_sleeptimer_start_timer()
Start a one shot 32 bits timer. When a timer expires, a user-supplied callback function is called. A pointer to this function is passed to sl_sleeptimer_start_timer(). See
callback
for details of the callback prototype.
sl_sleeptimer_restart_timer()
Restart a one shot 32 bits timer. When a timer expires, a user-supplied callback function is called. A pointer to this function is passed to sl_sleeptimer_start_timer(). See
callback
for details of the callback prototype.
sl_sleeptimer_start_periodic_timer()
Start a periodic 32 bits timer. When a timer expires, a user-supplied callback function is called. A pointer to this function is passed to sl_sleeptimer_start_timer(). See
callback
for details of the callback prototype.
sl_sleeptimer_restart_periodic_timer()
Restart a periodic 32 bits timer. When a timer expires, a user-supplied callback function is called. A pointer to this function is passed to sl_sleeptimer_start_timer(). See
callback
for details of the callback prototype.
sl_sleeptimer_stop_timer()
Stop a timer.
sl_sleeptimer_get_timer_time_remaining()
Get time left to the timer expiration.
sl_sleeptimer_delay_millisecond()
Delay for the given number of milliseconds. This is an "active wait" delay function.
sl_sleeptimer_is_timer_running()
Check if a timer is running.
sl_sleeptimer_get_time()
,
sl_sleeptimer_set_time()
Get or set wallclock time.
sl_sleeptimer_ms_to_tick()
,
sl_sleeptimer_ms32_to_tick()
,
sl_sleeptimer_tick_to_ms()
,
sl_sleeptimer_tick64_to_ms()
Convert between milliseconds and RTC/RTCC counter ticks.
The timer expiry callback function:
The callback function, prototyped as
sl_sleeptimer_timer_callback_t()
, is called from within the RTC peripheral interrupt handler on timer expiration. sl_sleeptimer_timer_callback_t(sl_sleeptimer_timer_handle_t *handle, void *data)
Example
sl_sleeptimer.h
"
Data Structures |
|
struct | sl_sleeptimer_timer_handle |
struct | time_date |
Time and Date structure.
|
|
Macros |
|
#define | SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG 0x01 |
#define | SLEEPTIMER_ENUM (name) typedef uint8_t name; enum name##_enum |
Typedefs |
|
typedef struct time_date | sl_sleeptimer_date_t |
Time and Date structure.
|
|
typedef int32_t | sl_sleeptimer_time_zone_offset_t |
Time zone offset from UTC(second).
|
|
typedef void(* | sl_sleeptimer_timer_callback_t ) ( sl_sleeptimer_timer_handle_t *handle, void *data) |
typedef struct sl_sleeptimer_timer_handle | sl_sleeptimer_timer_handle_t |
typedef uint32_t | sl_sleeptimer_timestamp_t |
Timestamp, wall clock time in seconds.
|
|
Typedef Documentation
typedef void(* sl_sleeptimer_timer_callback_t) ( sl_sleeptimer_timer_handle_t *handle, void *data) |
Typedef for the user supplied callback function which is called when a timer expires.
- Parameters
-
handle
The timer handle. data
An extra parameter for the user application.
Definition at line
61
of file
sl_sleeptimer.h
.
Function Documentation
sl_status_t sl_sleeptimer_build_datetime | ( | sl_sleeptimer_date_t * |
date,
|
uint16_t |
year,
|
||
sl_sleeptimer_month_t |
month,
|
||
uint8_t |
month_day,
|
||
uint8_t |
hour,
|
||
uint8_t |
min,
|
||
uint8_t |
sec,
|
||
sl_sleeptimer_time_zone_offset_t |
tz_offset
|
||
) |
Builds a date time structure based on the provided parameters.
- Parameters
-
date
Pointer to the structure to be populated. year
Current year. May be provided based on a 0 Epoch or a 1900 Epoch. month
Months since January. Expected value: 0-11. month_day
Day of the month. Expected value: 1-31. hour
Hours since midnight. Expected value: 0-23. min
Minutes after the hour. Expected value: 0-59. sec
Seconds after the minute. Expected value: 0-59. tzOffset
Offset, in seconds, from UTC.
- Returns
- 0 if successful. Error code otherwise.
Builds a date time structure based on the provided parameters.
Definition at line
532
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , SL_STATUS_NULL_POINTER , SL_STATUS_OK , time_date::time_zone , and time_date::year .
uint32_t sl_sleeptimer_convert_date_to_str | ( | char * |
str,
|
size_t |
size,
|
||
const uint8_t * |
format,
|
||
sl_sleeptimer_date_t * |
date
|
||
) |
Convert date to string.
- Parameters
-
str
Output string. size
Size of the input array. format
The format specification character. date
Pointer to date structure.
- Returns
- 0 if error. Number of character in the output string.
- Note
- Refer strftime() from UNIX. http://man7.org/linux/man-pages/man3/strftime.3.html
Definition at line
661
of file
sl_sleeptimer.c
.
References time_date::year .
sl_status_t sl_sleeptimer_convert_date_to_time | ( | sl_sleeptimer_date_t * |
date,
|
sl_sleeptimer_timestamp_t * |
time
|
||
) |
Converts a date into a Unix timestamp.
- Parameters
-
date
Pointer to date to convert. time
Pointer to converted Unix timestamp.
- Returns
- 0 if successful. Error code otherwise.
- Note
-
Dates are based on the Unix time representation. Range of dates supported :
- January 1, 1970, 00:00:00 to January 19, 2038, 03:14:00
Definition at line
620
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , SL_STATUS_OK , time_date::time_zone , and time_date::year .
Referenced by sl_sleeptimer_set_datetime() .
sl_status_t sl_sleeptimer_convert_ntp_time_to_unix | ( | uint32_t |
ntp_time,
|
sl_sleeptimer_timestamp_t * |
time
|
||
) |
Converts NTP timestamp into Unix timestamp.
- Parameters
-
ntp_time
NTP Timestamp. time
Pointer to Unix timestamp.
- Note
- NTP timestamp range supported : 0x83AA 7E80 to 0xFFFF FFFF ie. January 1, 1970, 00:00:00 to February 07, 2036, 06:28:15
- Returns
- 0 if successful. Error code otherwise.
Converts NTP timestamp into Unix timestamp.
Definition at line
738
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_convert_time_to_date | ( | sl_sleeptimer_timestamp_t |
time,
|
sl_sleeptimer_time_zone_offset_t |
time_zone,
|
||
sl_sleeptimer_date_t * |
date
|
||
) |
Converts a Unix timestamp into a date.
- Parameters
-
time
Unix timestamp to convert. time_zone
Offset from UTC in second. date
Pointer to converted date.
- Returns
- 0 if successful. Error code otherwise.
Definition at line
570
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , SL_STATUS_OK , time_date::time_zone , and time_date::year .
Referenced by sl_sleeptimer_get_datetime() .
sl_status_t sl_sleeptimer_convert_unix_time_to_ntp | ( | sl_sleeptimer_timestamp_t |
time,
|
uint32_t * |
ntp_time
|
||
) |
Converts Unix timestamp into NTP timestamp.
- Parameters
-
time
Unix timestamp. ntp_time
Pointer to NTP Timestamp.
- Note
- Unix timestamp range supported : 0x0 to 0x7C55 817F ie. January 1, 1970, 00:00:00 to February 07, 2036, 06:28:15
- Returns
- 0 if successful. Error code otherwise.
Converts Unix timestamp into NTP timestamp.
Definition at line
722
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_convert_unix_time_to_zigbee | ( | sl_sleeptimer_timestamp_t |
time,
|
uint32_t * |
zigbee_time
|
||
) |
Converts Unix timestamp into Zigbee timestamp.
- Parameters
-
time
Unix timestamp. zigbee_time
Pointer to NTP Timestamp.
- Note
- Unix timestamp range supported : 0x386D 4380 to 0x7FFF FFFF ie. January 1, 2000, 00:00:0 to January 19, 2038, 03:14:00
- Returns
- 0 if successful. Error code otherwise.
Converts Unix timestamp into Zigbee timestamp.
Definition at line
754
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_convert_zigbee_time_to_unix | ( | uint32_t |
zigbee_time,
|
sl_sleeptimer_timestamp_t * |
time
|
||
) |
Converts Zigbee timestamp into Unix timestamp.
- Parameters
-
zigbee_time
NTP Timestamp. time
Pointer to Unix timestamp.
- Note
- ZIGBEE timestamp range supported : 0x0 to 0x4792 BC7F ie. January 1, 2000, 00:00:00 to January 19, 2038, 03:14:00
- Returns
- 0 if successful. Error code otherwise.
Converts Zigbee timestamp into Unix timestamp.
Definition at line
770
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
void sl_sleeptimer_delay_millisecond | ( | uint16_t |
time_ms
|
) |
Active delay.
- Parameters
-
time_ms
Delay duration in milliseconds.
Definition at line
788
of file
sl_sleeptimer.c
.
References sl_sleeptimer_ms_to_tick() , sl_sleeptimer_start_timer() , and SL_STATUS_OK .
Referenced by delay_10ms() , and delay_1ms() .
sl_status_t sl_sleeptimer_get_datetime | ( | sl_sleeptimer_date_t * |
date
|
) |
Gets current date.
- Parameters
-
date
Pointer to a sl_sleeptimer_date_t structure.
- Returns
- 0 if successful. Error code otherwise.
Gets current date.
Definition at line
494
of file
sl_sleeptimer.c
.
References sl_sleeptimer_convert_time_to_date() , sl_sleeptimer_get_time() , sl_sleeptimer_get_tz() , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_get_remaining_time_of_first_timer | ( | uint16_t |
option_flags,
|
uint32_t * |
time_remaining
|
||
) |
Gets the time remaining until the first timer with the matching set of flags expires.
- Parameters
-
option_flags
Set of flags to match. time_remaining
Time left in timer ticks.
- Returns
- 0 if successful. Error code otherwise.
Gets the time remaining until the first timer with the matching set of flags expires.
Definition at line
376
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , CORE_EXIT_ATOMIC , sl_sleeptimer_timer_handle::delta , sl_sleeptimer_timer_handle::next , sl_sleeptimer_timer_handle::option_flags , SL_STATUS_EMPTY , and SL_STATUS_OK .
uint32_t sl_sleeptimer_get_tick_count | ( | void |
|
) |
Gets current 32 bits global tick count.
- Returns
- Current tick count.
Gets current 32 bits tick count.
Definition at line
405
of file
sl_sleeptimer.c
.
uint64_t sl_sleeptimer_get_tick_count64 | ( | void |
|
) |
Gets current 64 bits global tick count.
- Returns
- Current tick count.
Gets current 64 bits tick count.
Definition at line
413
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , and CORE_EXIT_ATOMIC .
sl_sleeptimer_timestamp_t sl_sleeptimer_get_time | ( | void |
|
) |
Retrieves current time.
- Returns
- Current timestamps in Unix format.
Retrieves current time.
Definition at line
437
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , CORE_EXIT_ATOMIC , and sl_sleeptimer_get_timer_frequency() .
Referenced by sl_sleeptimer_get_datetime() .
uint32_t sl_sleeptimer_get_timer_frequency | ( | void |
|
) |
Get timer frequency.
- Returns
- 0 if successful. Error code otherwise.
Get timer frequency.
Definition at line
428
of file
sl_sleeptimer.c
.
Referenced by sl_sleeptimer_get_time() , and sl_sleeptimer_set_time() .
sl_status_t sl_sleeptimer_get_timer_time_remaining | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t * |
time
|
||
) |
Gets remaining time until timer expires.
- Parameters
-
handle
Pointer to handle to timer. time
Time left in timer ticks.
- Returns
- 0 if successful. Error code otherwise.
Gets a 32 bits timer's time remaining.
Definition at line
333
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , CORE_EXIT_ATOMIC , sl_sleeptimer_timer_handle::delta , sl_sleeptimer_timer_handle::next , SL_STATUS_NOT_READY , SL_STATUS_NULL_POINTER , and SL_STATUS_OK .
Referenced by UTIL_waitForEvent() .
sl_sleeptimer_time_zone_offset_t sl_sleeptimer_get_tz | ( | void |
|
) |
Gets time zone offset.
- Returns
- Time zone offset, in seconds.
Definition at line
707
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , and CORE_EXIT_ATOMIC .
Referenced by sl_sleeptimer_get_datetime() .
sl_status_t sl_sleeptimer_init | ( | void |
|
) |
Initializes the Sleeptimer.
- Returns
- 0 if successful. Error code otherwise.
Initializes sleep timer.
Definition at line
128
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , CORE_EXIT_ATOMIC , and SL_STATUS_OK .
Referenced by SPIDRV_Init() , and UTIL_sleepInit() .
sl_status_t sl_sleeptimer_is_timer_running | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
bool * |
running
|
||
) |
Gets the status of a timer.
- Parameters
-
handle
Pointer to handle to timer. running
Pointer to the status of the timer.
- Note
- A non periodic timer is considered not running during its callback.
- Returns
- 0 if successful. Error code otherwise.
Gets the status of a timer.
Definition at line
306
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , CORE_EXIT_ATOMIC , sl_sleeptimer_timer_handle::next , SL_STATUS_NULL_POINTER , and SL_STATUS_OK .
Referenced by sl_sleeptimer_start_periodic_timer() , and sl_sleeptimer_start_timer() .
sl_status_t sl_sleeptimer_ms32_to_tick | ( | uint32_t |
time_ms,
|
uint32_t * |
tick
|
||
) |
Converts 32-bits milliseconds in ticks.
- Parameters
-
time_ms
Number of milliseconds. tick
Pointer to the converted tick number.
- Returns
- 0 if successful. Error code otherwise.
- Note
- The result is "rounded" to the superior tick number. If possible the sl_sleeptimer_ms_to_tick() function should be used. The millisecond 32-bits range is not fully supported, depending on the timer frequency. The function will return an error if the converted number of ticks would overflow.
Definition at line
818
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
Referenced by sl_sleeptimer_restart_periodic_timer_ms() , sl_sleeptimer_restart_timer_ms() , sl_sleeptimer_start_periodic_timer_ms() , and sl_sleeptimer_start_timer_ms() .
uint32_t sl_sleeptimer_ms_to_tick | ( | uint16_t |
time_ms
|
) |
Converts milliseconds in ticks.
- Parameters
-
time_ms
Number of milliseconds.
- Returns
- Corresponding ticks number.
- Note
- The result is "rounded" to the superior tick number. This function is light and cannot fail so it should be privilegied to perform a millisecond to tick conversion.
Definition at line
810
of file
sl_sleeptimer.c
.
Referenced by sl_sleeptimer_delay_millisecond() .
sl_status_t sl_sleeptimer_restart_periodic_timer | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Restarts a 32 bits periodic timer.
- Parameters
-
handle
Pointer to handle to timer. timeout
Timer periodic timeout, in timer ticks. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG or 0 for not flags.
- Returns
- 0 if successful. Error code otherwise.
Restarts a 32 bits periodic timer.
Definition at line
243
of file
sl_sleeptimer.c
.
References sl_sleeptimer_stop_timer() , and SL_STATUS_NULL_POINTER .
Referenced by sl_sleeptimer_restart_periodic_timer_ms() .
__STATIC_INLINE sl_status_t sl_sleeptimer_restart_periodic_timer_ms | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout_ms,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Restarts a 32 bits periodic timer.
- Parameters
-
handle
Pointer to handle to timer. timeout_ms
Timer periodic timeout, in milliseconds. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG or 0 for not flags.
- Returns
- 0 if successful. Error code otherwise.
Definition at line
673
of file
sl_sleeptimer.h
.
References sl_sleeptimer_ms32_to_tick() , sl_sleeptimer_restart_periodic_timer() , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_restart_timer | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Restarts a 32 bits timer.
- Parameters
-
handle
Pointer to handle to timer. timeout
Timer timeout, in timer ticks. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG or 0 for not flags.
- Returns
- 0 if successful. Error code otherwise.
Restarts a 32 bits timer.
Definition at line
186
of file
sl_sleeptimer.c
.
References sl_sleeptimer_stop_timer() , and SL_STATUS_NULL_POINTER .
Referenced by sl_sleeptimer_restart_timer_ms() .
__STATIC_INLINE sl_status_t sl_sleeptimer_restart_timer_ms | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout_ms,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Restarts a 32 bits timer.
- Parameters
-
handle
Pointer to handle to timer. timeout_ms
Timer timeout, in milliseconds. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG or 0 for not flags.
- Returns
- 0 if successful. Error code otherwise.
Definition at line
603
of file
sl_sleeptimer.h
.
References sl_sleeptimer_ms32_to_tick() , sl_sleeptimer_restart_timer() , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_set_datetime | ( | sl_sleeptimer_date_t * |
date
|
) |
Sets current time, in date format.
- Parameters
-
date
Pointer to current date.
- Returns
- 0 if successful. Error code otherwise.
Sets current time, in date format.
Definition at line
510
of file
sl_sleeptimer.c
.
References sl_sleeptimer_convert_date_to_time() , sl_sleeptimer_set_time() , SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_set_time | ( | sl_sleeptimer_timestamp_t |
time
|
) |
Sets current time.
- Parameters
-
time
Time to set.
- Returns
- 0 if successful. Error code otherwise.
Sets current time.
Definition at line
460
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , CORE_EXIT_ATOMIC , sl_sleeptimer_get_timer_frequency() , SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
Referenced by sl_sleeptimer_set_datetime() .
void sl_sleeptimer_set_tz | ( | sl_sleeptimer_time_zone_offset_t |
offset
|
) |
Sets time zone offset.
- Parameters
-
offset
Time zone offset, in seconds.
Definition at line
693
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , and CORE_EXIT_ATOMIC .
__STATIC_INLINE sl_sleeptimer_time_zone_offset_t sl_sleeptimer_set_tz_ahead_utc | ( | uint8_t |
hours,
|
uint8_t |
minutes
|
||
) |
Calculates offset for time zone after UTC-0.
- Parameters
-
hours
Number of hours from UTC-0. minutes
Number of minutes from UTC-0.
- Returns
- The time zone offset in seconds.
Definition at line
469
of file
sl_sleeptimer.h
.
__STATIC_INLINE sl_sleeptimer_time_zone_offset_t sl_sleeptimer_set_tz_behind_utc | ( | uint8_t |
hours,
|
uint8_t |
minutes
|
||
) |
Calculates offset for time zone before UTC-0.
- Parameters
-
hours
Number of hours to UTC-0. minutes
Number of minutes to UTC-0.
- Returns
- The time zone offset in seconds.
Definition at line
483
of file
sl_sleeptimer.h
.
sl_status_t sl_sleeptimer_start_periodic_timer | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Starts a 32 bits periodic timer.
- Parameters
-
handle
Pointer to handle to timer. timeout
Timer periodic timeout, in timer ticks. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG or 0 for not flags.
- Returns
- 0 if successful. Error code otherwise.
Starts a 32 bits periodic timer.
Definition at line
213
of file
sl_sleeptimer.c
.
References sl_sleeptimer_is_timer_running() , SL_STATUS_INVALID_STATE , and SL_STATUS_NULL_POINTER .
Referenced by sl_sleeptimer_start_periodic_timer_ms() .
__STATIC_INLINE sl_status_t sl_sleeptimer_start_periodic_timer_ms | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout_ms,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Starts a 32 bits periodic timer.
- Parameters
-
handle
Pointer to handle to timer. timeout_ms
Timer periodic timeout, in milliseconds. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG or 0 for not flags.
- Returns
- 0 if successful. Error code otherwise.
Definition at line
638
of file
sl_sleeptimer.h
.
References sl_sleeptimer_ms32_to_tick() , sl_sleeptimer_start_periodic_timer() , and SL_STATUS_OK .
sl_status_t sl_sleeptimer_start_timer | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Starts a 32 bits timer.
- Parameters
-
handle
Pointer to handle to timer. timeout
Timer timeout, in timer ticks. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG
- Returns
- 0 if successful. Error code otherwise.
Starts a 32 bits timer.
Definition at line
156
of file
sl_sleeptimer.c
.
References sl_sleeptimer_is_timer_running() , SL_STATUS_NOT_READY , and SL_STATUS_NULL_POINTER .
Referenced by sl_sleeptimer_delay_millisecond() , and sl_sleeptimer_start_timer_ms() .
__STATIC_INLINE sl_status_t sl_sleeptimer_start_timer_ms | ( | sl_sleeptimer_timer_handle_t * |
handle,
|
uint32_t |
timeout_ms,
|
||
sl_sleeptimer_timer_callback_t |
callback,
|
||
void * |
callback_data,
|
||
uint8_t |
priority,
|
||
uint16_t |
option_flags
|
||
) |
Starts a 32 bits timer.
- Parameters
-
handle
Pointer to handle to timer. timeout_ms
Timer timeout, in milliseconds. callback
Callback function that will be called when initial/periodic timeout expires. callback_data
Pointer to user data that will be passed to callback. priority
Priority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority. option_flags
Bit array of option flags for the timer. Valid bit-wise OR of one or more of the following: - SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG or 0 for not flags.
- Returns
- 0 if successful. Error code otherwise.
Definition at line
568
of file
sl_sleeptimer.h
.
References sl_sleeptimer_ms32_to_tick() , sl_sleeptimer_start_timer() , and SL_STATUS_OK .
Referenced by SPIDRV_SReceive() , SPIDRV_SReceiveB() , SPIDRV_STransfer() , SPIDRV_STransferB() , SPIDRV_STransmit() , SPIDRV_STransmitB() , UTIL_sleep() , and UTIL_waitForEvent() .
sl_status_t sl_sleeptimer_stop_timer | ( | sl_sleeptimer_timer_handle_t * |
handle
|
) |
Stops a timer.
- Parameters
-
handle
Pointer to handle to timer.
- Returns
Stops a 32 bits timer.
Definition at line
270
of file
sl_sleeptimer.c
.
References CORE_DECLARE_IRQ_STATE , CORE_ENTER_ATOMIC , CORE_EXIT_ATOMIC , SL_STATUS_NULL_POINTER , and SL_STATUS_OK .
Referenced by sl_sleeptimer_restart_periodic_timer() , sl_sleeptimer_restart_timer() , SPIDRV_AbortTransfer() , SPIDRV_DeInit() , and UTIL_waitForEvent() .
sl_status_t sl_sleeptimer_tick64_to_ms | ( | uint64_t |
tick,
|
uint64_t * |
ms
|
||
) |
Converts 64-bit ticks in milliseconds.
- Parameters
-
tick
Number of tick. ms
Pointer to the converted milliseconds number.
- Returns
- 0 if successful. Error code otherwise.
- Note
- The result is rounded to the inferior millisecond.
Definition at line
844
of file
sl_sleeptimer.c
.
References SL_STATUS_INVALID_PARAMETER , and SL_STATUS_OK .
uint32_t sl_sleeptimer_tick_to_ms | ( | uint32_t |
tick
|
) |
Converts ticks in milliseconds.
- Parameters
-
tick
Number of tick.
- Returns
- Corresponding milliseconds number.
- Note
- The result is rounded to the inferior millisecond.
Definition at line
832
of file
sl_sleeptimer.c
.
Referenced by UTIL_waitForEvent() .