Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
m480_rtc.h
00001 /**************************************************************************//** 00002 * @file rtc.h 00003 * @version V3.00 00004 * @brief M480 series RTC driver header file 00005 * 00006 * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without modification, 00009 * are permitted provided that the following conditions are met: 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 3. Neither the name of Nuvoton Technology Corp. nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00026 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 *****************************************************************************/ 00030 #ifndef __RTC_H__ 00031 #define __RTC_H__ 00032 00033 #ifdef __cplusplus 00034 extern "C" 00035 { 00036 #endif 00037 00038 00039 /** @addtogroup Standard_Driver Standard Driver 00040 @{ 00041 */ 00042 00043 /** @addtogroup RTC_Driver RTC Driver 00044 @{ 00045 */ 00046 00047 /** @addtogroup RTC_EXPORTED_CONSTANTS RTC Exported Constants 00048 @{ 00049 */ 00050 /*---------------------------------------------------------------------------------------------------------*/ 00051 /* RTC Initial Keyword Constant Definitions */ 00052 /*---------------------------------------------------------------------------------------------------------*/ 00053 #define RTC_INIT_KEY 0xA5EB1357UL /*!< RTC Initiation Key to make RTC leaving reset state \hideinitializer */ 00054 #define RTC_WRITE_KEY 0x0000A965UL /*!< RTC Register Access Enable Key to enable RTC read/write accessible and kept 1024 RTC clock \hideinitializer */ 00055 00056 /*---------------------------------------------------------------------------------------------------------*/ 00057 /* RTC Time Attribute Constant Definitions */ 00058 /*---------------------------------------------------------------------------------------------------------*/ 00059 #define RTC_CLOCK_12 0UL /*!< RTC as 12-hour time scale with AM and PM indication \hideinitializer */ 00060 #define RTC_CLOCK_24 1UL /*!< RTC as 24-hour time scale \hideinitializer */ 00061 #define RTC_AM 1UL /*!< RTC as AM indication \hideinitializer */ 00062 #define RTC_PM 2UL /*!< RTC as PM indication \hideinitializer */ 00063 00064 /*---------------------------------------------------------------------------------------------------------*/ 00065 /* RTC Tick Period Constant Definitions */ 00066 /*---------------------------------------------------------------------------------------------------------*/ 00067 #define RTC_TICK_1_SEC 0x0UL /*!< RTC time tick period is 1 second \hideinitializer */ 00068 #define RTC_TICK_1_2_SEC 0x1UL /*!< RTC time tick period is 1/2 second \hideinitializer */ 00069 #define RTC_TICK_1_4_SEC 0x2UL /*!< RTC time tick period is 1/4 second \hideinitializer */ 00070 #define RTC_TICK_1_8_SEC 0x3UL /*!< RTC time tick period is 1/8 second \hideinitializer */ 00071 #define RTC_TICK_1_16_SEC 0x4UL /*!< RTC time tick period is 1/16 second \hideinitializer */ 00072 #define RTC_TICK_1_32_SEC 0x5UL /*!< RTC time tick period is 1/32 second \hideinitializer */ 00073 #define RTC_TICK_1_64_SEC 0x6UL /*!< RTC time tick period is 1/64 second \hideinitializer */ 00074 #define RTC_TICK_1_128_SEC 0x7UL /*!< RTC time tick period is 1/128 second \hideinitializer */ 00075 00076 /*---------------------------------------------------------------------------------------------------------*/ 00077 /* RTC Day of Week Constant Definitions */ 00078 /*---------------------------------------------------------------------------------------------------------*/ 00079 #define RTC_SUNDAY 0x0UL /*!< Day of the Week is Sunday \hideinitializer */ 00080 #define RTC_MONDAY 0x1UL /*!< Day of the Week is Monday \hideinitializer */ 00081 #define RTC_TUESDAY 0x2UL /*!< Day of the Week is Tuesday \hideinitializer */ 00082 #define RTC_WEDNESDAY 0x3UL /*!< Day of the Week is Wednesday \hideinitializer */ 00083 #define RTC_THURSDAY 0x4UL /*!< Day of the Week is Thursday \hideinitializer */ 00084 #define RTC_FRIDAY 0x5UL /*!< Day of the Week is Friday \hideinitializer */ 00085 #define RTC_SATURDAY 0x6UL /*!< Day of the Week is Saturday \hideinitializer */ 00086 00087 /*---------------------------------------------------------------------------------------------------------*/ 00088 /* RTC Miscellaneous Constant Definitions */ 00089 /*---------------------------------------------------------------------------------------------------------*/ 00090 #define RTC_WAIT_COUNT 0xFFFFFFFFUL /*!< Initial Time-out Value \hideinitializer */ 00091 #define RTC_YEAR2000 2000UL /*!< RTC Reference for compute year data \hideinitializer */ 00092 #define RTC_FCR_REFERENCE 32761UL /*!< RTC Reference for frequency compensation \hideinitializer */ 00093 00094 00095 #define RTC_TAMPER0_SELECT (0x1ul << 0) /*!< Select Tamper 0 \hideinitializer */ 00096 #define RTC_TAMPER1_SELECT (0x1ul << 1) /*!< Select Tamper 1 \hideinitializer */ 00097 #define RTC_TAMPER2_SELECT (0x1ul << 2) /*!< Select Tamper 2 \hideinitializer */ 00098 #define RTC_TAMPER3_SELECT (0x1ul << 3) /*!< Select Tamper 3 \hideinitializer */ 00099 #define RTC_TAMPER4_SELECT (0x1ul << 4) /*!< Select Tamper 4 \hideinitializer */ 00100 #define RTC_TAMPER5_SELECT (0x1ul << 5) /*!< Select Tamper 5 \hideinitializer */ 00101 #define MAX_TAMPER_PIN_NUM 6ul /*!< Tamper Pin number \hideinitializer */ 00102 00103 #define RTC_TAMPER_HIGH_LEVEL_DETECT 1ul /*!< Tamper pin detect voltage level is high \hideinitializer */ 00104 #define RTC_TAMPER_LOW_LEVEL_DETECT 0ul /*!< Tamper pin detect voltage level is low \hideinitializer */ 00105 00106 #define RTC_TAMPER_DEBOUNCE_ENABLE 1ul /*!< Enable RTC tamper pin de-bounce function \hideinitializer */ 00107 #define RTC_TAMPER_DEBOUNCE_DISABLE 0ul /*!< Disable RTC tamper pin de-bounce function \hideinitializer */ 00108 00109 #define RTC_PAIR0_SELECT (0x1ul << 0) /*!< Select Pair 0 \hideinitializer */ 00110 #define RTC_PAIR1_SELECT (0x1ul << 1) /*!< Select Pair 1 \hideinitializer */ 00111 #define RTC_PAIR2_SELECT (0x1ul << 2) /*!< Select Pair 2 \hideinitializer */ 00112 #define MAX_PAIR_NUM 3ul /*!< Pair number \hideinitializer */ 00113 00114 #define RTC_2POW10_CLK (0x0 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 RTC clock cycles \hideinitializer */ 00115 #define RTC_2POW11_CLK (0x1 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 2 RTC clock cycles \hideinitializer */ 00116 #define RTC_2POW12_CLK (0x2 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 4 RTC clock cycles \hideinitializer */ 00117 #define RTC_2POW13_CLK (0x3 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 6 RTC clock cycles \hideinitializer */ 00118 #define RTC_2POW14_CLK (0x4 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 8 RTC clock cycles \hideinitializer */ 00119 #define RTC_2POW15_CLK (0x5 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 16 RTC clock cycles \hideinitializer */ 00120 #define RTC_2POW16_CLK (0x6 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 32 RTC clock cycles \hideinitializer */ 00121 #define RTC_2POW17_CLK (0x7 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 64 RTC clock cycles \hideinitializer */ 00122 00123 #define REF_RANDOM_PATTERN 0x0 /*!< The new reference pattern is generated by random number generator when the reference pattern run out \hideinitializer */ 00124 #define REF_PREVIOUS_PATTERN 0x1 /*!< The new reference pattern is repeated previous random value when the reference pattern run out \hideinitializer */ 00125 #define REF_SEED 0x3 /*!< The new reference pattern is repeated from SEED (RTC_TAMPSEED[31:0]) when the reference pattern run out \hideinitializer */ 00126 00127 /*@}*/ /* end of group RTC_EXPORTED_CONSTANTS */ 00128 00129 00130 /** @addtogroup RTC_EXPORTED_STRUCTS RTC Exported Structs 00131 @{ 00132 */ 00133 /** 00134 * @details RTC define Time Data Struct 00135 */ 00136 typedef struct { 00137 uint32_t u32Year ; /*!< Year value */ 00138 uint32_t u32Month ; /*!< Month value */ 00139 uint32_t u32Day ; /*!< Day value */ 00140 uint32_t u32DayOfWeek ; /*!< Day of week value */ 00141 uint32_t u32Hour ; /*!< Hour value */ 00142 uint32_t u32Minute ; /*!< Minute value */ 00143 uint32_t u32Second ; /*!< Second value */ 00144 uint32_t u32TimeScale ; /*!< 12-Hour, 24-Hour */ 00145 uint32_t u32AmPm ; /*!< Only Time Scale select 12-hr used */ 00146 } S_RTC_TIME_DATA_T ; 00147 00148 /*@}*/ /* end of group RTC_EXPORTED_STRUCTS */ 00149 00150 00151 /** @addtogroup RTC_EXPORTED_FUNCTIONS RTC Exported Functions 00152 @{ 00153 */ 00154 00155 /** 00156 * @brief Indicate is Leap Year or not 00157 * 00158 * @param None 00159 * 00160 * @retval 0 This year is not a leap year 00161 * @retval 1 This year is a leap year 00162 * 00163 * @details According to current date, return this year is leap year or not. 00164 * \hideinitializer 00165 */ 00166 #define RTC_IS_LEAP_YEAR() (RTC->LEAPYEAR & RTC_LEAPYEAR_LEAPYEAR_Msk ? 1:0) 00167 00168 /** 00169 * @brief Clear RTC Alarm Interrupt Flag 00170 * 00171 * @param None 00172 * 00173 * @return None 00174 * 00175 * @details This macro is used to clear RTC alarm interrupt flag. 00176 * \hideinitializer 00177 */ 00178 #define RTC_CLEAR_ALARM_INT_FLAG() (RTC->INTSTS = RTC_INTSTS_ALMIF_Msk) 00179 00180 /** 00181 * @brief Clear RTC Tick Interrupt Flag 00182 * 00183 * @param None 00184 * 00185 * @return None 00186 * 00187 * @details This macro is used to clear RTC tick interrupt flag. 00188 * \hideinitializer 00189 */ 00190 #define RTC_CLEAR_TICK_INT_FLAG() (RTC->INTSTS = RTC_INTSTS_TICKIF_Msk) 00191 00192 /** 00193 * @brief Clear RTC Tamper Interrupt Flag 00194 * 00195 * @param u32TamperFlag Tamper interrupt flag. It consists of: \n 00196 * - \ref RTC_INTSTS_TAMP0IF_Msk \n 00197 * - \ref RTC_INTSTS_TAMP1IF_Msk \n 00198 * - \ref RTC_INTSTS_TAMP2IF_Msk \n 00199 * - \ref RTC_INTSTS_TAMP3IF_Msk \n 00200 * - \ref RTC_INTSTS_TAMP4IF_Msk \n 00201 * - \ref RTC_INTSTS_TAMP5IF_Msk 00202 * 00203 * @return None 00204 * 00205 * @details This macro is used to clear RTC snooper pin interrupt flag. 00206 * \hideinitializer 00207 */ 00208 #define RTC_CLEAR_TAMPER_INT_FLAG(u32TamperFlag) (RTC->INTSTS = (u32TamperFlag)) 00209 00210 /** 00211 * @brief Get RTC Alarm Interrupt Flag 00212 * 00213 * @param None 00214 * 00215 * @retval 0 RTC alarm interrupt did not occur 00216 * @retval 1 RTC alarm interrupt occurred 00217 * 00218 * @details This macro indicates RTC alarm interrupt occurred or not. 00219 * \hideinitializer 00220 */ 00221 #define RTC_GET_ALARM_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_ALMIF_Msk)? 1:0) 00222 00223 /** 00224 * @brief Get RTC Time Tick Interrupt Flag 00225 * 00226 * @param None 00227 * 00228 * @retval 0 RTC time tick interrupt did not occur 00229 * @retval 1 RTC time tick interrupt occurred 00230 * 00231 * @details This macro indicates RTC time tick interrupt occurred or not. 00232 * \hideinitializer 00233 */ 00234 #define RTC_GET_TICK_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_TICKIF_Msk)? 1:0) 00235 00236 /** 00237 * @brief Get RTC Tamper Interrupt Flag 00238 * 00239 * @param None 00240 * 00241 * @retval 0 RTC snooper pin interrupt did not occur 00242 * @retval 1 RTC snooper pin interrupt occurred 00243 * 00244 * @details This macro indicates RTC snooper pin interrupt occurred or not. 00245 * \hideinitializer 00246 */ 00247 #define RTC_GET_TAMPER_INT_FLAG() ((RTC->INTSTS & (0x3F00))? 1:0) 00248 00249 /** 00250 * @brief Get RTC TAMPER Interrupt Status 00251 * 00252 * @param None 00253 * 00254 * @retval RTC_INTSTS_TAMP0IF_Msk Tamper 0 interrupt flag is generated 00255 * @retval RTC_INTSTS_TAMP1IF_Msk Tamper 1 interrupt flag is generated 00256 * @retval RTC_INTSTS_TAMP2IF_Msk Tamper 2 interrupt flag is generated 00257 * @retval RTC_INTSTS_TAMP3IF_Msk Tamper 3 interrupt flag is generated 00258 * @retval RTC_INTSTS_TAMP4IF_Msk Tamper 4 interrupt flag is generated 00259 * @retval RTC_INTSTS_TAMP5IF_Msk Tamper 5 interrupt flag is generated 00260 * 00261 * @details This macro indicates RTC snooper pin interrupt occurred or not. 00262 * \hideinitializer 00263 */ 00264 #define RTC_GET_TAMPER_INT_STATUS() ((RTC->INTSTS & (0x3F00))) 00265 00266 /** 00267 * @brief Read Spare Register 00268 * 00269 * @param[in] u32RegNum The spare register number, 0~19. 00270 * 00271 * @return Spare register content 00272 * 00273 * @details Read the specify spare register content. 00274 * @note The returned value is valid only when SPRRDY(SPRCTL[7] SPR Register Ready) bit is set. \n 00275 * And its controlled by RTC Access Enable Register. 00276 * \hideinitializer 00277 */ 00278 #define RTC_READ_SPARE_REGISTER(u32RegNum) (RTC->SPR[(u32RegNum)]) 00279 00280 /** 00281 * @brief Write Spare Register 00282 * 00283 * @param[in] u32RegNum The spare register number, 0~19. 00284 * @param[in] u32RegValue The spare register value. 00285 * 00286 * @return None 00287 * 00288 * @details Write specify data to spare register. 00289 * @note This macro is effect only when SPRRDY(SPRCTL[7] SPR Register Ready) bit is set. \n 00290 * And its controlled by RTC Access Enable Register(RTC_RWEN). 00291 * \hideinitializer 00292 */ 00293 #define RTC_WRITE_SPARE_REGISTER(u32RegNum, u32RegValue) (RTC->SPR[(u32RegNum)] = (u32RegValue)) 00294 00295 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */ 00296 __STATIC_INLINE void RTC_WaitAccessEnable(void); 00297 00298 /** 00299 * @brief Wait RTC Access Enable 00300 * 00301 * @param None 00302 * 00303 * @return None 00304 * 00305 * @details This function is used to enable the maximum RTC read/write accessible time. 00306 */ 00307 __STATIC_INLINE void RTC_WaitAccessEnable(void) 00308 { 00309 while ((RTC->RWEN & RTC_RWEN_RTCBUSY_Msk) == RTC_RWEN_RTCBUSY_Msk) { 00310 } 00311 00312 /* To wait RWENF bit is cleared and enable RWENF bit (Access Enable bit) again */ 00313 RTC->RWEN = RTC_WRITE_KEY; 00314 00315 /* To wait RWENF bit is set and user can access the protected-register of RTC from now on */ 00316 while ((RTC->RWEN & RTC_RWEN_RWENF_Msk) == (uint32_t)0x0) { 00317 } 00318 } 00319 00320 void RTC_Open(S_RTC_TIME_DATA_T *sPt); 00321 void RTC_Close(void); 00322 void RTC_32KCalibration(int32_t i32FrequencyX10000); 00323 void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt); 00324 void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt); 00325 void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt); 00326 void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt); 00327 void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek); 00328 void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm); 00329 void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day); 00330 void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm); 00331 uint32_t RTC_GetDayOfWeek(void); 00332 void RTC_SetTickPeriod(uint32_t u32TickSelection); 00333 void RTC_EnableInt(uint32_t u32IntFlagMask); 00334 void RTC_DisableInt(uint32_t u32IntFlagMask); 00335 void RTC_EnableSpareAccess(void); 00336 void RTC_DisableSpareRegister(void); 00337 void RTC_StaticTamperEnable(uint32_t u32TamperSelect, uint32_t u32DetecLevel, uint32_t u32DebounceEn); 00338 void RTC_StaticTamperDisable(uint32_t u32TamperSelect); 00339 void RTC_DynamicTamperEnable(uint32_t u32PairSel, uint32_t u32DebounceEn, uint32_t u32Pair1Source, uint32_t u32Pair2Source); 00340 void RTC_DynamicTamperDisable(uint32_t u32PairSel); 00341 void RTC_DynamicTamperConfig(uint32_t u32ChangeRate, uint32_t u32SeedReload, uint32_t u32RefPattern, uint32_t u32Seed); 00342 00343 /*@}*/ /* end of group RTC_EXPORTED_FUNCTIONS */ 00344 00345 /*@}*/ /* end of group RTC_Driver */ 00346 00347 /*@}*/ /* end of group Standard_Driver */ 00348 00349 #ifdef __cplusplus 00350 } 00351 #endif 00352 00353 #endif /* __RTC_H__ */ 00354 00355 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
Generated on Tue Jul 12 2022 15:37:20 by
1.7.2