Hardware Real Time Clock API.
More...
Hardware Real Time Clock API.
The RTC keeps track of time in human readable format and generates events when the time is equal to a preset value. Think of a digital clock, not epoch time used by most computers. There are seven fields, one each for year (12 bit), month (4 bit), day (5 bit), day of the week (3 bit), hour (5 bit) minute (6 bit) and second (6 bit), storing the data in binary format.
- See also
- datetime_t
Example
#include <stdio.h>
int main() {
printf("Hello RTC!\n");
char datetime_buf[256];
char *datetime_str = &datetime_buf[0];
.month = 06,
.day = 05,
.dotw = 5,
.hour = 15,
.min = 45,
.sec = 00
};
while (true) {
printf("\r%s ", datetime_str);
}
return 0;
}
bool rtc_get_datetime(datetime_t *t)
Get the current time from the RTC.
Definition: rtc.c:88
bool rtc_set_datetime(datetime_t *t)
Set the RTC to the specified time.
Definition: rtc.c:55
void rtc_init(void)
Initialise the RTC system.
Definition: rtc.c:22
void stdio_init_all(void)
Initialize all of the present standard stdio types that are linked into the binary.
Definition: stdio.c:265
void sleep_ms(uint32_t ms)
Wait for the given number of milliseconds before returning.
Definition: time.c:392
void datetime_to_str(char *buf, uint buf_size, const datetime_t *t)
Convert a datetime_t structure to a string.
Definition: datetime.c:30
Structure containing date and time information.
Definition: types.h:81
int16_t year
0..4095
Definition: types.h:82
◆ rtc_callback_t
typedef void(* rtc_callback_t) (void) |
◆ rtc_get_datetime()
Get the current time from the RTC.
- Parameters
-
t | Pointer to a datetime_t structure to receive the current RTC time |
- Returns
- true if datetime is valid, false if the RTC is not running.
◆ rtc_set_alarm()
Set a time in the future for the RTC to call a user provided callback.
- Parameters
-
t | Pointer to a datetime_t structure containing a time in the future to fire the alarm. Any values set to -1 will not be matched on. |
user_callback | pointer to a rtc_callback_t to call when the alarm fires |
◆ rtc_set_datetime()
Set the RTC to the specified time.
- Parameters
-
t | Pointer to a datetime_t structure contains time to set |
- Returns
- true if set, false if the passed in datetime was invalid.