pico-aon-timer
高级"常开定时器"抽象接口。
详细说明
此库在 RP2040 上使用 RTC,在 RP2350 上使用 Powman 定时器。
此库同时支持使用日历日期/时间(struct tm)的 aon_timer_xxx_calendar() 方法,以及使用相对内部参考时间线性时间值(struct timespec)的 aon_timer_xxx() 方法。
在 RP2040 上,非"日历日期/时间"方法需要在内部将线性时间值转换为日历日期/时间,这些方法包括:
-
-
-
-
- 此转换由
pico_localtime_r 方法处理。默认情况下,它会引入 C 库的 local_time_r 方法,可能导致二进制体积大幅增加。pico_localtime_r 的默认实现为弱符号,可在有更优/更小替代方案时覆盖;否则,在 RP2040 上可考虑改用以 _calendar()` 结尾的方法变体。
- 此转换由
-
-
-
在 RP2350 上,"日历日期/时间"方法需要在内部将日历日期/时间转换为线性时间值,这些方法包括:
-
-
-
- 此转换由
pico_mktime 方法处理。默认情况下,它会引入 C 库的 mktime 方法,可能导致二进制体积大幅增加。pico_mktime 的默认实现为弱符号,可在有更优/更小替代方案时覆盖;否则,在 RP2350 上可考虑改用不以 _calendar()` 结尾的方法变体。
- 此转换由
-
-
函数
void aon_timer_start_with_timeofday (void): 使用 gettimeofday() 函数的返回值作为当前时间,启动 AON 定时器。bool aon_timer_start (const struct timespec *ts)
使用指定的 timespec 作为当前时间,启动 AON 定时器。
bool aon_timer_start_calendar (const struct tm *tm)
使用指定的日历日期/时间作为当前时间,启动 AON 定时器。
void aon_timer_stop (void): 停止 AON 定时器。bool aon_timer_set_time (const struct timespec *ts)
设置 AON 定时器的当前时间。
bool aon_timer_set_time_calendar (const struct tm *tm)
将 AON 定时器的当前时间设置为给定的日历日期/时间。
bool aon_timer_get_time (struct timespec *ts)
获取 AON 定时器的当前时间。
bool aon_timer_get_time_calendar (struct tm *tm)
以日历日期/时间形式获取 AON 定时器的当前时间。
void aon_timer_get_resolution (struct timespec *ts)
获取 AON 定时器的精度。
aon_timer_alarm_handler_t aon_timer_enable_alarm (const struct timespec *ts, aon_timer_alarm_handler_t handler, bool wakeup_from_low_power)
为指定时间启用 AON 定时器闹钟。
aon_timer_alarm_handler_t aon_timer_enable_alarm_calendar (const struct tm *tm, aon_timer_alarm_handler_t handler, bool wakeup_from_low_power)
为指定的日历日期/时间启用 AON 定时器闹钟。
void aon_timer_disable_alarm (void): 禁用当前已启用的 AON 定时器闹钟(如有)。bool aon_timer_is_running (void): 检查 AON 定时器是否正在运行。
函数文档
aon_timer_disable_alarm
void aon_timer_disable_alarm (void)
禁用当前已启用的 AON 定时器闹钟(如有)。
aon_timer_enable_alarm
aon_timer_alarm_handler_t aon_timer_enable_alarm (const struct timespec * ts, aon_timer_alarm_handler_t handler, bool wakeup_from_low_power)
为指定时间启用 AON 定时器闹钟。
在 RP2350 上,若闹钟时间已过,闹钟仍会触发;在 RP2040 上,若闹钟时间已过,闹钟不会触发。
请参阅在 RP2040 上使用此方法的[注意事项]。
参数
ts: 闹钟时间handler: 定时器触发时调用的回调(当 wakeup_from_low_power = true 时可为 NULL)wakeup_from_low_power: 若 AON 定时器用于从 DORMANT 状态唤醒,则为 true
返回值
成功时返回旧的处理程序(若无则为 NULL),若内部时间格式转换失败则返回 PICO_ERROR_INVALID_ARG
参见
aon_timer_enable_alarm_calendar
aon_timer_alarm_handler_t aon_timer_enable_alarm_calendar (const struct tm * tm, aon_timer_alarm_handler_t handler, bool wakeup_from_low_power)
为指定的日历日期/时间启用 AON 定时器闹钟。
在 RP2350 上,若闹钟时间已过,闹钟仍会触发。
请参阅在 RP2350 上使用此方法的[注意事项]。
在 RP2040 上,若闹钟时间已过,闹钟不会触发。
参数
tm: 闹钟日历日期/时间handler: 定时器触发时调用的回调(当 wakeup_from_low_power = true 时可为 NULL)wakeup_from_low_power: 若 AON 定时器用于从 DORMANT 状态唤醒,则为 true
返回值
成功时返回旧的处理程序(若无则为 NULL),若内部时间格式转换失败则返回 PICO_ERROR_INVALID_ARG
参见
aon_timer_get_resolution
void aon_timer_get_resolution (struct timespec * ts)
获取 AON 定时器的精度。
参数
ts: AON 定时器精度的输出值
aon_timer_get_time
bool aon_timer_get_time (struct timespec * ts)
获取 AON 定时器的当前时间。
请参阅在 RP2040 上使用此方法的[注意事项]。
参数
ts: 当前时间的输出值
返回值
成功返回 true,若内部时间格式转换失败则返回 false
参见
aon_timer_get_time_calendar
bool aon_timer_get_time_calendar (struct tm * tm)
以日历日期/时间形式获取 AON 定时器的当前时间。
请参阅在 RP2350 上使用此方法的[注意事项]。
参数
tm: 当前日历日期/时间的输出值
返回值
成功返回 true,若内部时间格式转换失败则返回 false
参见