Menu Toggle
v2.3.1 (RP2040)
Toggle main menu visibility
Loading...
Searching...
No Matches
rtc.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3
*
4
* SPDX-License-Identifier: BSD-3-Clause
5
*/
6
7
#ifndef _HARDWARE_RTC_H
8
#define _HARDWARE_RTC_H
9
10
#include "
pico.h
"
11
#if HAS_RP2040_RTC
12
#include "hardware/structs/rtc.h"
13
14
// The RTC clock frequency is 48MHz divided by power of 2 (to ensure an integer
15
// division ratio will be used in the clocks block). A divisor of 1024 generates
16
// an RTC clock tick of 46875Hz. This frequency is relatively close to the
17
// customary 32 or 32.768kHz 'slow clock' crystals and provides good timing resolution.
18
#define RTC_CLOCK_FREQ_HZ (USB_CLK_HZ / 1024)
19
#endif
20
38
39
#ifdef __cplusplus
40
extern
"C"
{
41
#endif
42
48
typedef
void (*
rtc_callback_t
)(void);
49
53
void
rtc_init
(
void
);
54
65
bool
rtc_set_datetime
(
const
datetime_t
*t);
66
73
bool
rtc_get_datetime
(
datetime_t
*t);
74
79
bool
rtc_running
(
void
);
80
87
void
rtc_set_alarm
(
const
datetime_t
*t,
rtc_callback_t
user_callback);
88
92
void
rtc_enable_alarm
(
void
);
93
97
void
rtc_disable_alarm
(
void
);
98
108
bool
rtc_run_from_external_source
(uint32_t src_hz, uint gpio_pin);
109
110
#ifdef __cplusplus
111
}
112
#endif
113
114
#endif
rtc_set_datetime
bool rtc_set_datetime(const datetime_t *t)
Set the RTC to the specified time.
Definition
rtc.c:54
rtc_run_from_external_source
bool rtc_run_from_external_source(uint32_t src_hz, uint gpio_pin)
Run the RTC from an external clock source through GPIO.
Definition
rtc.c:192
rtc_disable_alarm
void rtc_disable_alarm(void)
Disable the RTC alarm (if active).
Definition
rtc.c:184
rtc_get_datetime
bool rtc_get_datetime(datetime_t *t)
Get the current time from the RTC.
Definition
rtc.c:87
rtc_callback_t
void(*) rtc_callback_t(void)
Definition
rtc.h:48
rtc_set_alarm
void rtc_set_alarm(const datetime_t *t, rtc_callback_t user_callback)
Set a time in the future for the RTC to call a user provided callback.
Definition
rtc.c:146
rtc_enable_alarm
void rtc_enable_alarm(void)
Enable the RTC alarm (if inactive).
Definition
rtc.c:108
rtc_running
bool rtc_running(void)
Is the RTC running?
Definition
rtc.c:18
rtc_init
void rtc_init(void)
Initialise the RTC system.
Definition
rtc.c:22
pico.h
datetime_t
Structure containing date and time information.
Definition
types.h:107