libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
f1/rtc.h
Go to the documentation of this file.
1/** @defgroup rtc_defines RTC Defines
2 *
3 * @brief <b>Defined Constants and Types for the STM32F1xx Real Time Clock</b>
4 *
5 * @ingroup STM32F1xx_defines
6 *
7 * @author @htmlonly &copy; @endhtmlonly 2010 Uwe Hermann <uwe@hermann-uwe.de>
8 *
9 * @version 1.0.0
10 *
11 * @date 4 March 2013
12 *
13 * LGPL License Terms @ref lgpl_license
14 * */
15/*
16 * This file is part of the libopencm3 project.
17 *
18 * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
19 *
20 * This library is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with this library. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34/*
35 * The F1 RTC is a straight time stamp, a completely different peripheral to
36 * that found in the F2, F3, F4, L1 and F0.
37 */
38
39#ifndef LIBOPENCM3_RTC_H
40#define LIBOPENCM3_RTC_H
41/**@{*/
42
45
46/* --- RTC registers ------------------------------------------------------- */
47
48/* RTC control register high (RTC_CRH) */
49#define RTC_CRH MMIO32(RTC_BASE + 0x00)
50
51/* RTC control register low (RTC_CRL) */
52#define RTC_CRL MMIO32(RTC_BASE + 0x04)
53
54/* RTC prescaler load register (RTC_PRLH / RTC_PRLL) */
55#define RTC_PRLH MMIO32(RTC_BASE + 0x08)
56#define RTC_PRLL MMIO32(RTC_BASE + 0x0c)
57
58/* RTC prescaler divider register (RTC_DIVH / RTC_DIVL) */
59#define RTC_DIVH MMIO32(RTC_BASE + 0x10)
60#define RTC_DIVL MMIO32(RTC_BASE + 0x14)
61
62/* RTC counter register (RTC_CNTH / RTC_CNTL) */
63#define RTC_CNTH MMIO32(RTC_BASE + 0x18)
64#define RTC_CNTL MMIO32(RTC_BASE + 0x1c)
65
66/* RTC alarm register high (RTC_ALRH / RTC_ALRL) */
67#define RTC_ALRH MMIO32(RTC_BASE + 0x20)
68#define RTC_ALRL MMIO32(RTC_BASE + 0x24)
69
70/* --- RTC_CRH values -------------------------------------------------------*/
71
72/* Note: Bits [15:3] are reserved, and forced to 0 by hardware. */
73
74/* OWIE: Overflow interrupt enable */
75#define RTC_CRH_OWIE (1 << 2)
76
77/* ALRIE: Alarm interrupt enable */
78#define RTC_CRH_ALRIE (1 << 1)
79
80/* SECIE: Second interrupt enable */
81#define RTC_CRH_SECIE (1 << 0)
82
83/* --- RTC_CRL values -------------------------------------------------------*/
84
85/* Note: Bits [15:6] are reserved, and forced to 0 by hardware. */
86
87/* RTOFF: RTC operation OFF */
88#define RTC_CRL_RTOFF (1 << 5)
89
90/* CNF: Configuration flag */
91#define RTC_CRL_CNF (1 << 4)
92
93/* RSF: Registers synchronized flag */
94#define RTC_CRL_RSF (1 << 3)
95
96/* OWF: Overflow flag */
97#define RTC_CRL_OWF (1 << 2)
98
99/* ALRF: Alarm flag */
100#define RTC_CRL_ALRF (1 << 1)
101
102/* SECF: Second flag */
103#define RTC_CRL_SECF (1 << 0)
104
105/* --- RTC_PRLH values ------------------------------------------------------*/
106
107/* Note: Bits [15:4] are reserved, and forced to 0 by hardware. */
108
109/* TODO */
110
111/* --- RTC_PRLL values ------------------------------------------------------*/
112
113/* TODO */
114
115/* --- RTC_DIVH values ------------------------------------------------------*/
116
117/* Bits [15:4] are reserved. */
118
119/* TODO */
120
121/* --- RTC_DIVL values ------------------------------------------------------*/
122
123/* TODO */
124
125/* --- RTC_CNTH values ------------------------------------------------------*/
126
127/* TODO */
128
129/* --- RTC_CNTL values ------------------------------------------------------*/
130
131/* TODO */
132
133/* --- RTC_ALRH values ------------------------------------------------------*/
134
135/* TODO */
136
137/* --- RTC_ALRL values ------------------------------------------------------*/
138
139/* TODO */
140
141/** RTC Interrupt Flags */
142typedef enum {
143 /** Counter Second Flag */
145 /** Alarm Event Flag */
147 /** Counter Overflow Flag */
149} rtcflag_t;
150
151/* --- Function prototypes --------------------------------------------------*/
152
154
155void rtc_awake_from_off(enum rcc_osc clock_source);
156void rtc_enter_config_mode(void);
157void rtc_exit_config_mode(void);
158void rtc_set_alarm_time(uint32_t alarm_time);
159void rtc_enable_alarm(void);
160void rtc_disable_alarm(void);
161void rtc_set_prescale_val(uint32_t prescale_val);
162uint32_t rtc_get_counter_val(void);
163uint32_t rtc_get_prescale_div_val(void);
164uint32_t rtc_get_alarm_val(void);
165void rtc_set_counter_val(uint32_t counter_val);
166void rtc_interrupt_enable(rtcflag_t flag_val);
167void rtc_interrupt_disable(rtcflag_t flag_val);
168void rtc_clear_flag(rtcflag_t flag_val);
169uint32_t rtc_check_flag(rtcflag_t flag_val);
170void rtc_awake_from_standby(void);
171void rtc_auto_awake(enum rcc_osc clock_source, uint32_t prescale_val);
172
174/**@}*/
175
176#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
rcc_osc
Definition: f1/rcc.h:567
uint32_t rtc_get_counter_val(void)
RTC return the Counter Value.
Definition: rtc.c:214
void rtc_awake_from_standby(void)
RTC Start RTC after Standby Mode.
Definition: rtc.c:368
void rtc_set_prescale_val(uint32_t prescale_val)
RTC Set the prescaler Value.
Definition: rtc.c:200
void rtc_clear_flag(rtcflag_t flag_val)
RTC Clear an Interrupt Flag.
Definition: rtc.c:313
void rtc_set_alarm_time(uint32_t alarm_time)
RTC Set the Alarm Time.
Definition: rtc.c:162
void rtc_interrupt_disable(rtcflag_t flag_val)
RTC Disable Interrupt.
Definition: rtc.c:287
void rtc_disable_alarm(void)
RTC Disable the Alarm.
Definition: rtc.c:187
void rtc_auto_awake(enum rcc_osc clock_source, uint32_t prescale_val)
RTC Configuration on Wakeup.
Definition: rtc.c:400
uint32_t rtc_get_alarm_val(void)
RTC return the Alarm Value.
Definition: rtc.c:236
rtcflag_t
RTC Interrupt Flags.
Definition: f1/rtc.h:142
uint32_t rtc_check_flag(rtcflag_t flag_val)
RTC Return a Flag Setting.
Definition: rtc.c:338
void rtc_exit_config_mode(void)
RTC Leave Configuration Mode.
Definition: rtc.c:145
void rtc_awake_from_off(enum rcc_osc clock_source)
RTC Set Operational from the Off state.
Definition: rtc.c:85
void rtc_interrupt_enable(rtcflag_t flag_val)
RTC Enable Interrupt.
Definition: rtc.c:261
void rtc_enable_alarm(void)
RTC Enable the Alarm.
Definition: rtc.c:175
uint32_t rtc_get_prescale_div_val(void)
RTC return the prescaler Value.
Definition: rtc.c:225
void rtc_set_counter_val(uint32_t counter_val)
RTC set the Counter.
Definition: rtc.c:247
void rtc_enter_config_mode(void)
RTC Enter Configuration Mode.
Definition: rtc.c:128
@ RTC_ALR
Alarm Event Flag.
Definition: f1/rtc.h:146
@ RTC_SEC
Counter Second Flag.
Definition: f1/rtc.h:144
@ RTC_OW
Counter Overflow Flag.
Definition: f1/rtc.h:148