1
0

at32f425_ertc.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. /**
  2. **************************************************************************
  3. * @file at32f425_ertc.h
  4. * @brief at32f425 ertc header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /* Define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F425_ERTC_H
  26. #define __AT32F425_ERTC_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "at32f425.h"
  32. /** @addtogroup AT32F425_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup ERTC
  36. * @{
  37. */
  38. /** @defgroup ERTC_interrupts_definition
  39. * @brief ertc interrupt
  40. * @{
  41. */
  42. #define ERTC_TP_INT ((uint32_t)0x00000004) /*!< ertc tamper interrupt */
  43. #define ERTC_ALA_INT ((uint32_t)0x00001000) /*!< ertc alarm a interrupt */
  44. #define ERTC_WAT_INT ((uint32_t)0x00004000) /*!< ertc wakeup timer interrupt */
  45. #define ERTC_TS_INT ((uint32_t)0x00008000) /*!< ertc timestamp interrupt */
  46. /**
  47. * @}
  48. */
  49. /** @defgroup ERTC_flags_definition
  50. * @brief ertc flag
  51. * @{
  52. */
  53. #define ERTC_ALAWF_FLAG ((uint32_t)0x00000001) /*!< ertc alarm a register allows write flag */
  54. #define ERTC_WATWF_FLAG ((uint32_t)0x00000004) /*!< ertc wakeup timer register allows write flag */
  55. #define ERTC_TADJF_FLAG ((uint32_t)0x00000008) /*!< ertc time adjustment flag */
  56. #define ERTC_INITF_FLAG ((uint32_t)0x00000010) /*!< ertc calendar initialization flag */
  57. #define ERTC_UPDF_FLAG ((uint32_t)0x00000020) /*!< ertc calendar update flag */
  58. #define ERTC_IMF_FLAG ((uint32_t)0x00000040) /*!< ertc enter initialization mode flag */
  59. #define ERTC_ALAF_FLAG ((uint32_t)0x00000100) /*!< ertc alarm clock a flag */
  60. #define ERTC_WATF_FLAG ((uint32_t)0x00000400) /*!< ertc wakeup timer flag */
  61. #define ERTC_TSF_FLAG ((uint32_t)0x00000800) /*!< ertc timestamp flag */
  62. #define ERTC_TSOF_FLAG ((uint32_t)0x00001000) /*!< ertc timestamp overflow flag */
  63. #define ERTC_TP1F_FLAG ((uint32_t)0x00002000) /*!< ertc tamper detection 1 flag */
  64. #define ERTC_CALUPDF_FLAG ((uint32_t)0x00010000) /*!< ertc calibration value update completed flag */
  65. /**
  66. * @brief ertc alarm mask
  67. */
  68. #define ERTC_ALARM_MASK_NONE ((uint32_t)0x00000000) /*!< ertc alarm match all */
  69. #define ERTC_ALARM_MASK_SEC ((uint32_t)0x00000080) /*!< ertc alarm don't match seconds */
  70. #define ERTC_ALARM_MASK_MIN ((uint32_t)0x00008000) /*!< ertc alarm don't match minute */
  71. #define ERTC_ALARM_MASK_HOUR ((uint32_t)0x00800000) /*!< ertc alarm don't match hour */
  72. #define ERTC_ALARM_MASK_DATE_WEEK ((uint32_t)0x80000000) /*!< ertc alarm don't match date or week */
  73. #define ERTC_ALARM_MASK_ALL ((uint32_t)0x80808080) /*!< ertc alarm don't match all */
  74. /**
  75. * @}
  76. */
  77. /**
  78. * @brief compatible with older versions
  79. */
  80. #define ERTC_WAT_CLK_CK_A_16BITS ERTC_WAT_CLK_CK_B_16BITS
  81. #define ERTC_WAT_CLK_CK_A_17BITS ERTC_WAT_CLK_CK_B_17BITS
  82. /**
  83. * @}
  84. */
  85. /** @defgroup ERTC_exported_types
  86. * @{
  87. */
  88. /**
  89. * @brief ertc hour mode
  90. */
  91. typedef enum
  92. {
  93. ERTC_HOUR_MODE_24 = 0x00, /*!< 24-hour format */
  94. ERTC_HOUR_MODE_12 = 0x01 /*!< 12-hour format */
  95. } ertc_hour_mode_set_type;
  96. /**
  97. * @brief ertc 12-hour format am/pm
  98. */
  99. typedef enum
  100. {
  101. ERTC_24H = 0x00, /*!< 24-hour format */
  102. ERTC_AM = 0x00, /*!< 12-hour format, ante meridiem */
  103. ERTC_PM = 0x01 /*!< 12-hour format, meridiem */
  104. } ertc_am_pm_type;
  105. /**
  106. * @brief ertc week or date select
  107. */
  108. typedef enum
  109. {
  110. ERTC_SLECT_DATE = 0x00, /*!< slect date mode */
  111. ERTC_SLECT_WEEK = 0x01 /*!< slect week mode */
  112. } ertc_week_date_select_type;
  113. /**
  114. * @brief ertc alarm x select
  115. */
  116. typedef enum
  117. {
  118. ERTC_ALA = 0x00, /*!< select alarm a */
  119. } ertc_alarm_type;
  120. /**
  121. * @brief ertc alarm sub second mask
  122. */
  123. typedef enum
  124. {
  125. ERTC_ALARM_SBS_MASK_ALL = 0x00, /*!< do not match the sub-second */
  126. ERTC_ALARM_SBS_MASK_14_1 = 0x01, /*!< only compare bit [0] */
  127. ERTC_ALARM_SBS_MASK_14_2 = 0x02, /*!< only compare bit [1:0] */
  128. ERTC_ALARM_SBS_MASK_14_3 = 0x03, /*!< only compare bit [2:0] */
  129. ERTC_ALARM_SBS_MASK_14_4 = 0x04, /*!< only compare bit [3:0] */
  130. ERTC_ALARM_SBS_MASK_14_5 = 0x05, /*!< only compare bit [4:0] */
  131. ERTC_ALARM_SBS_MASK_14_6 = 0x06, /*!< only compare bit [5:0] */
  132. ERTC_ALARM_SBS_MASK_14_7 = 0x07, /*!< only compare bit [6:0] */
  133. ERTC_ALARM_SBS_MASK_14_8 = 0x08, /*!< only compare bit [7:0] */
  134. ERTC_ALARM_SBS_MASK_14_9 = 0x09, /*!< only compare bit [8:0] */
  135. ERTC_ALARM_SBS_MASK_14_10 = 0x0A, /*!< only compare bit [9:0] */
  136. ERTC_ALARM_SBS_MASK_14_11 = 0x0B, /*!< only compare bit [10:0] */
  137. ERTC_ALARM_SBS_MASK_14_12 = 0x0C, /*!< only compare bit [11:0] */
  138. ERTC_ALARM_SBS_MASK_14_13 = 0x0D, /*!< only compare bit [12:0] */
  139. ERTC_ALARM_SBS_MASK_14 = 0x0E, /*!< only compare bit [13:0] */
  140. ERTC_ALARM_SBS_MASK_NONE = 0x0F /*!< compare bit [14:0] */
  141. } ertc_alarm_sbs_mask_type;
  142. /**
  143. * @brief ertc wakeup timer clock select
  144. */
  145. typedef enum
  146. {
  147. ERTC_WAT_CLK_ERTCCLK_DIV16 = 0x00, /*!< the wake up timer clock is ERTC_CLK / 16 */
  148. ERTC_WAT_CLK_ERTCCLK_DIV8 = 0x01, /*!< the wake up timer clock is ERTC_CLK / 8 */
  149. ERTC_WAT_CLK_ERTCCLK_DIV4 = 0x02, /*!< the wake up timer clock is ERTC_CLK / 4 */
  150. ERTC_WAT_CLK_ERTCCLK_DIV2 = 0x03, /*!< the wake up timer clock is ERTC_CLK / 2 */
  151. ERTC_WAT_CLK_CK_B_16BITS = 0x04, /*!< the wake up timer clock is CK_B, wakeup counter = ERTC_WAT */
  152. ERTC_WAT_CLK_CK_B_17BITS = 0x06 /*!< the wake up timer clock is CK_B, wakeup counter = ERTC_WAT + 65535 */
  153. } ertc_wakeup_clock_type;
  154. /**
  155. * @brief ertc smooth calibration period
  156. */
  157. typedef enum
  158. {
  159. ERTC_SMOOTH_CAL_PERIOD_32 = 0x00, /*!< 32 second calibration period */
  160. ERTC_SMOOTH_CAL_PERIOD_16 = 0x01, /*!< 16 second calibration period */
  161. ERTC_SMOOTH_CAL_PERIOD_8 = 0x02 /*!< 8 second calibration period */
  162. } ertc_smooth_cal_period_type;
  163. /**
  164. * @brief ertc smooth calibration clock add mode
  165. */
  166. typedef enum
  167. {
  168. ERTC_SMOOTH_CAL_CLK_ADD_0 = 0x00, /*!< do not increase clock */
  169. ERTC_SMOOTH_CAL_CLK_ADD_512 = 0x01 /*!< add 512 clocks */
  170. } ertc_smooth_cal_clk_add_type;
  171. /**
  172. * @brief ertc calibration output mode
  173. */
  174. typedef enum
  175. {
  176. ERTC_CAL_OUTPUT_512HZ = 0x00, /*!< output 512 hz */
  177. ERTC_CAL_OUTPUT_1HZ = 0x01 /*!< output 1 hz */
  178. } ertc_cal_output_select_type;
  179. /**
  180. * @brief time adjust add mode
  181. */
  182. typedef enum
  183. {
  184. ERTC_TIME_ADD_NONE = 0x00, /*!< none operation */
  185. ERTC_TIME_ADD_1S = 0x01 /*!< add 1 second */
  186. } ertc_time_adjust_type;
  187. /**
  188. * @brief ertc daylight saving time hour adjustment mode
  189. */
  190. typedef enum
  191. {
  192. ERTC_DST_ADD_1H = 0x00, /*!< add 1 hour */
  193. ERTC_DST_DEC_1H = 0x01 /*!< dec 1 hour */
  194. } ertc_dst_operation_type;
  195. /**
  196. * @brief ertc daylight saving time store operation mode
  197. */
  198. typedef enum
  199. {
  200. ERTC_DST_SAVE_0 = 0x00, /*!< set the bpr register value to 0 */
  201. ERTC_DST_SAVE_1 = 0x01 /*!< set the bpr register value to 1 */
  202. } ertc_dst_save_type;
  203. /**
  204. * @brief output source
  205. */
  206. typedef enum
  207. {
  208. ERTC_OUTPUT_DISABLE = 0x00, /*!< diable output */
  209. ERTC_OUTPUT_ALARM_A = 0x01, /*!< output alarm a event */
  210. ERTC_OUTPUT_WAKEUP = 0x03 /*!< output wakeup event */
  211. } ertc_output_source_type;
  212. /**
  213. * @brief output polarity
  214. */
  215. typedef enum
  216. {
  217. ERTC_OUTPUT_POLARITY_HIGH = 0x00, /*!< when the event occurs, the output is high */
  218. ERTC_OUTPUT_POLARITY_LOW = 0x01 /*!< when the event occurs, the output is low */
  219. } ertc_output_polarity_type;
  220. /**
  221. * @brief output type
  222. */
  223. typedef enum
  224. {
  225. ERTC_OUTPUT_TYPE_OPEN_DRAIN = 0x00, /*!< open drain output */
  226. ERTC_OUTPUT_TYPE_PUSH_PULL = 0x01 /*!< push pull output */
  227. } ertc_output_type;
  228. /**
  229. * @brief ertc timestamp valid edge
  230. */
  231. typedef enum
  232. {
  233. ERTC_TIMESTAMP_EDGE_RISING = 0x00, /*!< rising edge trigger */
  234. ERTC_TIMESTAMP_EDGE_FALLING = 0x01 /*!< falling edge trigger */
  235. } ertc_timestamp_valid_edge_type;
  236. /**
  237. * @brief ertc tamper x select
  238. */
  239. typedef enum
  240. {
  241. ERTC_TAMPER_1 = 0x00, /*!< tamper 1 */
  242. } ertc_tamper_select_type;
  243. /**
  244. * @brief tamper detection pre-charge time
  245. */
  246. typedef enum
  247. {
  248. ERTC_TAMPER_PR_1_ERTCCLK = 0x00, /*!< pre-charge time is 1 ERTC_CLK */
  249. ERTC_TAMPER_PR_2_ERTCCLK = 0x01, /*!< pre-charge time is 2 ERTC_CLK */
  250. ERTC_TAMPER_PR_4_ERTCCLK = 0x02, /*!< pre-charge time is 4 ERTC_CLK */
  251. ERTC_TAMPER_PR_8_ERTCCLK = 0x03 /*!< pre-charge time is 8 ERTC_CLK */
  252. } ertc_tamper_precharge_type;
  253. /**
  254. * @brief ertc tamper filter
  255. */
  256. typedef enum
  257. {
  258. ERTC_TAMPER_FILTER_DISABLE = 0x00, /*!< disable filter function */
  259. ERTC_TAMPER_FILTER_2 = 0x01, /*!< 2 consecutive samples arw valid, effective tamper event */
  260. ERTC_TAMPER_FILTER_4 = 0x02, /*!< 4 consecutive samples arw valid, effective tamper event */
  261. ERTC_TAMPER_FILTER_8 = 0x03 /*!< 8 consecutive samples arw valid, effective tamper event */
  262. } ertc_tamper_filter_type;
  263. /**
  264. * @brief ertc tamper detection frequency
  265. */
  266. typedef enum
  267. {
  268. ERTC_TAMPER_FREQ_DIV_32768 = 0x00, /*!< ERTC_CLK / 32768 */
  269. ERTC_TAMPER_FREQ_DIV_16384 = 0x01, /*!< ERTC_CLK / 16384 */
  270. ERTC_TAMPER_FREQ_DIV_8192 = 0x02, /*!< ERTC_CLK / 8192 */
  271. ERTC_TAMPER_FREQ_DIV_4096 = 0x03, /*!< ERTC_CLK / 4096 */
  272. ERTC_TAMPER_FREQ_DIV_2048 = 0x04, /*!< ERTC_CLK / 2048 */
  273. ERTC_TAMPER_FREQ_DIV_1024 = 0x05, /*!< ERTC_CLK / 1024 */
  274. ERTC_TAMPER_FREQ_DIV_512 = 0x06, /*!< ERTC_CLK / 512 */
  275. ERTC_TAMPER_FREQ_DIV_256 = 0x07 /*!< ERTC_CLK / 256 */
  276. } ertc_tamper_detect_freq_type;
  277. /**
  278. * @brief ertc tamper valid edge
  279. */
  280. typedef enum
  281. {
  282. ERTC_TAMPER_EDGE_RISING = 0x00, /*!< rising gedge */
  283. ERTC_TAMPER_EDGE_FALLING = 0x01, /*!< falling gedge */
  284. ERTC_TAMPER_EDGE_LOW = 0x00, /*!< low level */
  285. ERTC_TAMPER_EDGE_HIGH = 0x01 /*!< high level */
  286. } ertc_tamper_valid_edge_type;
  287. /**
  288. * @brief ertc bpr register
  289. */
  290. typedef enum
  291. {
  292. ERTC_DT1 = 0, /*!< bpr data register 0 */
  293. ERTC_DT2 = 1, /*!< bpr data register 1 */
  294. ERTC_DT3 = 2, /*!< bpr data register 2 */
  295. ERTC_DT4 = 3, /*!< bpr data register 3 */
  296. ERTC_DT5 = 4, /*!< bpr data register 4 */
  297. } ertc_dt_type;
  298. /**
  299. * @brief ertc time
  300. */
  301. typedef struct
  302. {
  303. uint8_t year; /*!< year */
  304. uint8_t month; /*!< month */
  305. uint8_t day; /*!< date */
  306. uint8_t hour; /*!< hour */
  307. uint8_t min; /*!< minute */
  308. uint8_t sec; /*!< second */
  309. uint8_t week; /*!< week */
  310. ertc_am_pm_type ampm; /*!< ante meridiem / post meridiem */
  311. } ertc_time_type;
  312. /**
  313. * @brief ertc alarm
  314. */
  315. typedef struct
  316. {
  317. uint8_t day; /*!< date */
  318. uint8_t hour; /*!< hour */
  319. uint8_t min; /*!< minute */
  320. uint8_t sec; /*!< second */
  321. ertc_am_pm_type ampm; /*!< ante meridiem / post meridiem */
  322. uint32_t mask; /*!< alarm mask*/
  323. uint8_t week_date_sel; /*!< week or date mode */
  324. uint8_t week; /*!< week */
  325. } ertc_alarm_value_type;
  326. /**
  327. * @brief ertc time reg union
  328. */
  329. typedef union
  330. {
  331. __IO uint32_t time;
  332. struct
  333. {
  334. __IO uint32_t s : 7; /* [6:0] */
  335. __IO uint32_t reserved1 : 1; /* [7] */
  336. __IO uint32_t m : 7; /* [14:8] */
  337. __IO uint32_t reserved2 : 1; /* [15] */
  338. __IO uint32_t h : 6; /* [21:16] */
  339. __IO uint32_t ampm : 1; /* [22] */
  340. __IO uint32_t reserved3 : 9; /* [31:23] */
  341. } time_bit;
  342. } ertc_reg_time_type;
  343. /**
  344. * @brief ertc date reg union
  345. */
  346. typedef union
  347. {
  348. __IO uint32_t date;
  349. struct
  350. {
  351. __IO uint32_t d :6; /* [5:0] */
  352. __IO uint32_t reserved1 :2; /* [7:6] */
  353. __IO uint32_t m :5; /* [12:8] */
  354. __IO uint32_t wk :3; /* [15:13] */
  355. __IO uint32_t y :8; /* [23:16] */
  356. __IO uint32_t reserved2 :8; /* [31:24] */
  357. } date_bit;
  358. } ertc_reg_date_type;
  359. /**
  360. * @brief ertc alarm reg union
  361. */
  362. typedef union
  363. {
  364. __IO uint32_t ala;
  365. struct
  366. {
  367. __IO uint32_t s :7; /* [6:0] */
  368. __IO uint32_t mask1 :1; /* [7] */
  369. __IO uint32_t m :7; /* [14:8] */
  370. __IO uint32_t mask2 :1; /* [15] */
  371. __IO uint32_t h :6; /* [21:16] */
  372. __IO uint32_t ampm :1; /* [22] */
  373. __IO uint32_t mask3 :1; /* [23] */
  374. __IO uint32_t d :6; /* [29:24] */
  375. __IO uint32_t wksel :1; /* [30] */
  376. __IO uint32_t mask4 :1; /* [31] */
  377. } ala_bit;
  378. } ertc_reg_alarm_type;
  379. /**
  380. * @brief ertc scal reg union
  381. */
  382. typedef union
  383. {
  384. __IO uint32_t scal;
  385. struct
  386. {
  387. __IO uint32_t dec :9; /* [8:0] */
  388. __IO uint32_t reserved1 :4; /* [12:9] */
  389. __IO uint32_t cal16 :1; /* [13] */
  390. __IO uint32_t cal8 :1; /* [14] */
  391. __IO uint32_t add :1; /* [15] */
  392. __IO uint32_t reserved2 :16;/* [31:16] */
  393. } scal_bit;
  394. } ertc_reg_scal_type;
  395. /**
  396. * @brief ertc tadj reg union
  397. */
  398. typedef union
  399. {
  400. __IO uint32_t tadj;
  401. struct
  402. {
  403. __IO uint32_t decsbs :15;/* [14:0] */
  404. __IO uint32_t reserved1 :16;/* [30:15] */
  405. __IO uint32_t add1s :1; /* [31] */
  406. } tadj_bit;
  407. } ertc_reg_tadj_type;
  408. /**
  409. * @brief ertc tstm reg union
  410. */
  411. typedef union
  412. {
  413. __IO uint32_t tstm;
  414. struct
  415. {
  416. __IO uint32_t s :7; /* [6:0] */
  417. __IO uint32_t reserved1 :1; /* [7] */
  418. __IO uint32_t m :7; /* [14:8] */
  419. __IO uint32_t reserved2 :1; /* [15] */
  420. __IO uint32_t h :6; /* [21:16] */
  421. __IO uint32_t ampm :1; /* [22] */
  422. __IO uint32_t reserved3 :9; /* [31:23] */
  423. } tstm_bit;
  424. } ertc_reg_tstm_type;
  425. /**
  426. * @brief ertc tsdt register, offset:0x34
  427. */
  428. typedef union
  429. {
  430. __IO uint32_t tsdt;
  431. struct
  432. {
  433. __IO uint32_t d :6; /* [5:0] */
  434. __IO uint32_t reserved1 :2; /* [7:6] */
  435. __IO uint32_t m :5; /* [12:8] */
  436. __IO uint32_t wk :3; /* [15:13] */
  437. __IO uint32_t reserved2 :16;/* [31:16] */
  438. } tsdt_bit;
  439. } ertc_reg_tsdt_type;
  440. /**
  441. * @brief type define ertc register all
  442. */
  443. typedef struct
  444. {
  445. /**
  446. * @brief ertc time register, offset:0x00
  447. */
  448. union
  449. {
  450. __IO uint32_t time;
  451. struct
  452. {
  453. __IO uint32_t s : 7; /* [6:0] */
  454. __IO uint32_t reserved1 : 1; /* [7] */
  455. __IO uint32_t m : 7; /* [14:8] */
  456. __IO uint32_t reserved2 : 1; /* [15] */
  457. __IO uint32_t h : 6; /* [21:16] */
  458. __IO uint32_t ampm : 1; /* [22] */
  459. __IO uint32_t reserved3 : 9; /* [31:23] */
  460. } time_bit;
  461. };
  462. /**
  463. * @brief ertc date register, offset:0x04
  464. */
  465. union
  466. {
  467. __IO uint32_t date;
  468. struct
  469. {
  470. __IO uint32_t d :6; /* [5:0] */
  471. __IO uint32_t reserved1 :2; /* [7:6] */
  472. __IO uint32_t m :5; /* [12:8] */
  473. __IO uint32_t wk :3; /* [15:13] */
  474. __IO uint32_t y :8; /* [23:16] */
  475. __IO uint32_t reserved2 :8; /* [31:24] */
  476. } date_bit;
  477. };
  478. /**
  479. * @brief ertc ctrl register, offset:0x08
  480. */
  481. union
  482. {
  483. __IO uint32_t ctrl;
  484. struct
  485. {
  486. __IO uint32_t watclk :3; /* [2:0] */
  487. __IO uint32_t tsedg :1; /* [3] */
  488. __IO uint32_t rcden :1; /* [4] */
  489. __IO uint32_t dren :1; /* [5] */
  490. __IO uint32_t hm :1; /* [6] */
  491. __IO uint32_t reserved1 :1; /* [7] */
  492. __IO uint32_t alaen :1; /* [8] */
  493. __IO uint32_t reserved2 :1; /* [9] */
  494. __IO uint32_t waten :1; /* [10] */
  495. __IO uint32_t tsen :1; /* [11] */
  496. __IO uint32_t alaien :1; /* [12] */
  497. __IO uint32_t reserved3 :1; /* [13] */
  498. __IO uint32_t watien :1; /* [14] */
  499. __IO uint32_t tsien :1; /* [15] */
  500. __IO uint32_t add1h :1; /* [16] */
  501. __IO uint32_t dec1h :1; /* [17] */
  502. __IO uint32_t bpr :1; /* [18] */
  503. __IO uint32_t calosel :1; /* [19] */
  504. __IO uint32_t outp :1; /* [20] */
  505. __IO uint32_t outsel :2; /* [22:21] */
  506. __IO uint32_t caloen :1; /* [23] */
  507. __IO uint32_t reserved4 :8; /* [31:24] */
  508. } ctrl_bit;
  509. };
  510. /**
  511. * @brief ertc sts register, offset:0x0C
  512. */
  513. union
  514. {
  515. __IO uint32_t sts;
  516. struct
  517. {
  518. __IO uint32_t alawf :1; /* [0] */
  519. __IO uint32_t reserved1 :1; /* [1] */
  520. __IO uint32_t watwf :1; /* [2] */
  521. __IO uint32_t tadjf :1; /* [3] */
  522. __IO uint32_t initf :1; /* [4] */
  523. __IO uint32_t updf :1; /* [5] */
  524. __IO uint32_t imf :1; /* [6] */
  525. __IO uint32_t imen :1; /* [7] */
  526. __IO uint32_t alaf :1; /* [8] */
  527. __IO uint32_t reserved2 :1; /* [9] */
  528. __IO uint32_t watf :1; /* [10] */
  529. __IO uint32_t tsf :1; /* [11] */
  530. __IO uint32_t tsof :1; /* [12] */
  531. __IO uint32_t tp1f :1; /* [13] */
  532. __IO uint32_t reserved3 :1; /* [14] */
  533. __IO uint32_t reserved4 :1; /* [15] */
  534. __IO uint32_t calupdf :1; /* [16] */
  535. __IO uint32_t reserved5 :15;/* [31:17] */
  536. } sts_bit;
  537. };
  538. /**
  539. * @brief ertc div register, offset:0x10
  540. */
  541. union
  542. {
  543. __IO uint32_t div;
  544. struct
  545. {
  546. __IO uint32_t divb :15;/* [14:0] */
  547. __IO uint32_t reserved1 :1; /* [15] */
  548. __IO uint32_t diva :7; /* [22:16] */
  549. __IO uint32_t reserved2 :9; /* [31:23] */
  550. } div_bit;
  551. };
  552. /**
  553. * @brief ertc wat register, offset:0x14
  554. */
  555. union
  556. {
  557. __IO uint32_t wat;
  558. struct
  559. {
  560. __IO uint32_t val :16;/* [15:0] */
  561. __IO uint32_t reserved1 :16;/* [31:16] */
  562. } wat_bit;
  563. };
  564. /**
  565. * @brief ertc reserved register, offset:0x18
  566. */
  567. __IO uint32_t reserved1;
  568. /**
  569. * @brief ertc ala register, offset:0x1C
  570. */
  571. union
  572. {
  573. __IO uint32_t ala;
  574. struct
  575. {
  576. __IO uint32_t s :7; /* [6:0] */
  577. __IO uint32_t mask1 :1; /* [7] */
  578. __IO uint32_t m :7; /* [14:8] */
  579. __IO uint32_t mask2 :1; /* [15] */
  580. __IO uint32_t h :6; /* [21:16] */
  581. __IO uint32_t ampm :1; /* [22] */
  582. __IO uint32_t mask3 :1; /* [23] */
  583. __IO uint32_t d :6; /* [29:24] */
  584. __IO uint32_t wksel :1; /* [30] */
  585. __IO uint32_t mask4 :1; /* [31] */
  586. } ala_bit;
  587. };
  588. /**
  589. * @brief ertc reserved register, offset:0x20
  590. */
  591. __IO uint32_t reserved2;
  592. /**
  593. * @brief ertc wp register, offset:0x24
  594. */
  595. union
  596. {
  597. __IO uint32_t wp;
  598. struct
  599. {
  600. __IO uint32_t cmd :8; /* [7:0] */
  601. __IO uint32_t reserved1 :24;/* [31:8] */
  602. } wp_bit;
  603. };
  604. /**
  605. * @brief ertc sbs register, offset:0x28
  606. */
  607. union
  608. {
  609. __IO uint32_t sbs;
  610. struct
  611. {
  612. __IO uint32_t sbs :16;/* [15:0] */
  613. __IO uint32_t reserved1 :16;/* [31:16] */
  614. } sbs_bit;
  615. };
  616. /**
  617. * @brief ertc tadj register, offset:0x2C
  618. */
  619. union
  620. {
  621. __IO uint32_t tadj;
  622. struct
  623. {
  624. __IO uint32_t decsbs :15;/* [14:0] */
  625. __IO uint32_t reserved1 :16;/* [30:15] */
  626. __IO uint32_t add1s :1; /* [31] */
  627. } tadj_bit;
  628. };
  629. /**
  630. * @brief ertc tstm register, offset:0x30
  631. */
  632. union
  633. {
  634. __IO uint32_t tstm;
  635. struct
  636. {
  637. __IO uint32_t s :7; /* [6:0] */
  638. __IO uint32_t reserved1 :1; /* [7] */
  639. __IO uint32_t m :7; /* [14:8] */
  640. __IO uint32_t reserved2 :1; /* [15] */
  641. __IO uint32_t h :6; /* [21:16] */
  642. __IO uint32_t ampm :1; /* [22] */
  643. __IO uint32_t reserved3 :9; /* [31:23] */
  644. } tstm_bit;
  645. };
  646. /**
  647. * @brief ertc tsdt register, offset:0x34
  648. */
  649. union
  650. {
  651. __IO uint32_t tsdt;
  652. struct
  653. {
  654. __IO uint32_t d :6; /* [5:0] */
  655. __IO uint32_t reserved1 :2; /* [7:6] */
  656. __IO uint32_t m :5; /* [12:8] */
  657. __IO uint32_t wk :3; /* [15:13] */
  658. __IO uint32_t reserved2 :16;/* [31:16] */
  659. } tsdt_bit;
  660. };
  661. /**
  662. * @brief ertc tssbs register, offset:0x38
  663. */
  664. union
  665. {
  666. __IO uint32_t tssbs;
  667. struct
  668. {
  669. __IO uint32_t sbs :16;/* [15:0] */
  670. __IO uint32_t reserved1 :16;/* [31:16] */
  671. } tssbs_bit;
  672. };
  673. /**
  674. * @brief ertc scal register, offset:0x3C
  675. */
  676. union
  677. {
  678. __IO uint32_t scal;
  679. struct
  680. {
  681. __IO uint32_t dec :9; /* [8:0] */
  682. __IO uint32_t reserved1 :4; /* [12:9] */
  683. __IO uint32_t cal16 :1; /* [13] */
  684. __IO uint32_t cal8 :1; /* [14] */
  685. __IO uint32_t add :1; /* [15] */
  686. __IO uint32_t reserved2 :16;/* [31:16] */
  687. } scal_bit;
  688. };
  689. /**
  690. * @brief ertc tamp register, offset:0x40
  691. */
  692. union
  693. {
  694. __IO uint32_t tamp;
  695. struct
  696. {
  697. __IO uint32_t tp1en :1; /* [0] */
  698. __IO uint32_t tp1edg :1; /* [1] */
  699. __IO uint32_t tpien :1; /* [2] */
  700. __IO uint32_t reserved1 :1; /* [3] */
  701. __IO uint32_t reserved2 :1; /* [4] */
  702. __IO uint32_t reserved3 :2; /* [6:5] */
  703. __IO uint32_t tptsen :1; /* [7] */
  704. __IO uint32_t tpfreq :3; /* [10:8] */
  705. __IO uint32_t tpflt :2; /* [12:11] */
  706. __IO uint32_t tppr :2; /* [14:13] */
  707. __IO uint32_t tppu :1; /* [15] */
  708. __IO uint32_t reserved4 :1; /* [16] */
  709. __IO uint32_t reserved5 :1; /* [17] */
  710. __IO uint32_t outtype :1; /* [18] */
  711. __IO uint32_t reserved6 :13;/* [31:19] */
  712. } tamp_bit;
  713. };
  714. /**
  715. * @brief ertc alasbs register, offset:0x44
  716. */
  717. union
  718. {
  719. __IO uint32_t alasbs;
  720. struct
  721. {
  722. __IO uint32_t sbs :15;/* [14:0] */
  723. __IO uint32_t reserved1 :9; /* [23:15] */
  724. __IO uint32_t sbsmsk :4; /* [27:24] */
  725. __IO uint32_t reserved2 :4; /* [31:28] */
  726. } alasbs_bit;
  727. };
  728. /**
  729. * @brief ertc reserved register, offset:0x48
  730. */
  731. __IO uint32_t reserved3;
  732. /**
  733. * @brief reserved register, offset:0x4c
  734. */
  735. __IO uint32_t reserved4;
  736. /**
  737. * @brief ertc dt1 register, offset:0x50
  738. */
  739. union
  740. {
  741. __IO uint32_t dt1;
  742. struct
  743. {
  744. __IO uint32_t dt :32;/* [31:0] */
  745. } dt1_bit;
  746. };
  747. /**
  748. * @brief ertc dt2 register, offset:0x54
  749. */
  750. union
  751. {
  752. __IO uint32_t dt2;
  753. struct
  754. {
  755. __IO uint32_t dt :32;/* [31:0] */
  756. } dt2_bit;
  757. };
  758. /**
  759. * @brief ertc dt3 register, offset:0x58
  760. */
  761. union
  762. {
  763. __IO uint32_t dt3;
  764. struct
  765. {
  766. __IO uint32_t dt :32;/* [31:0] */
  767. } dt3_bit;
  768. };
  769. /**
  770. * @brief ertc dt4 register, offset:0x5C
  771. */
  772. union
  773. {
  774. __IO uint32_t dt4;
  775. struct
  776. {
  777. __IO uint32_t dt :32;/* [31:0] */
  778. } dt4_bit;
  779. };
  780. /**
  781. * @brief ertc dt5 register, offset:0x60
  782. */
  783. union
  784. {
  785. __IO uint32_t dt5;
  786. struct
  787. {
  788. __IO uint32_t dt :32;/* [31:0] */
  789. } dt5_bit;
  790. };
  791. } ertc_type;
  792. /**
  793. * @}
  794. */
  795. #define ERTC ((ertc_type *) ERTC_BASE)
  796. /** @defgroup ERTC_exported_functions
  797. * @{
  798. */
  799. uint8_t ertc_num_to_bcd(uint8_t num);
  800. uint8_t ertc_bcd_to_num(uint8_t bcd);
  801. void ertc_write_protect_enable(void);
  802. void ertc_write_protect_disable(void);
  803. error_status ertc_wait_update(void);
  804. error_status ertc_wait_flag(uint32_t flag, flag_status status);
  805. error_status ertc_init_mode_enter(void);
  806. void ertc_init_mode_exit(void);
  807. error_status ertc_reset(void);
  808. error_status ertc_divider_set(uint16_t div_a, uint16_t div_b);
  809. error_status ertc_hour_mode_set(ertc_hour_mode_set_type mode);
  810. error_status ertc_date_set(uint8_t year, uint8_t month, uint8_t date, uint8_t week);
  811. error_status ertc_time_set(uint8_t hour, uint8_t min, uint8_t sec, ertc_am_pm_type ampm);
  812. void ertc_calendar_get(ertc_time_type* time);
  813. uint32_t ertc_sub_second_get(void);
  814. void ertc_alarm_mask_set(ertc_alarm_type alarm_x, uint32_t mask);
  815. void ertc_alarm_week_date_select(ertc_alarm_type alarm_x, ertc_week_date_select_type wk);
  816. void ertc_alarm_set(ertc_alarm_type alarm_x, uint8_t week_date, uint8_t hour, uint8_t min, uint8_t sec, ertc_am_pm_type ampm);
  817. void ertc_alarm_sub_second_set(ertc_alarm_type alarm_x, uint32_t value, ertc_alarm_sbs_mask_type mask);
  818. error_status ertc_alarm_enable(ertc_alarm_type alarm_x, confirm_state new_state);
  819. void ertc_alarm_get(ertc_alarm_type alarm_x, ertc_alarm_value_type* alarm);
  820. uint32_t ertc_alarm_sub_second_get(ertc_alarm_type alarm_x);
  821. void ertc_wakeup_clock_set(ertc_wakeup_clock_type clock);
  822. void ertc_wakeup_counter_set(uint32_t counter);
  823. uint16_t ertc_wakeup_counter_get(void);
  824. error_status ertc_wakeup_enable(confirm_state new_state);
  825. error_status ertc_smooth_calibration_config(ertc_smooth_cal_period_type period, ertc_smooth_cal_clk_add_type clk_add, uint32_t clk_dec);
  826. void ertc_cal_output_select(ertc_cal_output_select_type output);
  827. void ertc_cal_output_enable(confirm_state new_state);
  828. error_status ertc_time_adjust(ertc_time_adjust_type add1s, uint32_t decsbs);
  829. void ertc_daylight_set(ertc_dst_operation_type operation, ertc_dst_save_type save);
  830. uint8_t ertc_daylight_bpr_get(void);
  831. error_status ertc_refer_clock_detect_enable(confirm_state new_state);
  832. void ertc_direct_read_enable(confirm_state new_state);
  833. void ertc_output_set(ertc_output_source_type source, ertc_output_polarity_type polarity, ertc_output_type type);
  834. void ertc_timestamp_valid_edge_set(ertc_timestamp_valid_edge_type edge);
  835. void ertc_timestamp_enable(confirm_state new_state);
  836. void ertc_timestamp_get(ertc_time_type* time);
  837. uint32_t ertc_timestamp_sub_second_get(void);
  838. void ertc_tamper_pull_up_enable(confirm_state new_state);
  839. void ertc_tamper_precharge_set(ertc_tamper_precharge_type precharge);
  840. void ertc_tamper_filter_set(ertc_tamper_filter_type filter);
  841. void ertc_tamper_detect_freq_set(ertc_tamper_detect_freq_type freq);
  842. void ertc_tamper_valid_edge_set(ertc_tamper_select_type tamper_x, ertc_tamper_valid_edge_type trigger);
  843. void ertc_tamper_timestamp_enable(confirm_state new_state);
  844. void ertc_tamper_enable(ertc_tamper_select_type tamper_x, confirm_state new_state);
  845. void ertc_interrupt_enable(uint32_t source, confirm_state new_state);
  846. flag_status ertc_interrupt_get(uint32_t source);
  847. flag_status ertc_flag_get(uint32_t flag);
  848. void ertc_flag_clear(uint32_t flag);
  849. void ertc_bpr_data_write(ertc_dt_type dt, uint32_t data);
  850. uint32_t ertc_bpr_data_read(ertc_dt_type dt);
  851. /**
  852. * @}
  853. */
  854. /**
  855. * @}
  856. */
  857. /**
  858. * @}
  859. */
  860. #ifdef __cplusplus
  861. }
  862. #endif
  863. #endif