1 /****************************************************************************** 2 * Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved. 3 * 4 * This software is owned and published by: 5 * Huada Semiconductor Co.,Ltd ("HDSC"). 6 * 7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND 8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT. 9 * 10 * This software contains source code for use with HDSC 11 * components. This software is licensed by HDSC to be adapted only 12 * for use in systems utilizing HDSC components. HDSC shall not be 13 * responsible for misuse or illegal use of this software for devices not 14 * supported herein. HDSC is providing this software "AS IS" and will 15 * not be responsible for issues arising from incorrect user implementation 16 * of the software. 17 * 18 * Disclaimer: 19 * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE, 20 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS), 21 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING, 22 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED 23 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED 24 * WARRANTY OF NONINFRINGEMENT. 25 * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT, 26 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT 27 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, 28 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR 29 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT, 30 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA, 31 * SAVINGS OR PROFITS, 32 * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR 34 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED 35 * FROM, THE SOFTWARE. 36 * 37 * This software may be replicated in part or whole for the licensed use, 38 * with the restriction that this Disclaimer and Copyright notice must be 39 * included with each copy of this software, whether used in part or whole, 40 * at all times. 41 */ 42 /*****************************************************************************/ 43 /** \file rtc.h 44 ** 45 ** Headerfile for RTC functions 46 ** 47 ** 48 ** History: 49 ** - 2019-04-10 First Version 50 ** 51 *****************************************************************************/ 52 53 #ifndef __RTC_H__ 54 #define __RTC_H__ 55 56 /***************************************************************************** 57 * Include files 58 *****************************************************************************/ 59 #include "ddl.h" 60 61 #ifdef __cplusplus 62 extern "C" 63 { 64 #endif 65 66 /** 67 ****************************************************************************** 68 ** \defgroup RtcGroup Real Time Clock (RTC) 69 ** 70 ******************************************************************************/ 71 //@{ 72 73 /******************************************************************************/ 74 /* Global pre-processor symbols/macros ('#define') */ 75 /******************************************************************************/ 76 77 /****************************************************************************** 78 * Global type definitions 79 ******************************************************************************/ 80 81 /** 82 ****************************************************************************** 83 ** \brief rtc周期中断的时间间隔 RTC_CR0 PRDS 84 *****************************************************************************/ 85 typedef enum 86 { 87 RtcNone = 0u, //无周期中断 88 Rtc05S = 1u, //0.5S中断 89 Rtc1S = 2u, //1秒 90 Rtc1Min = 3u, //1分钟 91 Rtc1H = 4u, //1小时 92 Rtc1Day = 5u, //1天 93 Rtc1Mon = 6u //1月 94 }en_rtc_prds_t; 95 96 /** 97 ****************************************************************************** 98 ** \brief rtc 12h制或24h制方式选择 RTC_CR0 AMPM 99 *****************************************************************************/ 100 typedef enum 101 { 102 RtcAm = 0u, //12小时制 103 RtcPm = 1u //24小时制 104 }en_rtc_ampm_t; 105 106 /** 107 ****************************************************************************** 108 ** \brief 普通精度与高精度1Hz输出 RTC_CR0 HZ1SEL 109 *****************************************************************************/ 110 typedef enum 111 { 112 RtcHz1selGeneralPricision = 0u, //普通精度1Hz输出 113 RtcHz1selHighPricision = 1u //高精度1Hz输出 114 }en_rtc_hz1sel_t; 115 116 /** 117 ****************************************************************************** 118 ** \brief 周期中断选择 RTC_CR0 PRDSEL 119 *****************************************************************************/ 120 typedef enum 121 { 122 RtcPrds = 0u, //使用PRDS所设定的周期中断事件间隔 123 RtcPrdx = 1u //使用PRDX所设定的周期中断事件间隔 124 }en_rtc_prdsel_t; 125 126 /** 127 ****************************************************************************** 128 ** \brief rtc的时钟选择 RTC_CR1 CKSEL 129 *****************************************************************************/ 130 typedef enum 131 { 132 RtcClkXtl = 0u, //外部低速时钟XTL 32.768k 133 RtcClkRcl = 2u, //内部低速时钟RCL 32k 134 RtcClkXth128 = 4u, //外部晶振4M XTH/128 135 RtcClkXth256 = 5u, //外部晶振8M XTH/256 136 RtcClkXth512 = 6u, //外部晶振16M XTH/512 137 RtcClkXth1024 = 7u //外部晶振32M XTH/1024 138 }en_rtc_cksel_t; 139 140 /** 141 ****************************************************************************** 142 ** \brief 时钟误差补偿使能或禁止 RTC_COMPEN EN 143 *****************************************************************************/ 144 typedef enum 145 { 146 RtcCompenDisable = 0u, 147 RtcCompenEnable = 1u 148 }en_rtc_compen_t; 149 150 /** 151 ****************************************************************************** 152 ** \brief 配置PRD中断使能及其周期类型 153 *****************************************************************************/ 154 typedef struct 155 { 156 en_rtc_prdsel_t rtcPrdsel; 157 uint8_t rtcPrdx; 158 en_rtc_prds_t rtcPrds; 159 }stc_rtc_cyccfg_t; 160 161 /** 162 ****************************************************************************** 163 ** \brief 闹钟源配置 164 *****************************************************************************/ 165 typedef struct 166 { 167 uint8_t RtcAlarmSec; //闹钟秒钟 168 uint8_t RtcAlarmMinute; //闹钟分钟 169 uint8_t RtcAlarmHour; //闹钟小时 170 uint8_t RtcAlarmWeek; //闹钟周 171 }stc_rtc_alarmtime_t; 172 173 /** 174 ****************************************************************************** 175 ** \brief 时间 176 *****************************************************************************/ 177 /** 178 ****************************************************************************** 179 ** \brief rtc时钟年、月、日、时、分、秒读写结构 180 *****************************************************************************/ 181 typedef struct stc_rtc_time 182 { 183 uint8_t u8Second; //时间:秒 184 uint8_t u8Minute; //时间:分 185 uint8_t u8Hour; //时间:时 186 uint8_t u8DayOfWeek; //时间:周 187 uint8_t u8Day; //时间:日 188 uint8_t u8Month; //时间:月 189 uint8_t u8Year; //时间:年 190 } stc_rtc_time_t; 191 192 /** 193 ****************************************************************************** 194 ** \brief 初始化RTC的结构体 195 *****************************************************************************/ 196 typedef struct 197 { 198 en_rtc_ampm_t rtcAmpm; //小时的时制 199 stc_rtc_cyccfg_t rtcPrdsel; //确定PRDS或者PRDX所设定的周期中断时间间隔类型 200 en_rtc_cksel_t rtcClksrc; //实时时钟的时钟源 201 en_rtc_compen_t rtcCompen; //时钟误差补偿使能与禁止 202 uint16_t rtcCompValue; //使能补偿的情况下,补偿值取值范围为:0-255 203 stc_rtc_time_t rtcTime; //要写入时间寄存器的时间 204 }stc_rtc_initstruct_t; 205 206 /****************************************************************************** 207 Global function prototypes (definition in C source) 208 *******************************************************************************/ 209 //RTC计数器的使能或停止 210 extern void Rtc_Cmd(boolean_t NewState); 211 //RTC计数器启动等待函数 212 extern void Rtc_StartWait(void); 213 //RTC的1Hz输出的使能或停止 214 extern void Rtc_Hz1Cmd(en_rtc_hz1sel_t pricision, boolean_t NewState); 215 //设置周期中断的类型(PRDSEL)及其所选类型的时间(PRDS或PRDX) 216 extern en_result_t Rtc_SetCyc(stc_rtc_cyccfg_t* pstCyc); 217 //RTC闹钟中断的使能或停止 218 extern void Rtc_AlmIeCmd(boolean_t NewState); 219 //RTC闹钟的使能或停止 220 extern void Rtc_AlmEnCmd(boolean_t NewState); 221 //获取RTC闹钟中断状态位 222 extern boolean_t Rtc_GetAlmfItStatus(void); 223 //清除RTC闹钟中断状态位 224 extern void Rtc_ClearAlmfItStatus(void); 225 //清除RTC周期中断状态位 226 extern void Rtc_ClearPrdfItStatus(void); 227 //获取RTC周期中断状态位 228 extern boolean_t Rtc_GetPridItStatus(void); 229 //配置RTC的误差补偿寄存器 230 extern en_result_t Rtc_CompCfg(uint16_t CompVlue, en_rtc_compen_t NewStatus); 231 //RTC根据日期计算周数 232 extern en_result_t Check_BCD_Format(uint8_t u8data,uint8_t u8limit_min, uint8_t u8limit_max); 233 //RTC获取时间函数 234 extern en_result_t Rtc_ReadDateTime(stc_rtc_time_t* time); 235 //向RTC时间寄存器写入时间 236 extern en_result_t Rtc_SetTime(stc_rtc_time_t* time); 237 //RTC闹钟中断时间获取 238 extern void Rtc_GetAlarmTime(stc_rtc_alarmtime_t* pstcAlarmTime); 239 //RTC闹钟设置 240 extern en_result_t Rtc_SetAlarmTime(stc_rtc_alarmtime_t* pstcAlarmTime); 241 //初始化RTC 242 extern void Rtc_Init(stc_rtc_initstruct_t* Rtc_InitStruct); 243 #endif /* __RTC_H__ */ 244 /****************************************************************************** 245 * EOF (not truncated) 246 *****************************************************************************/ 247 248 249