Newer
Older
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
* @brief Real Time Clock (RTC) functions and prototypes.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
*
* $Date: 2018-11-05 19:40:08 +0000 (Mon, 05 Nov 2018) $
* $Revision: 38949 $
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _RTC_H_
#define _RTC_H_
/* **** Includes **** */
#include <stdint.h>
#include "mxc_config.h"
#include "rtc_regs.h"
#include "mxc_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup rtc RTC
* @ingroup periphlibs
* @{
*/
/* **** Definitions **** */
typedef enum {
SQUARE_WAVE_DISABLED, /**< Sq. wave output disabled */
SQUARE_WAVE_ENABLED, /**< Sq. wave output enabled */
} rtc_sqwave_en_t;
typedef enum {
F_1HZ = MXC_S_RTC_CTRL_FT_FREQ1HZ, /**< 1Hz (Compensated) */
F_512HZ = MXC_S_RTC_CTRL_FT_FREQ512HZ, /**< 512Hz (Compensated) */
F_4KHZ = MXC_S_RTC_CTRL_FT_FREQ4KHZ, /**< 4Khz */
F_32KHZ = 32, /**< 32Khz */
} rtc_freq_sel_t;
typedef enum {
NOISE_IMMUNE_MODE = MXC_S_RTC_CTRL_X32KMD_NOISEIMMUNEMODE,
QUIET_MODE = MXC_S_RTC_CTRL_X32KMD_QUIETMODE,
QUIET_STOP_WARMUP_MODE = MXC_S_RTC_CTRL_X32KMD_QUIETINSTOPWITHWARMUP,
QUIET_STOP_NOWARMUP_MODE = MXC_S_RTC_CTRL_X32KMD_QUIETINSTOPNOWARMUP,
} rtc_osc_mode_t;
/**
*@brief Enables Time-of-Day's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS If enable is successful.
*@return #E_BAD_STATE If RTC fails.
*@return #E_BUSY If RTC is busy.
*/
int RTC_EnableTimeofdayInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Disable Time-of-Day's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS If function is successful.
*@return #E_BAD_STATE If RTC is in a bad state.
*@return #E_BUSY If RTC is busy.
*/
int RTC_DisableTimeofdayInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Enables Sub-Second's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS If function is successful.
*@return #E_BAD_STATE If RTC is in a bad state.
*@return #E_BUSY If RTC is busy.
*/
int RTC_EnableSubsecondInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Disable Sub-Second's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS If function is successful.
*@return #E_BAD_STATE If RTC is in a bad state.
*@return #E_BUSY If RTC is busy.
*/
int RTC_DisableSubsecondInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Set Time-of-Day alarm value and enable Interrupt
*@param rtc pointer to the rtc register structure
*@param ras 20-bit value 0-0xFFFFF
*@return #E_SUCCESS If function is successful.
*@return #E_BAD_STATE If RTC is in a bad state.
*@return #E_BUSY If RTC is busy.
*/
int RTC_SetTimeofdayAlarm(mxc_rtc_regs_t *rtc, uint32_t ras);
/**
*@brief Set Sub-Second alarm value and enable interrupt,
*@brief this is to be called after the init_rtc() function
*@param rtc pointer to the rtc register structure
*@param rssa 32-bit value 0-0xFFFFFFFF
*@return #E_SUCCESS If function is successful.
*@return #E_BAD_STATE If RTC is in a bad state.
*@return #E_BUSY If RTC is busy.
*/
int RTC_SetSubsecondAlarm(mxc_rtc_regs_t *rtc, uint32_t rssa);
/**
*@brief Enable/Start the Real Time Clock
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS If function is successful.
*@return #E_BUSY If RTC is busy.
*/
int RTC_EnableRTCE(mxc_rtc_regs_t *rtc);
/**
*@brief Disable/Stop the Real Time Clock
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS If function is successful.
*@return #E_BUSY If RTC is busy.
*/
int RTC_DisableRTCE(mxc_rtc_regs_t *rtc);
/**
*@brief Initialize the sec and ssec registers and enable RTC
*@param rtc pointer to the rtc register structure
*@param sec set the RTC Sec counter (32-bit)
*@param ssec set the RTC Sub-second counter (8-bit)
*@param sys_cfg System configuration object
*@return #E_SUCCESS If function is successful.
*@return #E_BUSY If RTC is busy.
*/
int RTC_Init(mxc_rtc_regs_t *rtc, uint32_t sec, uint16_t ssec, sys_cfg_rtc_t *sys_cfg);
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* @brief Allow generation of Square Wave on the SQW pin
* @param rtc pointer to the rtc register structure
* @param sqe Enable/Disable square wave output
* @param ft Frequency output selection
* @param x32kmd 32KHz Oscillator mode
* @param sys_cfg The system configuration
* @return #E_SUCCESS If function is successful.
* @return #E_BUSY If RTC is busy.
*/
int RTC_SquareWave(mxc_rtc_regs_t *rtc, rtc_sqwave_en_t sqe, rtc_freq_sel_t ft,
rtc_osc_mode_t x32kmd, const sys_cfg_rtc_t* sys_cfg);
/**
*@brief Set Trim register value
*@param rtc pointer to the rtc register structure
*@param trm set the RTC Trim (8-bit, +/- 127)
*@return #E_SUCCESS If function is successful.
*@return #E_BUSY If RTC is busy.
*/
int RTC_Trim(mxc_rtc_regs_t *rtc, int8_t trm);
/**
*@brief Check if BUSY bit is 0.
*@return #E_SUCCESS If function is successful.
*@return #E_BUSY If RTC is busy.
*/
int RTC_CheckBusy(void);
/**
*@brief Gets Interrupt flags.
*@return Interrupts flags that have not been cleared
*/
int RTC_GetFlags(void);
/**
*@brief Clear Interrupt flag.
*@param flags the flags that need to be cleared
*/
int RTC_ClearFlags(int flags);
/**
*@brief Get SubSecond
*@return Returns subsecond value
*/
int RTC_GetSubSecond(void);
/**
*@brief Get Second
*@return returns Second value
*/
int RTC_GetSecond(void);
/**
* @brief Read seconds, then subseconds, and finally seconds. If RTC ready flag ever gets cleared during this sequence,
the RTC is in the middle of updating the counts and the user should come back later and try again. If the first
read of the seconds register doesn't match the next read, then a subsecond overflow condition has happened and
another attempt to read the counts should be made.
* @param sec variable that will be changed to hold second value
* @param subsec variable that will be changed to hold Subsecond value
*@return #E_SUCCESS If function is successful.
*@return #E_BUSY If RTC is busy.
*/
int RTC_GetTime(uint32_t* sec, uint32_t* subsec);
#ifdef __cplusplus
}
#endif
/**@} end of group rtc */
#endif /* _RTC_H_ */