aon_timer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_AON_TIMER_H
8#define _PICO_AON_TIMER_H
9
10#include "pico.h"
11#include <time.h>
12#include "pico/util/datetime.h"
13#include "hardware/regs/intctrl.h"
14
28#ifdef __cplusplus
29extern "C" {
30#endif
31
40#ifndef AON_TIMER_IRQ_NUM
41#if HAS_RP2040_RTC
42#define AON_TIMER_IRQ_NUM() RTC_IRQ
43#elif HAS_POWMAN_TIMER
44#define AON_TIMER_IRQ_NUM() POWMAN_IRQ_TIMER
45#endif
46#endif
47
48typedef void (*aon_timer_alarm_handler_t)(void);
49
55
61void aon_timer_start(const struct timespec *ts);
62
67void aon_timer_stop(void);
68
74void aon_timer_set_time(const struct timespec *ts);
75
81void aon_timer_get_time(struct timespec *ts);
82
88void aon_timer_get_resolution(struct timespec *ts);
89
105aon_timer_alarm_handler_t aon_timer_enable_alarm(const struct timespec *ts, aon_timer_alarm_handler_t handler, bool wakeup_from_low_power);
106
111void aon_timer_disable_alarm(void);
112
118bool aon_timer_is_running(void);
119
120static inline uint aon_timer_get_irq_num(void) {
121 return AON_TIMER_IRQ_NUM();
122}
123
124#ifdef __cplusplus
125}
126#endif
127
128#endif
bool aon_timer_is_running(void)
Disable the currently enabled AON timer alarm if any.
Definition: aon_timer.c:159
void aon_timer_disable_alarm(void)
Disable the currently enabled AON timer alarm if any.
Definition: aon_timer.c:103
void aon_timer_set_time(const struct timespec *ts)
Update the current time of the AON timer.
Definition: aon_timer.c:28
void aon_timer_start_with_timeofday(void)
Start the AON timer running using the result from the gettimeofday() function as the current time.
Definition: aon_timer.c:114
aon_timer_alarm_handler_t aon_timer_enable_alarm(const struct timespec *ts, aon_timer_alarm_handler_t handler, bool wakeup_from_low_power)
Enable an AON timer alarm for a specifed time.
Definition: aon_timer.c:61
void aon_timer_get_time(struct timespec *ts)
Get the current time of the AON timer.
Definition: aon_timer.c:41
void aon_timer_get_resolution(struct timespec *ts)
Get the resolution of the AON timer.
Definition: aon_timer.c:147
void aon_timer_start(const struct timespec *ts)
Start the AON timer running using the specified timespec as the current time.
Definition: aon_timer.c:123
void aon_timer_stop(void)
Stop the AON timer.
Definition: aon_timer.c:137