hpm_sysctl_drv.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /**
  2. * Copyright (c) 2021-2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SYSCTL_DRV_H
  8. #define HPM_SYSCTL_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_sysctl_regs.h"
  11. /**
  12. *
  13. * @brief SYSCTL driver APIs
  14. * @defgroup sysctl_interface SYSCTL driver APIs
  15. * @ingroup io_interfaces
  16. * @{
  17. */
  18. /**
  19. * @brief Retention domains
  20. */
  21. typedef enum {
  22. sysctl_retention_domain_sys = 0,
  23. sysctl_retention_domain_cpu0 = 2,
  24. sysctl_retention_domain_xtal24m = 4,
  25. sysctl_retention_domain_pll0 = 5,
  26. sysctl_retention_domain_pll1 = 6,
  27. sysctl_retention_domain_pll2 = 7,
  28. } sysctl_retention_domain_t;
  29. /**
  30. * @brief Clock presets
  31. */
  32. typedef enum {
  33. sysctl_preset_0 = 1 << 0,
  34. sysctl_preset_1 = 1 << 1,
  35. sysctl_preset_2 = 1 << 2,
  36. sysctl_preset_3 = 1 << 3,
  37. } sysctl_preset_t;
  38. /**
  39. * @brief Reset domains
  40. */
  41. typedef enum {
  42. sysctl_reset_domain_soc = 0,
  43. sysctl_reset_domain_cpu0,
  44. } sysctl_reset_domain_t;
  45. /**
  46. * @brief Resource
  47. */
  48. typedef enum {
  49. sysctl_resource_cpu0 = 0,
  50. sysctl_resource_cpx0 = 1,
  51. sysctl_resource_exe0 = 2,
  52. sysctl_resource_wak0 = 3,
  53. sysctl_resource_cpu0_per = 4,
  54. sysctl_resource_logic0 = 16,
  55. sysctl_resource_logic1 = 17,
  56. sysctl_resource_logic2 = 18,
  57. sysctl_resource_logic3 = 19,
  58. sysctl_resource_pmic = 20,
  59. sysctl_resource_pow_cpu0 = 21,
  60. sysctl_resource_rst_soc = 22,
  61. sysctl_resource_rst_cpu0 = 23,
  62. sysctl_resource_xtal = 32,
  63. sysctl_resource_pll0 = 33,
  64. sysctl_resource_clk0_pll0 = 34,
  65. sysctl_resource_clk1_pll0 = 35,
  66. sysctl_resource_clk2_pll0 = 36,
  67. sysctl_resource_pll1 = 37,
  68. sysctl_resource_clk0_pll1 = 38,
  69. sysctl_resource_clk1_pll1 = 39,
  70. sysctl_resource_pll2 = 40,
  71. sysctl_resource_clk0_pll2 = 41,
  72. sysctl_resource_clk1_pll2 = 42,
  73. sysctl_resource_pll0_ref = 43,
  74. sysctl_resource_pll1_ref = 44,
  75. sysctl_resource_pll2_ref = 45,
  76. sysctl_resource_mbist_soc = 48,
  77. sysctl_resource_mbist_cpu = 49,
  78. sysctl_resource_mbist_con = 50,
  79. sysctl_resource_dft_start_bus = 51,
  80. sysctl_resource_clk_top_cpu0 = 64,
  81. sysctl_resource_clk_top_mchtmr0 = 65,
  82. sysctl_resource_clk_top_femc = 66,
  83. sysctl_resource_clk_top_xpi0 = 67,
  84. sysctl_resource_clk_top_xpi1 = 68,
  85. sysctl_resource_clk_top_gptmr0 = 69,
  86. sysctl_resource_clk_top_gptmr1 = 70,
  87. sysctl_resource_clk_top_gptmr2 = 71,
  88. sysctl_resource_clk_top_gptmr3 = 72,
  89. sysctl_resource_clk_top_uart0 = 73,
  90. sysctl_resource_clk_top_uart1 = 74,
  91. sysctl_resource_clk_top_uart2 = 75,
  92. sysctl_resource_clk_top_uart3 = 76,
  93. sysctl_resource_clk_top_uart4 = 77,
  94. sysctl_resource_clk_top_uart5 = 78,
  95. sysctl_resource_clk_top_uart6 = 79,
  96. sysctl_resource_clk_top_uart7 = 80,
  97. sysctl_resource_clk_top_i2c0 = 81,
  98. sysctl_resource_clk_top_i2c1 = 82,
  99. sysctl_resource_clk_top_i2c2 = 83,
  100. sysctl_resource_clk_top_i2c3 = 84,
  101. sysctl_resource_clk_top_spi0 = 85,
  102. sysctl_resource_clk_top_spi1 = 86,
  103. sysctl_resource_clk_top_spi2 = 87,
  104. sysctl_resource_clk_top_spi3 = 88,
  105. sysctl_resource_clk_top_can0 = 89,
  106. sysctl_resource_clk_top_can1 = 90,
  107. sysctl_resource_clk_top_ptpc = 91,
  108. sysctl_resource_clk_top_ana0 = 92,
  109. sysctl_resource_clk_top_ana1 = 93,
  110. sysctl_resource_clk_top_ana2 = 94,
  111. sysctl_resource_clk_top_ana3 = 95,
  112. sysctl_resource_clk_top_aud0 = 96,
  113. sysctl_resource_clk_top_aud1 = 97,
  114. sysctl_resource_clk_top_eth0 = 98,
  115. sysctl_resource_clk_top_ptp0 = 99,
  116. sysctl_resource_clk_top_ref0 = 100,
  117. sysctl_resource_clk_top_ref1 = 101,
  118. sysctl_resource_clk_top_ntmr0 = 102,
  119. sysctl_resource_clk_top_sdxc0 = 103,
  120. sysctl_resource_clk_top_adc0 = 128,
  121. sysctl_resource_clk_top_adc1 = 129,
  122. sysctl_resource_clk_top_adc2 = 130,
  123. sysctl_resource_clk_top_dac0 = 131,
  124. sysctl_resource_clk_top_i2s0 = 132,
  125. sysctl_resource_clk_top_i2s1 = 133,
  126. sysctl_resource_eth0_mem = 192,
  127. sysctl_resource_sdxc0_mem = 193,
  128. sysctl_resource_usb0_mem = 194,
  129. sysctl_resource_ram0_mem = 195,
  130. sysctl_resource_ahbp_mem = 196,
  131. sysctl_resource_femc_mem = 197,
  132. sysctl_resource_rom0_mem = 198,
  133. sysctl_resource_xpi0_mem = 199,
  134. sysctl_resource_xpi1_mem = 200,
  135. sysctl_resource_can0_mem = 201,
  136. sysctl_resource_can1_mem = 202,
  137. sysctl_resource_i2s0_mem = 203,
  138. sysctl_resource_i2s1_mem = 204,
  139. sysctl_resource_pdm0_mem = 205,
  140. sysctl_resource_sdp0_mem = 206,
  141. sysctl_resource_ffa0_mem = 207,
  142. sysctl_resource_cpx_mem = 208,
  143. sysctl_resource_core_mem = 209,
  144. sysctl_resource_lmm0_mem = 210,
  145. sysctl_resource_linkable_start = 256,
  146. sysctl_resource_ahbp = 256,
  147. sysctl_resource_axis = 257,
  148. sysctl_resource_axic = 258,
  149. sysctl_resource_femc = 259,
  150. sysctl_resource_rom0 = 260,
  151. sysctl_resource_lmm0 = 261,
  152. sysctl_resource_ram0 = 262,
  153. sysctl_resource_mchtmr0 = 263,
  154. sysctl_resource_xpi0 = 264,
  155. sysctl_resource_xpi1 = 265,
  156. sysctl_resource_sdp0 = 266,
  157. sysctl_resource_rng0 = 267,
  158. sysctl_resource_kman = 268,
  159. sysctl_resource_dma0 = 269,
  160. sysctl_resource_dma1 = 270,
  161. sysctl_resource_ffa0 = 271,
  162. sysctl_resource_gpio = 272,
  163. sysctl_resource_mbx0 = 273,
  164. sysctl_resource_wdg0 = 274,
  165. sysctl_resource_wdg1 = 275,
  166. sysctl_resource_tsns = 276,
  167. sysctl_resource_gptmr0 = 277,
  168. sysctl_resource_gptmr1 = 278,
  169. sysctl_resource_gptmr2 = 279,
  170. sysctl_resource_gptmr3 = 280,
  171. sysctl_resource_uart0 = 281,
  172. sysctl_resource_uart1 = 282,
  173. sysctl_resource_uart2 = 283,
  174. sysctl_resource_uart3 = 284,
  175. sysctl_resource_uart4 = 285,
  176. sysctl_resource_uart5 = 286,
  177. sysctl_resource_uart6 = 287,
  178. sysctl_resource_uart7 = 288,
  179. sysctl_resource_i2c0 = 289,
  180. sysctl_resource_i2c1 = 290,
  181. sysctl_resource_i2c2 = 291,
  182. sysctl_resource_i2c3 = 292,
  183. sysctl_resource_spi0 = 293,
  184. sysctl_resource_spi1 = 294,
  185. sysctl_resource_spi2 = 295,
  186. sysctl_resource_spi3 = 296,
  187. sysctl_resource_can0 = 297,
  188. sysctl_resource_can1 = 298,
  189. sysctl_resource_ptpc = 299,
  190. sysctl_resource_adc0 = 300,
  191. sysctl_resource_adc1 = 301,
  192. sysctl_resource_adc2 = 302,
  193. sysctl_resource_dac0 = 303,
  194. sysctl_resource_acmp = 304,
  195. sysctl_resource_i2s0 = 305,
  196. sysctl_resource_i2s1 = 306,
  197. sysctl_resource_i2spdm0 = 307,
  198. sysctl_resource_i2sdao = 308,
  199. sysctl_resource_msyn = 309,
  200. sysctl_resource_mot0 = 310,
  201. sysctl_resource_mot1 = 311,
  202. sysctl_resource_eth0 = 312,
  203. sysctl_resource_ntmr0 = 313,
  204. sysctl_resource_sdxc0 = 314,
  205. sysctl_resource_usb0 = 315,
  206. sysctl_resource_ref0 = 316,
  207. sysctl_resource_ref1 = 317,
  208. sysctl_resource_linkable_end,
  209. sysctl_resource_end = sysctl_resource_linkable_end,
  210. } sysctl_resource_t;
  211. /**
  212. * @brief Resource modes
  213. */
  214. typedef enum {
  215. sysctl_resource_mode_auto = 0,
  216. sysctl_resource_mode_force_on,
  217. sysctl_resource_mode_force_off,
  218. } sysctl_resource_mode_t;
  219. /**
  220. * @brief Clock nodes
  221. */
  222. typedef enum {
  223. clock_node_mchtmr0 = 0,
  224. clock_node_femc = 1,
  225. clock_node_xpi0 = 2,
  226. clock_node_xpi1 = 3,
  227. clock_node_gptmr0 = 4,
  228. clock_node_gptmr1 = 5,
  229. clock_node_gptmr2 = 6,
  230. clock_node_gptmr3 = 7,
  231. clock_node_uart0 = 8,
  232. clock_node_uart1 = 9,
  233. clock_node_uart2 = 10,
  234. clock_node_uart3 = 11,
  235. clock_node_uart4 = 12,
  236. clock_node_uart5 = 13,
  237. clock_node_uart6 = 14,
  238. clock_node_uart7 = 15,
  239. clock_node_i2c0 = 16,
  240. clock_node_i2c1 = 17,
  241. clock_node_i2c2 = 18,
  242. clock_node_i2c3 = 19,
  243. clock_node_spi0 = 20,
  244. clock_node_spi1 = 21,
  245. clock_node_spi2 = 22,
  246. clock_node_spi3 = 23,
  247. clock_node_can0 = 24,
  248. clock_node_can1 = 25,
  249. clock_node_ptpc = 26,
  250. clock_node_ana0 = 27,
  251. clock_node_ana1 = 28,
  252. clock_node_ana2 = 29,
  253. clock_node_ana3 = 30,
  254. clock_node_aud0 = 31,
  255. clock_node_aud1 = 32,
  256. clock_node_eth0 = 33,
  257. clock_node_ptp0 = 34,
  258. clock_node_ref0 = 35,
  259. clock_node_ref1 = 36,
  260. clock_node_ntmr0 = 37,
  261. clock_node_sdxc0 = 38,
  262. clock_node_adc_i2s_start,
  263. clock_node_adc0 = clock_node_adc_i2s_start,
  264. clock_node_adc1,
  265. clock_node_adc2,
  266. clock_node_i2s0,
  267. clock_node_i2s1,
  268. clock_node_end,
  269. clock_node_core_start = 0xfc,
  270. clock_node_cpu0 = clock_node_core_start,
  271. clock_node_axi,
  272. clock_node_ahb,
  273. } clock_node_t;
  274. /**
  275. * @brief General clock sources
  276. */
  277. typedef enum {
  278. clock_source_osc0_clk0 = 0,
  279. clock_source_pll0_clk0 = 1,
  280. clock_source_pll0_clk1 = 2,
  281. clock_source_pll0_clk2 = 3,
  282. clock_source_pll1_clk0 = 4,
  283. clock_source_pll1_clk1 = 5,
  284. clock_source_pll2_clk0 = 6,
  285. clock_source_pll2_clk1 = 7,
  286. clock_source_general_source_end,
  287. } clock_source_t;
  288. /**
  289. * @brief ADC/I2S clock sources
  290. */
  291. typedef enum {
  292. clock_source_adc_ana_clk = 0,
  293. clock_source_adc_ahb_clk = 1,
  294. clock_source_i2s_aud0_clk = 0,
  295. clock_source_i2s_aud1_clk = 1,
  296. clock_source_adc_i2s_clk_end,
  297. } clock_source_adc_i2s_t;
  298. /**
  299. * @brief CPU low power mode
  300. */
  301. typedef enum {
  302. cpu_lp_mode_gate_cpu_clock = 0,
  303. cpu_lp_mode_trigger_system_lp = 0x1,
  304. cpu_lp_mode_ungate_cpu_clock = 0x2,
  305. } cpu_lp_mode_t;
  306. /**
  307. * @brief Monitor targets
  308. */
  309. typedef enum {
  310. monitor_target_clk_32k = 0,
  311. monitor_target_clk_irc24m = 1,
  312. monitor_target_clk_xtal_24m = 2,
  313. monitor_target_clk_usb0_phy = 3,
  314. monitor_target_clk0_osc0 = 8,
  315. monitor_target_clk0_pll0 = 9,
  316. monitor_target_clk1_pll0 = 10,
  317. monitor_target_clk2_pll0 = 11,
  318. monitor_target_clk0_pll1 = 12,
  319. monitor_target_clk1_pll1 = 13,
  320. monitor_target_clk0_pll2 = 14,
  321. monitor_target_clk1_pll2 = 15,
  322. monitor_target_clk_top_cpu0 = 128,
  323. monitor_target_clk_top_mchtmr0 = 129,
  324. monitor_target_clk_top_femc = 136,
  325. monitor_target_clk_top_xpi0 = 137,
  326. monitor_target_clk_top_xpi1 = 138,
  327. monitor_target_clk_top_gptmr0 = 139,
  328. monitor_target_clk_top_gptmr1 = 140,
  329. monitor_target_clk_top_gptmr2 = 141,
  330. monitor_target_clk_top_gptmr3 = 142,
  331. monitor_target_clk_top_uart0 = 147,
  332. monitor_target_clk_top_uart1 = 148,
  333. monitor_target_clk_top_uart2 = 149,
  334. monitor_target_clk_top_uart3 = 150,
  335. monitor_target_clk_top_uart4 = 151,
  336. monitor_target_clk_top_uart5 = 152,
  337. monitor_target_clk_top_uart6 = 153,
  338. monitor_target_clk_top_uart7 = 154,
  339. monitor_target_clk_top_i2c0 = 163,
  340. monitor_target_clk_top_i2c1 = 164,
  341. monitor_target_clk_top_i2c2 = 165,
  342. monitor_target_clk_top_i2c3 = 166,
  343. monitor_target_clk_top_spi0 = 167,
  344. monitor_target_clk_top_spi1 = 168,
  345. monitor_target_clk_top_spi2 = 169,
  346. monitor_target_clk_top_spi3 = 170,
  347. monitor_target_clk_top_can0 = 171,
  348. monitor_target_clk_top_can1 = 172,
  349. monitor_target_clk_top_ptpc = 175,
  350. monitor_target_clk_top_ana0 = 176,
  351. monitor_target_clk_top_ana1 = 177,
  352. monitor_target_clk_top_ana2 = 178,
  353. monitor_target_clk_top_ana3 = 179,
  354. monitor_target_clk_top_aud0 = 180,
  355. monitor_target_clk_top_aud1 = 181,
  356. monitor_target_clk_top_eth0 = 185,
  357. monitor_target_clk_top_ptp0 = 187,
  358. monitor_target_clk_top_ref0 = 189,
  359. monitor_target_clk_top_ref1 = 190,
  360. monitor_target_clk_top_ntmr0 = 191,
  361. monitor_target_clk_top_sdxc0 = 193,
  362. } monitor_target_t;
  363. /**
  364. * @brief Monitor work mode
  365. */
  366. typedef enum {
  367. monitor_work_mode_compare = 0,
  368. monitor_work_mode_record = 1,
  369. } monitor_work_mode_t;
  370. /**
  371. * @brief Monitor accuracy
  372. */
  373. typedef enum {
  374. monitor_accuracy_1khz = 0,
  375. monitor_accuracy_1hz = 1,
  376. } monitor_accuracy_t;
  377. /**
  378. * @brief Monitor reference clock source
  379. */
  380. typedef enum {
  381. monitor_reference_32khz = 0,
  382. monitor_reference_24mhz = 1,
  383. } monitor_reference_t;
  384. typedef enum {
  385. cpu_event_flag_mask_reset = SYSCTL_CPU_LP_RESET_FLAG_MASK,
  386. cpu_event_flag_mask_sleep = SYSCTL_CPU_LP_SLEEP_FLAG_MASK,
  387. cpu_event_flag_mask_wake = SYSCTL_CPU_LP_WAKE_FLAG_MASK,
  388. cpu_event_flag_mask_all = SYSCTL_CPU_LP_RESET_FLAG_MASK | SYSCTL_CPU_LP_SLEEP_FLAG_MASK | SYSCTL_CPU_LP_WAKE_FLAG_MASK,
  389. } cpu_event_flag_mask_t;
  390. /**
  391. * @brief Monitor config
  392. */
  393. typedef struct monitor_config {
  394. uint8_t divide_by; /**< Divider to be used for OBS output to pads */
  395. monitor_work_mode_t mode; /**< Monitor work mode */
  396. monitor_accuracy_t accuracy; /**< Monitor reference accuracy */
  397. monitor_reference_t reference; /**< Monitor reference clock source */
  398. monitor_target_t target; /**< Monitor target */
  399. bool start_measure; /**< Start flag */
  400. bool enable_output; /**< Enable output to pads if true */
  401. uint32_t high_limit; /**< Maximum frequency at compare mode */
  402. uint32_t low_limit; /**< Minimum frequency at compare mode */
  403. } monitor_config_t;
  404. #ifdef __cplusplus
  405. extern "C" {
  406. #endif
  407. /**
  408. * @brief Check if monitor result is valid
  409. *
  410. * @param[in] ptr SYSCTL_Type base address
  411. * @param[in] monitor_index specific monitor instance to be used
  412. *
  413. * @return true if it is valid
  414. */
  415. static inline bool sysctl_monitor_result_is_valid(SYSCTL_Type *ptr, uint8_t monitor_index)
  416. {
  417. return SYSCTL_MONITOR_CONTROL_VALID_GET(ptr->MONITOR[monitor_index].CONTROL);
  418. }
  419. /**
  420. * @brief Get target monitor instance result
  421. *
  422. * @param[in] ptr SYSCTL_Type base address
  423. * @param[in] monitor_index specific monitor instance to be used
  424. * @return value of monitor result measured
  425. */
  426. static inline uint32_t sysctl_monitor_get_current_result(SYSCTL_Type *ptr, uint8_t monitor_index)
  427. {
  428. while (!sysctl_monitor_result_is_valid(ptr, monitor_index)) {
  429. }
  430. return ptr->MONITOR[monitor_index].CURRENT;
  431. }
  432. /**
  433. * @brief Set work mode for target monitor instance
  434. *
  435. * @param[in] ptr SYSCTL_Type base address
  436. * @param[in] monitor_index specific monitor instance to be used
  437. * @param[in] mode monitor_work_mode_compare, monitor_work_mode_record
  438. */
  439. static inline void sysctl_monitor_set_work_mode(SYSCTL_Type *ptr, uint8_t monitor_index, monitor_work_mode_t mode)
  440. {
  441. ptr->MONITOR[monitor_index].CONTROL = (ptr->MONITOR[monitor_index].CONTROL & ~SYSCTL_MONITOR_CONTROL_MODE_MASK) |
  442. (SYSCTL_MONITOR_CONTROL_MODE_SET(mode));
  443. }
  444. /**
  445. * @brief Set minimum frequency for target monitor instance
  446. *
  447. * @param[in] ptr SYSCTL_Type base address
  448. * @param[in] monitor_index specific monitor instance to be used
  449. * @param[in] limit measurement low limit
  450. */
  451. static inline hpm_stat_t sysctl_monitor_set_limit_low(SYSCTL_Type *ptr, uint8_t monitor_index, uint32_t limit)
  452. {
  453. if (ptr->MONITOR[monitor_index].CONTROL & SYSCTL_MONITOR_CONTROL_MODE_MASK) {
  454. return status_invalid_argument;
  455. }
  456. ptr->MONITOR[monitor_index].LOW_LIMIT = SYSCTL_MONITOR_LOW_LIMIT_FREQUENCY_SET(limit);
  457. return status_success;
  458. }
  459. /**
  460. * @brief Set maximum frequency for target monitor instance
  461. *
  462. * @param[in] ptr SYSCTL_Type base address
  463. * @param[in] monitor_index specific monitor instance to be used
  464. * @param[in] limit measurement high limit
  465. */
  466. static inline hpm_stat_t sysctl_monitor_set_limit_high(SYSCTL_Type *ptr, uint8_t monitor_index, uint32_t limit)
  467. {
  468. if (ptr->MONITOR[monitor_index].CONTROL & SYSCTL_MONITOR_CONTROL_MODE_MASK) {
  469. return status_invalid_argument;
  470. }
  471. ptr->MONITOR[monitor_index].HIGH_LIMIT = SYSCTL_MONITOR_HIGH_LIMIT_FREQUENCY_SET(limit);
  472. return status_success;
  473. }
  474. /**
  475. * @brief Set frequency limit for target monitor instance
  476. *
  477. * @param[in] ptr SYSCTL_Type base address
  478. * @param[in] monitor_index specific monitor instance to be used
  479. * @param[in] limit_high measurement high limit
  480. * @param[in] limit_low measurement low limit
  481. */
  482. static inline hpm_stat_t
  483. sysctl_monitor_set_limit(SYSCTL_Type *ptr, uint8_t monitor_index, uint32_t limit_high, uint32_t limit_low)
  484. {
  485. if (ptr->MONITOR[monitor_index].CONTROL & SYSCTL_MONITOR_CONTROL_MODE_MASK) {
  486. return status_invalid_argument;
  487. }
  488. ptr->MONITOR[monitor_index].HIGH_LIMIT = SYSCTL_MONITOR_HIGH_LIMIT_FREQUENCY_SET(limit_high);
  489. ptr->MONITOR[monitor_index].LOW_LIMIT = SYSCTL_MONITOR_LOW_LIMIT_FREQUENCY_SET(limit_low);
  490. return status_success;
  491. }
  492. /**
  493. * @brief Get maximum frequency for target monitor instance
  494. *
  495. * @param[in] ptr SYSCTL_Type base address
  496. * @param[in] monitor_index specific monitor instance to be used
  497. * @return current high limit value
  498. */
  499. static inline uint32_t sysctl_monitor_get_limit_high(SYSCTL_Type *ptr, uint32_t monitor_index)
  500. {
  501. return SYSCTL_MONITOR_HIGH_LIMIT_FREQUENCY_GET(ptr->MONITOR[monitor_index].HIGH_LIMIT);
  502. }
  503. /**
  504. * @brief Get minimum frequency for target monitor instance
  505. *
  506. * @param[in] ptr SYSCTL_Type base address
  507. * @param[in] monitor_index specific monitor instance to be used
  508. * @return current low limit value
  509. */
  510. static inline uint32_t sysctl_monitor_get_limit_low(SYSCTL_Type *ptr, uint32_t monitor_index)
  511. {
  512. return SYSCTL_MONITOR_LOW_LIMIT_FREQUENCY_SET(ptr->MONITOR[monitor_index].LOW_LIMIT);
  513. }
  514. /**
  515. * @brief Measure specific target frequency
  516. *
  517. * @param[in] ptr SYSCTL_Type base address
  518. * @param[in] monitor_index specific monitor instance to be used
  519. * @param[in] target monitor target to be measured
  520. * @param[in] enable_output enable clock obs output
  521. * @return frequency of monitor target measured
  522. */
  523. uint32_t
  524. sysctl_monitor_measure_frequency(SYSCTL_Type *ptr, uint8_t monitor_index, monitor_target_t target, bool enable_output);
  525. /**
  526. * @brief Link current CPU core its own group
  527. *
  528. * Once it is linked, peripherals state in that group will keep on as long as this core is not in low power mode
  529. *
  530. * @param[in] ptr SYSCTL_Type base address
  531. * @param[in] cpu_index cpu index to enable its own affiliated group
  532. */
  533. static inline void sysctl_set_enable_cpu_affiliate(SYSCTL_Type *ptr, uint8_t cpu_index)
  534. {
  535. ptr->AFFILIATE[cpu_index].SET = 1 << cpu_index;
  536. }
  537. /**
  538. * @brief Unlink current CPU core with its own group
  539. *
  540. * @param[in] ptr SYSCTL_Type base address
  541. * @param[in] cpu_index cpu index to enable its own affiliated group
  542. */
  543. static inline void sysctl_set_disable_cpu_affiliate(SYSCTL_Type *ptr, uint8_t cpu_index)
  544. {
  545. ptr->AFFILIATE[cpu_index].CLEAR = 1 << cpu_index;
  546. }
  547. /**
  548. * @brief Check if any resource is busy
  549. *
  550. * @param[in] ptr SYSCTL_Type base address
  551. * @return true if any resource is busy
  552. */
  553. static inline bool sysctl_resource_any_is_busy(SYSCTL_Type *ptr)
  554. {
  555. return ptr->RESOURCE[0] & SYSCTL_RESOURCE_GLB_BUSY_MASK;
  556. }
  557. /**
  558. * @brief Check if specific target is busy
  559. *
  560. * @param[in] ptr SYSCTL_Type base address
  561. * @param[in] resource target resource index
  562. * @return true if target resource is busy
  563. */
  564. static inline bool sysctl_resource_target_is_busy(SYSCTL_Type *ptr, sysctl_resource_t resource)
  565. {
  566. return ptr->RESOURCE[resource] & SYSCTL_RESOURCE_LOC_BUSY_MASK;
  567. }
  568. /**
  569. * @brief Set target mode
  570. *
  571. * @param[in] ptr SYSCTL_Type base address
  572. * @param[in] resource target resource index
  573. * @param[in] mode target resource mode
  574. */
  575. static inline void
  576. sysctl_resource_target_set_mode(SYSCTL_Type *ptr, sysctl_resource_t resource, sysctl_resource_mode_t mode)
  577. {
  578. ptr->RESOURCE[resource] = (ptr->RESOURCE[resource] & ~SYSCTL_RESOURCE_MODE_MASK) | SYSCTL_RESOURCE_MODE_SET(mode);
  579. }
  580. /**
  581. * @brief Disable resource retention when specific CPU enters stop mode
  582. *
  583. * @param[in] ptr SYSCTL_Type base address
  584. * @param[in] cpu_index cpu index
  585. * @param[in] mask bit mask to clear
  586. */
  587. static inline void sysctl_clear_cpu_lp_retention_with_mask(SYSCTL_Type *ptr, uint8_t cpu_index, uint32_t mask)
  588. {
  589. ptr->RETENTION[cpu_index].CLEAR = mask;
  590. }
  591. /**
  592. * @brief Disable resource retention when CPU0 enters stop mode
  593. *
  594. * @param[in] ptr SYSCTL_Type base address
  595. * @param[in] mask bit mask to clear
  596. */
  597. static inline void sysctl_clear_cpu0_lp_retention_with_mask(SYSCTL_Type *ptr,
  598. uint32_t mask)
  599. {
  600. sysctl_clear_cpu_lp_retention_with_mask(ptr, 0, mask);
  601. }
  602. /**
  603. * @brief Enable resource retention when specific CPU enters stop mode
  604. *
  605. * @param[in] ptr SYSCTL_Type base address
  606. * @param[in] cpu_index cpu index
  607. * @param[in] mask bit mask to set
  608. */
  609. static inline void sysctl_set_cpu_lp_retention_with_mask(SYSCTL_Type *ptr, uint8_t cpu_index, uint32_t mask)
  610. {
  611. ptr->RETENTION[cpu_index].SET = mask;
  612. }
  613. /**
  614. * @brief Enable resource retention when CPU0 enters stop mode
  615. *
  616. * @param[in] ptr SYSCTL_Type base address
  617. * @param[in] mask bit mask to set
  618. */
  619. static inline void sysctl_set_cpu0_lp_retention_with_mask(SYSCTL_Type *ptr,
  620. uint32_t mask)
  621. {
  622. sysctl_set_cpu_lp_retention_with_mask(ptr, 0, mask);
  623. }
  624. /**
  625. * @brief Enable resource retention when CPU1 enters stop mode
  626. *
  627. * @param[in] ptr SYSCTL_Type base address
  628. * @param[in] mask bit mask to set
  629. */
  630. static inline void sysctl_set_cpu1_lp_retention_with_mask(SYSCTL_Type *ptr,
  631. uint32_t mask)
  632. {
  633. sysctl_set_cpu_lp_retention_with_mask(ptr, 1, mask);
  634. }
  635. /**
  636. * @brief Enable resource retention when specific CPU enters stop mode
  637. *
  638. * @param[in] ptr SYSCTL_Type base address
  639. * @param[in] cpu_index cpu index
  640. * @param[in] value value to be set
  641. */
  642. static inline void sysctl_set_cpu_lp_retention(SYSCTL_Type *ptr,
  643. uint8_t cpu_index,
  644. uint32_t value)
  645. {
  646. ptr->RETENTION[cpu_index].VALUE = value;
  647. }
  648. /**
  649. * @brief Enable resource retention when CPU0 enters stop mode
  650. *
  651. * @param[in] ptr SYSCTL_Type base address
  652. * @param[in] value value to be set
  653. */
  654. static inline void sysctl_set_cpu0_lp_retention(SYSCTL_Type *ptr, uint32_t value)
  655. {
  656. sysctl_set_cpu_lp_retention(ptr, 0, value);
  657. }
  658. /**
  659. * @brief Retain target domain for specific CPU
  660. *
  661. * @param[in] ptr SYSCTL_Type base address
  662. * @param[in] cpu_index CPU index
  663. * @param[in] domain target domain power to be retained
  664. * @param[in] retain_mem set true to retain memory/register of target domain
  665. */
  666. static inline void
  667. sysctl_set_cpu_lp_retain_domain(SYSCTL_Type *ptr, uint8_t cpu_index, sysctl_retention_domain_t domain, bool retain_mem)
  668. {
  669. uint8_t set_mask = 0x1;
  670. if (domain < sysctl_retention_domain_xtal24m) {
  671. set_mask = retain_mem ? 0x3 : 0x1;
  672. }
  673. ptr->RETENTION[cpu_index].SET = (set_mask << domain);
  674. }
  675. /**
  676. * @brief Retain target domain for specific CPU0
  677. *
  678. * @param[in] ptr SYSCTL_Type base address
  679. * @param[in] domain target domain power to be retained
  680. * @param[in] retain_mem set true to retain memory/register of target domain
  681. */
  682. static inline void sysctl_set_cpu0_lp_retain_domain(SYSCTL_Type *ptr,
  683. sysctl_retention_domain_t domain,
  684. bool retain_mem)
  685. {
  686. sysctl_set_cpu_lp_retain_domain(ptr, 0, domain, retain_mem);
  687. }
  688. /**
  689. * @brief Check if cpu clock is busy
  690. *
  691. * @param[in] ptr SYSCTL_Type base address
  692. * @return true if any clock is busy
  693. */
  694. static inline bool sysctl_cpu_clock_any_is_busy(SYSCTL_Type *ptr)
  695. {
  696. return ptr->CLOCK_CPU[0] & SYSCTL_CLOCK_CPU_GLB_BUSY_MASK;
  697. }
  698. /**
  699. * @brief Check if any clock is busy
  700. *
  701. * @param[in] ptr SYSCTL_Type base address
  702. * @return true if any clock is busy
  703. */
  704. static inline bool sysctl_clock_any_is_busy(SYSCTL_Type *ptr)
  705. {
  706. return ptr->CLOCK[0] & SYSCTL_CLOCK_GLB_BUSY_MASK;
  707. }
  708. /**
  709. * @brief Check if target clock is busy
  710. *
  711. * @param[in] ptr SYSCTL_Type base address
  712. * @param[in] clock target clock
  713. * @return true if target clock is busy
  714. */
  715. static inline bool sysctl_clock_target_is_busy(SYSCTL_Type *ptr, uint32_t clock)
  716. {
  717. return ptr->CLOCK[clock] & SYSCTL_CLOCK_LOC_BUSY_MASK;
  718. }
  719. /**
  720. * @brief Set clock preset
  721. *
  722. * @param[in] ptr SYSCTL_Type base address
  723. * @param[in] preset preset
  724. */
  725. static inline void sysctl_clock_set_preset(SYSCTL_Type *ptr, sysctl_preset_t preset)
  726. {
  727. ptr->GLOBAL00 = (ptr->GLOBAL00 & ~SYSCTL_GLOBAL00_MUX_MASK) | SYSCTL_GLOBAL00_MUX_SET(preset);
  728. }
  729. /**
  730. * @brief Check if target reset domain wakeup status
  731. *
  732. * @param[in] ptr SYSCTL_Type base address
  733. * @param[in] domain target domain to be checked
  734. * @return true if target domain was taken wakeup reset
  735. */
  736. static inline bool sysctl_reset_check_target_domain_wakeup_flag(SYSCTL_Type *ptr, sysctl_reset_domain_t domain)
  737. {
  738. return ptr->RESET[domain].CONTROL & SYSCTL_RESET_CONTROL_FLAG_WAKE_MASK;
  739. }
  740. /**
  741. * @brief Clear target reset domain wakeup status
  742. *
  743. * @param[in] ptr SYSCTL_Type base address
  744. * @param[in] domain target domain to be checked
  745. */
  746. static inline void sysctl_reset_clear_target_domain_wakeup_flag(SYSCTL_Type *ptr, sysctl_reset_domain_t domain)
  747. {
  748. ptr->RESET[domain].CONTROL |= SYSCTL_RESET_CONTROL_FLAG_WAKE_MASK;
  749. }
  750. /**
  751. * @brief Clear target reset domain reset status
  752. *
  753. * @param[in] ptr SYSCTL_Type base address
  754. * @param[in] domain target domain to be checked
  755. * @return true if target domain was taken reset
  756. */
  757. static inline bool sysctl_reset_check_target_domain_flag(SYSCTL_Type *ptr, sysctl_reset_domain_t domain)
  758. {
  759. return ptr->RESET[domain].CONTROL & SYSCTL_RESET_CONTROL_FLAG_MASK;
  760. }
  761. /**
  762. * @brief Clear target reset domain reset status
  763. *
  764. * @param[in] ptr SYSCTL_Type base address
  765. * @param[in] domain target domain to be checked
  766. */
  767. static inline void sysctl_reset_clear_target_domain_flag(SYSCTL_Type *ptr, sysctl_reset_domain_t domain)
  768. {
  769. ptr->RESET[domain].CONTROL |= SYSCTL_RESET_CONTROL_FLAG_MASK;
  770. }
  771. /**
  772. * @brief Clear target reset domain for all reset status
  773. *
  774. * @param[in] ptr SYSCTL_Type base address
  775. * @param[in] domain target domain to be checked
  776. */
  777. static inline void sysctl_reset_clear_target_domain_all_flags(SYSCTL_Type *ptr, sysctl_reset_domain_t domain)
  778. {
  779. ptr->RESET[domain].CONTROL |= SYSCTL_RESET_CONTROL_FLAG_MASK | SYSCTL_RESET_CONTROL_FLAG_WAKE_MASK;
  780. }
  781. /**
  782. * @brief Get target CPU wakeup source status
  783. *
  784. * @param[in] ptr SYSCTL_Type base address
  785. * @param[in] cpu_index CPU index
  786. * @param[in] status_index wakeup status index 0 - 7
  787. * @return wakeup source status mask
  788. */
  789. static inline uint32_t sysctl_get_wakeup_source_status(SYSCTL_Type *ptr, uint8_t cpu_index, uint8_t status_index)
  790. {
  791. return ptr->CPU[cpu_index].WAKEUP_STATUS[status_index];
  792. }
  793. /**
  794. * @brief Get target CPU0 wakeup source status
  795. *
  796. * @param[in] ptr SYSCTL_Type base address
  797. * @param[in] status_index wakeup status index 0 - 7
  798. * @return wakeup source status mask
  799. */
  800. static inline uint32_t sysctl_get_cpu0_wakeup_source_status(SYSCTL_Type *ptr,
  801. uint8_t status_index)
  802. {
  803. return sysctl_get_wakeup_source_status(ptr, 0, status_index);
  804. }
  805. /**
  806. * @brief Check wakeup source status with mask
  807. *
  808. * @param[in] ptr SYSCTL_Type base address
  809. * @param[in] cpu_index CPU index
  810. * @param[in] status_index wakeup status index 0 - 7
  811. * @param[in] mask expected status mask
  812. * @return wakeup status according to given bit mask
  813. */
  814. static inline uint32_t
  815. sysctl_check_wakeup_source_status_with_mask(SYSCTL_Type *ptr, uint8_t cpu_index, uint8_t status_index, uint32_t mask)
  816. {
  817. return ptr->CPU[cpu_index].WAKEUP_STATUS[status_index] & mask;
  818. }
  819. /**
  820. * @brief Check CPU0 wakeup source status with mask
  821. *
  822. * @param[in] ptr SYSCTL_Type base address
  823. * @param[in] status_index wakeup status index 0 - 7
  824. * @param[in] mask expected status mask
  825. * @return wakeup status according to given bit mask
  826. */
  827. static inline
  828. uint32_t sysctl_check_cpu0_wakeup_source_status_with_mask(SYSCTL_Type *ptr,
  829. uint8_t status_index,
  830. uint32_t mask)
  831. {
  832. return sysctl_check_wakeup_source_status_with_mask(ptr, 0, status_index, mask);
  833. }
  834. /**
  835. * @brief Enable wakeup source status with mask
  836. *
  837. * @param[in] ptr SYSCTL_Type base address
  838. * @param[in] cpu_index CPU index
  839. * @param[in] enable_index wakeup enable index 0 - 7
  840. * @param[in] mask expected status mask
  841. */
  842. static inline void
  843. sysctl_enable_wakeup_source_with_mask(SYSCTL_Type *ptr, uint8_t cpu_index, uint8_t enable_index, uint32_t mask)
  844. {
  845. ptr->CPU[cpu_index].WAKEUP_ENABLE[enable_index] |= mask;
  846. }
  847. /**
  848. * @brief Enable CPU0 wakeup source status with mask
  849. *
  850. * @param[in] ptr SYSCTL_Type base address
  851. * @param[in] enable_index wakeup enable index 0 - 7
  852. * @param[in] mask expected status mask
  853. */
  854. static inline void sysctl_enable_cpu0_wakeup_source_with_mask(SYSCTL_Type *ptr,
  855. uint8_t enable_index,
  856. uint32_t mask)
  857. {
  858. ptr->CPU[0].WAKEUP_ENABLE[enable_index] |= mask;
  859. }
  860. /**
  861. * @brief Disable wakeup source status with mask
  862. *
  863. * @param[in] ptr SYSCTL_Type base address
  864. * @param[in] cpu_index CPU index
  865. * @param[in] enable_index wakeup enable index 0 - 7
  866. * @param[in] mask expected status mask
  867. */
  868. static inline void
  869. sysctl_disable_wakeup_source_with_mask(SYSCTL_Type *ptr, uint8_t cpu_index, uint8_t enable_index, uint32_t mask)
  870. {
  871. ptr->CPU[cpu_index].WAKEUP_ENABLE[enable_index] &= ~mask;
  872. }
  873. /**
  874. * @brief Disable CPU0 wakeup source status with mask
  875. *
  876. * @param[in] ptr SYSCTL_Type base address
  877. * @param[in] enable_index wakeup enable index 0 - 7
  878. * @param[in] mask expected status mask
  879. */
  880. static inline void sysctl_disable_cpu0_wakeup_source_with_mask(SYSCTL_Type *ptr,
  881. uint8_t enable_index,
  882. uint32_t mask)
  883. {
  884. sysctl_disable_wakeup_source_with_mask(ptr, 0, enable_index, mask);
  885. }
  886. /**
  887. * @brief Disable wakeup source status with irq
  888. *
  889. * @param[in] ptr SYSCTL_Type base address
  890. * @param[in] cpu_index CPU index
  891. * @param[in] irq_num irq number to be set as wakeup source
  892. */
  893. static inline void sysctl_disable_wakeup_source_with_irq(SYSCTL_Type *ptr, uint8_t cpu_index, uint16_t irq_num)
  894. {
  895. ptr->CPU[cpu_index].WAKEUP_ENABLE[irq_num >> 2] &= ~(1UL << (irq_num % 32));
  896. }
  897. /**
  898. * @brief Disable CPU0 wakeup source status with irq
  899. *
  900. * @param[in] ptr SYSCTL_Type base address
  901. * @param[in] irq_num irq number to be disabled as wakeup source
  902. */
  903. static inline void sysctl_disable_cpu0_wakeup_source_with_irq(SYSCTL_Type *ptr,
  904. uint16_t irq_num)
  905. {
  906. sysctl_disable_wakeup_source_with_irq(ptr, 0, irq_num);
  907. }
  908. /**
  909. * @brief Enable wakeup source status with irq
  910. *
  911. * @param[in] ptr SYSCTL_Type base address
  912. * @param[in] cpu_index CPU index
  913. * @param[in] irq_num irq number to be set as wakeup source
  914. */
  915. static inline void sysctl_enable_wakeup_source_with_irq(SYSCTL_Type *ptr, uint8_t cpu_index, uint16_t irq_num)
  916. {
  917. ptr->CPU[cpu_index].WAKEUP_ENABLE[irq_num / 32] |= 1UL << (irq_num & 0x1F);
  918. }
  919. /**
  920. * @brief Enable CPU0 wakeup source status with irq
  921. *
  922. * @param[in] ptr SYSCTL_Type base address
  923. * @param[in] irq_num irq number to be set as wakeup source
  924. */
  925. static inline void sysctl_enable_cpu0_wakeup_source_with_irq(SYSCTL_Type *ptr,
  926. uint16_t irq_num)
  927. {
  928. sysctl_enable_wakeup_source_with_irq(ptr, 0, irq_num);
  929. }
  930. /**
  931. * @brief Lock CPU gpr with mask
  932. *
  933. * @param[in] ptr SYSCTL_Type base address
  934. * @param[in] cpu_index CPU index
  935. * @param[in] gpr_mask bit mask of gpr registers to be locked
  936. */
  937. static inline void sysctl_cpu_lock_gpr_with_mask(SYSCTL_Type *ptr,
  938. uint8_t cpu_index,
  939. uint16_t gpr_mask)
  940. {
  941. ptr->CPU[cpu_index].LOCK |= SYSCTL_CPU_LOCK_GPR_SET(gpr_mask);
  942. }
  943. /**
  944. * @brief Lock CPU0 gpr with mask
  945. *
  946. * @param[in] ptr SYSCTL_Type base address
  947. * @param[in] gpr_mask bit mask of gpr registers to be locked
  948. */
  949. static inline void sysctl_cpu0_lock_gpr_with_mask(SYSCTL_Type *ptr,
  950. uint16_t gpr_mask)
  951. {
  952. sysctl_cpu_lock_gpr_with_mask(ptr, 0, gpr_mask);
  953. }
  954. /**
  955. * @brief Lock CPU lock
  956. *
  957. * @param[in] ptr SYSCTL_Type base address
  958. * @param[in] cpu_index CPU index
  959. */
  960. static inline void sysctl_cpu_lock(SYSCTL_Type *ptr, uint8_t cpu_index)
  961. {
  962. ptr->CPU[cpu_index].LOCK |= SYSCTL_CPU_LOCK_LOCK_MASK;
  963. }
  964. /**
  965. * @brief Lock CPU0 lock
  966. *
  967. * @param[in] ptr SYSCTL_Type base address
  968. */
  969. static inline void sysctl_cpu0_lock(SYSCTL_Type *ptr)
  970. {
  971. sysctl_cpu_lock(ptr, 0);
  972. }
  973. /**
  974. * @brief Set CPU low power mode
  975. *
  976. * @param[in] ptr SYSCTL_Type base address
  977. * @param[in] cpu_index CPU index
  978. * @param[in] mode target mode to set
  979. */
  980. static inline void sysctl_set_cpu_lp_mode(SYSCTL_Type *ptr, uint8_t cpu_index, cpu_lp_mode_t mode)
  981. {
  982. ptr->CPU[cpu_index].LP = (ptr->CPU[cpu_index].LP & ~(SYSCTL_CPU_LP_MODE_MASK)) | (mode);
  983. }
  984. /**
  985. * @brief Set CPU0 low power mode
  986. *
  987. * @param[in] ptr SYSCTL_Type base address
  988. * @param[in] mode target mode to set
  989. */
  990. static inline void sysctl_set_cpu0_lp_mode(SYSCTL_Type *ptr, cpu_lp_mode_t mode)
  991. {
  992. sysctl_set_cpu_lp_mode(ptr, 0, mode);
  993. }
  994. /**
  995. * @brief Clear CPU event flags
  996. *
  997. * @param[in] ptr SYSCTL_Type base address
  998. * @param[in] cpu_index CPU index
  999. * @param[in] flags flag mask to be cleared
  1000. */
  1001. static inline void sysctl_clear_cpu_flags(SYSCTL_Type *ptr, uint8_t cpu_index, cpu_event_flag_mask_t flags)
  1002. {
  1003. ptr->CPU[cpu_index].LP |= ((SYSCTL_CPU_LP_SLEEP_FLAG_MASK | SYSCTL_CPU_LP_WAKE_FLAG_MASK | SYSCTL_CPU_LP_RESET_FLAG_MASK) & flags);
  1004. }
  1005. /**
  1006. * @brief Clear CPU0 event flags
  1007. *
  1008. * @param[in] ptr SYSCTL_Type base address
  1009. * @param[in] flags flag mask to be cleared
  1010. */
  1011. static inline void sysctl_clear_cpu0_flags(SYSCTL_Type *ptr, cpu_event_flag_mask_t flags)
  1012. {
  1013. sysctl_clear_cpu_flags(ptr, 0, flags);
  1014. }
  1015. /**
  1016. * @brief Get CPU event flags
  1017. *
  1018. * @param[in] ptr SYSCTL_Type base address
  1019. * @param[in] cpu_index CPU index
  1020. * @retval event flag mask
  1021. */
  1022. static inline uint32_t sysctl_get_cpu_flags(SYSCTL_Type *ptr, uint8_t cpu_index)
  1023. {
  1024. return ptr->CPU[cpu_index].LP & (SYSCTL_CPU_LP_SLEEP_FLAG_MASK | SYSCTL_CPU_LP_WAKE_FLAG_MASK | SYSCTL_CPU_LP_RESET_FLAG_MASK);
  1025. }
  1026. /**
  1027. * @brief Get CPU0 event flags
  1028. *
  1029. * @param[in] ptr SYSCTL_Type base address
  1030. * @retval event flag mask
  1031. */
  1032. static inline uint32_t sysctl_get_cpu0_flags(SYSCTL_Type *ptr)
  1033. {
  1034. return sysctl_get_cpu_flags(ptr, 0);
  1035. }
  1036. /**
  1037. * @brief Config lock
  1038. *
  1039. * @param[in] ptr SYSCTL_Type base address
  1040. * @param[in] node clock node to be configured
  1041. * @param[in] source clock source to be used
  1042. * @param[in] divide_by clock frequency divider
  1043. * @return status_success if everything is okay
  1044. */
  1045. hpm_stat_t sysctl_config_clock(SYSCTL_Type *ptr, clock_node_t node, clock_source_t source, uint32_t divide_by);
  1046. /**
  1047. * @brief Configure CPU domain clock
  1048. * @param ptr SYSCTL base address
  1049. * @param source clock source to be used
  1050. * @param cpu_div CPU divider
  1051. * @param axi_sub_div AXI BUS divider based on divided CPU clock
  1052. * @param ahb_sub_div AHB BUS divider based on divided CPU clock
  1053. * @return status_success if everything is okay
  1054. */
  1055. hpm_stat_t sysctl_config_cpu0_domain_clock(SYSCTL_Type *ptr, clock_source_t source, uint32_t cpu_div,
  1056. uint32_t axi_sub_div, uint32_t ahb_sub_div);
  1057. /**
  1058. * @brief Set ADC/I2S clock mux
  1059. *
  1060. * @param[in] ptr SYSCTL_Type base address
  1061. * @param[in] node clock node to be configured
  1062. * @param[in] source clock source to be used
  1063. * @return status_success if everything is okay
  1064. */
  1065. hpm_stat_t sysctl_set_adc_i2s_clock_mux(SYSCTL_Type *ptr, clock_node_t node, clock_source_adc_i2s_t source);
  1066. /**
  1067. * @brief Enable group resource
  1068. *
  1069. * @param[in] ptr SYSCTL_Type base address
  1070. * @param[in] group target group to be modified
  1071. * @param[in] resource target resource to be added/removed from group
  1072. * @param[in] enable set true to add resource, remove otherwise
  1073. * @return status_success if everything is okay
  1074. */
  1075. hpm_stat_t sysctl_enable_group_resource(SYSCTL_Type *ptr, uint8_t group, sysctl_resource_t resource, bool enable);
  1076. /**
  1077. * @brief Add resource to CPU0
  1078. *
  1079. * @param[in] ptr SYSCTL_Type base address
  1080. * @param[in] resource resource to be added to CPU0
  1081. * @return status_success if everything is okay
  1082. */
  1083. hpm_stat_t sysctl_add_resource_to_cpu0(SYSCTL_Type *ptr, sysctl_resource_t resource);
  1084. /**
  1085. * @brief Remove resource from CPU0
  1086. *
  1087. * @param[in] ptr SYSCTL_Type base address
  1088. * @param[in] resource Resource to be removed to CPU0
  1089. * @return status_success if everything is okay
  1090. */
  1091. hpm_stat_t sysctl_remove_resource_from_cpu0(SYSCTL_Type *ptr, sysctl_resource_t resource);
  1092. /**
  1093. * @brief Get default monitor config
  1094. *
  1095. * @param[in] ptr SYSCTL_Type base address
  1096. * @param[in] config Monitor config structure pointer
  1097. */
  1098. void sysctl_monitor_get_default_config(SYSCTL_Type *ptr, monitor_config_t *config);
  1099. /**
  1100. * @brief Initialize Monitor
  1101. *
  1102. * @param[in] ptr SYSCTL_Type base address
  1103. * @param[in] monitor_index Monitor instance to be initialized
  1104. * @param[in] config Monitor config structure pointer
  1105. */
  1106. void sysctl_monitor_init(SYSCTL_Type *ptr, uint8_t monitor_index, monitor_config_t *config);
  1107. /**
  1108. * @brief Save data to GPU0 GPR starting from given index
  1109. *
  1110. * @param[in] ptr SYSCTL_Type base address
  1111. * @param[in] start Starting GPR index
  1112. * @param[in] count Number of GPR registers to set
  1113. * @param[in] data Pointer to data buffer
  1114. * @param[in] lock Set true to lock written GPR registers after setting
  1115. * @return status_success if everything is okay
  1116. */
  1117. hpm_stat_t sysctl_cpu0_set_gpr(SYSCTL_Type *ptr, uint8_t start, uint8_t count, uint32_t *data, bool lock);
  1118. /**
  1119. * @brief Get data saved from GPU0 GPR starting from given index
  1120. *
  1121. * @param[in] ptr SYSCTL_Type base address
  1122. * @param[in] start Starting GPR index
  1123. * @param[in] count Number of GPR registers to set
  1124. * @param[out] data Pointer of buffer to save data
  1125. * @return status_success if everything is okay
  1126. */
  1127. hpm_stat_t sysctl_cpu0_get_gpr(SYSCTL_Type *ptr, uint8_t start, uint8_t count, uint32_t *data);
  1128. /**
  1129. * @brief Set entry point on CPU0 wakeup
  1130. *
  1131. * @param[in] ptr SYSCTL_Type base address
  1132. * @param[in] entry Entry address for CPU0 on its wakeup
  1133. * @return status_success if everything is okay
  1134. */
  1135. hpm_stat_t sysctl_set_cpu0_wakeup_entry(SYSCTL_Type *ptr, uint32_t entry);
  1136. #ifdef __cplusplus
  1137. }
  1138. #endif
  1139. /**
  1140. * @}
  1141. */
  1142. #endif /* HPM_SYSCTL_DRV_H */