1 /****************************************************************************** 2 * 3 * @brief Real-ETMe counter (RTC) driver head file. 4 * 5 ******************************************************************************/ 6 #ifndef RTC_H_ 7 #define RTC_H_ 8 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 /****************************************************************************** 12 * Includes 13 ******************************************************************************/ 14 15 /****************************************************************************** 16 * Constants 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * Macros 21 ******************************************************************************/ 22 23 /****************************************************************************** 24 * RTC control bit definition 25 * 26 *//*! @addtogroup rtc_controlbit 27 * @{ 28 *******************************************************************************/ 29 30 #define RTC_OUTPUT_ENABLE 1 /*!< enable RTCO pin */ 31 #define RTC_INTERRUPT_ENABLE 1 /*!< enable RTC interrupt */ 32 #define RTC_CLKSRC_EXTERNAL 0 /*!< select external clock as RTC clock source */ 33 #define RTC_CLKSRC_1KHZ 1 /*!< select LPO as RTC clock source */ 34 #define RTC_CLKSRC_IREF 2 /*!< select internal reference clock as RTC clock source */ 35 #define RTC_CLKSRC_BUS 3 /*!< select bus clock as RTC clock source */ 36 #define RTC_CLK_PRESCALER_128 1 /*!< presalcer is 1 or 128 according to RTCLKS bits */ 37 #define RTC_CLK_PRESCALER_256 2 /*!< presalcer is 2 or 256 according to RTCLKS bits */ 38 #define RTC_CLK_PRESCALER_512 3 /*!< presalcer is 4 or 512 according to RTCLKS bits */ 39 #define RTC_CLK_PRESCALER_1024 4 /*!< presalcer is 8 or 1024 according to RTCLKS bits */ 40 #define RTC_CLK_PRESCALER_2048 5 /*!< presalcer is 16 or 2048 according to RTCLKS bits */ 41 #define RTC_CLK_PRESCALER_100 6 /*!< presalcer is 32 or 100 according to RTCLKS bits */ 42 #define RTC_CLK_PRESCALER_1000 7 /*!< presalcer is 64 or 1000 according to RTCLKS bits */ 43 44 45 /*! @} End of rtc_controlbit */ 46 47 /****************************************************************************** 48 * Types 49 ******************************************************************************/ 50 51 /* 52 * Callback type 53 */ 54 55 /****************************************************************************** 56 * RTC callback function declaration 57 * 58 *//*! @addtogroup rtc_callback 59 * @{ 60 *******************************************************************************/ 61 62 /*! 63 * @brief RTC Callback type. 64 * 65 */ 66 67 typedef void (*RTC_CallbackType)(void); 68 69 /*! @} End of rtc_callback */ 70 71 72 /* RTC configuration structure 73 */ 74 /*! 75 * @brief RTC configuration type. 76 * 77 */ 78 typedef struct 79 { 80 uint16_t bReserved : 4; /*!< reserved */ 81 uint16_t bRTCOut : 1; /*!< 1: RTCO pin is enable, 0: RTCO pin is disable */ 82 uint16_t bReserved1 : 1; /*!< reserved */ 83 uint16_t bInterruptEn : 1; /*!< 1: RTC interrupt is enable, 0: RTC interrupt is disable */ 84 uint16_t bFlag : 1; /*!< 1: RTC flag is set, 0: RTC flag is not set */ 85 uint16_t bClockPresaler : 3; /*!< 1: RTC presclaer, from 0x0 to 0x7 */ 86 uint16_t bReserved2 : 3; /*!< reserved */ 87 uint16_t bClockSource : 2; /*!< RTC clock source selection from 0x0 to 0x3 */ 88 uint16_t u16ModuloValue ; /*!< 16-bit rtc modulo value */ 89 } RTC_ConfigType, *RTC_ConfigPtr; 90 91 92 /****************************************************************************** 93 * Global variables 94 ******************************************************************************/ 95 96 /*! 97 * inline functions 98 */ 99 100 /****************************************************************************** 101 * RTC API list 102 * 103 *//*! @addtogroup rtc_api_list 104 * @{ 105 *******************************************************************************/ 106 107 /*****************************************************************************//*! 108 * 109 * @brief enable rtc interrupt. 110 * 111 * @param none 112 * 113 * @return none 114 * 115 * @ Pass/ Fail criteria: none 116 *****************************************************************************/ RTC_EnableInt(void)117__STATIC_INLINE void RTC_EnableInt(void) 118 { 119 RTC->SC |= RTC_SC_RTIE_MASK; 120 } 121 122 123 /*****************************************************************************//*! 124 * 125 * @brief disable rtc interrupt. 126 * 127 * @param none 128 * 129 * @return non 130 * 131 * @ Pass/ Fail criteria: none 132 *****************************************************************************/ RTC_DisableInt(void)133__STATIC_INLINE void RTC_DisableInt(void) 134 { 135 RTC->SC &= ~RTC_SC_RTIE_MASK; 136 } 137 138 139 /*****************************************************************************//*! 140 * 141 * @brief set rtc modulo value. 142 * 143 * @param[in] u16Mod_Value 144 * 145 * @return none 146 * 147 * @ Pass/ Fail criteria: none 148 *****************************************************************************/ RTC_SetModulo(uint16_t u16Mod_Value)149__STATIC_INLINE void RTC_SetModulo(uint16_t u16Mod_Value) 150 { 151 152 RTC->MOD = u16Mod_Value; 153 } 154 155 /*****************************************************************************//*! 156 * 157 * @brief set rtc clock source and presalcer. 158 * 159 * @param[in] u16Clock_Number clock source number 160 * @param[in] u16Presalcer prescaler value 161 * 162 * @return none 163 * 164 * @ Pass/ Fail criteria: none 165 *****************************************************************************/ RTC_SetClock(uint16_t u16Clock_Number,uint16_t u16Presalcer)166__STATIC_INLINE void RTC_SetClock(uint16_t u16Clock_Number, uint16_t u16Presalcer) 167 { 168 uint32_t u32rtc_sc; 169 170 u32rtc_sc = RTC->SC; 171 u32rtc_sc &= ~(RTC_SC_RTCLKS_MASK | RTC_SC_RTCPS_MASK); 172 u32rtc_sc |= RTC_SC_RTCLKS(u16Clock_Number) | RTC_SC_RTCPS(u16Presalcer); 173 RTC->SC = u32rtc_sc; 174 } 175 176 /*****************************************************************************//*! 177 * 178 * @brief get rtc flag bit. 179 * 180 * @param none 181 * 182 * @return bflag. 183 * 184 * @ Pass/ Fail criteria: none 185 *****************************************************************************/ RTC_GetFlags(void)186__STATIC_INLINE uint8_t RTC_GetFlags(void) 187 { 188 uint8_t bflag; 189 190 bflag = RTC->SC & RTC_SC_RTIF_MASK; 191 192 return bflag; 193 } 194 195 196 /*****************************************************************************//*! 197 * 198 * @brief clear rtc flag bit. 199 * 200 * @param none 201 * 202 * @return none 203 * 204 * @ Pass/ Fail criteria: none 205 *****************************************************************************/ RTC_ClrFlags(void)206__STATIC_INLINE void RTC_ClrFlags(void) 207 { 208 RTC->SC |= RTC_SC_RTIF_MASK; 209 } 210 211 212 /****************************************************************************** 213 * Global functions 214 ******************************************************************************/ 215 void RTC_Init(RTC_ConfigType *pConfig); 216 void RTC_SetCallback(RTC_CallbackType pfnCallback); 217 void RTC_DeInit(void); 218 219 /*! @} End of rtc_api_list */ 220 221 #ifdef __cplusplus 222 } 223 #endif 224 #endif /* RTC_H_ */ 225