hpm_mtg_drv.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_MMC_DRV_H
  8. #define HPM_MMC_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_mtg_regs.h"
  11. /**
  12. * @brief MTG driver APIs
  13. * @defgroup mtg_interface MTG driver APIs
  14. * @ingroup motor_interfaces
  15. * @{
  16. */
  17. /**
  18. * @brief define the struct of mtg lock values
  19. *
  20. */
  21. typedef struct mtg_result {
  22. int32_t rev; /* revolution */
  23. uint32_t pos; /* postion */
  24. int32_t vel; /* velocity */
  25. int32_t acc; /* acceleration */
  26. uint32_t time_stamp; /* time stamp */
  27. } mtg_lock_value_t;
  28. /**
  29. * @brief define the enum of the postion of the observed object
  30. */
  31. typedef enum mtg_evnet_object_postion {
  32. event_source_before_filter = 1 << 0, /* before filter, also treat as input of mtg */
  33. event_source_filter_output = 1 << 1, /* after filter, also treat as input of mtg's time compensation module */
  34. event_source_tra0_output = 1 << 2, /* output of mtg's trajectory predictor0 */
  35. event_source_tra1_output = 1 << 3, /* output of mtg's trajectory predictor1 */
  36. } mtg_evnet_object_postion_t;
  37. /**
  38. * @brief define the enum of the observed object
  39. */
  40. typedef enum mtg_event_object {
  41. event_object_rev_pos = 1, /* location, revolution and position */
  42. event_object_vel = 2, /* velocity */
  43. event_object_acc = 4, /* acceleration */
  44. event_object_pos = 8, /* postion, ignore revolution */
  45. } mtg_event_object_t;
  46. /**
  47. * @brief define the enum of the event detection mode
  48. */
  49. typedef enum mtg_event_mode {
  50. event_mode_across = 1, /* across mode, change from greater than to less than, or opposite */
  51. event_mode_hold = 2, /* hold mode, maintain within a range for a period of time */
  52. event_mode_over_protect = 4, /* over protect mode, greater than or less than */
  53. event_mode_time_match = 8, /* time match mode, when the synt's cnt value is equal to the preset */
  54. } mtg_event_mode_t;
  55. /**
  56. * @brief define the enum of the event detection direction
  57. */
  58. typedef enum mtg_event_dir {
  59. event_dir_negative = 0,
  60. event_dir_positive = 1,
  61. event_dir_both = 2,
  62. } mtg_event_dir_t;
  63. /**
  64. * @brief define the enum of the event detection direction calculation mode
  65. */
  66. typedef enum mtg_event_dir_mode {
  67. event_dir_mode_dy = 0, /* use first derivative of object */
  68. event_dir_mode_y1_y0 = 1, /* use difference of current and previous */
  69. } mtg_event_dir_mode_t;
  70. /**
  71. * @brief define the enum of the event detection over protect mode
  72. */
  73. typedef enum mtg_event_over_mode_cmp {
  74. event_over_cmp_mode_smaller = 0,
  75. event_over_cmp_mode_bigger = 1,
  76. } mtg_event_over_mode_cmp_t;
  77. /**
  78. * @brief define the enum of the event trigger number
  79. */
  80. typedef enum mtg_event_trig_num {
  81. event_trig_once = 0, /* event can only be triggered once */
  82. event_trig_repeat = 1, /* event can be triggered multiple times */
  83. } mtg_event_trig_num_t;
  84. /**
  85. * @brief define the struct of the event setup parameter
  86. */
  87. typedef struct mtg_event_param {
  88. bool enable;
  89. bool irq_en; /* enable or disable the event irq */
  90. mtg_event_object_t obj;
  91. mtg_evnet_object_postion_t obj_postion;
  92. mtg_event_mode_t mode;
  93. mtg_event_dir_t dir;
  94. mtg_event_dir_mode_t dir_mode;
  95. mtg_event_over_mode_cmp_t cmp_mode;
  96. mtg_event_trig_num_t trig_num;
  97. /* union struct of event presets registers, different meaning when different event mode */
  98. union {
  99. struct {
  100. uint32_t cross_value_h; /* the high 32bit of cross_value, only need set when object is ${event_object_rev_pos} */
  101. uint32_t cross_value_l; /* the low 32bit of cross_value */
  102. } cross_param;
  103. struct {
  104. uint32_t hold_value_h; /* the high 32bit of hold_value, only need set when object is ${event_object_rev_pos} */
  105. uint32_t hold_value_l; /* the low 32bit of hold_value */
  106. uint32_t error_limit; /* the range is between ${hold value - error_limit} and ${hold value + error_limit} */
  107. uint32_t hold_clock_cnt; /* the event will be triggered when match the hold value and error_limit and last for &{hold_clock_cnt} clocks */
  108. } hold_param;
  109. struct {
  110. uint32_t limit_value_h; /* the high 32bit of limit_value */
  111. uint32_t limit_value_l; /* the low 32bit of limit_value */
  112. } over_protect_param;
  113. struct {
  114. uint32_t clock_count; /* the event will be triggered when synt clock match the value */
  115. } time_param;
  116. uint32_t preset[4];
  117. } preset;
  118. } mtg_event_param_t;
  119. /*
  120. * @brief define the struct of the trajectory predictor limit
  121. */
  122. typedef struct mtg_tra_limit_param {
  123. bool vel_step_limit_en; /* velocity step limit enable, when enable, the velocity variation per clock will be limited by vel_step_max and vel_step_min */
  124. uint32_t vel_step_max; /* velocity step limit value max */
  125. uint32_t vel_step_min; /* velocity step limit value min */
  126. bool pos_step_limit_en; /* postion step limit enable, when enable, the postion variation per clock will be limited by pos_step_max and pos_step_min */
  127. uint32_t pos_step_max; /* postion step limit value max */
  128. uint32_t pos_step_min; /* postion step limit value min */
  129. } mtg_tra_limit_param_t;
  130. /**
  131. * @brief define the enum of the software force one way mode
  132. */
  133. typedef enum mtg_software_force_one_way_mode {
  134. sw_force_negative = 0,
  135. sw_force_positive = 1,
  136. } mtg_software_force_one_way_mode_t;
  137. /**
  138. * @brief define the enum of the hardware force one way mode
  139. */
  140. typedef enum vel_one_way_mode {
  141. bigger_or_eq_zero = 0,
  142. smaller_or_eq_zero = 1,
  143. } vel_one_way_mode_t;
  144. /**
  145. * @brief define the struct of the hardware force one way mode
  146. */
  147. typedef struct mtg_hardware_force_one_way_mode {
  148. uint32_t vel_limit_p;
  149. uint32_t vel_limit_n;
  150. } mtg_hardware_force_one_way_mode_t;
  151. /**
  152. * @brief define the enum of the filter initialization mode
  153. */
  154. typedef enum mtg_filter_rev_init_mode {
  155. rev_init_mode_from_first_input_value = 0, /* the first input value will be used by the mtg filter to initialize the filter */
  156. rev_init_mode_from_register = 1, /* the value in the register will be used by the mtg filter to initialize the filter */
  157. } mtg_filter_rev_init_mode_t;
  158. /**
  159. * @brief define the enum of the filter judge mode
  160. * It affects the judgment conditions for changes in the number of revolution
  161. */
  162. typedef enum mtg_filter_rev_judge_mode {
  163. mtg_rev_judge_mode_new_sub_old = 0,
  164. mtg_rev_judge_mode_encoder_lines = 1,
  165. } mtg_filter_rev_judge_mode_t;
  166. /**
  167. * @brief define the enum of the filter ff mode
  168. */
  169. typedef enum mtg_filter_ff_mode {
  170. mtg_filter_ff_mode_from_register = 0,
  171. mtg_filter_ff_mode_from_input = 1,
  172. } mtg_filter_ff_mode_t;
  173. typedef struct mtg_filter_param {
  174. bool enable; /* filter enable */
  175. bool ff_en; /* filter feedforward enable */
  176. bool init_en; /* filter first value initialization enable */
  177. bool err_bypass_en; /* filter error bypass enable. when difference between filter input and output beyond the limit, filter output will be bypassed */
  178. bool err_init; /* filter error reset enable. when difference between filter input and output beyond the limit, the filter will reset */
  179. bool timeout_en; /* filter timeout enable */
  180. bool err_bypass_i_f_en;
  181. bool err_bypass_f_i_en;
  182. bool multi_err_irq_en;
  183. bool acceleration_en; /* filter acceleration enable. when enable, the filter will output acceleration value */
  184. mtg_filter_rev_init_mode_t rev_ini_mode;
  185. mtg_filter_rev_judge_mode_t rev_judge_mode;
  186. mtg_filter_ff_mode_t ff_mode;
  187. int32_t rev_init_value; /* the initial value of revolution. only used when init_en == true */
  188. int32_t vel_init_value; /* the initial value of velocity. only used when init_en == true */
  189. int32_t acc_init_value; /* the initial value of acceleration. only used when init_en == true */
  190. uint32_t pos_init_value; /* the initial value of postion. only used when init_en == true */
  191. uint32_t filter_mot_sel;
  192. uint32_t filter_stage_sel;
  193. uint32_t filter_time_constant_tp;
  194. uint32_t filter_time_constant_tz;
  195. uint32_t filter_time_constant_tz_1;
  196. uint32_t filter_zero_tz_sel;
  197. uint32_t filter_gain;
  198. uint32_t filter_stage_shift[2];
  199. uint32_t filter_param_shift;
  200. uint32_t filter_time_shift;
  201. uint32_t filter_ff_shift;
  202. uint32_t filter_error_limit_l;
  203. uint32_t filter_error_limit_h;
  204. } mtg_filter_param_t;
  205. /**
  206. * @brief define the enum of the trajectory predictor time input source
  207. */
  208. typedef enum mtg_time_input_source {
  209. mtg_time_input_from_filter = 1, /* the value in the filter will be used */
  210. mtg_time_input_from_input = 2, /* the value in the input will be used */
  211. } mtg_time_input_source_t;
  212. /**
  213. * @brief define the struct of the trajectory predictor time initialization
  214. */
  215. typedef struct mtg_time_init_param {
  216. bool enable;
  217. uint32_t adjust_value; /* time compensation clocks */
  218. uint8_t index;
  219. mtg_time_input_source_t source;
  220. } mtg_time_init_param_t;
  221. /**
  222. * @brief define the struct of the trajectory predictor timeout
  223. */
  224. typedef struct mtg_timeout_param {
  225. bool enable;
  226. uint32_t timeout_clock_count;
  227. } mtg_timeout_param_t;
  228. /**
  229. * @brief define the enum of the trajectory predictor link event
  230. * link the trigger source and the cmd object, it describes the
  231. * trigger source
  232. */
  233. typedef enum mtg_link_cfg {
  234. link_event0 = 0,
  235. link_event1 = 1,
  236. link_event2 = 2,
  237. link_event3 = 3,
  238. link_hw_trigger = 4,
  239. link_sw_trigger = 5,
  240. link_event_timeout = 6,
  241. } mtg_link_cfg_t;
  242. /**
  243. * @brief define the enum of the trajectory predictor command object
  244. */
  245. typedef enum {
  246. cmd_object_rev = 1 << 0,
  247. cmd_object_pos = 1 << 1,
  248. cmd_object_vel = 1 << 2,
  249. cmd_object_acc = 1 << 3,
  250. cmd_object_jer = 1 << 4,
  251. } mtg_tra_cmd_object_t;
  252. /**
  253. * @brief define the enum of the trajectory predictor command mode
  254. */
  255. typedef enum {
  256. cmd_mode_new_value = 0, /* when cmd exec, the preset value will replace the old value */
  257. cmd_mode_old_delta = 1, /* when cmd exec, the preset value will be added to the old value */
  258. } mtg_link_cmd_mode_t;
  259. /**
  260. * @brief define the struct of the trajectory shift struct
  261. */
  262. typedef struct mtg_tra_shift {
  263. uint8_t jerk_shift;
  264. uint8_t acc_shift;
  265. uint8_t vel_shift;
  266. } mtg_tra_shift_t;
  267. /**
  268. * @brief define the struct of the trajectory predictor command
  269. */
  270. typedef struct mtg_tra_cmd_cfg {
  271. uint8_t index;
  272. uint32_t object; /* cmd object, see ${mtg_tra_cmd_object_t} */
  273. mtg_link_cmd_mode_t mode;
  274. uint32_t rev_preset;
  275. uint32_t pos_preset;
  276. uint32_t vel_preset;
  277. uint32_t acc_preset;
  278. uint32_t jer_preset;
  279. } mtg_tra_cmd_cfg_t;
  280. #ifdef __cplusplus
  281. extern "C" {
  282. #endif
  283. /**
  284. * @brief MTG get trajectory predictor control register value
  285. * @param [in] base - MTG base address
  286. * @param [in] tra_index - trajectory predictor index
  287. * @retval control register value
  288. */
  289. static inline uint32_t mtg_get_tra_control_status(MTG_Type *base, uint8_t tra_index)
  290. {
  291. assert(tra_index < 2);
  292. return base->TRA[tra_index].CONTROL;
  293. }
  294. /**
  295. * @brief MTG get trajectory predictor commond control register value
  296. * @param [in] base - MTG base address
  297. * @param [in] tra_index - trajectory predictor index
  298. * @param [in] cmd_index - trajectory predicotr command index
  299. * @retval control register value
  300. */
  301. static inline uint32_t mtg_get_tra_cmd_control_status(MTG_Type *base, uint8_t tra_index, uint8_t cmd_index)
  302. {
  303. assert((tra_index < 2) && (cmd_index < 4));
  304. return base->TRA[tra_index].CMD[cmd_index].CONTROL;
  305. }
  306. /**
  307. * @brief MTG trigger trajectory predictor lock current values
  308. * @param [in] base - MTG base address
  309. * @param [in] tra_index - trajectory predictor index
  310. */
  311. static inline void mtg_trig_tra_lock(MTG_Type *base, uint8_t tra_index)
  312. {
  313. assert(tra_index < 2);
  314. base->TRA[tra_index].CONTROL |= MTG_TRA_CONTROL_SW_LOCK_SET(1);
  315. }
  316. /**
  317. * @brief MTG clear trajectory predictor lock status
  318. * @param [in] base - MTG base address
  319. * @param [in] tra_index - trajectory predictor index
  320. */
  321. static inline void mtg_clear_tra_lock(MTG_Type *base, uint8_t tra_index)
  322. {
  323. assert(tra_index < 2);
  324. base->TRA[tra_index].CONTROL &= ~MTG_TRA_CONTROL_SW_LOCK_MASK;
  325. }
  326. /**
  327. * @brief MTG get trajectory predictor revolution lock value
  328. * @param [in] base - MTG base address
  329. * @param [in] tra_index - trajectory predictor index
  330. * @retval trajectory predictor revolution value
  331. */
  332. static inline int32_t mtg_get_tra_rev_lock_value(MTG_Type *base, uint8_t tra_index)
  333. {
  334. assert(tra_index < 2);
  335. return base->TRA[tra_index].LOCK_REV;
  336. }
  337. /**
  338. * @brief MTG get trajectory predictor postion lock value
  339. * @param [in] base - MTG base address
  340. * @param [in] tra_index - trajectory predictor index
  341. * @retval trajectory predictor postion value
  342. */
  343. static inline uint32_t mtg_get_tra_pos_lock_value(MTG_Type *base, uint8_t tra_index)
  344. {
  345. assert(tra_index < 2);
  346. return base->TRA[tra_index].LOCK_POS;
  347. }
  348. /**
  349. * @brief MTG get trajectory predictor velocity lock value
  350. * @param [in] base - MTG base address
  351. * @param [in] tra_index - trajectory predictor index
  352. * @retval trajectory predictor velocity value
  353. */
  354. static inline int32_t mtg_get_tra_vel_lock_value(MTG_Type *base, uint8_t tra_index)
  355. {
  356. assert(tra_index < 2);
  357. return base->TRA[tra_index].LOCK_VEL;
  358. }
  359. /**
  360. * @brief MTG get trajectory predictor acceleration lock value
  361. * @param [in] base - MTG base address
  362. * @param [in] tra_index - trajectory predictor index
  363. * @retval trajectory predictor acceleration value
  364. */
  365. static inline int32_t mtg_get_tra_acc_lock_value(MTG_Type *base, uint8_t tra_index)
  366. {
  367. assert(tra_index < 2);
  368. return base->TRA[tra_index].LOCK_ACC;
  369. }
  370. /**
  371. * @brief MTG setup filter error bypass limit
  372. * @param [in] base MTG base address
  373. * @param [in] limit - bypass limit
  374. */
  375. static inline void mtg_filter_set_err_bypass_limit(MTG_Type *base, uint32_t limit)
  376. {
  377. base->FILTER_ERROR_LIMIT_H = limit;
  378. }
  379. /**
  380. * @brief MTG setup hardware switch from bypass status to filter status's limit
  381. * When the difference between input and filter's pos result is smaller than the limit,
  382. * the filter will use the filter's result inside of the input.
  383. * @param [in] base MTG base address
  384. * @param [in] param - filter params
  385. */
  386. static inline void mtg_filter_set_bypass_switch_filter_limit(MTG_Type *base, uint32_t limit)
  387. {
  388. base->FILTER_ERROR_LIMIT_L = limit;
  389. }
  390. /**
  391. * @brief MTG enable filter error bypass
  392. * When difference between input and filter's pos result is bigger than the limit,
  393. * the filter output will be bypass and input will be output to the filter's port.
  394. * @param [in] base MTG base address
  395. * @param [in] limit - bypass limit
  396. */
  397. static inline void mtg_filter_enable_bypass(MTG_Type *base)
  398. {
  399. base->FILTER_CONTROL |= MTG_FILTER_CONTROL_ERR_BYPASS_F_I_EN_SET(1);
  400. base->FILTER_CONTROL |= MTG_FILTER_CONTROL_ERR_BYPASS_EN_SET(1);
  401. }
  402. /**
  403. * @brief MTG disable filter error bypass
  404. * When difference between input and filter's pos result is bigger than the limit,
  405. * the filter output will be bypass and input will be output to the filter's port.
  406. * @param [in] base MTG base address
  407. * @param [in] limit - bypass limit
  408. */
  409. static inline void mtg_filter_disable_bypass(MTG_Type *base)
  410. {
  411. base->FILTER_CONTROL &= ~MTG_FILTER_CONTROL_ERR_BYPASS_F_I_EN_MASK;
  412. base->FILTER_CONTROL &= ~MTG_FILTER_CONTROL_ERR_BYPASS_EN_MASK;
  413. }
  414. /**
  415. * @brief MTG reset filter enable error reset
  416. * @param [in] base MTG base address
  417. */
  418. static inline void mtg_filter_enable_reset_init(MTG_Type *base)
  419. {
  420. base->FILTER_CONTROL |= MTG_FILTER_CONTROL_ERR_INI_SET(1);
  421. }
  422. /**
  423. * @brief MTG reset filter disable error reset
  424. * @param [in] base MTG base address
  425. */
  426. static inline void mtg_filter_disable_reset_init(MTG_Type *base)
  427. {
  428. base->FILTER_CONTROL &= ~MTG_FILTER_CONTROL_ERR_INI_MASK;
  429. }
  430. /**
  431. * @brief MTG enable hardware switch from bypass status to filter status's limit
  432. * When the difference between input and filter's pos result is smaller than the limit,
  433. * the filter will use the filter's result inside of the input.
  434. * The switch result can be defined by reading the switch status register.
  435. * @param [in] base MTG base address
  436. * @param [in] param - filter params
  437. */
  438. static inline void mtg_filter_switch_filter_result(MTG_Type *base)
  439. {
  440. base->FILTER_CONTROL |= MTG_FILTER_CONTROL_ERR_BYPASS_I_F_EN_SET(1);
  441. }
  442. /**
  443. * @brief MTG disable hardware switch from bypass status to filter status's limit
  444. * When the difference between input and filter's pos result is smaller than the limit,
  445. * the filter will use the filter's result inside of the input.
  446. * The switch result can be defined by reading the switch status register.
  447. * @param [in] base MTG base address
  448. * @param [in] param - filter params
  449. */
  450. static inline void mtg_filter_stop_auto_switch_filter_result(MTG_Type *base)
  451. {
  452. base->FILTER_CONTROL &= ~MTG_FILTER_CONTROL_ERR_BYPASS_I_F_EN_MASK;
  453. }
  454. /**
  455. * @brief MTG setup hardware switch from bypass status to filter status's limit
  456. * When the difference between input and filter's pos result is smaller than the limit,
  457. * the filter will use the filter's result inside of the input.
  458. * @param [in] base - MTG base address
  459. * @retval bypass status
  460. */
  461. static inline bool mtg_get_err_bypass_status(MTG_Type *base)
  462. {
  463. return MTG_FILTER_CONTROL_ERR_BYPASS_STATUS_GET(base->FILTER_CONTROL) == 0 ? true : false;
  464. }
  465. /**
  466. * @brief MTG set time0 adjust value
  467. * @param [in] base - MTG base address
  468. * @param [in] value - adjust value
  469. */
  470. static inline void mtg_set_time0_adjust_value(MTG_Type *base, uint32_t value)
  471. {
  472. base->FILTER_TIME0_SW_ADJUST = value;
  473. }
  474. /**
  475. * @brief MTG set time1 adjust value
  476. * @param [in] base - MTG base address
  477. * @param [in] value - adjust value
  478. */
  479. static inline void mtg_set_time1_adjust_value(MTG_Type *base, uint32_t value)
  480. {
  481. base->FILTER_TIME1_SW_ADJUST = value;
  482. }
  483. /**
  484. * @brief MTG set time shift value
  485. * @param [in] base - MTG base address
  486. * @param [in] index - tra index
  487. * @param [in] jer_shift - jerk shift
  488. * @param [in] acc_shift - acceleration shift
  489. * @param [in] vel_shift - velocity shift
  490. */
  491. static inline void mtg_tra_set_shift(MTG_Type *base, uint8_t index, uint8_t jer_shift, uint8_t acc_shift, uint8_t vel_shift)
  492. {
  493. assert(index < 2);
  494. base->TRA[index].SHIFT = MTG_TRA_SHIFT_JER_SHIFT_SET(jer_shift) |
  495. MTG_TRA_SHIFT_ACC_SHIFT_SET(acc_shift) |
  496. MTG_TRA_SHIFT_VEL_SHIFT_SET(vel_shift);
  497. }
  498. /**
  499. * @brief MTG global reset
  500. * @param [in] base - MTG base address
  501. */
  502. static inline void mtg_set_global_reset(MTG_Type *base)
  503. {
  504. base->SW_GLB_RESET = 1;
  505. }
  506. /**
  507. * @brief MTG stop global reset
  508. */
  509. static inline void mtg_stop_global_reset(MTG_Type *base)
  510. {
  511. base->SW_GLB_RESET = 0;
  512. }
  513. /**
  514. * @brief MTG predictor get lock result
  515. * @param [in] base MTG base address
  516. * @param [in] tra_index - trajectory predictor index
  517. * @param [out] para mtg_lock_value_t
  518. */
  519. void mtg_get_tra_lock_result(MTG_Type *base, uint8_t tra_index, mtg_lock_value_t *para);
  520. /**
  521. * @brief MTG setup event params
  522. * @param [in] base MTG base address
  523. * @param [in] event_index - event index
  524. * @param [in] param - event params
  525. * @param [out] setup status
  526. */
  527. hpm_stat_t mtg_setup_event(MTG_Type *base, uint8_t event_index, mtg_event_param_t *param);
  528. /**
  529. * @brief MTG setup trajectory limit params
  530. * @param [in] base MTG base address
  531. * @param [in] tra_index - trajectory index
  532. * @param [in] param - trajectory limit params
  533. * @param [out] setup status
  534. */
  535. hpm_stat_t mtg_setup_tra_limit(MTG_Type *base, uint8_t tra_index, mtg_tra_limit_param_t *param);
  536. /**
  537. * @brief MTG setup trajectory software one_way mode
  538. * @param [in] base MTG base address
  539. * @param [in] tra_index - trajectory index
  540. * @param [in] param - 0:force + , 1:force -
  541. * @param [out] setup status
  542. */
  543. void mtg_setup_tra_software_pos_one_way_mode(MTG_Type *base, uint8_t tra_index, mtg_software_force_one_way_mode_t param);
  544. /**
  545. * @brief MTG setup trajectory hardware one_way mode
  546. * @param [in] base MTG base address
  547. * @param [in] tra_index - trajectory index
  548. * @param [in] param - 0:force + , 1:force -
  549. * @param [out] setup status
  550. */
  551. void mtg_setup_tra_hardware_pos_one_way_mode(MTG_Type *base, uint8_t tra_index, mtg_hardware_force_one_way_mode_t *param);
  552. /**
  553. * @brief MTG disable trajectory postion one_way mode
  554. * @param [in] base MTG base address
  555. * @param [in] tra_index - trajectory index
  556. */
  557. void mtg_disable_tra_pos_one_way_mode(MTG_Type *base, uint8_t tra_index);
  558. /**
  559. * @brief MTG setup trajectory velocity one_way mode
  560. * @param [in] base MTG base address
  561. * @param [in] tra_index - trajectory index
  562. * @param [in] mode - 0:bigger_or_eq_zero , 1:smaller_or_eq_zero
  563. */
  564. void mtg_setup_tra_vel_one_way(MTG_Type *base, uint8_t tra_index, vel_one_way_mode_t mode, bool enable);
  565. /**
  566. * @brief MTG setup filter
  567. * @param [in] base MTG base address
  568. * @param [in] param - filter params
  569. */
  570. void mtg_filter_get_default_filter_stage_param(mtg_filter_param_t *param);
  571. /**
  572. * @brief MTG setup time compensation module
  573. * @param [in] base MTG base address
  574. * @param [in] param - time compensation params
  575. */
  576. void mtg_setup_time(MTG_Type *base, mtg_time_init_param_t *param);
  577. /**
  578. * @brief MTG setup filter
  579. * @param [in] base MTG base address
  580. * @param [in] param - filter params
  581. */
  582. void mtg_setup_filter(MTG_Type *base, mtg_filter_param_t *param);
  583. /**
  584. * @brief MTG setup timeout
  585. * @param [in] base MTG base address
  586. * @param [in] param - timeout params
  587. */
  588. void mtg_setup_timeout(MTG_Type *base, mtg_timeout_param_t *param);
  589. /**
  590. * @brief MTG link trigger source and trajectory command
  591. * @param [in] base MTG base address
  592. * @param [in] tra_index - trajectory index
  593. * @param [in] link_cfg - link config
  594. * @param [in] cmd_cfg - command config
  595. */
  596. void mtg_setup_link_cfg(MTG_Type *base, uint8_t tra_index, mtg_link_cfg_t link_cfg, mtg_tra_cmd_cfg_t *cmd_cfg);
  597. /**
  598. * @brief MTG software trigger trajectory command
  599. * @param [in] base MTG base address
  600. */
  601. void mtg_soft_event_trigger(MTG_Type *base);
  602. /**
  603. * @brief Get default trajectory shift
  604. * @param [out] cfg pointer to the tra shift var
  605. */
  606. void mtg_get_default_tra_shift(mtg_tra_shift_t *cfg);
  607. /**
  608. * @brief Get the event irq status
  609. * @param [in] ptr the mtg base
  610. * @param [in] idx the event index
  611. */
  612. static inline bool mtg_get_irq_status(MTG_Type *ptr, uint8_t idx)
  613. {
  614. return ((MTG_EVENT_CONTROL_EVENT_IRQ_GET(ptr->EVENT[idx].CONTROL) != 0) ? true : false);
  615. }
  616. /**
  617. * @brief Clear the event irq status
  618. * @param [in] ptr the mtg base
  619. * @param [in] idx the event index
  620. */
  621. static inline void mtg_clear_irq_status(MTG_Type *ptr, uint8_t idx)
  622. {
  623. ptr->EVENT[idx].CONTROL |= MTG_EVENT_CONTROL_EVENT_IRQ_MASK;
  624. }
  625. /**
  626. * @brief calculate the vel preset
  627. * @param [in] base MTG base address
  628. * @param [in] clock MTG clock name
  629. * @param [in] tra_index - trajectory index
  630. * @param [in] speed - speed in r/s
  631. */
  632. int32_t mtg_calc_vel_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float speed);
  633. /**
  634. * @brief calculate the acc preset
  635. * @param [in] base MTG base address
  636. * @param [in] clock MTG clock name
  637. * @param [in] tra_index - trajectory index
  638. * @param [in] acc - acc in r/s2
  639. */
  640. int32_t mtg_calc_acc_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float acc);
  641. /**
  642. * @brief MTG link trigger source and trajectory command
  643. * @param [in] base MTG base address
  644. * @param [in] clock MTG clock name
  645. * @param [in] tra_index - trajectory index
  646. * @param [in] jer - jer in r/s3
  647. */
  648. int32_t mtg_calc_jer_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float jer);
  649. #ifdef __cplusplus
  650. }
  651. #endif
  652. /**
  653. * @}
  654. */
  655. #endif /* HPM_MTG_DRV_H */