timer_group_struct.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /**
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /** Group: T0 Control and configuration registers */
  12. /** Type of txconfig register
  13. * Timer x configuration register
  14. */
  15. typedef union {
  16. struct {
  17. uint32_t reserved_0: 9;
  18. /** tx_use_xtal : R/W; bitpos: [9]; default: 0;
  19. * 1: Use XTAL_CLK as the source clock of timer group. 0: Use APB_CLK as the source
  20. * clock of timer group.
  21. */
  22. uint32_t tx_use_xtal: 1;
  23. /** tx_alarm_en : R/W/SC; bitpos: [10]; default: 0;
  24. * When set, the alarm is enabled. This bit is automatically cleared once an
  25. * alarm occurs.
  26. */
  27. uint32_t tx_alarm_en: 1;
  28. uint32_t reserved_11: 1;
  29. /** tx_divcnt_rst : WT; bitpos: [12]; default: 0;
  30. * When set, Timer x 's clock divider counter will be reset.
  31. */
  32. uint32_t tx_divcnt_rst: 1;
  33. /** tx_divider : R/W; bitpos: [28:13]; default: 1;
  34. * Timer x clock (Tx_clk) prescaler value.
  35. */
  36. uint32_t tx_divider: 16;
  37. /** tx_autoreload : R/W; bitpos: [29]; default: 1;
  38. * When set, timer x auto-reload at alarm is enabled.
  39. */
  40. uint32_t tx_autoreload: 1;
  41. /** tx_increase : R/W; bitpos: [30]; default: 1;
  42. * When set, the timer x time-base counter will increment every clock tick. When
  43. * cleared, the timer x time-base counter will decrement.
  44. */
  45. uint32_t tx_increase: 1;
  46. /** tx_en : R/W; bitpos: [31]; default: 0;
  47. * When set, the timer x time-base counter is enabled.
  48. */
  49. uint32_t tx_en: 1;
  50. };
  51. uint32_t val;
  52. } timg_txconfig_reg_t;
  53. /** Type of txlo register
  54. * Timer x current value, low 32 bits
  55. */
  56. typedef union {
  57. struct {
  58. /** tx_lo : RO; bitpos: [31:0]; default: 0;
  59. * After writing to TIMG_TxUPDATE_REG, the low 32 bits of the time-base counter
  60. * of timer x can be read here.
  61. */
  62. uint32_t tx_lo: 32;
  63. };
  64. uint32_t val;
  65. } timg_txlo_reg_t;
  66. /** Type of txhi register
  67. * Timer $x current value, high 22 bits
  68. */
  69. typedef union {
  70. struct {
  71. /** tx_hi : RO; bitpos: [21:0]; default: 0;
  72. * After writing to TIMG_T$xUPDATE_REG, the high 22 bits of the time-base counter
  73. * of timer $x can be read here.
  74. */
  75. uint32_t tx_hi: 22;
  76. uint32_t reserved_22: 10;
  77. };
  78. uint32_t val;
  79. } timg_txhi_reg_t;
  80. /** Type of txupdate register
  81. * Write to copy current timer value to TIMGn_T$x_(LO/HI)_REG
  82. */
  83. typedef union {
  84. struct {
  85. uint32_t reserved_0: 31;
  86. /** tx_update : R/W/SC; bitpos: [31]; default: 0;
  87. * After writing 0 or 1 to TIMG_T$xUPDATE_REG, the counter value is latched.
  88. */
  89. uint32_t tx_update: 1;
  90. };
  91. uint32_t val;
  92. } timg_txupdate_reg_t;
  93. /** Type of txalarmlo register
  94. * Timer $x alarm value, low 32 bits
  95. */
  96. typedef union {
  97. struct {
  98. /** tx_alarm_lo : R/W; bitpos: [31:0]; default: 0;
  99. * Timer $x alarm trigger time-base counter value, low 32 bits.
  100. */
  101. uint32_t tx_alarm_lo: 32;
  102. };
  103. uint32_t val;
  104. } timg_txalarmlo_reg_t;
  105. /** Type of txalarmhi register
  106. * Timer $x alarm value, high bits
  107. */
  108. typedef union {
  109. struct {
  110. /** tx_alarm_hi : R/W; bitpos: [21:0]; default: 0;
  111. * Timer $x alarm trigger time-base counter value, high 22 bits.
  112. */
  113. uint32_t tx_alarm_hi: 22;
  114. uint32_t reserved_22: 10;
  115. };
  116. uint32_t val;
  117. } timg_txalarmhi_reg_t;
  118. /** Type of txloadlo register
  119. * Timer $x reload value, low 32 bits
  120. */
  121. typedef union {
  122. struct {
  123. /** tx_load_lo : R/W; bitpos: [31:0]; default: 0;
  124. * Low 32 bits of the value that a reload will load onto timer $x time-base
  125. * Counter.
  126. */
  127. uint32_t tx_load_lo: 32;
  128. };
  129. uint32_t val;
  130. } timg_txloadlo_reg_t;
  131. /** Type of txloadhi register
  132. * Timer $x reload value, high 22 bits
  133. */
  134. typedef union {
  135. struct {
  136. /** tx_load_hi : R/W; bitpos: [21:0]; default: 0;
  137. * High 22 bits of the value that a reload will load onto timer $x time-base
  138. * counter.
  139. */
  140. uint32_t tx_load_hi: 22;
  141. uint32_t reserved_22: 10;
  142. };
  143. uint32_t val;
  144. } timg_txloadhi_reg_t;
  145. /** Type of txload register
  146. * Write to reload timer from TIMG_T$x_(LOADLOLOADHI)_REG
  147. */
  148. typedef union {
  149. struct {
  150. /** tx_load : WT; bitpos: [31:0]; default: 0;
  151. *
  152. * Write any value to trigger a timer $x time-base counter reload.
  153. */
  154. uint32_t tx_load: 32;
  155. };
  156. uint32_t val;
  157. } timg_txload_reg_t;
  158. /** Group: WDT Control and configuration registers */
  159. /** Type of wdtconfig0 register
  160. * Watchdog timer configuration register
  161. */
  162. typedef union {
  163. struct {
  164. uint32_t reserved_0: 12;
  165. /** wdt_appcpu_reset_en : R/W; bitpos: [12]; default: 0;
  166. * WDT reset CPU enable.
  167. */
  168. uint32_t wdt_appcpu_reset_en: 1;
  169. /** wdt_procpu_reset_en : R/W; bitpos: [13]; default: 0;
  170. * WDT reset CPU enable.
  171. */
  172. uint32_t wdt_procpu_reset_en: 1;
  173. /** wdt_flashboot_mod_en : R/W; bitpos: [14]; default: 1;
  174. * When set, Flash boot protection is enabled.
  175. */
  176. uint32_t wdt_flashboot_mod_en: 1;
  177. /** wdt_sys_reset_length : R/W; bitpos: [17:15]; default: 1;
  178. * System reset signal length selection. 0: 100 ns, 1: 200 ns,
  179. * 2: 300 ns, 3: 400 ns, 4: 500 ns, 5: 800 ns, 6: 1.6 us, 7: 3.2 us.
  180. */
  181. uint32_t wdt_sys_reset_length: 3;
  182. /** wdt_cpu_reset_length : R/W; bitpos: [20:18]; default: 1;
  183. * CPU reset signal length selection. 0: 100 ns, 1: 200 ns,
  184. * 2: 300 ns, 3: 400 ns, 4: 500 ns, 5: 800 ns, 6: 1.6 us, 7: 3.2 us.
  185. */
  186. uint32_t wdt_cpu_reset_length: 3;
  187. /** wdt_use_xtal : R/W; bitpos: [21]; default: 0;
  188. * choose WDT clock:0-apb_clk; 1-xtal_clk.
  189. */
  190. uint32_t wdt_use_xtal: 1;
  191. /** wdt_conf_update_en : WT; bitpos: [22]; default: 0;
  192. * update the WDT configuration registers
  193. */
  194. uint32_t wdt_conf_update_en: 1;
  195. /** wdt_stg3 : R/W; bitpos: [24:23]; default: 0;
  196. * Stage 3 configuration. 0: off, 1: interrupt, 2: reset CPU, 3: reset system.
  197. */
  198. uint32_t wdt_stg3: 2;
  199. /** wdt_stg2 : R/W; bitpos: [26:25]; default: 0;
  200. * Stage 2 configuration. 0: off, 1: interrupt, 2: reset CPU, 3: reset system.
  201. */
  202. uint32_t wdt_stg2: 2;
  203. /** wdt_stg1 : R/W; bitpos: [28:27]; default: 0;
  204. * Stage 1 configuration. 0: off, 1: interrupt, 2: reset CPU, 3: reset system.
  205. */
  206. uint32_t wdt_stg1: 2;
  207. /** wdt_stg0 : R/W; bitpos: [30:29]; default: 0;
  208. * Stage 0 configuration. 0: off, 1: interrupt, 2: reset CPU, 3: reset system.
  209. */
  210. uint32_t wdt_stg0: 2;
  211. /** wdt_en : R/W; bitpos: [31]; default: 0;
  212. * When set, MWDT is enabled.
  213. */
  214. uint32_t wdt_en: 1;
  215. };
  216. uint32_t val;
  217. } timg_wdtconfig0_reg_t;
  218. /** Type of wdtconfig1 register
  219. * Watchdog timer prescaler register
  220. */
  221. typedef union {
  222. struct {
  223. /** wdt_divcnt_rst : WT; bitpos: [0]; default: 0;
  224. * When set, WDT 's clock divider counter will be reset.
  225. */
  226. uint32_t wdt_divcnt_rst: 1;
  227. uint32_t reserved_1: 15;
  228. /** wdt_clk_prescale : R/W; bitpos: [31:16]; default: 1;
  229. * MWDT clock prescaler value. MWDT clock period = 12.5 ns *
  230. * TIMG_WDT_CLK_PRESCALE.
  231. */
  232. uint32_t wdt_clk_prescale: 16;
  233. };
  234. uint32_t val;
  235. } timg_wdtconfig1_reg_t;
  236. /** Type of wdtconfig2 register
  237. * Watchdog timer stage 0 timeout value
  238. */
  239. typedef union {
  240. struct {
  241. /** wdt_stg0_hold : R/W; bitpos: [31:0]; default: 26000000;
  242. * Stage 0 timeout value, in MWDT clock cycles.
  243. */
  244. uint32_t wdt_stg0_hold: 32;
  245. };
  246. uint32_t val;
  247. } timg_wdtconfig2_reg_t;
  248. /** Type of wdtconfig3 register
  249. * Watchdog timer stage 1 timeout value
  250. */
  251. typedef union {
  252. struct {
  253. /** wdt_stg1_hold : R/W; bitpos: [31:0]; default: 134217727;
  254. * Stage 1 timeout value, in MWDT clock cycles.
  255. */
  256. uint32_t wdt_stg1_hold: 32;
  257. };
  258. uint32_t val;
  259. } timg_wdtconfig3_reg_t;
  260. /** Type of wdtconfig4 register
  261. * Watchdog timer stage 2 timeout value
  262. */
  263. typedef union {
  264. struct {
  265. /** wdt_stg2_hold : R/W; bitpos: [31:0]; default: 1048575;
  266. * Stage 2 timeout value, in MWDT clock cycles.
  267. */
  268. uint32_t wdt_stg2_hold: 32;
  269. };
  270. uint32_t val;
  271. } timg_wdtconfig4_reg_t;
  272. /** Type of wdtconfig5 register
  273. * Watchdog timer stage 3 timeout value
  274. */
  275. typedef union {
  276. struct {
  277. /** wdt_stg3_hold : R/W; bitpos: [31:0]; default: 1048575;
  278. * Stage 3 timeout value, in MWDT clock cycles.
  279. */
  280. uint32_t wdt_stg3_hold: 32;
  281. };
  282. uint32_t val;
  283. } timg_wdtconfig5_reg_t;
  284. /** Type of wdtfeed register
  285. * Write to feed the watchdog timer
  286. */
  287. typedef union {
  288. struct {
  289. /** wdt_feed : WT; bitpos: [31:0]; default: 0;
  290. * Write any value to feed the MWDT. (WO)
  291. */
  292. uint32_t wdt_feed: 32;
  293. };
  294. uint32_t val;
  295. } timg_wdtfeed_reg_t;
  296. /** Type of wdtwprotect register
  297. * Watchdog write protect register
  298. */
  299. typedef union {
  300. struct {
  301. /** wdt_wkey : R/W; bitpos: [31:0]; default: 1356348065;
  302. * If the register contains a different value than its reset value, write
  303. * protection is enabled.
  304. */
  305. uint32_t wdt_wkey: 32;
  306. };
  307. uint32_t val;
  308. } timg_wdtwprotect_reg_t;
  309. /** Group: RTC CALI Control and configuration registers */
  310. /** Type of rtccalicfg register
  311. * RTC calibration configure register
  312. */
  313. typedef union {
  314. struct {
  315. uint32_t reserved_0: 12;
  316. /** rtc_cali_start_cycling : R/W; bitpos: [12]; default: 1;
  317. * Reserved
  318. */
  319. uint32_t rtc_cali_start_cycling: 1;
  320. /** rtc_cali_clk_sel : R/W; bitpos: [14:13]; default: 1;
  321. * 0:rtc slow clock. 1:clk_8m, 2:xtal_32k.
  322. */
  323. uint32_t rtc_cali_clk_sel: 2;
  324. /** rtc_cali_rdy : RO; bitpos: [15]; default: 0;
  325. * Reserved
  326. */
  327. uint32_t rtc_cali_rdy: 1;
  328. /** rtc_cali_max : R/W; bitpos: [30:16]; default: 1;
  329. * Reserved
  330. */
  331. uint32_t rtc_cali_max: 15;
  332. /** rtc_cali_start : R/W; bitpos: [31]; default: 0;
  333. * Reserved
  334. */
  335. uint32_t rtc_cali_start: 1;
  336. };
  337. uint32_t val;
  338. } timg_rtccalicfg_reg_t;
  339. /** Type of rtccalicfg1 register
  340. * RTC calibration configure1 register
  341. */
  342. typedef union {
  343. struct {
  344. /** rtc_cali_cycling_data_vld : RO; bitpos: [0]; default: 0;
  345. * Reserved
  346. */
  347. uint32_t rtc_cali_cycling_data_vld: 1;
  348. uint32_t reserved_1: 6;
  349. /** rtc_cali_value : RO; bitpos: [31:7]; default: 0;
  350. * Reserved
  351. */
  352. uint32_t rtc_cali_value: 25;
  353. };
  354. uint32_t val;
  355. } timg_rtccalicfg1_reg_t;
  356. /** Type of rtccalicfg2 register
  357. * Timer group calibration register
  358. */
  359. typedef union {
  360. struct {
  361. /** rtc_cali_timeout : RO; bitpos: [0]; default: 0;
  362. * RTC calibration timeout indicator
  363. */
  364. uint32_t rtc_cali_timeout: 1;
  365. uint32_t reserved_1: 2;
  366. /** rtc_cali_timeout_rst_cnt : R/W; bitpos: [6:3]; default: 3;
  367. * Cycles that release calibration timeout reset
  368. */
  369. uint32_t rtc_cali_timeout_rst_cnt: 4;
  370. /** rtc_cali_timeout_thres : R/W; bitpos: [31:7]; default: 33554431;
  371. * Threshold value for the RTC calibration timer. If the calibration timer's value
  372. * exceeds this threshold, a timeout is triggered.
  373. */
  374. uint32_t rtc_cali_timeout_thres: 25;
  375. };
  376. uint32_t val;
  377. } timg_rtccalicfg2_reg_t;
  378. /** Group: Interrupt registers */
  379. /** Type of int_ena_timers register
  380. * Interrupt enable bits
  381. */
  382. typedef union {
  383. struct {
  384. /** t0_int_ena : R/W; bitpos: [0]; default: 0;
  385. * The interrupt enable bit for the TIMG_T$x_INT interrupt.
  386. */
  387. uint32_t t0_int_ena: 1;
  388. /** wdt_int_ena : R/W; bitpos: [1]; default: 0;
  389. * The interrupt enable bit for the TIMG_WDT_INT interrupt.
  390. */
  391. uint32_t wdt_int_ena: 1;
  392. uint32_t reserved_2: 30;
  393. };
  394. uint32_t val;
  395. } timg_int_ena_timers_reg_t;
  396. /** Type of int_raw_timers register
  397. * Raw interrupt status
  398. */
  399. typedef union {
  400. struct {
  401. /** t0_int_raw : R/SS/WTC; bitpos: [0]; default: 0;
  402. * The raw interrupt status bit for the TIMG_T$x_INT interrupt.
  403. */
  404. uint32_t t0_int_raw: 1;
  405. /** wdt_int_raw : R/SS/WTC; bitpos: [1]; default: 0;
  406. * The raw interrupt status bit for the TIMG_WDT_INT interrupt.
  407. */
  408. uint32_t wdt_int_raw: 1;
  409. uint32_t reserved_2: 30;
  410. };
  411. uint32_t val;
  412. } timg_int_raw_timers_reg_t;
  413. /** Type of int_st_timers register
  414. * Masked interrupt status
  415. */
  416. typedef union {
  417. struct {
  418. /** t0_int_st : RO; bitpos: [0]; default: 0;
  419. * The masked interrupt status bit for the TIMG_T$x_INT interrupt.
  420. */
  421. uint32_t t0_int_st: 1;
  422. /** wdt_int_st : RO; bitpos: [1]; default: 0;
  423. * The masked interrupt status bit for the TIMG_WDT_INT interrupt.
  424. */
  425. uint32_t wdt_int_st: 1;
  426. uint32_t reserved_2: 30;
  427. };
  428. uint32_t val;
  429. } timg_int_st_timers_reg_t;
  430. /** Type of int_clr_timers register
  431. * Interrupt clear bits
  432. */
  433. typedef union {
  434. struct {
  435. /** t0_int_clr : WT; bitpos: [0]; default: 0;
  436. * Set this bit to clear the TIMG_T$x_INT interrupt.
  437. */
  438. uint32_t t0_int_clr: 1;
  439. /** wdt_int_clr : WT; bitpos: [1]; default: 0;
  440. * Set this bit to clear the TIMG_WDT_INT interrupt.
  441. */
  442. uint32_t wdt_int_clr: 1;
  443. uint32_t reserved_2: 30;
  444. };
  445. uint32_t val;
  446. } timg_int_clr_timers_reg_t;
  447. /** Group: Version register */
  448. /** Type of ntimers_date register
  449. * Timer version control register
  450. */
  451. typedef union {
  452. struct {
  453. /** ntimgs_date : R/W; bitpos: [27:0]; default: 33579409;
  454. * Timer version control register
  455. */
  456. uint32_t ntimgs_date: 28;
  457. uint32_t reserved_28: 4;
  458. };
  459. uint32_t val;
  460. } timg_ntimers_date_reg_t;
  461. /** Group: Clock configuration registers */
  462. /** Type of regclk register
  463. * Timer group clock gate register
  464. */
  465. typedef union {
  466. struct {
  467. uint32_t reserved_0: 29;
  468. /** wdt_clk_is_active : R/W; bitpos: [29]; default: 1;
  469. * enable WDT's clock
  470. */
  471. uint32_t wdt_clk_is_active: 1;
  472. /** timer_clk_is_active : R/W; bitpos: [30]; default: 1;
  473. * enable Timer $x's clock
  474. */
  475. uint32_t timer_clk_is_active: 1;
  476. /** clk_en : R/W; bitpos: [31]; default: 0;
  477. * Register clock gate signal. 1: Registers can be read and written to by software. 0:
  478. * Registers can not be read or written to by software.
  479. */
  480. uint32_t clk_en: 1;
  481. };
  482. uint32_t val;
  483. } timg_regclk_reg_t;
  484. typedef struct {
  485. volatile timg_txconfig_reg_t config;
  486. volatile timg_txlo_reg_t lo;
  487. volatile timg_txhi_reg_t hi;
  488. volatile timg_txupdate_reg_t update;
  489. volatile timg_txalarmlo_reg_t alarmlo;
  490. volatile timg_txalarmhi_reg_t alarmhi;
  491. volatile timg_txloadlo_reg_t loadlo;
  492. volatile timg_txloadhi_reg_t loadhi;
  493. volatile timg_txload_reg_t load;
  494. } timg_hwtimer_reg_t;
  495. typedef struct timg_dev_t {
  496. volatile timg_hwtimer_reg_t hw_timer[1];
  497. uint32_t reserved_024[9];
  498. volatile timg_wdtconfig0_reg_t wdtconfig0;
  499. volatile timg_wdtconfig1_reg_t wdtconfig1;
  500. volatile timg_wdtconfig2_reg_t wdtconfig2;
  501. volatile timg_wdtconfig3_reg_t wdtconfig3;
  502. volatile timg_wdtconfig4_reg_t wdtconfig4;
  503. volatile timg_wdtconfig5_reg_t wdtconfig5;
  504. volatile timg_wdtfeed_reg_t wdtfeed;
  505. volatile timg_wdtwprotect_reg_t wdtwprotect;
  506. volatile timg_rtccalicfg_reg_t rtccalicfg;
  507. volatile timg_rtccalicfg1_reg_t rtccalicfg1;
  508. volatile timg_int_ena_timers_reg_t int_ena_timers;
  509. volatile timg_int_raw_timers_reg_t int_raw_timers;
  510. volatile timg_int_st_timers_reg_t int_st_timers;
  511. volatile timg_int_clr_timers_reg_t int_clr_timers;
  512. volatile timg_rtccalicfg2_reg_t rtccalicfg2;
  513. uint32_t reserved_084[29];
  514. volatile timg_ntimers_date_reg_t ntimers_date;
  515. volatile timg_regclk_reg_t regclk;
  516. } timg_dev_t;
  517. extern timg_dev_t TIMERG0;
  518. extern timg_dev_t TIMERG1;
  519. #ifndef __cplusplus
  520. _Static_assert(sizeof(timg_dev_t) == 0x100, "Invalid size of timg_dev_t structure");
  521. #endif
  522. #ifdef __cplusplus
  523. }
  524. #endif