libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
rtc.c
Go to the documentation of this file.
1/** @addtogroup rtc_file RTC peripheral API
2 *
3 * @brief <b>Access functions for the Real Time Counter Controller </b>
4 *
5 * @ingroup peripheral_apis
6 * LGPL License Terms @ref lgpl_license
7 * @author @htmlonly &copy; @endhtmlonly 2016
8 * Maxim Sloyko <maxims@google.com>
9 *
10 */
11
12/*
13 * This file is part of the libopencm3 project.
14 *
15 * Copyright (C) 2017-2018 Unicore MX project<dev(at)lists(dot)unicore-mx(dot)org>
16 * Copyright (C) 2021 Eduard Drusa <ventyl86(at)netkosice(dot)sk>
17 *
18 * This library is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU Lesser General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with this library. If not, see <http://www.gnu.org/licenses/>.
30 */
31
32#include <libopencm3/nrf/rtc.h>
33/**@{*/
34
35/** @brief RTC set Prescaler value.
36 *
37 * @details The clock needs to be stopped for this to have any effect.
38 *
39 * @param[in] rtc uint32_t RTC base
40 * @param[in] presc uint16_t 12 bit prescaler value.
41 */
42void rtc_set_prescaler(uint32_t rtc, uint16_t presc)
43{
44 RTC_PRESCALER(rtc) = presc & 0xfff;
45}
46
47/** @brief RTC get Counter value.
48 *
49 * @param[in] rtc uint32_t RTC base
50 */
51uint32_t rtc_get_counter(uint32_t rtc)
52{
53 return RTC_COUNTER(rtc);
54}
55
56/** @brief Enable events
57 *
58 * @param[in] rtc uint32_t RTC base
59 * @param[in] mask uint32_t which events to enable
60 */
61void rtc_enable_events(uint32_t rtc, uint32_t mask)
62{
63 RTC_EVTENSET(rtc) = mask;
64}
65
66/** @brief Disable events
67 *
68 * @param[in] rtc uint32_t RTC base
69 * @param[in] mask uint32_t which events to disable
70 */
71void rtc_disable_events(uint32_t rtc, uint32_t mask)
72{
73 RTC_EVTENCLR(rtc) = mask;
74}
75
76/** @brief Start the RTC
77 *
78 * @param[in] rtc uint32_t RTC base
79 */
80void rtc_start(uint32_t rtc)
81{
83}
84
85/** @brief Stop the RTC
86 *
87 * @param[in] rtc uint32_t RTC base
88 */
89void rtc_stop(uint32_t rtc)
90{
92}
93
94/** @brief Clear the RTC
95 *
96 * @param[in] rtc uint32_t RTC base
97 */
98void rtc_clear(uint32_t rtc)
99{
101}
102
103/** @brief Set compare register
104 *
105 * @param[in] rtc uint32_t RTC base
106 * @param[in] cmp uint8_t compare number (0-3)
107 * @param[in] value uint32_t compare value
108 */
109void rtc_set_compare(uint32_t rtc, uint8_t cmp, uint32_t value)
110{
111 if (cmp < 4) {
112 RTC_CC(rtc, cmp) = value;
113 }
114}
115/**@}*/
116
#define PERIPH_TRIGGER_TASK(task)
#define RTC_TASK_START(rtc)
Definition: common/rtc.h:45
#define RTC_EVTENSET(rtc)
Definition: common/rtc.h:60
#define RTC_EVTENCLR(rtc)
Definition: common/rtc.h:61
#define RTC_PRESCALER(rtc)
Definition: common/rtc.h:63
#define RTC_TASK_STOP(rtc)
Definition: common/rtc.h:46
#define RTC_COUNTER(rtc)
Definition: common/rtc.h:62
#define RTC_CC(rtc, i)
Definition: common/rtc.h:64
#define RTC_TASK_CLEAR(rtc)
Definition: common/rtc.h:47
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