hpm_rdc_drv.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_RDC_DRV_H
  8. #define HPM_RDC_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_rdc_regs.h"
  11. #include "hpm_soc_feature.h"
  12. /**
  13. * @brief RDC driver APIs
  14. * @defgroup rdc_interface RDC driver APIs
  15. * @ingroup rdc_interfaces
  16. * @{
  17. */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @name Initialization and Deinitialization
  23. * @{
  24. */
  25. /**
  26. * @brief Rdc output precision, use n points to form an excitation signal period.
  27. *
  28. */
  29. typedef enum rdc_output_precision {
  30. rdc_output_precision_4_point = 0,
  31. rdc_output_precision_8_point = 1,
  32. rdc_output_precision_16_point = 2,
  33. rdc_output_precision_32_point = 3,
  34. rdc_output_precision_64_point = 4,
  35. rdc_output_precision_128_point = 5,
  36. rdc_output_precision_256_point = 6,
  37. rdc_output_precision_512_point = 7,
  38. rdc_output_precision_1024_point = 8,
  39. } rdc_output_precision_t;
  40. /**
  41. * @brief Pwm output period in samples
  42. *
  43. */
  44. typedef enum rdc_output_pwm_period {
  45. rdc_output_pwm_period_1_sample = 0,
  46. rdc_output_pwm_period_2_sample,
  47. rdc_output_pwm_period_3_sample,
  48. rdc_output_pwm_period_4_sample,
  49. rdc_output_pwm_period_5_sample,
  50. rdc_output_pwm_period_6_sample,
  51. rdc_output_pwm_period_7_sample,
  52. rdc_output_pwm_period_8_sample,
  53. rdc_output_pwm_period_9_sample,
  54. rdc_output_pwm_period_10_sample,
  55. rdc_output_pwm_period_11_sample,
  56. rdc_output_pwm_period_12_sample,
  57. rdc_output_pwm_period_13_sample,
  58. rdc_output_pwm_period_14_sample,
  59. rdc_output_pwm_period_15_sample,
  60. rdc_output_pwm_period_16_sample,
  61. } rdc_output_pwm_period_t;
  62. /**
  63. * @brief Rdc output mode
  64. *
  65. */
  66. typedef enum rdc_output_mode {
  67. rdc_output_dac,
  68. rdc_output_pwm
  69. } rdc_output_mode_t;
  70. /**
  71. * @brief Synchronize output trig adc position
  72. *
  73. */
  74. typedef enum rdc_sync_out_src {
  75. rdc_sync_out_exc_0_ph = RDC_SYNC_OUT_CTRL_SYNC_OUT_SEL_SET(0),
  76. rdc_sync_out_exc_90_ph = RDC_SYNC_OUT_CTRL_SYNC_OUT_SEL_SET(1),
  77. rdc_sync_out_exc_180_ph = RDC_SYNC_OUT_CTRL_SYNC_OUT_SEL_SET(2),
  78. rdc_sync_out_exc_270_ph = RDC_SYNC_OUT_CTRL_SYNC_OUT_SEL_SET(3),
  79. rdc_sync_out_max = RDC_SYNC_OUT_CTRL_MAX2TRIG_EN_MASK,
  80. rdc_sync_out_min = RDC_SYNC_OUT_CTRL_MIN2TRIG_EN_MASK,
  81. } rdc_sync_out_src_t;
  82. /**
  83. * @brief Select reference point of rectify signal
  84. *
  85. */
  86. typedef enum rdc_rectify_signal {
  87. rdc_rectify_signal_exc_0_ph = 0,
  88. rdc_rectify_signal_exc_90_ph = 1,
  89. rdc_rectify_signal_exc_180_ph = 2,
  90. rdc_rectify_signal_exc_270_ph = 3,
  91. rdc_rectify_signal_external = 4,
  92. rdc_rectify_signal_external_invert = 5,
  93. } rdc_rectify_signal_t;
  94. /**
  95. * @brief Time stamp selection for accumulation
  96. *
  97. */
  98. typedef enum rdc_acc_stamp_time {
  99. rdc_acc_stamp_end_of_acc = 0, /**< End of accumulation */
  100. rdc_acc_stamp_start_of_acc = 1, /**< Start of accumulation */
  101. rdc_acc_stamp_center_of_acc = 2, /**< Center of accumulation */
  102. } rdc_acc_stamp_time_t;
  103. /**
  104. * @brief Rdc trigger out channel 0 or channel 1
  105. *
  106. */
  107. typedef enum rdc_output_trig_chn {
  108. trigger_out_0 = 0,
  109. trigger_out_1 = 1
  110. } rdc_output_trig_chn_t;
  111. /**
  112. * @brief Rdc input channel
  113. *
  114. */
  115. typedef enum rdc_input_acc_chn {
  116. rdc_acc_chn_i = 0,
  117. rdc_acc_chn_q = 1
  118. } rdc_input_acc_chn_t;
  119. typedef enum rdc_input_max_min_value_source {
  120. rdc_value_at_adc = 0,
  121. rdc_value_at_iir = 1
  122. } rdc_input_max_min_value_source_t;
  123. /**
  124. * @brief Rdc status flags
  125. *
  126. */
  127. typedef enum rdc_interrupt_stat {
  128. acc_vld_i_stat = RDC_INT_EN_ACC_VLD_I_EN_MASK,
  129. acc_vld_q_stat = RDC_INT_EN_ACC_VLD_Q_EN_MASK,
  130. rising_delay_i_stat = RDC_INT_EN_RISING_DELAY_I_EN_MASK,
  131. falling_delay_i_stat = RDC_INT_EN_FALLING_DELAY_I_EN_MASK,
  132. rising_delay_q_stat = RDC_INT_EN_RISING_DELAY_Q_EN_MASK,
  133. falling_delay_q_stat = RDC_INT_EN_FALLING_DELAY_Q_EN_MASK,
  134. sample_rising_i_stat = RDC_INT_EN_SAMPLE_RISING_I_EN_MASK,
  135. sample_falling_i_stat = RDC_INT_EN_SAMPLE_FALLING_I_EN_MASK,
  136. sample_rising_q_stat = RDC_INT_EN_SAMPLE_RISING_Q_EN_MASK,
  137. sample_falling_q_stat = RDC_INT_EN_SAMPLE_FALLING_Q_EN_MASK,
  138. acc_vld_i_ovh_stat = RDC_INT_EN_ACC_VLD_I_OVH_EN_MASK,
  139. acc_vld_q_ovh_stat = RDC_INT_EN_ACC_VLD_Q_OVH_EN_MASK,
  140. acc_vld_i_ovl_stat = RDC_INT_EN_ACC_VLD_I_OVL_EN_MASK,
  141. acc_vld_q_ovl_stat = RDC_INT_EN_ACC_VLD_Q_OVL_EN_MASK,
  142. acc_amp_ovh_stat = RDC_INT_EN_ACC_AMP_OVH_EN_MASK,
  143. acc_amp_ovl_stat = RDC_INT_EN_ACC_AMP_OVL_EN_MASK,
  144. } rdc_interrupt_stat_t;
  145. /**
  146. * @brief Rdc output configuration
  147. *
  148. */
  149. typedef struct rdc_output_cfg {
  150. rdc_output_mode_t mode; /**< pwm or dac */
  151. uint32_t excitation_period_cycle; /**< The period of the excitation signal, in cycles */
  152. rdc_output_precision_t excitation_precision; /**< Excitation signal precision */
  153. rdc_output_pwm_period_t pwm_period; /**< Pwm period in samples */
  154. bool output_swap; /**< Swap output of PWM and DAC */
  155. int32_t amp_offset; /**< Offset for excitation, signed value*/
  156. uint16_t amp_man; /**< Amplitude scaling for excitation, amplitude = [table value] x man / 2^exp */
  157. uint16_t amp_exp; /**< Amplitude scaling for excitation, amplitude = [table value] x man / 2^exp */
  158. bool pwm_dither_enable; /**< Enable dither of pwm */
  159. bool pwm_exc_p_low_active; /**< Polarity of exc_p signal */
  160. bool pwm_exc_n_low_active; /**< Polarity of exc_n signal */
  161. bool trig_by_hw; /**< Hardware triggered excitation signal generation. Software triggering is required after shutdown */
  162. uint32_t hw_trig_delay; /**< Trigger in delay timming in bus cycle from rising edge of trigger signal */
  163. uint8_t dac_chn_i_sel; /**< Output channel selection for i_channel */
  164. uint8_t dac_chn_q_sel; /**< Output channel selection for q_channel */
  165. uint8_t pwm_deadzone_p; /**< Exc_p dead zone in clock cycle before swap */
  166. uint8_t pwm_deadzone_n; /**< Exc_n dead zone in clock cycle before swap */
  167. } rdc_output_cfg_t;
  168. /**
  169. * @brief Rdc input configuration
  170. *
  171. */
  172. typedef struct rdc_input_cfg {
  173. rdc_rectify_signal_t rectify_signal_sel; /**< Select reference point of rectify signal */
  174. #if defined(HPM_IP_FEATURE_RDC_IIR) && (HPM_IP_FEATURE_RDC_IIR)
  175. bool acc_fast; /**< every adc value can be as one accumulate value, */
  176. rdc_input_max_min_value_source_t max_min_value_position; /**< max min value position */
  177. #endif
  178. uint8_t acc_cycle_len; /**< Accumulate time, support on the fly change, Only acc_fast is zero, this bit is available */
  179. rdc_acc_stamp_time_t acc_stamp; /**< Time stamp selection for accumulation */
  180. uint32_t acc_input_chn_i; /**< Input channel selection for i_channel */
  181. uint32_t acc_input_port_i; /**< Input port selection for i_channel */
  182. uint32_t acc_input_chn_q; /**< Input channel selection for q_channel */
  183. uint32_t acc_input_port_q; /**< Input port selection for q_channel */
  184. } rdc_input_cfg_t;
  185. /**
  186. * @brief Accumulated configuration information
  187. *
  188. */
  189. typedef struct rdc_acc_cfg {
  190. struct {
  191. uint16_t continue_edge_num: 3; /**< Filtering val: 1 - 8 */
  192. uint16_t edge_distance: 6; /**< Minimum distance between two edges 0-63 */
  193. };
  194. #if defined(HPM_IP_FEATURE_RDC_IIR) && (HPM_IP_FEATURE_RDC_IIR)
  195. bool enable_i_thrs_data_for_acc; /**< enable thrs data for accumulate */
  196. bool enable_q_thrs_data_for_acc; /**< enable thrs data for accumulate */
  197. #endif
  198. uint8_t right_shift_without_sign; /**< Right shift without sign bit */
  199. bool error_data_remove; /**< Toxic accumulation data be removed */
  200. uint32_t exc_carrier_period; /**< The num in clock cycle for period of excitation 0-NULL others-cycles */
  201. uint32_t sync_delay_i; /**< Delay in clock cycle for synchronous signal, the value should less than half of exc_period.exc_period. */
  202. uint32_t sync_delay_q; /**< Delay in clock cycle for synchronous signal, the value should less than half of exc_period.exc_period. */
  203. uint32_t amp_max; /**< The maximum of acc amplitude */
  204. uint32_t amp_min; /**< The minimum of acc amplitude */
  205. } rdc_acc_cfg_t;
  206. #if defined(HPM_IP_FEATURE_RDC_IIR) && (HPM_IP_FEATURE_RDC_IIR)
  207. /**
  208. * @brief IIR Filter Configuration
  209. *
  210. */
  211. typedef struct rdc_iir_cfg {
  212. float b; /**< IIR parameter for b branch */
  213. float a1; /**< IIR parameter a1 for a1 branch*/
  214. float a2; /**< IIR parameter a1 for a2 branch*/
  215. bool enable_lowpass; /**< IIR in lowpass mode */
  216. } rdc_iir_cfg_t;
  217. #endif
  218. /** @} */
  219. /**
  220. * @name RDC Control
  221. * @{
  222. */
  223. /**
  224. * @brief Rdc output configuration, can be configured pwm output or dac output
  225. *
  226. * @param ptr @ref RDC_Type base
  227. * @param cfg @ref rdc_output_cfg_t
  228. */
  229. void rdc_output_config(RDC_Type *ptr, rdc_output_cfg_t *cfg);
  230. /**
  231. * @brief Rdc input configuration, configuration of adc signal source and calculation parameters
  232. *
  233. * @param ptr @ref RDC_Type base
  234. * @param cfg @ref rdc_input_cfg_t
  235. */
  236. void rdc_input_config(RDC_Type *ptr, rdc_input_cfg_t *cfg);
  237. /**
  238. * @brief Configuration accumulate time, support on the fly change
  239. *
  240. * @param ptr @ref RDC_Type base
  241. * @param len accumulate time 0-255
  242. */
  243. static inline void rdc_set_acc_len(RDC_Type *ptr, uint8_t len)
  244. {
  245. ptr->RDC_CTL = (ptr->RDC_CTL & (~RDC_RDC_CTL_ACC_LEN_MASK))
  246. | RDC_RDC_CTL_ACC_LEN_SET(len);
  247. }
  248. /**
  249. * @brief Enable accumulate calculation function
  250. *
  251. * @param ptr @ref RDC_Type base
  252. */
  253. static inline void rdc_acc_enable(RDC_Type *ptr)
  254. {
  255. ptr->RDC_CTL |= RDC_RDC_CTL_ACC_EN_MASK;
  256. }
  257. /**
  258. * @brief Disable accumulate calculation function
  259. *
  260. * @param ptr @ref RDC_Type base
  261. */
  262. static inline void rdc_acc_disable(RDC_Type *ptr)
  263. {
  264. ptr->RDC_CTL &= ~RDC_RDC_CTL_ACC_EN_MASK;
  265. }
  266. #if defined(HPM_IP_FEATURE_RDC_IIR) && (HPM_IP_FEATURE_RDC_IIR)
  267. /**
  268. * @brief Enable IIR for adc input
  269. *
  270. * @param ptr @ref RDC_Type base
  271. */
  272. static inline void rdc_irr_enable(RDC_Type *ptr)
  273. {
  274. ptr->RDC_CTL |= RDC_RDC_CTL_IIR_EN_MASK;
  275. }
  276. /**
  277. * @brief Disable IIR for adc input
  278. *
  279. * @param ptr @ref RDC_Type base
  280. */
  281. static inline void rdc_irr_disable(RDC_Type *ptr)
  282. {
  283. ptr->RDC_CTL &= ~RDC_RDC_CTL_IIR_EN_MASK;
  284. }
  285. /**
  286. * @brief enable i thrs data for accumulate
  287. *
  288. * @param ptr @ref RDC_Type base
  289. */
  290. static inline void rdc_enable_i_channel_thrs_data_for_acc(RDC_Type *ptr)
  291. {
  292. ptr->THRS_I |= RDC_THRS_I_THRS4ACC_MASK;
  293. }
  294. /**
  295. * @brief disable i thrs data for accumulate
  296. *
  297. * @param ptr @ref RDC_Type base
  298. */
  299. static inline void rdc_disable_i_channel_thrs_data_for_acc(RDC_Type *ptr)
  300. {
  301. ptr->THRS_I &= ~RDC_THRS_I_THRS4ACC_MASK;
  302. }
  303. /**
  304. * @brief enable q thrs data for accumulate
  305. *
  306. * @param ptr @ref RDC_Type base
  307. */
  308. static inline void rdc_enable_q_channel_thrs_data_for_acc(RDC_Type *ptr)
  309. {
  310. ptr->THRS_Q |= RDC_THRS_Q_THRS4ACC_MASK;
  311. }
  312. /**
  313. * @brief disable q thrs data for accumulate
  314. *
  315. * @param ptr @ref RDC_Type base
  316. */
  317. static inline void rdc_disable_q_channel_thrs_data_for_acc(RDC_Type *ptr)
  318. {
  319. ptr->THRS_Q &= ~RDC_THRS_Q_THRS4ACC_MASK;
  320. }
  321. #endif
  322. /**
  323. * @brief Get the accumulate value
  324. *
  325. * @param ptr @ref RDC_Type base
  326. * @param chn @ref rdc_input_acc_chn_t
  327. * @return uint32_t accumulate value
  328. */
  329. uint32_t rdc_get_acc_avl(RDC_Type *ptr, rdc_input_acc_chn_t chn);
  330. /**
  331. * @brief Output trigger configuration
  332. * Lead time for trigger out0 or out1 from center of low level , this is a signed value
  333. * @param ptr @ref RDC_Type base
  334. * @param chn @ref rdc_output_trig_chn_t
  335. * @param offset lead_time
  336. */
  337. void rdc_output_trig_offset_config(RDC_Type *ptr, rdc_output_trig_chn_t chn, int32_t offset);
  338. /**
  339. * @brief Enable output trigger configuration
  340. *
  341. * @param ptr @ref RDC_Type base
  342. * @param chn @ref rdc_output_trig_chn_t
  343. */
  344. void rdc_output_trig_enable(RDC_Type *ptr, rdc_output_trig_chn_t chn);
  345. /**
  346. * @brief Disable rdc output trigger configuration
  347. *
  348. * @param ptr @ref RDC_Type base
  349. * @param chn @ref rdc_output_trig_chn_t
  350. */
  351. void rdc_output_trig_disable(RDC_Type *ptr, rdc_output_trig_chn_t chn);
  352. /**
  353. * @brief Select output synchornize signal
  354. *
  355. * @param ptr @ref RDC_Type base
  356. * @param sel @ref rdc_sync_out_src_t
  357. */
  358. static inline void rdc_sync_output_trig_adc_cfg(RDC_Type *ptr, rdc_sync_out_src_t sel)
  359. {
  360. ptr->SYNC_OUT_CTRL = sel;
  361. }
  362. /**
  363. * @brief Enable rdc excite signal
  364. *
  365. * @param ptr @ref RDC_Type base
  366. */
  367. static inline void rdc_exc_enable(RDC_Type *ptr)
  368. {
  369. ptr->RDC_CTL |= RDC_RDC_CTL_EXC_EN_MASK;
  370. }
  371. /**
  372. * @brief Disable rdc excite signal
  373. *
  374. * @param ptr @ref RDC_Type base
  375. */
  376. static inline void rdc_exc_disable(RDC_Type *ptr)
  377. {
  378. ptr->RDC_CTL &= ~RDC_RDC_CTL_EXC_EN_MASK;
  379. }
  380. /**
  381. * @brief Software triggered excitation signal output
  382. *
  383. * @param ptr @ref RDC_Type base
  384. */
  385. static inline void rdc_output_trig_sw(RDC_Type *ptr)
  386. {
  387. ptr->RDC_CTL |= RDC_RDC_CTL_EXC_START_MASK;
  388. }
  389. /**
  390. * @brief Get I-phase maximum
  391. *
  392. * @param ptr @ref RDC_Type base
  393. * @retval - other max value
  394. * - -1 illegal data
  395. */
  396. int32_t rdc_get_i_maxval(RDC_Type *ptr);
  397. /**
  398. * @brief Clear Maximum
  399. *
  400. * @param ptr @ref RDC_Type base
  401. */
  402. static inline void rdc_clear_i_maxval(RDC_Type *ptr)
  403. {
  404. ptr->MAX_I = 0;
  405. }
  406. /**
  407. * @brief Get I-phase minimum
  408. *
  409. * @param ptr @ref RDC_Type base
  410. * @retval - other max value
  411. * - -1 illegal data
  412. */
  413. int32_t rdc_get_i_minval(RDC_Type *ptr);
  414. /**
  415. * @brief Clear I-phase minimum
  416. *
  417. * @param ptr @ref RDC_Type base
  418. */
  419. static inline void rdc_clear_i_minval(RDC_Type *ptr)
  420. {
  421. ptr->MIN_I = 0;
  422. }
  423. /**
  424. * @brief Set Acc sync delay
  425. *
  426. * @param ptr @ref RDC_Type base
  427. * @param chn @ref rdc_input_acc_chn_t
  428. * @param delay delay tick
  429. */
  430. void rdc_set_acc_sync_delay(RDC_Type *ptr, rdc_input_acc_chn_t chn, uint32_t delay);
  431. /**
  432. * @brief Delay bettween the delyed trigger and
  433. * the first pwm pulse in clock cycle
  434. *
  435. * @param ptr @ref RDC_Type base
  436. * @retval delay tick
  437. */
  438. static inline uint32_t rdc_get_sync_output_delay(RDC_Type *ptr)
  439. {
  440. return RDC_SYNC_OUT_CTRL_PWM_OUT_DLY_GET(ptr->SYNC_OUT_CTRL);
  441. }
  442. /**
  443. * @brief Get Q-phase maximum
  444. *
  445. * @param ptr @ref RDC_Type base
  446. * @retval - other max value
  447. * - -1 illegal data
  448. */
  449. int32_t rdc_get_q_maxval(RDC_Type *ptr);
  450. /**
  451. * @brief Clear Q-phase maxval
  452. *
  453. * @param ptr @ref RDC_Type base
  454. */
  455. static inline void rdc_clear_q_maxval(RDC_Type *ptr)
  456. {
  457. ptr->MAX_Q = 0;
  458. }
  459. /**
  460. * @brief Get Q-phase Minval
  461. *
  462. * @param ptr @ref RDC_Type base
  463. * @retval - other max value
  464. * - -1 illegal data
  465. */
  466. int32_t rdc_get_q_minval(RDC_Type *ptr);
  467. /**
  468. * @brief Clear Q-phase Minval
  469. *
  470. * @param ptr @ref RDC_Type base
  471. */
  472. static inline void rdc_clear_q_minval(RDC_Type *ptr)
  473. {
  474. ptr->MIN_Q = 0;
  475. }
  476. /**
  477. * @brief The offset setting for edge detection of the i_channel or q_channel
  478. *
  479. * @param ptr @ref RDC_Type base
  480. * @param chn @ref rdc_input_acc_chn_t
  481. * @param offset offset value
  482. */
  483. void rdc_set_edge_detection_offset(RDC_Type *ptr, rdc_input_acc_chn_t chn, int32_t offset);
  484. /**
  485. * @brief RDC set accumulate configuration
  486. *
  487. * @param ptr @ref RDC_Type base
  488. * @param cfg @ref rdc_acc_cfg_t
  489. */
  490. void rdc_set_acc_config(RDC_Type *ptr, rdc_acc_cfg_t *cfg);
  491. /**
  492. * @brief Get delay in clock cycle between excitation synchrnous signal and rising edge of i_channel data
  493. *
  494. * @param ptr @ref RDC_Type base
  495. * @retval clock cycle
  496. */
  497. static inline uint32_t rdc_get_rise_delay_i(RDC_Type *ptr)
  498. {
  499. return RDC_RISE_DELAY_I_RISE_DELAY_GET(ptr->RISE_DELAY_I);
  500. }
  501. /**
  502. * @brief Get delay in clock cycle between excitation synchrnous signal and fall edge of i_channel data
  503. *
  504. * @param ptr @ref RDC_Type base
  505. * @retval clock cycle
  506. */
  507. static inline uint32_t rdc_get_fall_delay_i(RDC_Type *ptr)
  508. {
  509. return RDC_FALL_DELAY_I_FALL_DELAY_GET(ptr->FALL_DELAY_I);
  510. }
  511. /**
  512. * @brief Get sample value on rising edge of rectify signal
  513. *
  514. * @param ptr @ref RDC_Type base
  515. * @retval clock cycle
  516. */
  517. static inline uint32_t rdc_get_sample_rise_i(RDC_Type *ptr)
  518. {
  519. return RDC_SAMPLE_RISE_I_VALUE_GET(ptr->SAMPLE_RISE_I);
  520. }
  521. /**
  522. * @brief Get sample value on falling edge of rectify signal
  523. *
  524. * @param ptr @ref RDC_Type base
  525. * @retval clock cycle
  526. */
  527. static inline uint32_t rdc_get_sample_fall_i(RDC_Type *ptr)
  528. {
  529. return RDC_SAMPLE_FALL_I_VALUE_GET(ptr->SAMPLE_FALL_I);
  530. }
  531. /**
  532. * @brief Get sample number during the positive of rectify signal
  533. *
  534. * @param ptr @ref RDC_Type base
  535. * @retval counter
  536. */
  537. static inline uint32_t rdc_get_acc_cnt_positive_i(RDC_Type *ptr)
  538. {
  539. return RDC_ACC_CNT_I_CNT_POS_GET(ptr->ACC_CNT_I);
  540. }
  541. /**
  542. * @brief Get sample number during the negtive of rectify signal
  543. *
  544. * @param ptr @ref RDC_Type base
  545. * @retval counter
  546. */
  547. static inline uint32_t rdc_get_acc_cnt_negative_i(RDC_Type *ptr)
  548. {
  549. return RDC_ACC_CNT_I_CNT_POS_GET(ptr->ACC_CNT_I);
  550. }
  551. /**
  552. * @brief Get Negative sample counter during positive rectify signal
  553. *
  554. * @param ptr @ref RDC_Type base
  555. * @retval counter
  556. */
  557. static inline uint32_t rdc_get_sign_cnt_poitive_i(RDC_Type *ptr)
  558. {
  559. return RDC_SIGN_CNT_I_CNT_POS_GET(ptr->SIGN_CNT_I);
  560. }
  561. /**
  562. * @brief Get Positive sample counter during negative rectify signal
  563. *
  564. * @param ptr @ref RDC_Type base
  565. * @retval counter
  566. */
  567. static inline uint32_t rdc_get_sign_cnt_negative_i(RDC_Type *ptr)
  568. {
  569. return RDC_SIGN_CNT_I_CNT_NEG_GET(ptr->SIGN_CNT_I);
  570. }
  571. /**
  572. * @brief Get delay in clock cycle between excitation synchrnous signal and rising edge of q_channel data
  573. *
  574. * @param ptr @ref RDC_Type base
  575. * @retval cycles
  576. */
  577. static inline uint32_t rdc_get_rise_delay_q(RDC_Type *ptr)
  578. {
  579. return RDC_RISE_DELAY_Q_RISE_DELAY_GET(ptr->RISE_DELAY_Q);
  580. }
  581. /**
  582. * @brief Get delay in clock cycle between excitation synchrnous signal and falling edge of q_channel data
  583. *
  584. * @param ptr @ref RDC_Type base
  585. * @retval cycles
  586. */
  587. static inline uint32_t rdc_get_fall_delay_q(RDC_Type *ptr)
  588. {
  589. return RDC_FALL_DELAY_Q_FALL_DELAY_GET(ptr->FALL_DELAY_Q);
  590. }
  591. /**
  592. * @brief Get q channel sample value on rising edge of rectify signal
  593. *
  594. * @param ptr @ref RDC_Type base
  595. * @retval cycles
  596. */
  597. static inline uint32_t rdc_get_sample_rise_q(RDC_Type *ptr)
  598. {
  599. return RDC_SAMPLE_RISE_Q_VALUE_GET(ptr->SAMPLE_RISE_Q);
  600. }
  601. /**
  602. * @brief Get q channel sample value on falling edge of rectify signal
  603. *
  604. * @param ptr @ref RDC_Type base
  605. * @retval cycles
  606. */
  607. static inline uint32_t rdc_get_sample_fall_q(RDC_Type *ptr)
  608. {
  609. return RDC_SAMPLE_FALL_Q_VALUE_GET(ptr->SAMPLE_FALL_Q);
  610. }
  611. /**
  612. * @brief Get q channel sample number during the positive of rectify signal
  613. *
  614. * @param ptr @ref RDC_Type base
  615. * @retval number
  616. */
  617. static inline uint32_t rdc_get_acc_cnt_positive_q(RDC_Type *ptr)
  618. {
  619. return RDC_ACC_CNT_Q_CNT_POS_GET(ptr->ACC_CNT_Q);
  620. }
  621. /**
  622. * @brief Get q channel sample number during the negtive of rectify signal
  623. *
  624. * @param ptr @ref RDC_Type base
  625. * @retval number
  626. */
  627. static inline uint32_t rdc_get_acc_cnt_negative_q(RDC_Type *ptr)
  628. {
  629. return RDC_ACC_CNT_Q_CNT_POS_GET(ptr->ACC_CNT_Q);
  630. }
  631. /**
  632. * @brief Get q channel negative sample counter during positive rectify signal
  633. *
  634. * @param ptr @ref RDC_Type base
  635. * @retval counter
  636. */
  637. static inline uint32_t rdc_get_sign_cnt_poitive_q(RDC_Type *ptr)
  638. {
  639. return RDC_SIGN_CNT_Q_CNT_POS_GET(ptr->SIGN_CNT_Q);
  640. }
  641. /**
  642. * @brief Get q channel sample number during the negtive of rectify signal
  643. *
  644. * @param ptr @ref RDC_Type base
  645. * @retval counter
  646. */
  647. static inline uint32_t rdc_get_sign_cnt_negative_q(RDC_Type *ptr)
  648. {
  649. return RDC_SIGN_CNT_Q_CNT_NEG_GET(ptr->SIGN_CNT_Q);
  650. }
  651. /**
  652. * @brief Enables configured interrupts
  653. *
  654. * @param ptr @ref RDC_Type base
  655. * @param status @ref rdc_interrupt_stat_t
  656. */
  657. static inline void rdc_interrupt_config(RDC_Type *ptr, uint32_t status)
  658. {
  659. ptr->INT_EN |= status;
  660. }
  661. /**
  662. * @brief Clear interrupts configured
  663. *
  664. * @param ptr @ref RDC_Type base
  665. * @param status @ref rdc_interrupt_stat_t
  666. */
  667. static inline void rdc_interrupt_reset_config(RDC_Type *ptr, uint32_t status)
  668. {
  669. ptr->INT_EN &= ~status;
  670. }
  671. /**
  672. * @brief Enable rdc interrupt
  673. *
  674. * @param ptr @ref RDC_Type base
  675. */
  676. static inline void rdc_interrupt_enable(RDC_Type *ptr)
  677. {
  678. ptr->INT_EN |= RDC_INT_EN_INT_EN_MASK;
  679. }
  680. /**
  681. * @brief Disable rdc interrupt
  682. *
  683. * @param ptr @ref RDC_Type base
  684. */
  685. static inline void rdc_interrupt_disable(RDC_Type *ptr)
  686. {
  687. ptr->INT_EN &= ~RDC_INT_EN_INT_EN_MASK;
  688. }
  689. /**
  690. * @brief Clear interrupt flag bits
  691. *
  692. * @param ptr @ref RDC_Type base
  693. * @param mask @ref rdc_interrupt_stat_t
  694. */
  695. static inline void rdc_interrupt_clear_flag_bits(RDC_Type *ptr, uint32_t mask)
  696. {
  697. ptr->ADC_INT_STATE &= mask;
  698. }
  699. /**
  700. * @brief Get the interrupt status object
  701. *
  702. * @param ptr @ref RDC_Type base
  703. * @return @ref rdc_interrupt_stat_t
  704. */
  705. static inline uint32_t get_interrupt_status(RDC_Type *ptr)
  706. {
  707. return ptr->ADC_INT_STATE;
  708. }
  709. /** @} */
  710. #ifdef __cplusplus
  711. }
  712. #endif
  713. /** @} */
  714. #endif /* HPM_ADC12_DRV_H */