gossamer 0.0.0
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
rtc.h
Go to the documentation of this file.
1
5/*
6 * MIT License
7 *
8 * Copyright (c) 2020 Joey Castillo
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in all
18 * copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29#pragma once
30
31#include <stdint.h>
32#include <stdbool.h>
33
34#define RTC_REFERENCE_YEAR (2020)
35
36typedef union {
37 struct {
38 uint32_t second : 6; // 0-59
39 uint32_t minute : 6; // 0-59
40 uint32_t hour : 5; // 0-23
41 uint32_t day : 5; // 1-31
42 uint32_t month : 4; // 1-12
43 uint32_t year : 6; // 0-63 (representing 2020-2083)
44 } unit;
45 uint32_t reg; // the bit-packed value as expected by the RTC peripheral's CLOCK register.
47
48typedef enum rtc_alarm_match {
49 ALARM_MATCH_DISABLED = 0,
50 ALARM_MATCH_SS,
51 ALARM_MATCH_MMSS,
52 ALARM_MATCH_HHMMSS,
53} rtc_alarm_match;
54
55typedef void (*rtc_cb_t)(uint8_t source);
56
62void rtc_init(void);
63
66void rtc_enable(void);
67
71bool rtc_is_enabled(void);
72
81void rtc_set_date_time(rtc_date_time date_time);
82
88
93void rtc_enable_alarm_interrupt(rtc_date_time alarm_time, rtc_alarm_match mask);
94
98
102void rtc_configure_callback(rtc_cb_t callback);
void rtc_disable_alarm_interrupt(void)
Disables the alarm callback.
Definition: rtc.c:103
void rtc_set_date_time(rtc_date_time date_time)
Sets the date and time.
Definition: rtc.c:75
bool rtc_is_enabled(void)
Checks if the RTC is enabled.
Definition: rtc.c:37
void rtc_configure_callback(rtc_cb_t callback)
Configures the RTC alarm callback.
Definition: rtc.c:99
void rtc_enable(void)
Enables the RTC.
Definition: rtc.c:69
void rtc_init(void)
Initializes the RTC.
Definition: rtc.c:49
void rtc_enable_alarm_interrupt(rtc_date_time alarm_time, rtc_alarm_match mask)
Enables the alarm interrupt.
Definition: rtc.c:90
rtc_date_time rtc_get_date_time(void)
Returns the date and time.
Definition: rtc.c:80
Definition: rtc.h:36