Ref::Timers and Alarms

Leo Selavo edited this page Jan 19, 2016 · 7 revisions

Alarms (timers) are used for waiting for a certain time. There are also features available for measuring time since the reboot of the system.

Location

Functions

Setting Alarms

  • Timer callback function signature

      typedef void (*AlarmCallback)(void *);
    
  • Initialize an alarm callback

      void alarmInit(Alarm_t *alarm, AlarmCallback cb, void *param)
    
  • Schedule an alarm timer for N milliseconds after which the timer will fire (relative value). If the alarm is already scheduled, the function removes it first.

      void alarmSchedule(Alarm_t *alarm, uint32_t milliseconds);
    
  • Remove an alarm timer

      void alarmRemove(Alarm_t *alarm);
    
  • Get the milliseconds (relative value) after which the alarm is going to fire. Valid only when the alarm is active (i.e. scheduled)

      uint32_t getAlarmTime(Alarm_t *)
    

Getting time

  • Getting time elapsed since system start

      ticks_t getJiffies()
      uint32_t getTimeMs()
      uint64_t getTimeMs64()
      uint32_t getTimeSec()
    
  • Convert time values

      uint16_t convertAlarmTimerToMs(uint16_t ticks)
      uint16_t convertMsToAlarmTimer(uint16_t ms)
      uint16_t convertSleepTimerToMs(uint16_t ticks)
      uint16_t convertMsToSleepTimer(uint16_t ms)
    
  • Get the network-wide synchronized time in milliseconds or seconds

      uint32_t getSyncTimeMs()
      uint64_t getSyncTimeMs64()
      uint32_t getSyncTimeSec()
    

Example

The example code using alarms and timers is available here: apps/tests/AlarmTest

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.