hpm_qeov2_drv.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_QEOV2_DRV_H
  8. #define HPM_QEOV2_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_qeov2_regs.h"
  11. /**
  12. * @brief QEOV2 driver APIs
  13. * @defgroup qeov2_interface QEOV2 driver APIs
  14. * @ingroup qeov2_interfaces
  15. * @{
  16. */
  17. typedef enum {
  18. qeo_wave_cosine = 0,
  19. qeo_wave_saddle = 1,
  20. qeo_wave_abs_cosine = 2,
  21. qeo_wave_saw = 3,
  22. } qeo_wave_type_t;
  23. typedef enum {
  24. qeo_saddle_standard = 0,
  25. qeo_saddle_triple
  26. } qeo_saddle_type_t;
  27. typedef enum {
  28. qeo_wave_above_max_limit_max_val = 0,
  29. qeo_wave_above_max_limit_zero = 1,
  30. qeo_wave_above_max_limit_max_level0_val = 2,
  31. qeo_wave_high_area_limit_max_val = 0,
  32. qeo_wave_high_area_limit_max_level0_val = 1,
  33. qeo_wave_low_area_limit_zero = 0,
  34. qeo_wave_low_area_limit_min_level1_val = 1,
  35. qeo_wave_below_min_limit_zero = 0,
  36. qeo_wave_below_min_limit_max_val = 1,
  37. qeo_wave_below_min_limit_min_level1_val = 2,
  38. } qeo_wave_limit_t;
  39. typedef struct {
  40. qeo_wave_limit_t above_max_limit;
  41. qeo_wave_limit_t high_area0_limit;
  42. qeo_wave_limit_t high_area1_limit;
  43. qeo_wave_limit_t low_area0_limit;
  44. qeo_wave_limit_t low_area1_limit;
  45. qeo_wave_limit_t below_min_limit;
  46. } qeo_wave_limit_config_t;
  47. typedef struct {
  48. qeo_wave_limit_config_t wave0;
  49. qeo_wave_limit_config_t wave1;
  50. qeo_wave_limit_config_t wave2;
  51. bool dq_valid_trig_enable; /*!< DQ valid trigger calculate */
  52. bool pos_valid_trig_enable; /*!< Position valid trigger calculate */
  53. bool vd_vq_inject_enable;
  54. bool vd_vq_from_sw; /*!< true: DQ from register; false: DQ from CLC module */
  55. qeo_wave_type_t wave_type;
  56. qeo_saddle_type_t saddle_type;
  57. } qeo_wave_mode_t;
  58. typedef enum {
  59. qeo_abz_output_abz = 0, /*!< A and B are orthogonal signals, Z is zero pulse */
  60. qeo_abz_output_pulse_revise = 1, /*!< A is speed pulse, B is directional pulse, Z not used */
  61. qeo_abz_output_up_down = 2, /*!< A is forward pulse, B is reverse pusle, Z not used */
  62. qeo_abz_output_three_phase = 3, /*!< A/B/Z are 3-phase orthogonal pulse */
  63. } qeo_abz_type_t;
  64. typedef enum {
  65. qeo_z_as_zero_signal_mode0 = 0,
  66. qeo_z_as_zero_signal_mode1 = 1,
  67. qeo_z_as_no_output_signal = 2,
  68. qeo_z_as_third_phase_signal = 3,
  69. } qeo_z_pulse_type_t;
  70. typedef struct {
  71. bool z_inv_pol;
  72. bool b_inv_pol;
  73. bool a_inv_pol;
  74. bool enable_wdog;
  75. bool sync_step_position;
  76. bool reverse_align_clk_falling_edge;
  77. qeo_abz_type_t output_type; /*!< @ref qeo_abz_type_t */
  78. } qeo_abz_mode_t;
  79. /*!< zero pusle legth mode */
  80. typedef struct {
  81. uint8_t type;
  82. uint32_t start_line;
  83. uint32_t end_line;
  84. uint8_t start_step;
  85. uint8_t end_step;
  86. uint32_t width;
  87. } qeo_z_output_mode_t;
  88. typedef enum {
  89. qeo_pwm_output_force_0 = 2,
  90. qeo_pwm_output_force_1 = 3,
  91. qeo_pwm_output_not_force = 0,
  92. } qeo_pwm_force_output_t;
  93. typedef enum {
  94. qeo_pwm_safety_output_0 = 0,
  95. qeo_pwm_safety_output_1 = 1,
  96. qeo_pwm_safety_output_highz = 2,
  97. } qeo_pwm_safety_output_t;
  98. typedef struct {
  99. qeo_pwm_force_output_t pwm0_output; /*!< @ref qeo_pwm_force_output_t */
  100. qeo_pwm_force_output_t pwm1_output;
  101. qeo_pwm_force_output_t pwm2_output;
  102. qeo_pwm_force_output_t pwm3_output;
  103. qeo_pwm_force_output_t pwm4_output;
  104. qeo_pwm_force_output_t pwm5_output;
  105. qeo_pwm_force_output_t pwm6_output;
  106. qeo_pwm_force_output_t pwm7_output;
  107. } qeo_pwm_phase_output_table_t;
  108. typedef struct {
  109. qeo_pwm_safety_output_t pwm0_output; /*!< @ref qeo_pwm_safety_output_t */
  110. qeo_pwm_safety_output_t pwm1_output;
  111. qeo_pwm_safety_output_t pwm2_output;
  112. qeo_pwm_safety_output_t pwm3_output;
  113. qeo_pwm_safety_output_t pwm4_output;
  114. qeo_pwm_safety_output_t pwm5_output;
  115. qeo_pwm_safety_output_t pwm6_output;
  116. qeo_pwm_safety_output_t pwm7_output;
  117. } qeo_pwm_safety_output_table_t;
  118. typedef struct {
  119. uint8_t phase_num;
  120. bool shield_hardware_trig_safety;
  121. bool revise_pairs_output;
  122. } qeo_pwm_mode_t;
  123. #ifdef __cplusplus
  124. extern "C" {
  125. #endif
  126. /* WAVE API */
  127. /**
  128. * @brief QEO set resolution lines for wave mode
  129. * @param [in] base QEO base address
  130. * @param [in] lines resolution lines
  131. */
  132. static inline void qeo_wave_set_resolution_lines(QEOV2_Type *base, uint32_t lines)
  133. {
  134. base->WAVE.RESOLUTION = QEOV2_WAVE_RESOLUTION_LINES_SET(lines);
  135. }
  136. /**
  137. * @brief QEO set output type for wave mode
  138. * @param [in] base QEO base address
  139. * @param [in] type qeo_wave_type_t
  140. */
  141. static inline void qeo_wave_set_output_type(QEOV2_Type *base, qeo_wave_type_t type)
  142. {
  143. base->WAVE.MODE = (base->WAVE.MODE & ~QEOV2_WAVE_MODE_WAVES_OUTPUT_TYPE_MASK) | QEOV2_WAVE_MODE_WAVES_OUTPUT_TYPE_SET(type);
  144. }
  145. /**
  146. * @brief QEO set saddle type for wave mode
  147. * @param [in] base QEO base address
  148. * @param [in] standard true for standard saddle, false for triangular wave stacking
  149. */
  150. static inline void qeo_wave_set_saddle_type(QEOV2_Type *base, bool standard)
  151. {
  152. if (standard) {
  153. base->WAVE.MODE &= ~QEOV2_WAVE_MODE_SADDLE_TYPE_MASK;
  154. } else {
  155. base->WAVE.MODE |= QEOV2_WAVE_MODE_SADDLE_TYPE_MASK;
  156. }
  157. }
  158. /**
  159. * @brief QEO set phase shift for wave mode
  160. * @param [in] base QEO base address
  161. * @param [in] index wave index(0/1/2)
  162. * @param [in] angle left shift angle
  163. */
  164. static inline void qeo_wave_set_phase_shift(QEOV2_Type *base, uint8_t index, double angle)
  165. {
  166. assert((angle >= 0) && (angle <= 360));
  167. uint32_t val = (uint32_t)(angle * 0x100000000UL / 360);
  168. base->WAVE.PHASE_SHIFT[index] = QEOV2_WAVE_PHASE_SHIFT_VAL_SET(val);
  169. }
  170. /**
  171. * @brief QEO enable vd vq inject and select vq vq source for wave mode
  172. * @param [in] base QEO base address
  173. * @param [in] from_sw false for vd vq data from clc module, true for vd vq from software inject register
  174. */
  175. static inline void qeo_wave_enable_vd_vq_inject(QEOV2_Type *base, bool from_sw)
  176. {
  177. if (from_sw) {
  178. base->WAVE.MODE |= QEOV2_WAVE_MODE_VD_VQ_SEL_MASK;
  179. } else {
  180. base->WAVE.MODE &= ~QEOV2_WAVE_MODE_VD_VQ_SEL_MASK;
  181. }
  182. base->WAVE.MODE |= QEOV2_WAVE_MODE_EN_WAVE_VD_VQ_INJECT_MASK;
  183. }
  184. /**
  185. * @brief QEO disable vd vq inject for wave mode
  186. * @param [in] base QEO base address
  187. */
  188. static inline void qeo_wave_disable_vd_vq_inject(QEOV2_Type *base)
  189. {
  190. base->WAVE.MODE &= ~QEOV2_WAVE_MODE_EN_WAVE_VD_VQ_INJECT_MASK;
  191. }
  192. /**
  193. * @brief QEO config vd vq value when vd vq from register
  194. * @param [in] base QEO base address
  195. * @param [in] vd_val vd value
  196. * @param [in] vq_val vq value
  197. */
  198. static inline void qeo_wave_config_vd_vq_value(QEOV2_Type *base, int32_t vd_val, int32_t vq_val)
  199. {
  200. base->WAVE.VD_INJECT = QEOV2_WAVE_VD_INJECT_VD_VAL_SET(vd_val);
  201. base->WAVE.VQ_INJECT = QEOV2_WAVE_VQ_INJECT_VQ_VAL_SET(vq_val);
  202. }
  203. /**
  204. * @brief QEO load vd vq inject value when vd vq from register
  205. * @param [in] base QEO base address
  206. */
  207. static inline void qeo_wave_load_vd_vq(QEOV2_Type *base)
  208. {
  209. base->WAVE.VD_VQ_LOAD = QEOV2_WAVE_VD_VQ_LOAD_LOAD_MASK;
  210. }
  211. /**
  212. * @brief QEO enable amplitude for wave mode
  213. * @param [in] base QEO base address
  214. * @param [in] index wave index(0/1/2)
  215. * @param [in] amp amplitude value
  216. */
  217. static inline void qeo_wave_enable_amplitude(QEOV2_Type *base, uint8_t index, double amp)
  218. {
  219. assert(amp > 0);
  220. uint32_t val = (uint32_t)(amp * (1U << 12U));
  221. base->WAVE.AMPLITUDE[index] = QEOV2_WAVE_AMPLITUDE_EN_SCAL_MASK | QEOV2_WAVE_AMPLITUDE_AMP_VAL_SET(val);
  222. }
  223. /**
  224. * @brief QEO disable amplitude for wave mode
  225. * @param [in] base QEO base address
  226. * @param [in] index wave index(0/1/2)
  227. */
  228. static inline void qeo_wave_disable_amplitude(QEOV2_Type *base, uint8_t index)
  229. {
  230. base->WAVE.AMPLITUDE[index] &= ~QEOV2_WAVE_AMPLITUDE_EN_SCAL_MASK;
  231. }
  232. /**
  233. * @brief QEO set mid point shift for wave mode
  234. * @param [in] base QEO base address
  235. * @param [in] index wave index(0/1/2)
  236. * @param [in] shift mid point shift value
  237. */
  238. static inline void qeo_wave_set_mid_point_shift(QEOV2_Type *base, uint8_t index, double shift)
  239. {
  240. int32_t val = (int32_t)(shift * (1U << 27U));
  241. base->WAVE.MID_POINT[index] = QEOV2_WAVE_MID_POINT_VAL_SET(val);
  242. }
  243. /**
  244. * @brief QEO set max limmit for wave mode
  245. * @param [in] base QEO base address
  246. * @param [in] index wave index(0/1/2)
  247. * @param [in] limit0 limit0 value
  248. * @param [in] limit1 limit1 value
  249. */
  250. static inline void qeo_wave_set_max_limit(QEOV2_Type *base, uint8_t index, uint32_t limit0, uint32_t limit1)
  251. {
  252. base->WAVE.LIMIT0[index].MAX_LEVEL0 = QEOV2_WAVE_LIMIT0_MAX_LEVEL0_LIMIT_LEVEL0_SET(limit0);
  253. base->WAVE.LIMIT1[index].MAX_LEVEL1 = QEOV2_WAVE_LIMIT1_MAX_LEVEL1_LIMIT_LEVEL1_SET(limit1);
  254. }
  255. /**
  256. * @brief QEO set min limmit for wave mode
  257. * @param [in] base QEO base address
  258. * @param [in] index wave index(0/1/2)
  259. * @param [in] limit0 limit0 value
  260. * @param [in] limit1 limit1 value
  261. */
  262. static inline void qeo_wave_set_min_limit(QEOV2_Type *base, uint8_t index, uint32_t limit0, uint32_t limit1)
  263. {
  264. base->WAVE.LIMIT0[index].MIN_LEVEL0 = QEOV2_WAVE_LIMIT0_MIN_LEVEL0_LIMIT_LEVEL0_SET(limit0);
  265. base->WAVE.LIMIT1[index].MIN_LEVEL1 = QEOV2_WAVE_LIMIT1_MIN_LEVEL1_LIMIT_LEVEL1_SET(limit1);
  266. }
  267. /**
  268. * @brief QEO set deadzone shift for wave mode
  269. * @param [in] base QEO base address
  270. * @param [in] index wave index(0/1/2)
  271. * @param [in] shift deadzone shift value
  272. */
  273. static inline void qeo_wave_set_deadzone_shift(QEOV2_Type *base, uint8_t index, int32_t shift)
  274. {
  275. base->WAVE.DEADZONE_SHIFT[index] = QEOV2_WAVE_DEADZONE_SHIFT_VAL_SET(shift);
  276. }
  277. /**
  278. * @brief QEO wave set pwm cycle
  279. *
  280. * @note when cycle is 0, output value is 0 - 0xFFFFFFFF, others, output value is 0 - cycle
  281. *
  282. * @param [in] base QEO base address
  283. * @param [in] cycle pwm period cycle
  284. */
  285. static inline void qeo_wave_set_pwm_cycle(QEOV2_Type *base, uint32_t cycle)
  286. {
  287. base->WAVE.PWM_CYCLE = QEOV2_WAVE_PWM_CYCLE_VAL_SET(cycle);
  288. }
  289. /**
  290. * @brief QEO get wave output value
  291. * @param [in] base QEO base address
  292. * @param [in] index wave index(0/1/2)
  293. * @retval wave output value
  294. */
  295. static inline uint32_t qeo_get_wave_output_val(QEOV2_Type *base, uint8_t index)
  296. {
  297. if (index == 0) {
  298. return QEOV2_DEBUG0_VALUE_DAC0_GET(base->DEBUG0);
  299. } else if (index == 1) {
  300. return QEOV2_DEBUG4_VALUE_DAC1_GET(base->DEBUG4);
  301. } else if (index == 2) {
  302. return QEOV2_DEBUG5_VALUE_DAC2_GET(base->DEBUG5);
  303. }
  304. return 0;
  305. }
  306. /**
  307. * @brief QEO wave get defalut mode config
  308. * @param [in] base QEO base address
  309. * @param [in] config qeo_wave_mode_t
  310. */
  311. void qeo_wave_get_default_mode_config(QEOV2_Type *base, qeo_wave_mode_t *config);
  312. /**
  313. * @brief QEO wave config mode
  314. * @param [in] base QEO base address
  315. * @param [in] config qeo_wave_mode_t
  316. */
  317. void qeo_wave_config_mode(QEOV2_Type *base, qeo_wave_mode_t *config);
  318. /* ABZ API */
  319. /**
  320. * @brief QEO set resolution lines for ABZ mode
  321. * @param [in] base QEO base address
  322. * @param [in] lines resolution lines
  323. */
  324. static inline void qeo_abz_set_resolution_lines(QEOV2_Type *base, uint32_t lines)
  325. {
  326. base->ABZ.RESOLUTION = QEOV2_ABZ_RESOLUTION_LINES_SET(lines);
  327. }
  328. /**
  329. * @brief QEO set phase shift for three phase output mode
  330. * @param [in] base QEO base address
  331. * @param [in] index ABZ index(0/1/2)
  332. * @param [in] angle left shift angle
  333. */
  334. static inline void qeo_abz_set_phase_shift(QEOV2_Type *base, uint8_t index, double angle)
  335. {
  336. assert((angle >= 0) && (angle <= 360));
  337. uint32_t val = (uint32_t)(angle * 0x100000000U / 360);
  338. base->ABZ.PHASE_SHIFT[index] = QEOV2_ABZ_PHASE_SHIFT_VAL_SET(val);
  339. }
  340. /**
  341. * @brief QEO set offset for output signal in ABZ mode
  342. * @param [in] base QEO base address
  343. * @param [in] physical_angle physical angle
  344. */
  345. static inline void qeo_abz_set_offset(QEOV2_Type *base, double physical_angle)
  346. {
  347. assert((physical_angle >= 0) && (physical_angle <= 360));
  348. uint32_t val = (uint32_t)(physical_angle * 0x100000000U / 360);
  349. base->ABZ.OVERALL_OFFSET = QEOV2_ABZ_OVERALL_OFFSET_VAL_SET(val);
  350. }
  351. /**
  352. * @brief QEO set max frequency for ABZ mode
  353. * @param [in] base QEO base address
  354. * @param [in] src_freq QEO(MOTO system) frequency
  355. * @param [in] freq abz signal frequency (A pulse frequency)
  356. * @retval status_success or status_invalid_argument
  357. */
  358. hpm_stat_t qeo_abz_set_max_frequency(QEOV2_Type *base, uint32_t src_freq, uint32_t freq);
  359. /**
  360. * @brief QEO set wdog frequency for ABZ mode
  361. * @param [in] base QEO base address
  362. * @param [in] src_freq QEO(MOTO system) frequency
  363. * @param [in] freq wdog frequency
  364. * @retval status_success or status_invalid_argument
  365. */
  366. hpm_stat_t qeo_abz_set_wdog_frequency(QEOV2_Type *base, uint32_t src_freq, uint32_t freq);
  367. /**
  368. * @brief QEO disable wdog for ABZ mode
  369. * @param [in] base QEO base address
  370. */
  371. static inline void qeo_abz_disable_wdog(QEOV2_Type *base)
  372. {
  373. base->ABZ.MODE &= ~QEOV2_ABZ_MODE_EN_WDOG_MASK;
  374. }
  375. /**
  376. * @brief QEO config reverse edge for ABZ mode
  377. * @param [in] base QEO base address
  378. * @param [in] speed_pulse_negedge true for reverse edge point speed pulse's negedge
  379. * false for reverse edge point between speed pulse's posedge and negedge, min period dedicated by the num line_width
  380. *
  381. * @note take effect when ABZ work on qeo_abz_output_pulse_revise mode
  382. */
  383. static inline void qeo_abz_config_reverse_edge(QEOV2_Type *base, bool speed_pulse_negedge)
  384. {
  385. if (speed_pulse_negedge) {
  386. base->ABZ.MODE |= QEOV2_ABZ_MODE_REVERSE_EDGE_TYPE_MASK;
  387. } else {
  388. base->ABZ.MODE &= ~QEOV2_ABZ_MODE_REVERSE_EDGE_TYPE_MASK;
  389. }
  390. }
  391. /**
  392. * @brief QEO ABZ get default mode config
  393. * @param [in] base QEO base address
  394. * @param [in] config qeo_abz_mode_t
  395. */
  396. void qeo_abz_get_default_mode_config(QEOV2_Type *base, qeo_abz_mode_t *config);
  397. /**
  398. * @brief QEO ABZ config mode
  399. * @param [in] base QEO base address
  400. * @param [in] config qeo_abz_mode_t
  401. */
  402. void qeo_abz_config_mode(QEOV2_Type *base, qeo_abz_mode_t *config);
  403. /**
  404. * @brief QEO ABZ mode enable output
  405. * @param [in] base QEO base address
  406. */
  407. static inline void qeo_abz_enable_output(QEOV2_Type *base)
  408. {
  409. base->ABZ.MODE |= QEOV2_ABZ_MODE_ABZ_OUTPUT_ENABLE_MASK;
  410. }
  411. /**
  412. * @brief QEO ABZ mode disable output
  413. * @param [in] base QEO base address
  414. */
  415. static inline void qeo_abz_disable_output(QEOV2_Type *base)
  416. {
  417. base->ABZ.MODE &= ~QEOV2_ABZ_MODE_ABZ_OUTPUT_ENABLE_MASK;
  418. }
  419. /**
  420. * @brief QEO ABZ mode enable and configure position sync mode
  421. * @param [in] base QEO base address
  422. * @param [in] sync_identical_pos true: sync identical posistion; false: sync step of position
  423. */
  424. static inline void qeo_abz_enable_position_sync(QEOV2_Type *base, bool sync_identical_pos)
  425. {
  426. if (sync_identical_pos) {
  427. base->ABZ.MODE |= QEOV2_ABZ_MODE_POSITION_SYNC_MODE_MASK;
  428. } else {
  429. base->ABZ.MODE &= ~QEOV2_ABZ_MODE_POSITION_SYNC_MODE_MASK;
  430. }
  431. base->ABZ.POSTION_SYNC = QEOV2_ABZ_POSTION_SYNC_POSTION_MASK;
  432. }
  433. /**
  434. * @brief QEO ABZ mode get default zero pulse output mode
  435. * @param [in] base QEO base address
  436. * @param [out] mode qeo_z_output_mode_t
  437. */
  438. void qeo_abz_get_default_z_output_mode(QEOV2_Type *base, qeo_z_output_mode_t *mode);
  439. /**
  440. * @brief QEO ABZ mode configure zero pulse output mode
  441. * @param [in] base QEO base address
  442. * @param [in] mode qeo_z_output_mode_t
  443. */
  444. void qeo_abz_config_z_output_mode(QEOV2_Type *base, qeo_z_output_mode_t *mode);
  445. /* PWM API */
  446. /**
  447. * @brief QEO set resolution lines for PWM mode
  448. * @param [in] base QEO base address
  449. * @param [in] lines resolution lines
  450. */
  451. static inline void qeo_pwm_set_resolution_lines(QEOV2_Type *base, uint32_t lines)
  452. {
  453. base->PWM.RESOLUTION = QEOV2_PWM_RESOLUTION_LINES_SET(lines);
  454. }
  455. /**
  456. * @brief QEO set phase shift for PWM mode
  457. * @param [in] base QEO base address
  458. * @param [in] index PWM index(0/1/2/3)
  459. * @param [in] angle left shift angle
  460. */
  461. static inline void qeo_pwm_set_phase_shift(QEOV2_Type *base, uint8_t index, double angle)
  462. {
  463. assert((angle >= 0) && (angle <= 360));
  464. uint32_t val = (uint32_t)(angle * 0x1000010000U / 360);
  465. base->PWM.PHASE_SHIFT[index] = QEOV2_PWM_PHASE_SHIFT_VAL_SET(val);
  466. }
  467. /**
  468. * @brief QEO PWM mode enable output
  469. * @param [in] base QEO base address
  470. */
  471. static inline void qeo_pwm_enable_output(QEOV2_Type *base)
  472. {
  473. base->PWM.MODE |= QEOV2_PWM_MODE_ENABLE_PWM_MASK;
  474. }
  475. /**
  476. * @brief QEO PWM mode disable output
  477. * @param [in] base QEO base address
  478. */
  479. static inline void qeo_pwm_disable_output(QEOV2_Type *base)
  480. {
  481. base->PWM.MODE &= ~QEOV2_PWM_MODE_ENABLE_PWM_MASK;
  482. }
  483. /**
  484. * @brief QEO PWM check if it is triggered by hardware to enter safety mode
  485. *
  486. * @note This bit is only valid if the hardware trigger source has not been cleared
  487. *
  488. * @param [in] base QEO base address
  489. * @retval true or false
  490. */
  491. static inline bool qeo_pwm_check_hardware_trig_safety(QEOV2_Type *base)
  492. {
  493. return ((base->STATUS & QEOV2_STATUS_PWM_SAFETY_MASK) != 0) ? true : false;
  494. }
  495. /**
  496. * @brief QEO PWM select phase table
  497. * @param [in] base QEO base address
  498. * @param [in] positive true for using positive phase table, false for using negative phase table
  499. */
  500. static inline void qeo_pwm_select_phase_table(QEOV2_Type *base, bool positive)
  501. {
  502. if (positive) {
  503. base->PWM.MODE &= ~QEOV2_PWM_MODE_REVISE_UP_DN_MASK;
  504. } else {
  505. base->PWM.MODE |= QEOV2_PWM_MODE_REVISE_UP_DN_MASK;
  506. }
  507. }
  508. /**
  509. * @brief QEO PWM enter safety mode by software
  510. *
  511. * @note call qeo_pwm_software_exit_safety to exit safety mode
  512. *
  513. * @param [in] base QEO base address
  514. */
  515. static inline void qeo_pwm_software_enter_safety(QEOV2_Type *base)
  516. {
  517. base->PWM.MODE |= QEOV2_PWM_MODE_PWM_ENTER_SAFETY_MODE_MASK;
  518. }
  519. /**
  520. * @brief QEO PWM exit safety mode by software
  521. * @param [in] base QEO base address
  522. */
  523. static inline void qeo_pwm_software_exit_safety(QEOV2_Type *base)
  524. {
  525. base->PWM.MODE &= ~QEOV2_PWM_MODE_PWM_ENTER_SAFETY_MODE_MASK;
  526. }
  527. /**
  528. * @brief QEO PWM get default mode config
  529. * @param [in] base QEO base address
  530. * @param [in] config qeo_pwm_mode_t
  531. */
  532. void qeo_pwm_get_default_mode_config(QEOV2_Type *base, qeo_pwm_mode_t *config);
  533. /**
  534. * @brief QEO PWM config mode
  535. * @param [in] base QEO base address
  536. * @param [in] config qeo_pwm_mode_t
  537. */
  538. void qeo_pwm_config_mode(QEOV2_Type *base, qeo_pwm_mode_t *config);
  539. /**
  540. * @brief QEO PWM get default safety table
  541. * @param [in] base QEO base address
  542. * @param [in] table qeo_pwm_safety_output_table_t
  543. */
  544. void qeo_pwm_get_default_safety_table_config(QEOV2_Type *base, qeo_pwm_safety_output_table_t *table);
  545. /**
  546. * @brief QEO PWM get default phase table
  547. * @param [in] base QEO base address
  548. * @param [in] table qeo_pwm_phase_output_table_t
  549. */
  550. void qeo_pwm_get_default_phase_table_config(QEOV2_Type *base, qeo_pwm_phase_output_table_t *table);
  551. /**
  552. * @brief QEO PWM config safety table
  553. * @param [in] base QEO base address
  554. * @param [in] table qeo_pwm_safety_output_table_t
  555. */
  556. void qeo_pwm_config_safety_table(QEOV2_Type *base, qeo_pwm_safety_output_table_t *table);
  557. /**
  558. * @brief QEO PWM onfig phase table
  559. * @param [in] base QEO base address
  560. * @param [in] index phase table index
  561. * @param [in] table qeo_pwm_phase_output_table_t
  562. */
  563. void qeo_pwm_config_phase_table(QEOV2_Type *base, uint8_t index, qeo_pwm_phase_output_table_t *table);
  564. /**
  565. * @brief QEO enable software position inject
  566. * @param [in] base QEO base address
  567. */
  568. static inline void qeo_enable_software_position_inject(QEOV2_Type *base)
  569. {
  570. base->POSTION_SEL |= QEOV2_POSTION_SEL_POSTION_SEL_MASK;
  571. }
  572. /**
  573. * @brief QEO software inject position
  574. * @param [in] base QEO base address
  575. * @param [in] position position value
  576. */
  577. static inline void qeo_software_position_inject(QEOV2_Type *base, uint32_t position)
  578. {
  579. base->POSTION_SOFTWARE = QEOV2_POSTION_SOFTWARE_POSTION_SOFTWAVE_SET(position);
  580. }
  581. /**
  582. * @brief QEO disable software position inject, QEO will using position from hardware
  583. * @param [in] base QEO base address
  584. */
  585. static inline void qeo_disable_software_position_inject(QEOV2_Type *base)
  586. {
  587. base->POSTION_SEL &= ~QEOV2_POSTION_SEL_POSTION_SEL_MASK;
  588. }
  589. /**
  590. * @brief QEO check calculate finish status
  591. * @param [in] base QEO base address
  592. * @retval true or false
  593. */
  594. static inline bool qeo_check_calculate_finish(QEOV2_Type *base)
  595. {
  596. return (QEOV2_DEBUG1_QEO_FINISH_GET(base->DEBUG1) != 0) ? true : false;
  597. }
  598. #ifdef __cplusplus
  599. }
  600. #endif
  601. /**
  602. * @}
  603. */
  604. #endif /* HPM_QEOV2_DRV_H */