n32g45x_rtc.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_rtc.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __N32G45X_RTC_H__
  35. #define __N32G45X_RTC_H__
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include "n32g45x.h"
  40. /** @addtogroup N32G45X_StdPeriph_Driver
  41. * @{
  42. */
  43. /** @addtogroup RTC
  44. * @{
  45. */
  46. /**
  47. * @brief RTC Init structures definition
  48. */
  49. typedef struct
  50. {
  51. uint32_t RTC_HourFormat; /*!< Specifies the RTC Hour Format.
  52. This parameter can be a value of @ref RTC_Hour_Formats */
  53. uint32_t RTC_AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
  54. This parameter must be set to a value lower than 0x7F */
  55. uint32_t RTC_SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
  56. This parameter must be set to a value lower than 0x7FFF */
  57. } RTC_InitType;
  58. /**
  59. * @brief RTC Time structure definition
  60. */
  61. typedef struct
  62. {
  63. uint8_t Hours; /*!< Specifies the RTC Time Hour.
  64. This parameter must be set to a value in the 0-12 range
  65. if the RTC_12HOUR_FORMAT is selected or 0-23 range if
  66. the RTC_24HOUR_FORMAT is selected. */
  67. uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
  68. This parameter must be set to a value in the 0-59 range. */
  69. uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
  70. This parameter must be set to a value in the 0-59 range. */
  71. uint8_t H12; /*!< Specifies the RTC AM/PM Time.
  72. This parameter can be a value of @ref RTC_AM_PM_Definitions */
  73. } RTC_TimeType;
  74. /**
  75. * @brief RTC Date structure definition
  76. */
  77. typedef struct
  78. {
  79. uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay.
  80. This parameter can be a value of @ref RTC_WeekDay_Definitions */
  81. uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
  82. This parameter can be a value of @ref RTC_Month_Date_Definitions */
  83. uint8_t Date; /*!< Specifies the RTC Date.
  84. This parameter must be set to a value in the 1-31 range. */
  85. uint8_t Year; /*!< Specifies the RTC Date Year.
  86. This parameter must be set to a value in the 0-99 range. */
  87. } RTC_DateType;
  88. /**
  89. * @brief RTC Alarm structure definition
  90. */
  91. typedef struct
  92. {
  93. RTC_TimeType AlarmTime; /*!< Specifies the RTC Alarm Time members. */
  94. uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks.
  95. This parameter can be a value of @ref RTC_AlarmMask_Definitions */
  96. uint32_t DateWeekMode; /*!< Specifies the RTC Alarm is on Date or WeekDay.
  97. This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
  98. uint8_t DateWeekValue; /*!< Specifies the RTC Alarm Date/WeekDay.
  99. If the Alarm Date is selected, this parameter
  100. must be set to a value in the 1-31 range.
  101. If the Alarm WeekDay is selected, this
  102. parameter can be a value of @ref RTC_WeekDay_Definitions */
  103. } RTC_AlarmType;
  104. /** @addtogroup RTC_Exported_Constants
  105. * @{
  106. */
  107. /** @addtogroup RTC_Hour_Formats
  108. * @{
  109. */
  110. #define RTC_24HOUR_FORMAT ((uint32_t)0x00000000)
  111. #define RTC_12HOUR_FORMAT ((uint32_t)0x00000040)
  112. #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_12HOUR_FORMAT) || ((FORMAT) == RTC_24HOUR_FORMAT))
  113. /**
  114. * @}
  115. */
  116. /** @addtogroup RTC_Asynchronous_Predivider
  117. * @{
  118. */
  119. #define IS_RTC_PREDIV_ASYNCH(PREDIV) ((PREDIV) <= 0x7F)
  120. /**
  121. * @}
  122. */
  123. /** @addtogroup RTC_Synchronous_Predivider
  124. * @{
  125. */
  126. #define IS_RTC_PREDIV_SYNCH(PREDIV) ((PREDIV) <= 0x7FFF)
  127. /**
  128. * @}
  129. */
  130. /** @addtogroup RTC_Time_Definitions
  131. * @{
  132. */
  133. #define IS_RTC_12HOUR(HOUR) (((HOUR) > 0) && ((HOUR) <= 12))
  134. #define IS_RTC_24HOUR(HOUR) ((HOUR) <= 23)
  135. #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59)
  136. #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59)
  137. /**
  138. * @}
  139. */
  140. /** @addtogroup RTC_AM_PM_Definitions
  141. * @{
  142. */
  143. #define RTC_AM_H12 ((uint8_t)0x00)
  144. #define RTC_PM_H12 ((uint8_t)0x40)
  145. #define IS_RTC_H12(PM) (((PM) == RTC_AM_H12) || ((PM) == RTC_PM_H12))
  146. /**
  147. * @}
  148. */
  149. /** @addtogroup RTC_Year_Date_Definitions
  150. * @{
  151. */
  152. #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99)
  153. /**
  154. * @}
  155. */
  156. /** @addtogroup RTC_Month_Date_Definitions
  157. * @{
  158. */
  159. /* Coded in BCD format */
  160. #define RTC_MONTH_JANUARY ((uint8_t)0x01)
  161. #define RTC_MONTH_FEBRURY ((uint8_t)0x02)
  162. #define RTC_MONTH_MARCH ((uint8_t)0x03)
  163. #define RTC_MONTH_APRIL ((uint8_t)0x04)
  164. #define RTC_MONTH_MAY ((uint8_t)0x05)
  165. #define RTC_MONTH_JUNE ((uint8_t)0x06)
  166. #define RTC_MONTH_JULY ((uint8_t)0x07)
  167. #define RTC_MONTH_AUGUST ((uint8_t)0x08)
  168. #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
  169. #define RTC_MONTH_OCTOBER ((uint8_t)0x10)
  170. #define RTC_MONTH_NOVEMBER ((uint8_t)0x11)
  171. #define RTC_MONTH_DECEMBER ((uint8_t)0x12)
  172. #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12))
  173. #define IS_RTC_DATE(DATE) (((DATE) >= 1) && ((DATE) <= 31))
  174. /**
  175. * @}
  176. */
  177. /** @addtogroup RTC_WeekDay_Definitions
  178. * @{
  179. */
  180. #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01)
  181. #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02)
  182. #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
  183. #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04)
  184. #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05)
  185. #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06)
  186. #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07)
  187. #define IS_RTC_WEEKDAY(WEEKDAY) \
  188. (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) \
  189. || ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) \
  190. || ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  191. /**
  192. * @}
  193. */
  194. /** @addtogroup RTC_Alarm_Definitions
  195. * @{
  196. */
  197. #define IS_RTC_ALARM_WEEKDAY_DATE(DATE) (((DATE) > 0) && ((DATE) <= 31))
  198. #define IS_RTC_ALARM_WEEKDAY_WEEKDAY(WEEKDAY) \
  199. (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) \
  200. || ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) \
  201. || ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  202. /**
  203. * @}
  204. */
  205. /** @addtogroup RTC_AlarmDateWeekDay_Definitions
  206. * @{
  207. */
  208. #define RTC_ALARM_SEL_WEEKDAY_DATE ((uint32_t)0x00000000)
  209. #define RTC_ALARM_SEL_WEEKDAY_WEEKDAY ((uint32_t)0x40000000)
  210. #define IS_RTC_ALARM_WEEKDAY_SEL(SEL) \
  211. (((SEL) == RTC_ALARM_SEL_WEEKDAY_DATE) || ((SEL) == RTC_ALARM_SEL_WEEKDAY_WEEKDAY))
  212. /**
  213. * @}
  214. */
  215. /** @addtogroup RTC_AlarmMask_Definitions
  216. * @{
  217. */
  218. #define RTC_ALARMMASK_NONE ((uint32_t)0x00000000)
  219. #define RTC_ALARMMASK_WEEKDAY ((uint32_t)0x80000000)
  220. #define RTC_ALARMMASK_HOURS ((uint32_t)0x00800000)
  221. #define RTC_ALARMMASK_MINUTES ((uint32_t)0x00008000)
  222. #define RTC_ALARMMASK_SECONDS ((uint32_t)0x00000080)
  223. #define RTC_ALARMMASK_ALL ((uint32_t)0x80808080)
  224. #define IS_ALARM_MASK(INTEN) (((INTEN)&0x7F7F7F7F) == (uint32_t)RESET)
  225. /**
  226. * @}
  227. */
  228. /** @addtogroup RTC_Alarms_Definitions
  229. * @{
  230. */
  231. #define RTC_A_ALARM ((uint32_t)0x00000100)
  232. #define RTC_B_ALARM ((uint32_t)0x00000200)
  233. #define IS_RTC_ALARM_SEL(ALARM) (((ALARM) == RTC_A_ALARM) || ((ALARM) == RTC_B_ALARM))
  234. #define IS_RTC_ALARM_ENABLE(ALARM) (((ALARM) & (RTC_A_ALARM | RTC_B_ALARM)) != (uint32_t)RESET)
  235. /**
  236. * @}
  237. */
  238. /** @addtogroup RTC_Alarm_Sub_Seconds_Masks_Definitions
  239. * @{
  240. */
  241. #define RTC_SUBS_MASK_ALL \
  242. ((uint32_t)0x00000000) /*!< All Alarm SS fields are masked. \
  243. There is no comparison on sub seconds \
  244. for Alarm */
  245. #define RTC_SUBS_MASK_SS14_1 \
  246. ((uint32_t)0x01000000) /*!< SS[14:1] are don't care in Alarm \
  247. comparison. Only SS[0] is compared. */
  248. #define RTC_SUBS_MASK_SS14_2 \
  249. ((uint32_t)0x02000000) /*!< SS[14:2] are don't care in Alarm \
  250. comparison. Only SS[1:0] are compared */
  251. #define RTC_SUBS_MASK_SS14_3 \
  252. ((uint32_t)0x03000000) /*!< SS[14:3] are don't care in Alarm \
  253. comparison. Only SS[2:0] are compared */
  254. #define RTC_SUBS_MASK_SS14_4 \
  255. ((uint32_t)0x04000000) /*!< SS[14:4] are don't care in Alarm \
  256. comparison. Only SS[3:0] are compared */
  257. #define RTC_SUBS_MASK_SS14_5 \
  258. ((uint32_t)0x05000000) /*!< SS[14:5] are don't care in Alarm \
  259. comparison. Only SS[4:0] are compared */
  260. #define RTC_SUBS_MASK_SS14_6 \
  261. ((uint32_t)0x06000000) /*!< SS[14:6] are don't care in Alarm \
  262. comparison. Only SS[5:0] are compared */
  263. #define RTC_SUBS_MASK_SS14_7 \
  264. ((uint32_t)0x07000000) /*!< SS[14:7] are don't care in Alarm \
  265. comparison. Only SS[6:0] are compared */
  266. #define RTC_SUBS_MASK_SS14_8 \
  267. ((uint32_t)0x08000000) /*!< SS[14:8] are don't care in Alarm \
  268. comparison. Only SS[7:0] are compared */
  269. #define RTC_SUBS_MASK_SS14_9 \
  270. ((uint32_t)0x09000000) /*!< SS[14:9] are don't care in Alarm \
  271. comparison. Only SS[8:0] are compared */
  272. #define RTC_SUBS_MASK_SS14_10 \
  273. ((uint32_t)0x0A000000) /*!< SS[14:10] are don't care in Alarm \
  274. comparison. Only SS[9:0] are compared */
  275. #define RTC_SUBS_MASK_SS14_11 \
  276. ((uint32_t)0x0B000000) /*!< SS[14:11] are don't care in Alarm \
  277. comparison. Only SS[10:0] are compared */
  278. #define RTC_SUBS_MASK_SS14_12 \
  279. ((uint32_t)0x0C000000) /*!< SS[14:12] are don't care in Alarm \
  280. comparison.Only SS[11:0] are compared */
  281. #define RTC_SUBS_MASK_SS14_13 \
  282. ((uint32_t)0x0D000000) /*!< SS[14:13] are don't care in Alarm \
  283. comparison. Only SS[12:0] are compared */
  284. #define RTC_SUBS_MASK_SS14_14 \
  285. ((uint32_t)0x0E000000) /*!< SS[14] is don't care in Alarm \
  286. comparison.Only SS[13:0] are compared */
  287. #define RTC_SUBS_MASK_NONE \
  288. ((uint32_t)0x0F000000) /*!< SS[14:0] are compared and must match \
  289. to activate alarm. */
  290. #define IS_RTC_ALARM_SUB_SECOND_MASK_MODE(INTEN) \
  291. (((INTEN) == RTC_SUBS_MASK_ALL) || ((INTEN) == RTC_SUBS_MASK_SS14_1) || ((INTEN) == RTC_SUBS_MASK_SS14_2) \
  292. || ((INTEN) == RTC_SUBS_MASK_SS14_3) || ((INTEN) == RTC_SUBS_MASK_SS14_4) || ((INTEN) == RTC_SUBS_MASK_SS14_5) \
  293. || ((INTEN) == RTC_SUBS_MASK_SS14_6) || ((INTEN) == RTC_SUBS_MASK_SS14_7) || ((INTEN) == RTC_SUBS_MASK_SS14_8) \
  294. || ((INTEN) == RTC_SUBS_MASK_SS14_9) || ((INTEN) == RTC_SUBS_MASK_SS14_10) || ((INTEN) == RTC_SUBS_MASK_SS14_11) \
  295. || ((INTEN) == RTC_SUBS_MASK_SS14_12) || ((INTEN) == RTC_SUBS_MASK_SS14_13) || ((INTEN) == RTC_SUBS_MASK_SS14_14) \
  296. || ((INTEN) == RTC_SUBS_MASK_NONE))
  297. /**
  298. * @}
  299. */
  300. /** @addtogroup RTC_Alarm_Sub_Seconds_Value
  301. * @{
  302. */
  303. #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFF)
  304. /**
  305. * @}
  306. */
  307. /** @addtogroup RTC_Wakeup_Timer_Definitions
  308. * @{
  309. */
  310. #define RTC_WKUPCLK_RTCCLK_DIV16 ((uint32_t)0x00000000)
  311. #define RTC_WKUPCLK_RTCCLK_DIV8 ((uint32_t)0x00000001)
  312. #define RTC_WKUPCLK_RTCCLK_DIV4 ((uint32_t)0x00000002)
  313. #define RTC_WKUPCLK_RTCCLK_DIV2 ((uint32_t)0x00000003)
  314. #define RTC_WKUPCLK_CK_SPRE_16BITS ((uint32_t)0x00000004)
  315. #define IS_RTC_WKUP_CLOCK(CLOCK) \
  316. (((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV16) || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV8) \
  317. || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV4) || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV2) \
  318. || ((CLOCK) == RTC_WKUPCLK_CK_SPRE_16BITS))
  319. #define IS_RTC_WKUP_COUNTER(COUNTER) ((COUNTER) <= 0xFFFF)
  320. /**
  321. * @}
  322. */
  323. /** @addtogroup RTC_Time_Stamp_Edges_definitions
  324. * @{
  325. */
  326. #define RTC_TIMESTAMP_EDGE_RISING ((uint32_t)0x00000000)
  327. #define RTC_TIMESTAMP_EDGE_FALLING ((uint32_t)0x00000008)
  328. #define IS_RTC_TIMESTAMP_EDGE_MODE(EDGE) \
  329. (((EDGE) == RTC_TIMESTAMP_EDGE_RISING) || ((EDGE) == RTC_TIMESTAMP_EDGE_FALLING))
  330. /**
  331. * @}
  332. */
  333. /** @addtogroup RTC_Output_selection_Definitions
  334. * @{
  335. */
  336. #define RTC_OUTPUT_DIS ((uint32_t)0x00000000)
  337. #define RTC_OUTPUT_ALA ((uint32_t)0x00200000)
  338. #define RTC_OUTPUT_ALB ((uint32_t)0x00400000)
  339. #define RTC_OUTPUT_WKUP ((uint32_t)0x00600000)
  340. #define IS_RTC_OUTPUT_MODE(OUTPUT) \
  341. (((OUTPUT) == RTC_OUTPUT_DIS) || ((OUTPUT) == RTC_OUTPUT_ALA) || ((OUTPUT) == RTC_OUTPUT_ALB) \
  342. || ((OUTPUT) == RTC_OUTPUT_WKUP))
  343. /**
  344. * @}
  345. */
  346. /** @addtogroup RTC_Output_Polarity_Definitions
  347. * @{
  348. */
  349. #define RTC_OUTPOL_HIGH ((uint32_t)0x00000000)
  350. #define RTC_OUTPOL_LOW ((uint32_t)0x00100000)
  351. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPOL_HIGH) || ((POL) == RTC_OUTPOL_LOW))
  352. /**
  353. * @}
  354. */
  355. /** @addtogroup RTC_Calib_Output_selection_Definitions
  356. * @{
  357. */
  358. #define RTC_CALIB_OUTPUT_256HZ ((uint32_t)0x00000000)
  359. #define RTC_CALIB_OUTPUT_1HZ ((uint32_t)0x00080000)
  360. #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CALIB_OUTPUT_256HZ) || ((OUTPUT) == RTC_CALIB_OUTPUT_1HZ))
  361. /**
  362. * @}
  363. */
  364. /** @addtogroup RTC_Smooth_calib_period_Definitions
  365. * @{
  366. */
  367. #define SMOOTH_CALIB_32SEC \
  368. ((uint32_t)0x00000000) /*!< if RTCCLK = 32768 Hz, Smooth calibation \
  369. period is 32s, else 2exp20 RTCCLK seconds */
  370. #define SMOOTH_CALIB_16SEC \
  371. ((uint32_t)0x00002000) /*!< if RTCCLK = 32768 Hz, Smooth calibation \
  372. period is 16s, else 2exp19 RTCCLK seconds */
  373. #define SMOOTH_CALIB_8SEC \
  374. ((uint32_t)0x00004000) /*!< if RTCCLK = 32768 Hz, Smooth calibation \
  375. period is 8s, else 2exp18 RTCCLK seconds */
  376. #define IS_RTC_SMOOTH_CALIB_PERIOD_SEL(PERIOD) \
  377. (((PERIOD) == SMOOTH_CALIB_32SEC) || ((PERIOD) == SMOOTH_CALIB_16SEC) || ((PERIOD) == SMOOTH_CALIB_8SEC))
  378. /**
  379. * @}
  380. */
  381. /** @addtogroup RTC_Smooth_calib_Plus_pulses_Definitions
  382. * @{
  383. */
  384. #define RTC_SMOOTH_CALIB_PLUS_PULSES_SET \
  385. ((uint32_t)0x00008000) /*!< The number of RTCCLK pulses added \
  386. during a X -second window = Y - CALM[8:0]. \
  387. with Y = 512, 256, 128 when X = 32, 16, 8 */
  388. #define RTC_SMOOTH_CALIB_PLUS_PULSES__RESET \
  389. ((uint32_t)0x00000000) /*!< The number of RTCCLK pulses subbstited \
  390. during a 32-second window = CALM[8:0]. */
  391. #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) \
  392. (((PLUS) == RTC_SMOOTH_CALIB_PLUS_PULSES_SET) || ((PLUS) == RTC_SMOOTH_CALIB_PLUS_PULSES__RESET))
  393. /**
  394. * @}
  395. */
  396. /** @addtogroup RTC_Smooth_calib_Minus_pulses_Definitions
  397. * @{
  398. */
  399. #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FF)
  400. /**
  401. * @}
  402. */
  403. /** @addtogroup RTC_DayLightSaving_Definitions
  404. * @{
  405. */
  406. #define RTC_DAYLIGHT_SAVING_SUB1H ((uint32_t)0x00020000)
  407. #define RTC_DAYLIGHT_SAVING_ADD1H ((uint32_t)0x00010000)
  408. #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHT_SAVING_SUB1H) || ((SAVE) == RTC_DAYLIGHT_SAVING_ADD1H))
  409. #define RTC_STORE_OPERATION_RESET ((uint32_t)0x00000000)
  410. #define RTC_STORE_OPERATION_SET ((uint32_t)0x00040000)
  411. #define IS_RTC_STORE_OPERATION(OPERATION) \
  412. (((OPERATION) == RTC_STORE_OPERATION_RESET) || ((OPERATION) == RTC_STORE_OPERATION_SET))
  413. /**
  414. * @}
  415. */
  416. /** @addtogroup RTC_Output_Type_ALARM_OUT
  417. * @{
  418. */
  419. #define RTC_OUTPUT_OPENDRAIN ((uint32_t)0x00000000)
  420. #define RTC_OUTPUT_PUSHPULL ((uint32_t)0x00000001)
  421. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_OPENDRAIN) || ((TYPE) == RTC_OUTPUT_PUSHPULL))
  422. /**
  423. * @}
  424. */
  425. /** @addtogroup RTC_Add_Fraction_Of_Second_Value
  426. * @{
  427. */
  428. #define RTC_SHIFT_SUB1S_DISABLE ((uint32_t)0x00000000)
  429. #define RTC_SHIFT_SUB1S_ENABLE ((uint32_t)0x80000000)
  430. #define IS_RTC_SHIFT_SUB1S(SEL) (((SEL) == RTC_SHIFT_SUB1S_DISABLE) || ((SEL) == RTC_SHIFT_SUB1S_ENABLE))
  431. /**
  432. * @}
  433. */
  434. /** @addtogroup RTC_Substract_1_Second_Parameter_Definitions
  435. * @{
  436. */
  437. #define IS_RTC_SHIFT_ADFS(FS) ((FS) <= 0x00007FFF)
  438. /**
  439. * @}
  440. */
  441. /** @addtogroup RTC_Input_parameter_format_definitions
  442. * @{
  443. */
  444. #define RTC_FORMAT_BIN ((uint32_t)0x000000000)
  445. #define RTC_FORMAT_BCD ((uint32_t)0x000000001)
  446. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
  447. /**
  448. * @}
  449. */
  450. /** @addtogroup RTC_Flags_Definitions
  451. * @{
  452. */
  453. #define RTC_FLAG_RECPF ((uint32_t)0x00010000)
  454. #define RTC_FLAG_TISOVF ((uint32_t)0x00001000)
  455. #define RTC_FLAG_TISF ((uint32_t)0x00000800)
  456. #define RTC_FLAG_WTF ((uint32_t)0x00000400)
  457. #define RTC_FLAG_ALBF ((uint32_t)0x00000200)
  458. #define RTC_FLAG_ALAF ((uint32_t)0x00000100)
  459. #define RTC_FLAG_INITF ((uint32_t)0x00000040)
  460. #define RTC_FLAG_RSYF ((uint32_t)0x00000020)
  461. #define RTC_FLAG_INITSF ((uint32_t)0x00000010)
  462. #define RTC_FLAG_SHOPF ((uint32_t)0x00000008)
  463. #define RTC_FLAG_WTWF ((uint32_t)0x00000004)
  464. #define RTC_FLAG_ALBWF ((uint32_t)0x00000002)
  465. #define RTC_FLAG_ALAWF ((uint32_t)0x00000001)
  466. #define IS_RTC_GET_FLAG(FLAG) \
  467. (((FLAG) == RTC_FLAG_TISOVF) || ((FLAG) == RTC_FLAG_TISF) || ((FLAG) == RTC_FLAG_WTF) || ((FLAG) == RTC_FLAG_ALBF) \
  468. || ((FLAG) == RTC_FLAG_ALAF) || ((FLAG) == RTC_FLAG_INITF) || ((FLAG) == RTC_FLAG_RSYF) \
  469. || ((FLAG) == RTC_FLAG_WTWF) || ((FLAG) == RTC_FLAG_ALBWF) || ((FLAG) == RTC_FLAG_ALAWF) \
  470. || ((FLAG) == RTC_FLAG_RECPF) || ((FLAG) == RTC_FLAG_SHOPF) || ((FLAG) == RTC_FLAG_INITSF))
  471. #define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG)&0x00011fff) == (uint32_t)SET))
  472. /**
  473. * @}
  474. */
  475. /** @addtogroup RTC_Interrupts_Definitions
  476. * @{
  477. */
  478. #define RTC_INT_WUT ((uint32_t)0x00004000)
  479. #define RTC_INT_ALRB ((uint32_t)0x00002000)
  480. #define RTC_INT_ALRA ((uint32_t)0x00001000)
  481. #define IS_RTC_CONFIG_INT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0xFFFF0FFB) == (uint32_t)RESET))
  482. #define IS_RTC_GET_INT(IT) \
  483. (((IT) == RTC_INT_WUT) || ((IT) == RTC_INT_ALRB) || ((IT) == RTC_INT_ALRA))
  484. #define IS_RTC_CLEAR_INT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0x00007000) == (uint32_t)SET))
  485. /**
  486. * @}
  487. */
  488. /** @addtogroup RTC_Legacy
  489. * @{
  490. */
  491. #define RTC_DigitalCalibConfig RTC_CoarseCalibConfig
  492. #define RTC_DigitalCalibCmd RTC_CoarseCalibCmd
  493. /**
  494. * @}
  495. */
  496. /**
  497. * @}
  498. */
  499. /* Function used to set the RTC configuration to the default reset state *****/
  500. ErrorStatus RTC_DeInit(void);
  501. /* Initialization and Configuration functions *********************************/
  502. ErrorStatus RTC_Init(RTC_InitType* RTC_InitStruct);
  503. void RTC_StructInit(RTC_InitType* RTC_InitStruct);
  504. void RTC_EnableWriteProtection(FunctionalState Cmd);
  505. ErrorStatus RTC_EnterInitMode(void);
  506. void RTC_ExitInitMode(void);
  507. ErrorStatus RTC_WaitForSynchro(void);
  508. ErrorStatus RTC_EnableRefClock(FunctionalState Cmd);
  509. void RTC_EnableBypassShadow(FunctionalState Cmd);
  510. /* Time and Date configuration functions **************************************/
  511. ErrorStatus RTC_ConfigTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct);
  512. void RTC_TimeStructInit(RTC_TimeType* RTC_TimeStruct);
  513. void RTC_GetTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct);
  514. uint32_t RTC_GetSubSecond(void);
  515. ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct);
  516. void RTC_DateStructInit(RTC_DateType* RTC_DateStruct);
  517. void RTC_GetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct);
  518. /* Alarms (Alarm A and Alarm B) configuration functions **********************/
  519. void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct);
  520. void RTC_AlarmStructInit(RTC_AlarmType* RTC_AlarmStruct);
  521. void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct);
  522. ErrorStatus RTC_EnableAlarm(uint32_t RTC_Alarm, FunctionalState Cmd);
  523. void RTC_ConfigAlarmSubSecond(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask);
  524. uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm);
  525. /* WakeUp Timer configuration functions ***************************************/
  526. void RTC_ConfigWakeUpClock(uint32_t RTC_WakeUpClock);
  527. void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter);
  528. uint32_t RTC_GetWakeUpCounter(void);
  529. ErrorStatus RTC_EnableWakeUp(FunctionalState Cmd);
  530. /* Daylight Saving configuration functions ************************************/
  531. void RTC_ConfigDayLightSaving(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation);
  532. uint32_t RTC_GetStoreOperation(void);
  533. /* Output pin Configuration function ******************************************/
  534. void RTC_ConfigOutput(uint32_t RTC_Output, uint32_t RTC_OutputPolarity);
  535. /* Coarse and Smooth Calibration configuration functions **********************/
  536. void RTC_EnableCalibOutput(FunctionalState Cmd);
  537. void RTC_ConfigCalibOutput(uint32_t RTC_CalibOutput);
  538. ErrorStatus RTC_ConfigSmoothCalib(uint32_t RTC_SmoothCalibPeriod,
  539. uint32_t RTC_SmoothCalibPlusPulses,
  540. uint32_t RTC_SmouthCalibMinusPulsesValue);
  541. /* TimeStamp configuration functions ******************************************/
  542. void RTC_EnableTimeStamp(uint32_t RTC_TimeStampEdge, FunctionalState Cmd);
  543. void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeType* RTC_StampTimeStruct, RTC_DateType* RTC_StampDateStruct);
  544. uint32_t RTC_GetTimeStampSubSecond(void);
  545. /* Output Type Config configuration functions *********************************/
  546. void RTC_ConfigOutputType(uint32_t RTC_OutputType);
  547. /* RTC_Shift_control_synchonisation_functions *********************************/
  548. ErrorStatus RTC_ConfigSynchroShift(uint32_t RTC_ShiftAddFS, uint32_t RTC_ShiftSub1s);
  549. /* Interrupts and flags management functions **********************************/
  550. void RTC_ConfigInt(uint32_t RTC_INT, FunctionalState Cmd);
  551. FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG);
  552. void RTC_ClrFlag(uint32_t RTC_FLAG);
  553. INTStatus RTC_GetITStatus(uint32_t RTC_INT);
  554. void RTC_ClrIntPendingBit(uint32_t RTC_INT);
  555. /* WakeUp TSC function **********************************/
  556. void RTC_EnableWakeUpTsc(uint32_t count);
  557. #ifdef __cplusplus
  558. }
  559. #endif
  560. #endif /*__N32G45X_RTC_H__ */
  561. /**
  562. * @}
  563. */
  564. /**
  565. * @}
  566. */