mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**************************************************************************//**
<> 149:156823d33999 2 * @file rtc.h
<> 149:156823d33999 3 * @version V3.00
<> 149:156823d33999 4 * $Revision: 10 $
<> 149:156823d33999 5 * $Date: 15/08/11 10:26a $
<> 149:156823d33999 6 * @brief M451 series RTC driver header file
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * @note
<> 149:156823d33999 9 * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved.
<> 149:156823d33999 10 *****************************************************************************/
<> 149:156823d33999 11 #ifndef __RTC_H__
<> 149:156823d33999 12 #define __RTC_H__
<> 149:156823d33999 13
<> 149:156823d33999 14 #ifdef __cplusplus
<> 149:156823d33999 15 extern "C"
<> 149:156823d33999 16 {
<> 149:156823d33999 17 #endif
<> 149:156823d33999 18
<> 149:156823d33999 19
<> 149:156823d33999 20 /** @addtogroup Standard_Driver Standard Driver
<> 149:156823d33999 21 @{
<> 149:156823d33999 22 */
<> 149:156823d33999 23
<> 149:156823d33999 24 /** @addtogroup RTC_Driver RTC Driver
<> 149:156823d33999 25 @{
<> 149:156823d33999 26 */
<> 149:156823d33999 27
<> 149:156823d33999 28 /** @addtogroup RTC_EXPORTED_CONSTANTS RTC Exported Constants
<> 149:156823d33999 29 @{
<> 149:156823d33999 30 */
<> 149:156823d33999 31 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 32 /* RTC Initial Keyword Constant Definitions */
<> 149:156823d33999 33 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 34 #define RTC_INIT_KEY 0xA5EB1357UL /*!< RTC Initiation Key to make RTC leaving reset state */
<> 149:156823d33999 35 #define RTC_WRITE_KEY 0x0000A965UL /*!< RTC Register Access Enable Key to enable RTC read/write accessible and kept 1024 RTC clock */
<> 149:156823d33999 36
<> 149:156823d33999 37 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 38 /* RTC Time Attribute Constant Definitions */
<> 149:156823d33999 39 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 40 #define RTC_CLOCK_12 0 /*!< RTC as 12-hour time scale with AM and PM indication */
<> 149:156823d33999 41 #define RTC_CLOCK_24 1 /*!< RTC as 24-hour time scale */
<> 149:156823d33999 42 #define RTC_AM 1 /*!< RTC as AM indication */
<> 149:156823d33999 43 #define RTC_PM 2 /*!< RTC as PM indication */
<> 149:156823d33999 44
<> 149:156823d33999 45 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 46 /* RTC Tick Period Constant Definitions */
<> 149:156823d33999 47 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 48 #define RTC_TICK_1_SEC 0x0UL /*!< RTC time tick period is 1 second */
<> 149:156823d33999 49 #define RTC_TICK_1_2_SEC 0x1UL /*!< RTC time tick period is 1/2 second */
<> 149:156823d33999 50 #define RTC_TICK_1_4_SEC 0x2UL /*!< RTC time tick period is 1/4 second */
<> 149:156823d33999 51 #define RTC_TICK_1_8_SEC 0x3UL /*!< RTC time tick period is 1/8 second */
<> 149:156823d33999 52 #define RTC_TICK_1_16_SEC 0x4UL /*!< RTC time tick period is 1/16 second */
<> 149:156823d33999 53 #define RTC_TICK_1_32_SEC 0x5UL /*!< RTC time tick period is 1/32 second */
<> 149:156823d33999 54 #define RTC_TICK_1_64_SEC 0x6UL /*!< RTC time tick period is 1/64 second */
<> 149:156823d33999 55 #define RTC_TICK_1_128_SEC 0x7UL /*!< RTC time tick period is 1/128 second */
<> 149:156823d33999 56
<> 149:156823d33999 57 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 58 /* RTC Day of Week Constant Definitions */
<> 149:156823d33999 59 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 60 #define RTC_SUNDAY 0x0UL /*!< Day of the Week is Sunday */
<> 149:156823d33999 61 #define RTC_MONDAY 0x1UL /*!< Day of the Week is Monday */
<> 149:156823d33999 62 #define RTC_TUESDAY 0x2UL /*!< Day of the Week is Tuesday */
<> 149:156823d33999 63 #define RTC_WEDNESDAY 0x3UL /*!< Day of the Week is Wednesday */
<> 149:156823d33999 64 #define RTC_THURSDAY 0x4UL /*!< Day of the Week is Thursday */
<> 149:156823d33999 65 #define RTC_FRIDAY 0x5UL /*!< Day of the Week is Friday */
<> 149:156823d33999 66 #define RTC_SATURDAY 0x6UL /*!< Day of the Week is Saturday */
<> 149:156823d33999 67
<> 149:156823d33999 68 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 69 /* RTC Snooper Detection Mode Constant Definitions */
<> 149:156823d33999 70 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 71 #define RTC_SNOOPER_LOW_LEVEL 0x0UL /*!< Snooper pin detected is low-level trigger */
<> 149:156823d33999 72 #define RTC_SNOOPER_HIGH_LEVEL 0x2UL /*!< Snooper pin detected is high-level trigger */
<> 149:156823d33999 73 #define RTC_SNOOPER_FALLING_EDGE 0x8UL /*!< Snooper pin detected is falling-edge trigger */
<> 149:156823d33999 74 #define RTC_SNOOPER_RISING_EDGE 0xAUL /*!< Snooper pin detected is rising-edge trigger */
<> 149:156823d33999 75 #define RTC_SNOOPER_DETECT_Msk 0xAUL /*!< Snooper pin detected mask bits */
<> 149:156823d33999 76
<> 149:156823d33999 77 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 78 /* RTC Miscellaneous Constant Definitions */
<> 149:156823d33999 79 /*---------------------------------------------------------------------------------------------------------*/
<> 149:156823d33999 80 #define RTC_WAIT_COUNT 0xFFFFFFFF /*!< Initial Time-out Value */
<> 149:156823d33999 81 #define RTC_YEAR2000 2000 /*!< RTC Reference for compute year data */
<> 149:156823d33999 82 #define RTC_FCR_REFERENCE 32761 /*!< RTC Reference for frequency compensation */
<> 149:156823d33999 83
<> 149:156823d33999 84 /*@}*/ /* end of group RTC_EXPORTED_CONSTANTS */
<> 149:156823d33999 85
<> 149:156823d33999 86
<> 149:156823d33999 87 /** @addtogroup RTC_EXPORTED_STRUCTS RTC Exported Structs
<> 149:156823d33999 88 @{
<> 149:156823d33999 89 */
<> 149:156823d33999 90 /**
<> 149:156823d33999 91 * @details RTC define Time Data Struct
<> 149:156823d33999 92 */
<> 149:156823d33999 93 typedef struct
<> 149:156823d33999 94 {
<> 149:156823d33999 95 uint32_t u32Year; /*!< Year value */
<> 149:156823d33999 96 uint32_t u32Month; /*!< Month value */
<> 149:156823d33999 97 uint32_t u32Day; /*!< Day value */
<> 149:156823d33999 98 uint32_t u32DayOfWeek; /*!< Day of week value */
<> 149:156823d33999 99 uint32_t u32Hour; /*!< Hour value */
<> 149:156823d33999 100 uint32_t u32Minute; /*!< Minute value */
<> 149:156823d33999 101 uint32_t u32Second; /*!< Second value */
<> 149:156823d33999 102 uint32_t u32TimeScale; /*!< 12-Hour, 24-Hour */
<> 149:156823d33999 103 uint32_t u32AmPm; /*!< Only Time Scale select 12-hr used */
<> 149:156823d33999 104 } S_RTC_TIME_DATA_T;
<> 149:156823d33999 105
<> 149:156823d33999 106 /*@}*/ /* end of group RTC_EXPORTED_STRUCTS */
<> 149:156823d33999 107
<> 149:156823d33999 108
<> 149:156823d33999 109 /** @addtogroup RTC_EXPORTED_FUNCTIONS RTC Exported Functions
<> 149:156823d33999 110 @{
<> 149:156823d33999 111 */
<> 149:156823d33999 112
<> 149:156823d33999 113 /**
<> 149:156823d33999 114 * @brief Indicate is Leap Year or not
<> 149:156823d33999 115 *
<> 149:156823d33999 116 * @param None
<> 149:156823d33999 117 *
<> 149:156823d33999 118 * @retval 0 This year is not a leap year
<> 149:156823d33999 119 * @retval 1 This year is a leap year
<> 149:156823d33999 120 *
<> 149:156823d33999 121 * @details According to current date, return this year is leap year or not.
<> 149:156823d33999 122 */
<> 149:156823d33999 123 #define RTC_IS_LEAP_YEAR() (RTC->LEAPYEAR & RTC_LEAPYEAR_LEAPYEAR_Msk ? 1:0)
<> 149:156823d33999 124
<> 149:156823d33999 125 /**
<> 149:156823d33999 126 * @brief Clear RTC Alarm Interrupt Flag
<> 149:156823d33999 127 *
<> 149:156823d33999 128 * @param None
<> 149:156823d33999 129 *
<> 149:156823d33999 130 * @return None
<> 149:156823d33999 131 *
<> 149:156823d33999 132 * @details This macro is used to clear RTC alarm interrupt flag.
<> 149:156823d33999 133 */
<> 149:156823d33999 134 #define RTC_CLEAR_ALARM_INT_FLAG() (RTC->INTSTS = (RTC->INTSTS & ~(RTC_INTSTS_TICKIF_Msk | RTC_INTSTS_SNPDIF_Msk)) | RTC_INTSTS_ALMIF_Msk)
<> 149:156823d33999 135
<> 149:156823d33999 136 /**
<> 149:156823d33999 137 * @brief Clear RTC Tick Interrupt Flag
<> 149:156823d33999 138 *
<> 149:156823d33999 139 * @param None
<> 149:156823d33999 140 *
<> 149:156823d33999 141 * @return None
<> 149:156823d33999 142 *
<> 149:156823d33999 143 * @details This macro is used to clear RTC tick interrupt flag.
<> 149:156823d33999 144 */
<> 149:156823d33999 145 #define RTC_CLEAR_TICK_INT_FLAG() (RTC->INTSTS = (RTC->INTSTS & ~(RTC_INTSTS_ALMIF_Msk | RTC_INTSTS_SNPDIF_Msk)) | RTC_INTSTS_TICKIF_Msk)
<> 149:156823d33999 146
<> 149:156823d33999 147 /**
<> 149:156823d33999 148 * @brief Clear RTC Snooper Interrupt Flag
<> 149:156823d33999 149 *
<> 149:156823d33999 150 * @param None
<> 149:156823d33999 151 *
<> 149:156823d33999 152 * @return None
<> 149:156823d33999 153 *
<> 149:156823d33999 154 * @details This macro is used to clear RTC snooper pin interrupt flag.
<> 149:156823d33999 155 */
<> 149:156823d33999 156 #define RTC_CLEAR_SNOOPER_INT_FLAG() (RTC->INTSTS = (RTC->INTSTS & ~(RTC_INTSTS_ALMIF_Msk | RTC_INTSTS_TICKIF_Msk)) | RTC_INTSTS_SNPDIF_Msk)
<> 149:156823d33999 157
<> 149:156823d33999 158 /**
<> 149:156823d33999 159 * @brief Get RTC Alarm Interrupt Flag
<> 149:156823d33999 160 *
<> 149:156823d33999 161 * @param None
<> 149:156823d33999 162 *
<> 149:156823d33999 163 * @retval 0 RTC alarm interrupt did not occur
<> 149:156823d33999 164 * @retval 1 RTC alarm interrupt occurred
<> 149:156823d33999 165 *
<> 149:156823d33999 166 * @details This macro indicates RTC alarm interrupt occurred or not.
<> 149:156823d33999 167 */
<> 149:156823d33999 168 #define RTC_GET_ALARM_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_ALMIF_Msk)? 1:0)
<> 149:156823d33999 169
<> 149:156823d33999 170 /**
<> 149:156823d33999 171 * @brief Get RTC Time Tick Interrupt Flag
<> 149:156823d33999 172 *
<> 149:156823d33999 173 * @param None
<> 149:156823d33999 174 *
<> 149:156823d33999 175 * @retval 0 RTC time tick interrupt did not occur
<> 149:156823d33999 176 * @retval 1 RTC time tick interrupt occurred
<> 149:156823d33999 177 *
<> 149:156823d33999 178 * @details This macro indicates RTC time tick interrupt occurred or not.
<> 149:156823d33999 179 */
<> 149:156823d33999 180 #define RTC_GET_TICK_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_TICKIF_Msk)? 1:0)
<> 149:156823d33999 181
<> 149:156823d33999 182 /**
<> 149:156823d33999 183 * @brief Get RTC Snooper Interrupt Flag
<> 149:156823d33999 184 *
<> 149:156823d33999 185 * @param None
<> 149:156823d33999 186 *
<> 149:156823d33999 187 * @retval 0 RTC snooper pin interrupt did not occur
<> 149:156823d33999 188 * @retval 1 RTC snooper pin interrupt occurred
<> 149:156823d33999 189 *
<> 149:156823d33999 190 * @details This macro indicates RTC snooper pin interrupt occurred or not.
<> 149:156823d33999 191 */
<> 149:156823d33999 192 #define RTC_GET_SNPPOER_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_SNPDIF_Msk)? 1:0)
<> 149:156823d33999 193
<> 149:156823d33999 194 /**
<> 149:156823d33999 195 * @brief Read Spare Register
<> 149:156823d33999 196 *
<> 149:156823d33999 197 * @param[in] u32RegNum The spare register number, 0~19.
<> 149:156823d33999 198 *
<> 149:156823d33999 199 * @return Spare register content
<> 149:156823d33999 200 *
<> 149:156823d33999 201 * @details Read the specify spare register content.
<> 149:156823d33999 202 * @note The returned value is valid only when SPRRDY(SPRCTL[7] SPR Register Ready) bit is set. \n
<> 149:156823d33999 203 * And its controlled by RTC Access Enable Register.
<> 149:156823d33999 204 */
<> 149:156823d33999 205 #define RTC_READ_SPARE_REGISTER(u32RegNum) (RTC->SPR[(u32RegNum)])
<> 149:156823d33999 206
<> 149:156823d33999 207 /**
<> 149:156823d33999 208 * @brief Write Spare Register
<> 149:156823d33999 209 *
<> 149:156823d33999 210 * @param[in] u32RegNum The spare register number, 0~19.
<> 149:156823d33999 211 * @param[in] u32RegValue The spare register value.
<> 149:156823d33999 212 *
<> 149:156823d33999 213 * @return None
<> 149:156823d33999 214 *
<> 149:156823d33999 215 * @details Write specify data to spare register.
<> 149:156823d33999 216 * @note This macro is effect only when SPRRDY(SPRCTL[7] SPR Register Ready) bit is set. \n
<> 149:156823d33999 217 * And its controlled by RTC Access Enable Register(RTC_RWEN).
<> 149:156823d33999 218 */
<> 149:156823d33999 219 #define RTC_WRITE_SPARE_REGISTER(u32RegNum, u32RegValue) (RTC->SPR[(u32RegNum)] = (u32RegValue))
<> 149:156823d33999 220
<> 149:156823d33999 221 /**
<> 149:156823d33999 222 * @brief Wait RTC Access Enable
<> 149:156823d33999 223 *
<> 149:156823d33999 224 * @param None
<> 149:156823d33999 225 *
<> 149:156823d33999 226 * @return None
<> 149:156823d33999 227 *
<> 149:156823d33999 228 * @details This function is used to enable the maximum RTC read/write accessible time.
<> 149:156823d33999 229 */
<> 149:156823d33999 230 static __INLINE void RTC_WaitAccessEnable(void)
<> 149:156823d33999 231 {
<> 149:156823d33999 232 /* To wait RWENF bit is cleared and enable RWENF bit (Access Enable bit) again */
<> 149:156823d33999 233 while((RTC->RWEN & RTC_RWEN_RWENF_Msk) == RTC_RWEN_RWENF_Msk);
<> 149:156823d33999 234 RTC->RWEN = RTC_WRITE_KEY;
<> 149:156823d33999 235
<> 149:156823d33999 236 /* To wait RWENF bit is set and user can access the protected-register of RTC from now on */
<> 149:156823d33999 237 while((RTC->RWEN & RTC_RWEN_RWENF_Msk) == 0x0);
<> 149:156823d33999 238 }
<> 149:156823d33999 239
<> 149:156823d33999 240 void RTC_Open(S_RTC_TIME_DATA_T *sPt);
<> 149:156823d33999 241 void RTC_Close(void);
<> 149:156823d33999 242 void RTC_32KCalibration(int32_t i32FrequencyX100);
<> 149:156823d33999 243 void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt);
<> 149:156823d33999 244 void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
<> 149:156823d33999 245 void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt);
<> 149:156823d33999 246 void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
<> 149:156823d33999 247 void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek);
<> 149:156823d33999 248 void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
<> 149:156823d33999 249 void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day);
<> 149:156823d33999 250 void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
<> 149:156823d33999 251 uint32_t RTC_GetDayOfWeek(void);
<> 149:156823d33999 252 void RTC_SetTickPeriod(uint32_t u32TickSelection);
<> 149:156823d33999 253 void RTC_EnableInt(uint32_t u32IntFlagMask);
<> 149:156823d33999 254 void RTC_DisableInt(uint32_t u32IntFlagMask);
<> 149:156823d33999 255 void RTC_EnableSpareAccess(void);
<> 149:156823d33999 256 void RTC_DisableSpareRegister(void);
<> 149:156823d33999 257 void RTC_EnableSnooperDetection(uint32_t u32PinCondition);
<> 149:156823d33999 258 void RTC_DisableSnooperDetection(void);
<> 149:156823d33999 259
<> 149:156823d33999 260 /*@}*/ /* end of group RTC_EXPORTED_FUNCTIONS */
<> 149:156823d33999 261
<> 149:156823d33999 262 /*@}*/ /* end of group RTC_Driver */
<> 149:156823d33999 263
<> 149:156823d33999 264 /*@}*/ /* end of group Standard_Driver */
<> 149:156823d33999 265
<> 149:156823d33999 266 #ifdef __cplusplus
<> 149:156823d33999 267 }
<> 149:156823d33999 268 #endif
<> 149:156823d33999 269
<> 149:156823d33999 270 #endif //__RTC_H__
<> 149:156823d33999 271
<> 149:156823d33999 272 /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/