forked from stm32duino/Arduino_Core_STM32
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrtc.h
164 lines (138 loc) · 6.37 KB
/
rtc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
******************************************************************************
* @file rtc.h
* @author WI6LABS
* @version V1.0.0
* @date 12-December-2017
* @brief Header for RTC driver
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __RTC_H
#define __RTC_H
/* Includes ------------------------------------------------------------------*/
#include <stdbool.h>
#include "backup.h"
#include "clock.h"
#ifdef HAL_RTC_MODULE_ENABLED
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
typedef enum {
HOUR_FORMAT_12,
HOUR_FORMAT_24
} hourFormat_t;
typedef enum {
HOUR_AM,
HOUR_PM
} hourAM_PM_t;
/* See AN4579 Table 5 for possible values */
typedef enum {
OFF_MSK = 0,
SS_MSK = 1, /* MSK0 */
MM_MSK = 2, /* MSK1 */
HH_MSK = 4, /* MSK2 */
D_MSK = 8, /* MSK3 */
/* NOTE: STM32 RTC can't assign a month or a year to an alarm. Those enum
are kept for compatibility but are ignored inside enableAlarm(). */
M_MSK = 16,
Y_MSK = 32
} alarmMask_t;
typedef void(*voidCallbackPtr)(void *);
/* Exported constants --------------------------------------------------------*/
#define HSE_RTC_MAX 1000000U
#if !defined(STM32F1xx)
#if !defined(RTC_PRER_PREDIV_S) || !defined(RTC_PRER_PREDIV_S)
#error "Unknown Family - unknown synchronous prescaler"
#endif
#define PREDIVA_MAX (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos)
#define PREDIVS_MAX (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos)
#endif /* !STM32F1xx */
/* Ultra Low Power High (ULPH) density */
#if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) ||\
defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) ||\
defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) ||\
defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) ||\
defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) ||\
defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) ||\
defined (STM32L162xDX)
#define STM32L1_ULPH
#endif
#if defined(STM32F0xx) || defined(STM32L0xx)
#define RTC_Alarm_IRQn RTC_IRQn
#define RTC_Alarm_IRQHandler RTC_IRQHandler
#endif
#if defined(STM32F1xx) && !defined(IS_RTC_WEEKDAY)
/* Compensate missing HAL definition */
#define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
/* F1 doesn't manage 12h format */
#define IS_RTC_HOUR12(HOUR) IS_RTC_HOUR24(HOUR)
#endif /* !STM32F1xx && !IS_RTC_WEEKDAY */
/* __HAL_RCC_GET_RTC_SOURCE is not defined for F2*/
/*
#ifndef __HAL_RCC_GET_RTC_SOURCE
static uint32_t RTC_getSource(void) {
RCC_PeriphCLKInitTypeDef *PeriphClkInit;
HAL_RCCEx_GetPeriphCLKConfig(PeriphClkInit);
return PeriphClkInit->RTCClockSelection;
}
#define __HAL_RCC_GET_RTC_SOURCE() RTC_getSource()
#endif
*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void RTC_SetClockSource(sourceClock_t source);
void RTC_getPrediv(int8_t *asynch, int16_t *synch);
void RTC_setPrediv(int8_t asynch, int16_t synch);
void RTC_init(hourFormat_t format, sourceClock_t source, bool reset);
void RTC_DeInit(void);
bool RTC_IsTimeSet(void);
void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period);
void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period);
void RTC_SetDate(uint8_t year, uint8_t month, uint8_t day, uint8_t wday);
void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday);
void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period, uint8_t mask);
void RTC_StopAlarm(void);
void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period, uint8_t *mask);
void attachAlarmCallback(voidCallbackPtr func, void *data);
void detachAlarmCallback(void);
#ifdef __cplusplus
}
#endif
#endif /* HAL_RTC_MODULE_ENABLED */
#endif /* __RTC_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/