1 /*********************************************************************************************************//**
2  * @file    ht32f5xxxx_rtc.h
3  * @version $Rev:: 8260         $
4  * @date    $Date:: 2024-11-05 #$
5  * @brief   The header file of the RTC library.
6  *************************************************************************************************************
7  * @attention
8  *
9  * Firmware Disclaimer Information
10  *
11  * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
12  *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
13  *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
14  *    other intellectual property laws.
15  *
16  * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
17  *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
18  *    other than HOLTEK and the customer.
19  *
20  * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
21  *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
22  *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
23  *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
24  *
25  * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
26  ************************************************************************************************************/
27 
28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/
29 #ifndef __HT32F5XXXX_RTC_H
30 #define __HT32F5XXXX_RTC_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------------------------------------*/
37 #include "ht32.h"
38 
39 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
40   * @{
41   */
42 
43 /** @addtogroup RTC
44   * @{
45   */
46 
47 
48 /* Exported types ------------------------------------------------------------------------------------------*/
49 /** @defgroup RTC_Exported_Types RTC exported types
50   * @{
51   */
52 
53 /**
54  * @brief Selection of RTC clock source
55  */
56 typedef enum
57 {
58   RTC_SRC_LSI = 0,                /*!< Low speed internal clock, about 32 kHz                               */
59   #if (LIBCFG_LSE)
60   RTC_SRC_LSE                     /*!< Low speed external 32768 Hz clock                                    */
61   #endif
62 } RTC_SRC_Enum;
63 
64 #if (LIBCFG_LSE)
65 /**
66  * @brief Selection of RTC LSE startup mode
67  */
68 typedef enum
69 {
70   RTC_LSESM_NORMAL = 0,       /*!< Little power consumption but longer startup time.                        */
71   RTC_LSESM_FAST              /*!< Shortly startup time but higher power consumption.                       */
72 } RTC_LSESM_Enum;
73 #endif
74 /**
75  * @brief Selection of RTC prescaler
76  */
77 typedef enum
78 {
79   RTC_RPRE_1     = 0x0000,           /*!< CK_SECOND = CK_RTC                                                */
80   RTC_RPRE_2     = 0x0100,           /*!< CK_SECOND = CK_RTC / 2                                            */
81   RTC_RPRE_4     = 0x0200,           /*!< CK_SECOND = CK_RTC / 4                                            */
82   RTC_RPRE_8     = 0x0300,           /*!< CK_SECOND = CK_RTC / 8                                            */
83   RTC_RPRE_16    = 0x0400,           /*!< CK_SECOND = CK_RTC / 16                                           */
84   RTC_RPRE_32    = 0x0500,           /*!< CK_SECOND = CK_RTC / 32                                           */
85   RTC_RPRE_64    = 0x0600,           /*!< CK_SECOND = CK_RTC / 64                                           */
86   RTC_RPRE_128   = 0x0700,           /*!< CK_SECOND = CK_RTC / 128                                          */
87   RTC_RPRE_256   = 0x0800,           /*!< CK_SECOND = CK_RTC / 256                                          */
88   RTC_RPRE_512   = 0x0900,           /*!< CK_SECOND = CK_RTC / 512                                          */
89   RTC_RPRE_1024  = 0x0A00,           /*!< CK_SECOND = CK_RTC / 1024                                         */
90   RTC_RPRE_2048  = 0x0B00,           /*!< CK_SECOND = CK_RTC / 2048                                         */
91   RTC_RPRE_4096  = 0x0C00,           /*!< CK_SECOND = CK_RTC / 4096                                         */
92   RTC_RPRE_8192  = 0x0D00,           /*!< CK_SECOND = CK_RTC / 8192                                         */
93   RTC_RPRE_16384 = 0x0E00,           /*!< CK_SECOND = CK_RTC / 16384                                        */
94   RTC_RPRE_32768 = 0x0F00            /*!< CK_SECOND = CK_RTC / 32768                                        */
95 } RTC_RPRE_Enum;
96 /**
97  * @brief Active polarity of RTC output
98  */
99 typedef enum
100 {
101   RTC_ROAP_HIGH = 0,              /*!< Active level is high                                                 */
102   RTC_ROAP_LOW                    /*!< Active level is low                                                  */
103 } RTC_ROAP_Enum;
104 /**
105  * @brief Waveform mode of RTC output
106  */
107 typedef enum
108 {
109   RTC_ROWM_PULSE = 0,              /*!< Pulse mode.                                                         */
110   RTC_ROWM_LEVEL                   /*!< Level mode.                                                         */
111 } RTC_ROWM_Enum;
112 /**
113  * @brief Event selection of RTC output
114  */
115 typedef enum
116 {
117   RTC_ROES_MATCH = 0,              /*!< Selected RTC compare match.                                         */
118   RTC_ROES_SECOND                  /*!< Selected RTC second clock.                                          */
119 } RTC_ROES_Enum;
120 /**
121   * @}
122   */
123 
124 /* Exported constants --------------------------------------------------------------------------------------*/
125 /** @defgroup RTC_Exported_Constants RTC exported constants
126   * @{
127   */
128 
129 /** @defgroup RTC_WAKEUP  Selection of RTC wakeup source
130   * @{
131   */
132 #define RTC_WAKEUP_CSEC   0x00000100
133 #define RTC_WAKEUP_CM     0x00000200
134 #define RTC_WAKEUP_OV     0x00000400
135 /**
136   * @}
137   */
138 
139 /** @defgroup RTC_IT RTC Selection of interrupt source
140   * @{
141   */
142 #define RTC_INT_CSEC      0x00000001
143 #define RTC_INT_CM        0x00000002
144 #define RTC_INT_OV        0x00000004
145 /**
146   * @}
147   */
148 
149 /** @defgroup RTC_FLAG RTC Definitions of flags
150   * @{
151   */
152 #define RTC_FLAG_CSEC     0x00000001
153 #define RTC_FLAG_CM       0x00000002
154 #define RTC_FLAG_OV       0x00000004
155 /**
156   * @}
157   */
158 
159 /** @defgroup RTC_Check_Parameter Selection of Vdd18 power good
160   * @{
161   */
162 
163 /**
164  * @brief Used to check RTC_SRC_Enum parameter
165  */
166 #if (LIBCFG_LSE)
167 #define IS_RTC_SRC_LSE(x)  (x == RTC_SRC_LSE)
168 #else
169 #define IS_RTC_SRC_LSE(x)  (0)
170 #endif
171 #define IS_RTC_SRC(x) ((x == RTC_SRC_LSI) || IS_RTC_SRC_LSE(x))
172 
173 #if (LIBCFG_LSE)
174 /**
175  * @brief Used to check RTC_LSESM_Enum parameter
176  */
177 #define IS_RTC_LSESM(x) ((x == RTC_LSESM_NORMAL) || (x == RTC_LSESM_FAST))
178 #endif
179 /**
180  * @brief Used to check RTC_RPRE_Enum parameter
181  */
182 #define IS_RTC_PSC(x) ((x == RTC_RPRE_1) || (x == RTC_RPRE_2) || (x == RTC_RPRE_4) ||\
183                        (x == RTC_RPRE_8) || (x == RTC_RPRE_16) || (x == RTC_RPRE_32) ||\
184                        (x == RTC_RPRE_64) || (x == RTC_RPRE_128) || (x == RTC_RPRE_256) ||\
185                        (x == RTC_RPRE_512) || (x == RTC_RPRE_1024) || (x == RTC_RPRE_2048) ||\
186                        (x == RTC_RPRE_4096) || (x == RTC_RPRE_8192) || (x == RTC_RPRE_16384) ||\
187                        (x == RTC_RPRE_32768))
188 /**
189  * @brief Used to check RTC_ROAP_Enum parameter
190  */
191 #define IS_RTC_ROAP(x) ((x == RTC_ROAP_HIGH) || (x == RTC_ROAP_LOW))
192 /**
193  * @brief Used to check RTC_ROWM_Enum parameter
194  */
195 #define IS_RTC_ROWM(x) ((x == RTC_ROWM_PULSE) || (x == RTC_ROWM_LEVEL))
196 /**
197  * @brief Used to check RTC_ROES_Enum parameter
198  */
199 #define IS_RTC_ROES(x) ((x == RTC_ROES_MATCH) || (x == RTC_ROES_SECOND))
200 /**
201  * @brief Used to check RTC_WAKEUP parameter
202  */
203 #define IS_RTC_WAKEUP(x) ((((x) & (u32)0xFFFFF8FF) == 0x00) && ((x) != 0x00))
204 /**
205  * @brief Used to check RTC_INT parameter
206  */
207 #define IS_RTC_INT(x) ((((x) & (u32)0xFFFFFFF8) == 0x00) && ((x) != 0x00))
208 /**
209  * @brief Used to check RTC_FLAG parameter
210  */
211 #define IS_RTC_FLAG(x) ((((x) & (u32)0xFFFFFFF8) == 0x00) && ((x) != 0x00))
212 /**
213   * @}
214   */
215 
216 /**
217   * @}
218   */
219 
220 /* Exported functions --------------------------------------------------------------------------------------*/
221 /** @defgroup RTC_Exported_Functions RTC exported functions
222   * @{
223   */
224 void RTC_DeInit(void);
225 void RTC_ClockSourceConfig(RTC_SRC_Enum Source);
226 #if (LIBCFG_RTC_LSI_LOAD_TRIM)
227 void RTC_LSILoadTrimData(void);
228 #endif
229 #if (LIBCFG_LSE)
230 void RTC_LSESMConfig(RTC_LSESM_Enum Mode);
231 #endif
232 void RTC_LSECmd(ControlStatus NewState);
233 void RTC_CMPCLRCmd(ControlStatus NewState);
234 void RTC_SetPrescaler(RTC_RPRE_Enum Psc);
235 u16 RTC_GetPrescaler(void);
236 void RTC_Cmd(ControlStatus NewState);
237 u32 RTC_GetCounter(void);
238 void RTC_SetCompare(u32 Compare);
239 u32 RTC_GetCompare(void);
240 void RTC_WakeupConfig(u32 RTC_WAKEUP, ControlStatus NewState);
241 void RTC_IntConfig(u32 RTC_INT, ControlStatus NewState);
242 u8 RTC_GetFlagStatus(void);
243 void RTC_OutConfig(RTC_ROWM_Enum WMode, RTC_ROES_Enum EventSel, RTC_ROAP_Enum Pol);
244 void RTC_OutCmd(ControlStatus NewState);
245 FlagStatus RTC_GetOutStatus(void);
246 /**
247   * @}
248   */
249 
250 
251 /**
252   * @}
253   */
254 
255 /**
256   * @}
257   */
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif
264