gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
rtc.h
1
2/*
3 * MIT License
4 *
5 * Copyright (c) 2020 Joey Castillo
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#pragma once
27
28#include <stdint.h>
29#include <stdbool.h>
30
38#define RTC_REFERENCE_YEAR (2020)
39
40typedef union {
41 struct {
42 uint32_t second : 6; // 0-59
43 uint32_t minute : 6; // 0-59
44 uint32_t hour : 5; // 0-23
45 uint32_t day : 5; // 1-31
46 uint32_t month : 4; // 1-12
47 uint32_t year : 6; // 0-63 (representing 2020-2083)
48 } unit;
49 uint32_t reg; // the bit-packed value as expected by the RTC peripheral's CLOCK register.
51
52typedef enum rtc_alarm_match_t {
53 ALARM_MATCH_DISABLED = 0,
54 ALARM_MATCH_SS,
55 ALARM_MATCH_MMSS,
56 ALARM_MATCH_HHMMSS,
57} rtc_alarm_match_t;
58
59typedef void (*rtc_cb_t)(uint16_t intflag);
60
66void rtc_init(void);
67
70void rtc_enable(void);
71
75bool rtc_is_enabled(void);
76
86
92
97void rtc_enable_alarm_interrupt(rtc_date_time_t alarm_time, rtc_alarm_match_t mask);
98
102
103#if !defined(_SAMD21_) && !defined(_SAMD11_)
113void rtc_enable_periodic_interrupt(uint8_t index);
114
119void rtc_disable_periodic_interrupt(uint8_t index);
120#endif
121
126
131
137void rtc_configure_callback(rtc_cb_t callback);
138
164void rtc_enable_periodic_event_output(uint8_t index, bool enabled);
165
170void rtc_enable_alarm_event_output(bool enabled);
171
176void rtc_enable_overflow_event_output(bool enabled);
177
178#if defined(_SAML22_) || defined(_SAMD51_)
183void rtc_enable_tamper_event_input(bool enabled);
184
189void rtc_enable_tamper_event_output(bool enabled);
190#endif
191
void rtc_disable_alarm_interrupt(void)
Disables the alarm callback.
Definition rtc.c:118
void rtc_set_date_time(rtc_date_time_t date_time)
Sets the date and time.
Definition rtc.c:79
void rtc_enable_alarm_event_output(bool enabled)
Enables or disables the alarm event output.
Definition rtc.c:154
void rtc_enable_overflow_event_output(bool enabled)
Enables or disables the overflow event output.
Definition rtc.c:161
void rtc_disable_periodic_interrupt(uint8_t index)
Disables a periodic interval interrupt.
Definition rtc.c:130
void rtc_enable_periodic_interrupt(uint8_t index)
Enables a periodic interval interrupt.
Definition rtc.c:124
bool rtc_is_enabled(void)
Checks if the RTC is enabled.
Definition rtc.c:37
rtc_date_time_t rtc_get_date_time(void)
Returns the date and time.
Definition rtc.c:86
void rtc_enable_alarm_interrupt(rtc_date_time_t alarm_time, rtc_alarm_match_t mask)
Enables the alarm interrupt.
Definition rtc.c:98
void rtc_configure_callback(rtc_cb_t callback)
Configures the RTC alarm callback.
Definition rtc.c:107
void rtc_disable_overflow_interrupt(void)
Disables the overflow interrupt.
Definition rtc.c:142
void rtc_enable_periodic_event_output(uint8_t index, bool enabled)
Enables or disables a periodic interval event output.
Definition rtc.c:147
void rtc_enable(void)
Enables the RTC.
Definition rtc.c:73
void rtc_init(void)
Initializes the RTC.
Definition rtc.c:49
void rtc_enable_overflow_interrupt(void)
Enables the overflow interrupt.
Definition rtc.c:136
Definition rtc.h:40