hpm_gptmr_drv.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_GPTMR_DRV_H
  8. #define HPM_GPTMR_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_gptmr_regs.h"
  11. #include "hpm_soc_feature.h"
  12. /**
  13. * @brief GPTMR driver APIs
  14. * @defgroup gptmr_interface GPTMR driver APIs
  15. * @ingroup io_interfaces
  16. * @{
  17. */
  18. /**
  19. * @brief GPTMR channel IRQ mask
  20. */
  21. #define GPTMR_CH_CMP_IRQ_MASK(ch, cmp) (1 << (ch * 4 + 2 + cmp))
  22. #define GPTMR_CH_CAP_IRQ_MASK(ch) (1 << (ch * 4 + 1))
  23. #define GPTMR_CH_RLD_IRQ_MASK(ch) (1 << (ch * 4))
  24. /**
  25. * @brief GPTMR channel status
  26. */
  27. #define GPTMR_CH_CMP_STAT_MASK(ch, cmp) (1 << (ch * 4 + 2 + cmp))
  28. #define GPTMR_CH_CAP_STAT_MASK(ch) (1 << (ch * 4 + 1))
  29. #define GPTMR_CH_RLD_STAT_MASK(ch) (1 << (ch * 4))
  30. /**
  31. * @brief GPTMR channel swsynct mask
  32. */
  33. #define GPTMR_CH_GCR_SWSYNCT_MASK(ch) (1 << ch)
  34. /**
  35. * @brief GPTMR one channel support output comparator count
  36. */
  37. #define GPTMR_CH_CMP_COUNT (2U)
  38. /**
  39. * @brief GPTMR synci valid edge
  40. */
  41. typedef enum gptmr_synci_edge {
  42. gptmr_synci_edge_none = 0,
  43. gptmr_synci_edge_falling = GPTMR_CHANNEL_CR_SYNCIFEN_MASK,
  44. gptmr_synci_edge_rising = GPTMR_CHANNEL_CR_SYNCIREN_MASK,
  45. gptmr_synci_edge_both = gptmr_synci_edge_falling | gptmr_synci_edge_rising,
  46. } gptmr_synci_edge_t;
  47. /**
  48. * @brief GPTMR work mode
  49. */
  50. typedef enum gptmr_work_mode {
  51. gptmr_work_mode_no_capture = 0,
  52. gptmr_work_mode_capture_at_rising_edge = 1,
  53. gptmr_work_mode_capture_at_falling_edge = 2,
  54. gptmr_work_mode_capture_at_both_edge = 3,
  55. gptmr_work_mode_measure_width = 4,
  56. } gptmr_work_mode_t;
  57. /**
  58. * @brief GPTMR DMA request event
  59. */
  60. typedef enum gptmr_dma_request_event {
  61. gptmr_dma_request_on_cmp0 = 0,
  62. gptmr_dma_request_on_cmp1 = 1,
  63. gptmr_dma_request_on_input_signal_toggle = 2,
  64. gptmr_dma_request_on_reload = 3,
  65. gptmr_dma_request_disabled = 0xFF,
  66. } gptmr_dma_request_event_t;
  67. /**
  68. * @brief GPTMR counter type
  69. */
  70. typedef enum gptmr_counter_type {
  71. gptmr_counter_type_rising_edge,
  72. gptmr_counter_type_falling_edge,
  73. gptmr_counter_type_measured_period,
  74. gptmr_counter_type_measured_duty_cycle,
  75. gptmr_counter_type_normal,
  76. } gptmr_counter_type_t;
  77. /**
  78. * @brief GPTMR counter mode
  79. */
  80. #if defined(HPM_IP_FEATURE_GPTMR_CNT_MODE) && (HPM_IP_FEATURE_GPTMR_CNT_MODE == 1)
  81. typedef enum gptmr_counter_mode {
  82. gptmr_counter_mode_internal = 0,
  83. gptmr_counter_mode_external,
  84. } gptmr_counter_mode_t;
  85. #endif
  86. /**
  87. * @brief GPTMR channel config
  88. */
  89. typedef struct gptmr_channel_config {
  90. gptmr_work_mode_t mode;
  91. gptmr_dma_request_event_t dma_request_event;
  92. gptmr_synci_edge_t synci_edge;
  93. uint32_t cmp[GPTMR_CH_CMP_COUNT];
  94. uint32_t reload;
  95. bool cmp_initial_polarity_high;
  96. bool enable_cmp_output;
  97. bool enable_sync_follow_previous_channel;
  98. bool enable_software_sync;
  99. bool debug_mode;
  100. } gptmr_channel_config_t;
  101. #if defined(HPM_IP_FEATURE_GPTMR_MONITOR) && (HPM_IP_FEATURE_GPTMR_MONITOR == 1)
  102. typedef enum gptmr_channel_monitor_type {
  103. monitor_signal_period = 0,
  104. monitor_signal_high_level_time,
  105. } gptmr_channel_monitor_type_t;
  106. typedef struct gptmr_channel_monitor_config {
  107. gptmr_channel_monitor_type_t monitor_type;
  108. uint32_t max_value; /**< The unit is the gptmr clock source period */
  109. uint32_t min_value; /**< The unit is the gptmr clock source period */
  110. } gptmr_channel_monitor_config_t;
  111. #endif
  112. #ifdef __cplusplus
  113. extern "C" {
  114. #endif
  115. /**
  116. * @brief gptmr channel enable
  117. *
  118. * @param [in] ptr GPTMR base address
  119. * @param [in] ch_index channel index
  120. * @param [in] enable
  121. * @arg true: enable
  122. * @arg false: disable
  123. */
  124. static inline void gptmr_channel_enable(GPTMR_Type *ptr, uint8_t ch_index, bool enable)
  125. {
  126. ptr->CHANNEL[ch_index].CR = (ptr->CHANNEL[ch_index].CR
  127. & ~(GPTMR_CHANNEL_CR_CNTRST_MASK | GPTMR_CHANNEL_CR_CMPEN_MASK))
  128. | GPTMR_CHANNEL_CR_CMPEN_SET(enable);
  129. }
  130. /**
  131. * @brief gptmr channel reset counter
  132. *
  133. * @param [in] ptr GPTMR base address
  134. * @param [in] ch_index channel index
  135. */
  136. static inline void gptmr_channel_reset_count(GPTMR_Type *ptr, uint8_t ch_index)
  137. {
  138. ptr->CHANNEL[ch_index].CR |= GPTMR_CHANNEL_CR_CNTRST_MASK;
  139. ptr->CHANNEL[ch_index].CR &= ~GPTMR_CHANNEL_CR_CNTRST_MASK;
  140. }
  141. /**
  142. * @brief gptmr channel update counter
  143. *
  144. * @param [in] ptr GPTMR base address
  145. * @param [in] ch_index channel index
  146. * @param [in] value updated vaue
  147. */
  148. static inline void gptmr_channel_update_count(GPTMR_Type *ptr,
  149. uint8_t ch_index,
  150. uint32_t value)
  151. {
  152. if (value > 0) {
  153. value--;
  154. }
  155. ptr->CHANNEL[ch_index].CNTUPTVAL = GPTMR_CHANNEL_CNTUPTVAL_CNTUPTVAL_SET(value);
  156. ptr->CHANNEL[ch_index].CR |= GPTMR_CHANNEL_CR_CNTUPT_MASK;
  157. }
  158. /**
  159. * @brief gptmr channel slect synci valid edge
  160. *
  161. * @param [in] ptr GPTMR base address
  162. * @param [in] ch_index channel index
  163. * @param [in] edge gptmr_synci_edge_t
  164. */
  165. static inline void gptmr_channel_select_synci_valid_edge(GPTMR_Type *ptr,
  166. uint8_t ch_index,
  167. gptmr_synci_edge_t edge)
  168. {
  169. ptr->CHANNEL[ch_index].CR = (ptr->CHANNEL[ch_index].CR
  170. & ~(GPTMR_CHANNEL_CR_SYNCIFEN_MASK
  171. | GPTMR_CHANNEL_CR_SYNCIREN_MASK)) | edge;
  172. }
  173. /**
  174. * @brief gptmr channel enable dma request
  175. *
  176. * @param [in] ptr GPTMR base address
  177. * @param [in] ch_index channel index
  178. * @param [in] enable
  179. * @arg true: enable
  180. * @arg false: disable
  181. */
  182. static inline void gptmr_channel_enable_dma_request(GPTMR_Type *ptr,
  183. uint8_t ch_index,
  184. bool enable)
  185. {
  186. ptr->CHANNEL[ch_index].CR = (ptr->CHANNEL[ch_index].CR
  187. & ~(GPTMR_CHANNEL_CR_DMAEN_MASK)) | GPTMR_CHANNEL_CR_DMAEN_SET(enable);
  188. }
  189. /**
  190. * @brief gptmr channel get counter value
  191. *
  192. * @param [in] ptr GPTMR base address
  193. * @param [in] ch_index channel index
  194. * @param [in] capture gptmr_counter_type_t
  195. */
  196. static inline uint32_t gptmr_channel_get_counter(GPTMR_Type *ptr,
  197. uint8_t ch_index,
  198. gptmr_counter_type_t capture)
  199. {
  200. uint32_t value;
  201. switch (capture) {
  202. case gptmr_counter_type_rising_edge:
  203. value = (ptr->CHANNEL[ch_index].CAPPOS & GPTMR_CHANNEL_CAPPOS_CAPPOS_MASK) >> GPTMR_CHANNEL_CAPPOS_CAPPOS_SHIFT;
  204. break;
  205. case gptmr_counter_type_falling_edge:
  206. value = (ptr->CHANNEL[ch_index].CAPNEG & GPTMR_CHANNEL_CAPNEG_CAPNEG_MASK) >> GPTMR_CHANNEL_CAPNEG_CAPNEG_SHIFT;
  207. break;
  208. case gptmr_counter_type_measured_period:
  209. value = (ptr->CHANNEL[ch_index].CAPPRD & GPTMR_CHANNEL_CAPPRD_CAPPRD_MASK) >> GPTMR_CHANNEL_CAPPRD_CAPPRD_SHIFT;
  210. break;
  211. case gptmr_counter_type_measured_duty_cycle:
  212. value = (ptr->CHANNEL[ch_index].CAPDTY & GPTMR_CHANNEL_CAPDTY_MEAS_HIGH_MASK) >> GPTMR_CHANNEL_CAPDTY_MEAS_HIGH_SHIFT;
  213. break;
  214. default:
  215. value = (ptr->CHANNEL[ch_index].CNT & GPTMR_CHANNEL_CNT_COUNTER_MASK) >> GPTMR_CHANNEL_CNT_COUNTER_SHIFT;
  216. break;
  217. }
  218. return value;
  219. }
  220. /**
  221. * @brief gptmr trigger channel software sync
  222. *
  223. * @param [in] ptr GPTMR base address
  224. * @param [in] ch_index_mask channel index mask
  225. */
  226. static inline void gptmr_trigger_channel_software_sync(GPTMR_Type *ptr, uint32_t ch_index_mask)
  227. {
  228. ptr->GCR = ch_index_mask;
  229. }
  230. /**
  231. * @brief gptmr enable irq
  232. *
  233. * @param [in] ptr GPTMR base address
  234. * @param [in] irq_mask irq mask
  235. */
  236. static inline void gptmr_enable_irq(GPTMR_Type *ptr, uint32_t irq_mask)
  237. {
  238. ptr->IRQEN |= irq_mask;
  239. }
  240. /**
  241. * @brief gptmr disable irq
  242. *
  243. * @param [in] ptr GPTMR base address
  244. * @param [in] irq_mask irq mask
  245. */
  246. static inline void gptmr_disable_irq(GPTMR_Type *ptr, uint32_t irq_mask)
  247. {
  248. ptr->IRQEN &= ~irq_mask;
  249. }
  250. /**
  251. * @brief gptmr check status
  252. *
  253. * @param [in] ptr GPTMR base address
  254. * @param [in] mask channel flag mask
  255. */
  256. static inline bool gptmr_check_status(GPTMR_Type *ptr, uint32_t mask)
  257. {
  258. return (ptr->SR & mask) == mask;
  259. }
  260. /**
  261. * @brief gptmr clear status
  262. *
  263. * @param [in] ptr GPTMR base address
  264. * @param [in] mask channel flag mask
  265. */
  266. static inline void gptmr_clear_status(GPTMR_Type *ptr, uint32_t mask)
  267. {
  268. ptr->SR = mask;
  269. }
  270. /**
  271. * @brief gptmr get status
  272. *
  273. * @param [in] ptr GPTMR base address
  274. * @retval SR register value
  275. */
  276. static inline uint32_t gptmr_get_status(GPTMR_Type *ptr)
  277. {
  278. return ptr->SR;
  279. }
  280. /**
  281. * @brief gptmr channel start counter
  282. *
  283. * @param [in] ptr GPTMR base address
  284. * @param [in] ch_index channel index
  285. */
  286. static inline void gptmr_start_counter(GPTMR_Type *ptr, uint8_t ch_index)
  287. {
  288. ptr->CHANNEL[ch_index].CR |= GPTMR_CHANNEL_CR_CEN_MASK;
  289. }
  290. /**
  291. * @brief gptmr channel stop counter
  292. *
  293. * @param [in] ptr GPTMR base address
  294. * @param [in] ch_index channel index
  295. */
  296. static inline void gptmr_stop_counter(GPTMR_Type *ptr, uint8_t ch_index)
  297. {
  298. ptr->CHANNEL[ch_index].CR &= ~GPTMR_CHANNEL_CR_CEN_MASK;
  299. }
  300. /**
  301. * @brief gptmr channel enable compare output
  302. *
  303. * @param [in] ptr GPTMR base address
  304. * @param [in] ch_index channel index
  305. */
  306. static inline void gptmr_enable_cmp_output(GPTMR_Type *ptr, uint8_t ch_index)
  307. {
  308. ptr->CHANNEL[ch_index].CR |= GPTMR_CHANNEL_CR_CMPEN_MASK;
  309. }
  310. /**
  311. * @brief gptmr channel disable compare output
  312. *
  313. * @param [in] ptr GPTMR base address
  314. * @param [in] ch_index channel index
  315. */
  316. static inline void gptmr_disable_cmp_output(GPTMR_Type *ptr, uint8_t ch_index)
  317. {
  318. ptr->CHANNEL[ch_index].CR &= ~GPTMR_CHANNEL_CR_CMPEN_MASK;
  319. }
  320. /**
  321. * @brief gptmr channel set capmode
  322. *
  323. * @param [in] ptr GPTMR base address
  324. * @param [in] ch_index channel index
  325. * @param [in] mode enum gptmr_work_mode_capture_at_rising_edge or gptmr_work_mode_capture_at_falling_edge and so on
  326. */
  327. static inline void gptmr_channel_set_capmode(GPTMR_Type *ptr, uint8_t ch_index, gptmr_work_mode_t mode)
  328. {
  329. ptr->CHANNEL[ch_index].CR = (ptr->CHANNEL[ch_index].CR & ~GPTMR_CHANNEL_CR_CAPMODE_MASK) | GPTMR_CHANNEL_CR_CAPMODE_SET(mode);
  330. }
  331. /**
  332. * @brief gptmr channel get capmode
  333. *
  334. * @param [in] ptr GPTMR base address
  335. * @param [in] ch_index channel index
  336. * @retval gptmr_work_mode_t enum gptmr_work_mode_capture_at_rising_edge or gptmr_work_mode_capture_at_falling_edge
  337. */
  338. static inline gptmr_work_mode_t gptmr_channel_get_capmode(GPTMR_Type *ptr, uint8_t ch_index)
  339. {
  340. return (gptmr_work_mode_t)GPTMR_CHANNEL_CR_CAPMODE_GET(ptr->CHANNEL[ch_index].CR);
  341. }
  342. /**
  343. * @brief gptmr channel update comparator
  344. *
  345. * @param [in] ptr GPTMR base address
  346. * @param [in] ch_index channel index
  347. * @param [in] cmp_index comparator index
  348. * @param [in] cmp comparator value
  349. */
  350. static inline void gptmr_update_cmp(GPTMR_Type *ptr, uint8_t ch_index, uint8_t cmp_index, uint32_t cmp)
  351. {
  352. if (cmp > 0) {
  353. cmp--;
  354. }
  355. ptr->CHANNEL[ch_index].CMP[cmp_index] = GPTMR_CHANNEL_CMP_CMP_SET(cmp);
  356. }
  357. /**
  358. * @brief gptmr channel get reload
  359. *
  360. * @param [in] ptr GPTMR base address
  361. * @param [in] ch_index channel index
  362. * @retval RLD register value
  363. */
  364. static inline uint32_t gptmr_channel_get_reload(GPTMR_Type *ptr, uint8_t ch_index)
  365. {
  366. return ptr->CHANNEL[ch_index].RLD;
  367. }
  368. /**
  369. * @brief gptmr channel update reload
  370. *
  371. * @param [in] ptr GPTMR base address
  372. * @param [in] ch_index channel index
  373. * @param [in] reload reload value
  374. */
  375. static inline void gptmr_channel_config_update_reload(GPTMR_Type *ptr, uint8_t ch_index, uint32_t reload)
  376. {
  377. if (reload > 0) {
  378. reload--;
  379. }
  380. ptr->CHANNEL[ch_index].RLD = GPTMR_CHANNEL_RLD_RLD_SET(reload);
  381. }
  382. /**
  383. * @brief gptmr channel get dma request event
  384. *
  385. * @param [in] ptr GPTMR base address
  386. * @param [in] ch_index channel index
  387. * @retval gptmr_dma_request_event_t gptmr_dma_request_on_cmp0 or gptmr_dma_request_on_reload
  388. */
  389. static inline gptmr_dma_request_event_t gptmr_channel_get_dma_request_event(GPTMR_Type *ptr, uint8_t ch_index)
  390. {
  391. return (gptmr_dma_request_event_t)GPTMR_CHANNEL_CR_DMASEL_GET(ptr->CHANNEL[ch_index].CR);
  392. }
  393. /**
  394. * @brief gptmr channel config
  395. *
  396. * @param [in] ptr GPTMR base address
  397. * @param [in] ch_index channel index
  398. * @param [in] config gptmr_channel_config_t
  399. * @param [in] enable
  400. * @arg true: enable
  401. * @arg false: disable
  402. *
  403. * @retval hpm_stat_t status_invalid_argument or status_success
  404. */
  405. hpm_stat_t gptmr_channel_config(GPTMR_Type *ptr,
  406. uint8_t ch_index,
  407. gptmr_channel_config_t *config,
  408. bool enable);
  409. /**
  410. * @brief gptmr channel get default config
  411. *
  412. * @param [in] ptr GPTMR base address
  413. * @param [out] config gptmr_channel_config_t
  414. */
  415. void gptmr_channel_get_default_config(GPTMR_Type *ptr, gptmr_channel_config_t *config);
  416. #if defined(HPM_IP_FEATURE_GPTMR_CNT_MODE) && (HPM_IP_FEATURE_GPTMR_CNT_MODE == 1)
  417. /**
  418. * @brief gptmr set counter mode.
  419. *
  420. * @param [in] ptr GPTMR base address
  421. * @param [in] ch_index channel index
  422. * @param [in] mode gptmr_counter_mode_t, gptmr_counter_mode_external for gptmr enable external counting mode
  423. */
  424. static inline void gptmr_channel_set_counter_mode(GPTMR_Type *ptr, uint8_t ch_index, gptmr_counter_mode_t mode)
  425. {
  426. ptr->CHANNEL[ch_index].CR = (ptr->CHANNEL[ch_index].CR & ~GPTMR_CHANNEL_CR_CNT_MODE_MASK) | GPTMR_CHANNEL_CR_CNT_MODE_SET(mode);
  427. }
  428. /**
  429. * @brief gptmr channel get external trigger input counting mode.
  430. *
  431. * @param [in] ptr GPTMR base address
  432. * @param [in] ch_index channel index
  433. * @retval gptmr_counter_mode_external for external counting mode, gptmr_counter_mode_internal for internal counting mode
  434. */
  435. static inline gptmr_counter_mode_t gptmr_channel_get_counter_mode(GPTMR_Type *ptr, uint8_t ch_index)
  436. {
  437. return ((ptr->CHANNEL[ch_index].CR & GPTMR_CHANNEL_CR_CNT_MODE_MASK) ==
  438. GPTMR_CHANNEL_CR_CNT_MODE_MASK) ?
  439. gptmr_counter_mode_external : gptmr_counter_mode_internal;
  440. }
  441. #endif
  442. #if defined(HPM_IP_FEATURE_GPTMR_OP_MODE) && (HPM_IP_FEATURE_GPTMR_OP_MODE == 1)
  443. /**
  444. * @brief gptmr channel enable opmode, it's one-shot mode, timer will stopped at reload point.
  445. *
  446. * @note reload irq will be always set at one-shot mode at end
  447. *
  448. * @param [in] ptr GPTMR base address
  449. * @param [in] ch_index channel index
  450. */
  451. static inline void gptmr_channel_enable_opmode(GPTMR_Type *ptr, uint8_t ch_index)
  452. {
  453. ptr->CHANNEL[ch_index].CR |= GPTMR_CHANNEL_CR_OPMODE_MASK;
  454. }
  455. /**
  456. * @brief gptmr channel disable opmode, it's round mode.
  457. *
  458. * @param [in] ptr GPTMR base address
  459. * @param [in] ch_index channel index
  460. */
  461. static inline void gptmr_channel_disable_opmode(GPTMR_Type *ptr, uint8_t ch_index)
  462. {
  463. ptr->CHANNEL[ch_index].CR &= ~GPTMR_CHANNEL_CR_OPMODE_MASK;
  464. }
  465. /**
  466. * @brief gptmr channel get opmode.
  467. *
  468. * @param [in] ptr GPTMR base address
  469. * @param [in] ch_index channel index
  470. * @retval bool true for opmode, false for normal mode
  471. */
  472. static inline bool gptmr_channel_is_opmode(GPTMR_Type *ptr, uint8_t ch_index)
  473. {
  474. return ((ptr->CHANNEL[ch_index].CR & GPTMR_CHANNEL_CR_OPMODE_MASK) == GPTMR_CHANNEL_CR_OPMODE_MASK) ? true : false;
  475. }
  476. #endif
  477. #if defined(HPM_IP_FEATURE_GPTMR_MONITOR) && (HPM_IP_FEATURE_GPTMR_MONITOR == 1)
  478. /**
  479. * @brief gptmr channel enable monitor, set to monitor input signal period or high level time.
  480. *
  481. * @param [in] ptr GPTMR base address
  482. * @param [in] ch_index channel index
  483. */
  484. static inline void gptmr_channel_enable_monitor(GPTMR_Type *ptr, uint8_t ch_index)
  485. {
  486. ptr->CHANNEL[ch_index].CR |= GPTMR_CHANNEL_CR_MONITOR_EN_MASK;
  487. }
  488. /**
  489. * @brief gptmr channel disable monitor
  490. *
  491. * @param [in] ptr GPTMR base address
  492. * @param [in] ch_index channel index
  493. */
  494. static inline void gptmr_channel_disable_monitor(GPTMR_Type *ptr, uint8_t ch_index)
  495. {
  496. ptr->CHANNEL[ch_index].CR &= ~GPTMR_CHANNEL_CR_MONITOR_EN_MASK;
  497. }
  498. /**
  499. * @brief gptmr channel set to monitor input signal period or high level time.
  500. *
  501. * @param [in] ptr GPTMR base address
  502. * @param [in] ch_index channel index
  503. * @param [in] type gptmr_channel_monitor_type_t
  504. */
  505. static inline void gptmr_channel_set_monitor_type(GPTMR_Type *ptr, uint8_t ch_index, gptmr_channel_monitor_type_t type)
  506. {
  507. ptr->CHANNEL[ch_index].CR = (ptr->CHANNEL[ch_index].CR & ~GPTMR_CHANNEL_CR_MONITOR_SEL_MASK) | GPTMR_CHANNEL_CR_MONITOR_SEL_SET(type);
  508. }
  509. /**
  510. * @brief gptmr channel get to monitor input signal period or high level time.
  511. *
  512. * @param [in] ptr GPTMR base address
  513. * @param [in] ch_index channel index
  514. * @retval gptmr_channel_monitor_type_t monitor_signal_high_level_time or monitor_signal_period
  515. */
  516. static inline gptmr_channel_monitor_type_t gptmr_channel_get_monitor_type(GPTMR_Type *ptr, uint8_t ch_index)
  517. {
  518. return (gptmr_channel_monitor_type_t)GPTMR_CHANNEL_CR_MONITOR_SEL_GET(ptr->CHANNEL[ch_index].CR);
  519. }
  520. /**
  521. * @brief gptmr channel get default monitor config
  522. *
  523. * @param [in] ptr GPTMR base address
  524. * @param [out] config gptmr_channel_monitor_config_t
  525. */
  526. void gptmr_channel_get_default_monitor_config(GPTMR_Type *ptr, gptmr_channel_monitor_config_t *config);
  527. /**
  528. * @brief gptmr channel monitor config
  529. *
  530. * @param [in] ptr GPTMR base address
  531. * @param [in] ch_index channel index
  532. * @param [in] config gptmr_channel_monitor_config_t
  533. * @param [in] enable
  534. * @arg true: enable monitor and reset reload count
  535. * @arg false: disable monitor
  536. *
  537. * @retval hpm_stat_t status_invalid_argument or status_success
  538. */
  539. hpm_stat_t gptmr_channel_monitor_config(GPTMR_Type *ptr, uint8_t ch_index,
  540. gptmr_channel_monitor_config_t *config,
  541. bool enable);
  542. #endif
  543. /**
  544. * @}
  545. */
  546. #ifdef __cplusplus
  547. }
  548. #endif
  549. #endif /* HPM_GPTMR_DRV_H */