Module device.wakeupmgr
RTC wakeup interface.
Many devices can schedule hardware wakeups with a real time clock alarm.
On embedded devices this can typically be easily manipulated by the user
through /sys/class/rtc/rtc0/wakealarm
. Some, like the Kobo Aura H2O,
can only schedule wakeups through ioctl.
See ffi.rtc for implementation details.
See also: https://linux.die.net/man/4/rtc.
Functions
WakeupMgr:new (o) | Initiate a WakeupMgr instance. |
WakeupMgr:addTask (seconds_from_now, callback) | Add a task to the queue. |
WakeupMgr:removeTasks (epoch, callback) | Remove task(s) from queue. |
WakeupMgr:removeTask (idx) | Variant of removeTasks that will only remove a single task, identified by its task queue index. |
WakeupMgr:wakeupAction (proximity) | Execute wakeup action. |
WakeupMgr:setWakeupAlarm (epoch, enabled) | Set wakeup alarm. |
WakeupMgr:unsetWakeupAlarm () | Unset wakeup alarm. |
WakeupMgr:getWakeupAlarm () | Get wakealarm as set by us. |
WakeupMgr:getWakeupAlarmEpoch () | Get wakealarm epoch as set by us. |
WakeupMgr:getWakeupAlarmSys () | Get RTC wakealarm from system. |
WakeupMgr:validateWakeupAlarmByProximity (task_alarm_epoch, proximity) | Validate wakeup alarm. |
WakeupMgr:isWakeupAlarmScheduled () | Check if a wakeup is scheduled. |
Tables
WakeupMgr | WakeupMgr base class. |
Functions
- WakeupMgr:new (o)
-
Initiate a WakeupMgr instance.
Parameters:
- o
Usage:
local WakeupMgr = require("device/wakeupmgr") local wakeup_mgr = WakeupMgr:new{ -- The default is
/dev/rtc0
, but some devices have more than one RTC. -- You might therefore need to use/dev/rtc1
, etc. dev_rtc = "/dev/rtc0", } - WakeupMgr:addTask (seconds_from_now, callback)
-
Add a task to the queue.
Parameters:
- seconds_from_now
- callback Make sure we passed valid input, so that stuff doesn't break in fun and interesting ways (especially in removeTasks).
- WakeupMgr:removeTasks (epoch, callback)
-
Remove task(s) from queue.
This method removes one or more tasks by either scheduled time or callback. If any tasks are left on exit, the upcoming one will automatically be scheduled (if necessary).
Parameters:
- epoch integer The epoch for when this task is scheduled to wake up. Normally the preferred method for outside callers.
- callback integer A scheduled callback function. Store a reference for use with anonymous functions.
Returns:
-
bool
(true if one or more tasks were removed; false otherwise; nil if the task queue is empty).
- WakeupMgr:removeTask (idx)
-
Variant of removeTasks that will only remove a single task, identified by its task queue index.
Parameters:
- idx integer Task queue index. Mainly useful within this module.
Returns:
-
bool
(true if a task was removed; false otherwise).
- WakeupMgr:wakeupAction (proximity)
-
Execute wakeup action.
This method should be called by the device resume logic in case of a scheduled wakeup.
It checks if the wakeup was scheduled by us using validateWakeupAlarmByProximity, in which case the task is executed.
If necessary, the next upcoming task (if any) is scheduled on exit.
Parameters:
- proximity integer Proximity window to the scheduled wakeup (passed to validateWakeupAlarmByProximity).
Returns:
-
bool
(true if we were truly woken up by the scheduled wakeup; false otherwise; nil if there weren't any tasks scheduled).
- WakeupMgr:setWakeupAlarm (epoch, enabled)
-
Set wakeup alarm.
Simple wrapper for ffi.rtc.setWakeupAlarm.
Parameters:
- epoch
- enabled
- WakeupMgr:unsetWakeupAlarm ()
-
Unset wakeup alarm.
Simple wrapper for ffi.rtc.unsetWakeupAlarm.
- WakeupMgr:getWakeupAlarm ()
-
Get wakealarm as set by us.
Simple wrapper for ffi.rtc.getWakeupAlarm.
- WakeupMgr:getWakeupAlarmEpoch ()
-
Get wakealarm epoch as set by us.
Simple wrapper for ffi.rtc.getWakeupAlarmEpoch.
- WakeupMgr:getWakeupAlarmSys ()
-
Get RTC wakealarm from system.
Simple wrapper for ffi.rtc.getWakeupAlarmSys.
- WakeupMgr:validateWakeupAlarmByProximity (task_alarm_epoch, proximity)
-
Validate wakeup alarm.
Checks if we set the alarm.
Simple wrapper for ffi.rtc.validateWakeupAlarmByProximity.
Parameters:
- task_alarm_epoch
- proximity
- WakeupMgr:isWakeupAlarmScheduled ()
-
Check if a wakeup is scheduled.
Simple wrapper for ffi.rtc.isWakeupAlarmScheduled.
Tables
- WakeupMgr
-
WakeupMgr base class.
Fields:
- dev_rtc RTC device
- _task_queue Table with epoch at which to schedule the task and the function to be scheduled.
- rtc The RTC implementation to use, defaults to the RTC module.
- dodgy_rtc If the RTC has trouble with timers further away than UINT16_MAX (e.g., on i.MX5).