libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
common/rtc.h
Go to the documentation of this file.
1/** @addtogroup rtc_defines
2 *
3 * @author @htmlonly &copy; @endhtmlonly 2016 Maxim Sloyko <maxims@google.com>
4 * @author @htmlonly &copy; @endhtmlonly 2021 Eduard Drusa <ventyl86 at netkosice dot sk>
5 *
6 **/
7
8/*
9 * This file is part of the libopencm3 project.
10 *
11 * Copyright (C) 2017-2018 Unicore MX project<dev(at)lists(dot)unicore-mx(dot)org>
12 * Copyright (C) 2021 Eduard Drusa <ventyl86(at)netkosice(dot)sk>
13 *
14 * This library is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this library. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
33/**@{*/
34
35/* Only two RTCs on this device. */
36/** @addtogroup rtc_block RTC instances
37 * @{
38 */
39#define RTC0 RTC0_BASE
40#define RTC1 RTC1_BASE
41
42/**@}*/
43
44/* Tasks */
45#define RTC_TASK_START(rtc) MMIO32((rtc) + 0x000)
46#define RTC_TASK_STOP(rtc) MMIO32((rtc) + 0x004)
47#define RTC_TASK_CLEAR(rtc) MMIO32((rtc) + 0x008)
48#define RTC_TASK_TRIGOVRFLW(rtc) MMIO32((rtc) + 0x00C)
49
50/* Events */
51#define RTC_EVENT_TICK(rtc) MMIO32((rtc) + 0x100)
52#define RTC_EVENT_OVRFLW(rtc) MMIO32((rtc) + 0x104)
53#define RTC_EVENT_COMPARE(rtc, i) MMIO32((rtc) + 0x140 + 0x4 * (i))
54
55/* Registers */
56#define RTC_INTEN(rtc) _PERIPH_INTEN(rtc)
57#define RTC_INTENSET(rtc) _PERIPH_INTENSET(rtc)
58#define RTC_INTENCLR(rtc) _PERIPH_INTENCLR(rtc)
59#define RTC_EVTEN(rtc) MMIO32((rtc) + 0x340)
60#define RTC_EVTENSET(rtc) MMIO32((rtc) + 0x344)
61#define RTC_EVTENCLR(rtc) MMIO32((rtc) + 0x348)
62#define RTC_COUNTER(rtc) MMIO32((rtc) + 0x504)
63#define RTC_PRESCALER(rtc) MMIO32((rtc) + 0x508)
64#define RTC_CC(rtc, i) MMIO32((rtc) + 0x540 + 0x4 * (i))
65
66/* Register Contents */
67#define RTC_INTEN_TICK (1 << 0)
68#define RTC_INTEN_OVRFLW (1 << 1)
69#define RTC_INTEN_COMPARE(n) (1 << (16 + (n)))
70/**@}*/
71
73
74void rtc_set_prescaler(uint32_t rtc, uint16_t presc);
75uint32_t rtc_get_counter(uint32_t rtc);
76void rtc_enable_events(uint32_t rtc, uint32_t mask);
77void rtc_disable_events(uint32_t rtc, uint32_t mask);
78void rtc_start(uint32_t rtc);
79void rtc_stop(uint32_t rtc);
80void rtc_clear(uint32_t rtc);
81void rtc_set_compare(uint32_t rtc, uint8_t cmp, uint32_t value);
82
84
85
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void rtc_clear(uint32_t rtc)
Clear the RTC.
Definition: rtc.c:98
uint32_t rtc_get_counter(uint32_t rtc)
RTC get Counter value.
Definition: rtc.c:51
void rtc_disable_events(uint32_t rtc, uint32_t mask)
Disable events.
Definition: rtc.c:71
void rtc_start(uint32_t rtc)
Start the RTC.
Definition: rtc.c:80
void rtc_set_compare(uint32_t rtc, uint8_t cmp, uint32_t value)
Set compare register.
Definition: rtc.c:109
void rtc_set_prescaler(uint32_t rtc, uint16_t presc)
RTC set Prescaler value.
Definition: rtc.c:42
void rtc_stop(uint32_t rtc)
Stop the RTC.
Definition: rtc.c:89
void rtc_enable_events(uint32_t rtc, uint32_t mask)
Enable events.
Definition: rtc.c:61