SLEEPTIMEREMDRV

Detailed Description

Low frequency timer utilities.

Utilities (timer, delays and time keeping).

Data Structures

struct  sl_sleeptimer_timer_handle
 
struct  time_date
 Time and Date structure.
 

Macros

#define ECODE_EMDRV_SLEEPTIMER_OK   (ECODE_OK)
 A successful return value.
 
#define ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR   (ECODE_EMDRV_SLEEPTIMER_BASE | 0x00000001)
 An illegal input parameter.
 
#define ECODE_EMDRV_SLEEPTIMER_TIMER_NOT_RUNNING   (ECODE_EMDRV_SLEEPTIMER_BASE | 0x00000002)
 A timer is not running.
 
#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.
 

Functions

void sl_sleeptimer_delay_millisecond (uint16_t time_ms)
 
uint32_t sl_sleeptimer_get_tick_count (void)
 
uint64_t sl_sleeptimer_get_tick_count64 (void)
 
uint32_t sl_sleeptimer_get_timer_frequency (void)
 
Ecode_t sl_sleeptimer_get_timer_time_remaining (sl_sleeptimer_timer_handle_t *handle, uint32_t *time)
 
Ecode_t sl_sleeptimer_init (void)
 
Ecode_t sl_sleeptimer_is_timer_running (sl_sleeptimer_timer_handle_t *handle, bool *running)
 
Ecode_t sl_sleeptimer_ms32_to_tick (uint32_t time_ms, uint32_t *tick)
 
uint32_t sl_sleeptimer_ms_to_tick (uint16_t time_ms)
 
Ecode_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)
 
Ecode_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)
 
Ecode_t sl_sleeptimer_stop_timer (sl_sleeptimer_timer_handle_t *handle)
 
Ecode_t sl_sleeptimer_tick64_to_ms (uint64_t tick, uint64_t *ms)
 
uint32_t sl_sleeptimer_tick_to_ms (uint32_t tick)
 
 SLEEPTIMER_ENUM (sl_sleeptimer_month_t)
 Month enum.
 
 SLEEPTIMER_ENUM (sl_sleeptimer_weekDay_t)
 Week Day enum.
 

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
handleThe timer handle.
dataAn extra parameter for the user application.

Definition at line 64 of file sleeptimer.h.

Function Documentation

void sl_sleeptimer_delay_millisecond ( uint16_t  time_ms)

Active delay.

Parameters
time_msDelay duration in milliseconds.

Definition at line 684 of file sleeptimer.c.

References ECODE_EMDRV_SLEEPTIMER_OK, sl_sleeptimer_ms_to_tick(), and sl_sleeptimer_start_timer().

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 301 of file 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 309 of file sleeptimer.c.

References CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, and CORE_EXIT_ATOMIC.

uint32_t sl_sleeptimer_get_timer_frequency ( void  )

Get timer frequency.

Returns
0 if successful. Error code otherwise.

Get timer frequency.

Definition at line 324 of file sleeptimer.c.

Ecode_t sl_sleeptimer_get_timer_time_remaining ( sl_sleeptimer_timer_handle_t handle,
uint32_t *  time 
)

Gets remaining time until timer expires.

Parameters
handlePointer to handle to timer.
timeTime left in timer ticks.
Returns
0 if successful. Error code otherwise.

Gets a 32 bits timer's time remaining.

Definition at line 259 of file sleeptimer.c.

References CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, CORE_EXIT_ATOMIC, sl_sleeptimer_timer_handle::delta, ECODE_EMDRV_SLEEPTIMER_OK, ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR, ECODE_EMDRV_SLEEPTIMER_TIMER_NOT_RUNNING, and sl_sleeptimer_timer_handle::next.

Ecode_t sl_sleeptimer_init ( void  )

Initializes the Sleeptimer.

Returns
0 if successful. Error code otherwise.

Initializes sleep timer.

Definition at line 126 of file sleeptimer.c.

References CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, CORE_EXIT_ATOMIC, and ECODE_EMDRV_SLEEPTIMER_OK.

Ecode_t sl_sleeptimer_is_timer_running ( sl_sleeptimer_timer_handle_t handle,
bool *  running 
)

Gets the status of a timer.

Parameters
handlePointer to handle to timer.
runningPointer to the status of the timer.
Returns
0 if successful. Error code otherwise.

Gets the status of a timer.

Definition at line 232 of file sleeptimer.c.

References CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, CORE_EXIT_ATOMIC, ECODE_EMDRV_SLEEPTIMER_OK, ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR, and sl_sleeptimer_timer_handle::next.

Ecode_t sl_sleeptimer_ms32_to_tick ( uint32_t  time_ms,
uint32_t *  tick 
)

Converts 32-bits milliseconds in ticks.

Parameters
time_msNumber of milliseconds.
tickPointer 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 713 of file sleeptimer.c.

References ECODE_EMDRV_SLEEPTIMER_OK, and ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR.

uint32_t sl_sleeptimer_ms_to_tick ( uint16_t  time_ms)

Converts milliseconds in ticks.

Parameters
time_msNumber 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 705 of file sleeptimer.c.

Referenced by sl_sleeptimer_delay_millisecond().

Ecode_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 
)

Starts a 32 bits periodic timer.

Parameters
handlePointer to handle to timer.
timeoutTimer periodic timeout, in timer ticks.
callbackCallback function that will be called when initial/periodic timeout expires.
callbackDataPointer to user data that will be passed to callback.
priorityPriority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority.
Returns
0 if successful. Error code otherwise.

Starts a 32 bits periodic timer.

Definition at line 175 of file sleeptimer.c.

References ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR.

Ecode_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 
)

Starts a 32 bits timer.

Parameters
handlePointer to handle to timer.
timeoutTimer timeout, in timer ticks.
callbackCallback function that will be called when initial/periodic timeout expires.
callbackDataPointer to user data that will be passed to callback.
priorityPriority of callback. Useful in case multiple timer expire at the same time. 0 = highest priority.
Returns
0 if successful. Error code otherwise.

Starts a 32 bits timer.

Definition at line 154 of file sleeptimer.c.

References ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR.

Referenced by sl_sleeptimer_delay_millisecond().

Ecode_t sl_sleeptimer_stop_timer ( sl_sleeptimer_timer_handle_t handle)

Stops a timer.

Parameters
handlePointer to handle to timer.
Returns

Stops a 32 bits timer.

Definition at line 196 of file sleeptimer.c.

References CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, CORE_EXIT_ATOMIC, ECODE_EMDRV_SLEEPTIMER_OK, and ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR.

Ecode_t sl_sleeptimer_tick64_to_ms ( uint64_t  tick,
uint64_t *  ms 
)

Converts 64-bit ticks in milliseconds.

Parameters
tickNumber of tick.
msPointer to the converted milliseconds number.
Returns
0 if successful. Error code otherwise.
Note
The result is rounded to the inferior millisecond.

Definition at line 739 of file sleeptimer.c.

References ECODE_EMDRV_SLEEPTIMER_OK, and ECODE_EMDRV_SLEEPTIMER_PARAM_ERROR.

uint32_t sl_sleeptimer_tick_to_ms ( uint32_t  tick)

Converts ticks in milliseconds.

Parameters
tickNumber of tick.
Returns
Corresponding milliseconds number.
Note
The result is rounded to the inferior millisecond.

Definition at line 727 of file sleeptimer.c.