HPM SDK
HPMicro Software Development Kit
hpm_mtgv2_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_MMC_DRV_H
9 #define HPM_MMC_DRV_H
10 
11 #include "hpm_common.h"
12 #include "hpm_mtgv2_regs.h"
20 typedef enum mtg_irq_enable {
24  irq_event3 = 1 << 3,
26  irq_event2 = 1 << 5,
28  irq_event1 = 1 << 7,
30  irq_event0 = 1 << 9,
31  irq_tra1_lock = 1 << 10,
35  irq_tra1_cmd3 = 1 << 14,
36  irq_tra1_cmd2 = 1 << 15,
37  irq_tra1_cmd1 = 1 << 16,
38  irq_tra1_cmd0 = 1 << 17,
39  irq_tra0_lock = 1 << 18,
43  irq_tra0_cmd3 = 1 << 22,
44  irq_tra0_cmd2 = 1 << 23,
45  irq_tra0_cmd1 = 1 << 24,
46  irq_tra0_cmd0 = 1 << 25,
47  irq_f_i_irq = 1 << 26,
48  irq_i_f_irq0 = 1 << 27,
49 
51 
56 typedef struct mtg_result {
57  int32_t rev; /* revolution */
58  uint32_t pos; /* postion */
59  int32_t vel; /* velocity */
60  int32_t acc; /* acceleration */
61  uint32_t time_stamp; /* time stamp */
63 
68  event_source_before_filter = 1 << 0, /* before filter, also treat as input of mtg */
69  event_source_filter_output = 1 << 1, /* after filter, also treat as input of mtg's time compensation module */
70  event_source_tra0_output = 1 << 2, /* output of mtg's trajectory predictor0 */
71  event_source_tra1_output = 1 << 3, /* output of mtg's trajectory predictor1 */
73 
77 typedef enum mtg_event_object {
78  event_object_rev_pos = 1, /* location, revolution and position */
79  event_object_vel = 2, /* velocity */
80  event_object_acc = 4, /* acceleration */
81  event_object_pos = 8, /* postion, ignore revolution */
83 
87 typedef enum mtg_event_mode {
88  event_mode_across = 1, /* across mode, change from greater than to less than, or opposite */
89  event_mode_hold = 2, /* hold mode, maintain within a range for a period of time */
90  event_mode_over_protect = 4, /* over protect mode, greater than or less than */
91  event_mode_time_match = 8, /* time match mode, when the synt's cnt value is equal to the preset */
93 
97 typedef enum mtg_event_dir {
102 
106 typedef enum mtg_event_dir_mode {
107  event_dir_mode_dy = 0, /* use first derivative of object */
108  event_dir_mode_y1_y0 = 1, /* use difference of current and previous */
110 
118 
122 typedef enum mtg_event_trig_num {
123  event_trig_once = 0, /* event can only be triggered once */
124  event_trig_repeat = 1, /* event can be triggered multiple times */
126 
130 typedef struct mtg_event_param {
131  bool enable;
132  bool irq_en; /* enable or disable the event irq */
139 
140  /* union struct of event presets registers, different meaning when different event mode */
141  union {
142  struct {
143  uint32_t cross_value_h; /* the high 32bit of cross_value, only need set when object is ${event_object_rev_pos} */
144  uint32_t cross_value_l; /* the low 32bit of cross_value */
146  struct {
147  uint32_t hold_value_h; /* the high 32bit of hold_value, only need set when object is ${event_object_rev_pos} */
148  uint32_t hold_value_l; /* the low 32bit of hold_value */
149  uint32_t error_limit; /* the range is between ${hold value - error_limit} and ${hold value + error_limit} */
150  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 */
152  struct {
153  uint32_t limit_value_h; /* the high 32bit of limit_value */
154  uint32_t limit_value_l; /* the low 32bit of limit_value */
156  struct {
157  uint32_t clock_count; /* the event will be triggered when synt clock match the value */
159  uint32_t preset[4];
162 
163 /*
164  * @brief define the struct of the trajectory predictor limit
165  */
166 typedef struct mtg_tra_limit_param {
167  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 */
168  uint32_t vel_step_max; /* velocity step limit value max */
169  uint32_t vel_step_min; /* velocity step limit value min */
170  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 */
171  uint32_t pos_step_max; /* postion step limit value max */
172  uint32_t pos_step_min; /* postion step limit value min */
174 
182 
186 typedef enum vel_one_way_mode {
190 
194 typedef struct mtg_hardware_force_one_way_mode {
195  uint32_t vel_limit_p;
196  uint32_t vel_limit_n;
198 
202 typedef enum mtg_filter_ff_mode {
206 
214 
222 
223 typedef struct mtg_filter_param {
224  bool enable; /* filter enable */
225  bool ff_en; /* filter feedforward enable */
226  bool init_en; /* filter first value initialization enable */
227  bool err_bypass_en; /* filter error bypass enable. when difference between filter input and output beyond the limit, filter output will be bypassed */
229  bool err_init; /* filter error reset enable. when difference between filter input and output beyond the limit, the filter will reset */
230  bool timeout_en; /* filter timeout enable */
231  bool err_bypass_i_f_en;
232  bool err_bypass_f_i_en;
233  bool multi_err_irq_en;
234  bool acceleration_en; /* filter acceleration enable. when enable, the filter will output acceleration value */
237  int32_t vel_init_value; /* the initial value of velocity. only used when init_en == true */
238  int32_t acc_init_value; /* the initial value of acceleration. only used when init_en == true */
239  uint32_t filter_time_constant_tp;
240  uint32_t filter_time_constant_tz;
241  uint32_t filter_time_constant_tz_1;
242  uint32_t filter_gain;
243  uint32_t filter_stage_shift[2];
244  uint32_t filter_param_shift;
245  uint32_t filter_time_shift;
246  uint32_t filter_ff_shift;
247 
249 
253 typedef enum mtg_time_input_source {
254  mtg_time_input_from_filter = 1, /* the value in the filter will be used */
255  mtg_time_input_from_input = 2, /* the value in the input will be used */
257 
261 typedef struct mtg_time_init_param {
262  bool enable;
263  uint32_t adjust_value; /* time compensation clocks */
264  uint8_t index;
267 
271 typedef struct mtg_timeout_param {
272  bool enable;
273  uint32_t timeout_clock_count;
275 
281 typedef enum mtg_link_cfg {
290 
294 typedef enum {
295  cmd_object_rev = 1 << 0,
296  cmd_object_pos = 1 << 1,
297  cmd_object_vel = 1 << 2,
298  cmd_object_acc = 1 << 3,
299  cmd_object_jer = 1 << 4,
301 
305 typedef enum {
306  cmd_mode_new_value = 0, /* when cmd exec, the preset value will replace the old value */
307  cmd_mode_old_delta = 1, /* when cmd exec, the preset value will be added to the old value */
309 
313 typedef struct mtg_tra_shift {
314  uint8_t jerk_shift;
315  uint8_t acc_shift;
316  uint8_t vel_shift;
318 
322 typedef struct mtg_tra_cmd_cfg {
323  uint8_t index;
324  uint32_t object; /* cmd object, see ${mtg_tra_cmd_object_t} */
326  uint32_t rev_preset;
327  uint32_t pos_preset;
328  uint32_t vel_preset;
329  uint32_t acc_preset;
330  uint32_t jer_preset;
332 
333 #ifdef __cplusplus
334 extern "C" {
335 #endif
336 
343 static inline uint32_t mtg_get_tra_control_status(MTGV2_Type *base, uint8_t tra_index)
344 {
345  assert(tra_index < 2);
346  return base->TRA[tra_index].CONTROL;
347 }
348 
356 static inline uint32_t mtg_get_tra_cmd_control_status(MTGV2_Type *base, uint8_t tra_index, uint8_t cmd_index)
357 {
358  assert((tra_index < 2) && (cmd_index < 4));
359  return base->TRA[tra_index].CMD[cmd_index].CONTROL;
360 }
361 
367 static inline void mtg_trig_tra_lock(MTGV2_Type *base, uint8_t tra_index)
368 {
369  assert(tra_index < 2);
370  base->TRA[tra_index].CONTROL |= MTGV2_TRA_CONTROL_SW_LOCK_SET(1);
371 }
372 
378 static inline void mtg_clear_tra_lock(MTGV2_Type *base, uint8_t tra_index)
379 {
380  assert(tra_index < 2);
381  base->TRA[tra_index].CONTROL &= ~MTGV2_TRA_CONTROL_SW_LOCK_MASK;
382 }
383 
390 static inline int32_t mtg_get_tra_rev_lock_value(MTGV2_Type *base, uint8_t tra_index)
391 {
392  assert(tra_index < 2);
393  return base->TRA[tra_index].LOCK_REV;
394 }
395 
402 static inline uint32_t mtg_get_tra_pos_lock_value(MTGV2_Type *base, uint8_t tra_index)
403 {
404  assert(tra_index < 2);
405  return base->TRA[tra_index].LOCK_POS;
406 }
407 
414 static inline int32_t mtg_get_tra_vel_lock_value(MTGV2_Type *base, uint8_t tra_index)
415 {
416  assert(tra_index < 2);
417  return base->TRA[tra_index].LOCK_VEL;
418 }
419 
426 static inline int32_t mtg_get_tra_acc_lock_value(MTGV2_Type *base, uint8_t tra_index)
427 {
428  assert(tra_index < 2);
429  return base->TRA[tra_index].LOCK_ACC;
430 }
431 
432 
440 static inline void mtg_filter_enable_bypass(MTGV2_Type *base)
441 {
442  base->FILTER_CONTROL |= MTGV2_FILTER_CONTROL_ERR_BYPASS_F_I_EN_SET(1);
443  base->FILTER_CONTROL |= MTGV2_FILTER_CONTROL_ERR_BYPASS_EN_SET(1);
444 }
445 
453 static inline void mtg_filter_disable_bypass(MTGV2_Type *base)
454 {
455  base->FILTER_CONTROL &= ~MTGV2_FILTER_CONTROL_ERR_BYPASS_F_I_EN_MASK;
456  base->FILTER_CONTROL &= ~MTGV2_FILTER_CONTROL_ERR_BYPASS_EN_MASK;
457 }
458 
467 static inline void mtg_filter_switch_filter_result(MTGV2_Type *base)
468 {
469  base->FILTER_CONTROL |= MTGV2_FILTER_CONTROL_ERR_BYPASS_I_F_EN_SET(1);
470 }
471 
480 static inline void mtg_filter_stop_auto_switch_filter_result(MTGV2_Type *base)
481 {
482  base->FILTER_CONTROL &= ~MTGV2_FILTER_CONTROL_ERR_BYPASS_I_F_EN_MASK;
483 }
484 
492 static inline bool mtg_get_err_bypass_status(MTGV2_Type *base)
493 {
494  return MTGV2_FILTER_CONTROL_ERR_BYPASS_STATUS_GET(base->FILTER_CONTROL) == 0 ? true : false;
495 }
496 
502 static inline void mtg_set_time0_adjust_value(MTGV2_Type *base, uint32_t value)
503 {
504  base->FILTER_TIME0_SW_ADJUST = value;
505 }
506 
512 static inline void mtg_set_time1_adjust_value(MTGV2_Type *base, uint32_t value)
513 {
514  base->FILTER_TIME1_SW_ADJUST = value;
515 }
516 
525 static inline void mtg_tra_set_shift(MTGV2_Type *base, uint8_t index, uint8_t jer_shift, uint8_t acc_shift, uint8_t vel_shift)
526 {
527  assert(index < 2);
528  base->TRA[index].SHIFT = MTGV2_TRA_SHIFT_JER_SHIFT_SET(jer_shift) |
529  MTGV2_TRA_SHIFT_ACC_SHIFT_SET(acc_shift) |
530  MTGV2_TRA_SHIFT_VEL_SHIFT_SET(vel_shift);
531 }
532 
537 static inline void mtg_set_global_reset(MTGV2_Type *base)
538 {
539  base->SW_GLB_RESET = 1;
540 }
541 
545 static inline void mtg_stop_global_reset(MTGV2_Type *base)
546 {
547  base->SW_GLB_RESET = 0;
548 }
549 
556 void mtg_get_tra_lock_result(MTGV2_Type *base, uint8_t tra_index, mtg_lock_value_t *para);
557 
565 hpm_stat_t mtg_setup_event(MTGV2_Type *base, uint8_t event_index, mtg_event_param_t *param);
566 
574 hpm_stat_t mtg_setup_tra_limit(MTGV2_Type *base, uint8_t tra_index, mtg_tra_limit_param_t *param);
575 
583 void mtg_setup_tra_software_pos_one_way_mode(MTGV2_Type *base, uint8_t tra_index, mtg_software_force_one_way_mode_t param);
584 
592 void mtg_setup_tra_hardware_pos_one_way_mode(MTGV2_Type *base, uint8_t tra_index, mtg_hardware_force_one_way_mode_t *param);
593 
599 void mtg_disable_tra_pos_one_way_mode(MTGV2_Type *base, uint8_t tra_index);
600 
607 void mtg_setup_tra_vel_one_way(MTGV2_Type *base, uint8_t tra_index, vel_one_way_mode_t mode, bool enable);
608 
615 
621 void mtg_setup_time(MTGV2_Type *base, mtg_time_init_param_t *param);
622 
628 void mtg_setup_filter(MTGV2_Type *base, mtg_filter_param_t *param);
629 
635 void mtg_setup_timeout(MTGV2_Type *base, mtg_timeout_param_t *param);
636 
644 void mtg_setup_link_cfg(MTGV2_Type *base, uint8_t tra_index, mtg_link_cfg_t link_cfg, mtg_tra_cmd_cfg_t *cmd_cfg);
645 
650 void mtg_soft_event_trigger(MTGV2_Type *base);
651 
657 
663 static inline uint32_t mtg_get_irq_status(MTGV2_Type *ptr)
664 {
665  return ptr->IRQ_STATUS;
666 }
667 
673 static inline void mtg_enable_irq(MTGV2_Type *ptr, mtg_irq_enable_t irq)
674 {
675  ptr->IRQ_ENABLE |= MTGV2_IRQ_ENABLE_IRQ_ENABLE_SET(irq);
676 }
677 
683 static inline void mtg_clear_irq_status(MTGV2_Type *ptr, uint32_t irq)
684 {
685  ptr->IRQ_STATUS = irq;
686 }
687 
695 int32_t mtg_calc_vel_preset(MTGV2_Type *base, clock_name_t clock, uint8_t tra_index, float speed);
696 
704 int32_t mtg_calc_acc_preset(MTGV2_Type *base, clock_name_t clock, uint8_t tra_index, float acc);
705 
713 int32_t mtg_calc_jer_preset(MTGV2_Type *base, clock_name_t clock, uint8_t tra_index, float jer);
714 
715 #ifdef __cplusplus
716 }
717 #endif
721 #endif /* HPM_MTGV2_DRV_H */
enum _clock_name clock_name_t
Peripheral Clock Type Description.
uint32_t hpm_stat_t
Definition: hpm_common.h:123
static void mtg_filter_switch_filter_result(MTGV2_Type *base)
MTG enable hardware switch from bypass status to filter status's limit When the difference between in...
Definition: hpm_mtgv2_drv.h:467
static void mtg_set_time0_adjust_value(MTGV2_Type *base, uint32_t value)
MTG set time0 adjust value.
Definition: hpm_mtgv2_drv.h:502
enum mtg_filter_ff_mode mtg_filter_ff_mode_t
define the enum of the filter ff mode
mtg_event_object
define the enum of the observed object
Definition: hpm_mtg_drv.h:45
struct mtg_tra_limit_param mtg_tra_limit_param_t
void mtg_soft_event_trigger(MTGV2_Type *base)
MTG software trigger trajectory command.
Definition: hpm_mtgv2_drv.c:310
struct mtg_result mtg_lock_value_t
define the struct of mtg lock values
void mtg_setup_time(MTGV2_Type *base, mtg_time_init_param_t *param)
MTG setup time compensation module.
Definition: hpm_mtgv2_drv.c:244
void mtg_setup_timeout(MTGV2_Type *base, mtg_timeout_param_t *param)
MTG setup timeout.
Definition: hpm_mtgv2_drv.c:267
static void mtg_trig_tra_lock(MTGV2_Type *base, uint8_t tra_index)
MTG trigger trajectory predictor lock current values.
Definition: hpm_mtgv2_drv.h:367
enum mtg_event_trig_num mtg_event_trig_num_t
define the enum of the event trigger number
mtg_irq_enable
Definition: hpm_mtgv2_drv.h:20
static bool mtg_get_err_bypass_status(MTGV2_Type *base)
MTG setup hardware switch from bypass status to filter status's limit When the difference between inp...
Definition: hpm_mtgv2_drv.h:492
enum vel_one_way_mode vel_one_way_mode_t
define the enum of the hardware force one way mode
void mtg_setup_filter(MTGV2_Type *base, mtg_filter_param_t *param)
MTG setup filter.
Definition: hpm_mtgv2_drv.c:210
struct mtg_tra_cmd_cfg mtg_tra_cmd_cfg_t
define the struct of the trajectory predictor command
void mtg_setup_link_cfg(MTGV2_Type *base, uint8_t tra_index, mtg_link_cfg_t link_cfg, mtg_tra_cmd_cfg_t *cmd_cfg)
MTG link trigger source and trajectory command.
Definition: hpm_mtgv2_drv.c:277
mtg_tra_cmd_object_t
define the enum of the trajectory predictor command object
Definition: hpm_mtgv2_drv.h:294
static void mtg_clear_irq_status(MTGV2_Type *ptr, uint32_t irq)
Clear the event irq status.
Definition: hpm_mtgv2_drv.h:683
static void mtg_enable_irq(MTGV2_Type *ptr, mtg_irq_enable_t irq)
Enable irq.
Definition: hpm_mtgv2_drv.h:673
static void mtg_filter_stop_auto_switch_filter_result(MTGV2_Type *base)
MTG disable hardware switch from bypass status to filter status's limit When the difference between i...
Definition: hpm_mtgv2_drv.h:480
hpm_stat_t mtg_setup_event(MTGV2_Type *base, uint8_t event_index, mtg_event_param_t *param)
MTG setup event params.
Definition: hpm_mtgv2_drv.c:54
static int32_t mtg_get_tra_rev_lock_value(MTGV2_Type *base, uint8_t tra_index)
MTG get trajectory predictor revolution lock value.
Definition: hpm_mtgv2_drv.h:390
void mtg_get_tra_lock_result(MTGV2_Type *base, uint8_t tra_index, mtg_lock_value_t *para)
MTG predictor get lock result.
Definition: hpm_mtgv2_drv.c:43
static int32_t mtg_get_tra_vel_lock_value(MTGV2_Type *base, uint8_t tra_index)
MTG get trajectory predictor velocity lock value.
Definition: hpm_mtgv2_drv.h:414
int32_t mtg_calc_acc_preset(MTGV2_Type *base, clock_name_t clock, uint8_t tra_index, float acc)
calculate the acc preset
Definition: hpm_mtgv2_drv.c:20
mtg_time_input_source
define the enum of the trajectory predictor time input source
Definition: hpm_mtg_drv.h:229
struct mtg_filter_param mtg_filter_param_t
void mtg_filter_get_default_filter_stage_param(mtg_filter_param_t *param)
MTG setup filter.
Definition: hpm_mtg_drv.c:156
enum mtg_link_cfg mtg_link_cfg_t
define the enum of the trajectory predictor link event link the trigger source and the cmd object,...
enum mtg_software_force_one_way_mode mtg_software_force_one_way_mode_t
define the enum of the software force one way mode
enum mtg_event_dir_mode mtg_event_dir_mode_t
define the enum of the event detection direction calculation mode
enum mtg_event_over_mode_cmp mtg_event_over_mode_cmp_t
define the enum of the event detection over protect mode
enum mtg_event_object mtg_event_object_t
define the enum of the observed object
static void mtg_filter_enable_bypass(MTGV2_Type *base)
MTG enable filter error bypass When difference between input and filter's pos result is bigger than t...
Definition: hpm_mtgv2_drv.h:440
mtg_event_dir_mode
define the enum of the event detection direction calculation mode
Definition: hpm_mtg_drv.h:74
mtg_filter_err_bypass_mode
define the enum of the filter first load mode
Definition: hpm_mtgv2_drv.h:218
mtg_event_dir
define the enum of the event detection direction
Definition: hpm_mtg_drv.h:65
void mtg_setup_tra_software_pos_one_way_mode(MTGV2_Type *base, uint8_t tra_index, mtg_software_force_one_way_mode_t param)
MTG setup trajectory software one_way mode.
Definition: hpm_mtgv2_drv.c:129
static void mtg_set_global_reset(MTGV2_Type *base)
MTG global reset.
Definition: hpm_mtgv2_drv.h:537
struct mtg_tra_shift mtg_tra_shift_t
define the struct of the trajectory shift struct
struct mtg_event_param mtg_event_param_t
define the struct of the event setup parameter
static void mtg_tra_set_shift(MTGV2_Type *base, uint8_t index, uint8_t jer_shift, uint8_t acc_shift, uint8_t vel_shift)
MTG set time shift value.
Definition: hpm_mtgv2_drv.h:525
struct mtg_timeout_param mtg_timeout_param_t
define the struct of the trajectory predictor timeout
mtg_filter_first_load_mode
define the enum of the filter first load mode
Definition: hpm_mtgv2_drv.h:210
int32_t mtg_calc_vel_preset(MTGV2_Type *base, clock_name_t clock, uint8_t tra_index, float speed)
calculate the vel preset
Definition: hpm_mtgv2_drv.c:10
mtg_link_cmd_mode_t
define the enum of the trajectory predictor command mode
Definition: hpm_mtgv2_drv.h:305
void mtg_get_default_tra_shift(mtg_tra_shift_t *cfg)
Get default trajectory shift.
Definition: hpm_mtg_drv.c:335
mtg_event_over_mode_cmp
define the enum of the event detection over protect mode
Definition: hpm_mtg_drv.h:82
void mtg_setup_tra_vel_one_way(MTGV2_Type *base, uint8_t tra_index, vel_one_way_mode_t mode, bool enable)
MTG setup trajectory velocity one_way mode.
Definition: hpm_mtgv2_drv.c:152
mtg_link_cfg
define the enum of the trajectory predictor link event link the trigger source and the cmd object,...
Definition: hpm_mtg_drv.h:257
static int32_t mtg_get_tra_acc_lock_value(MTGV2_Type *base, uint8_t tra_index)
MTG get trajectory predictor acceleration lock value.
Definition: hpm_mtgv2_drv.h:426
mtg_event_mode
define the enum of the event detection mode
Definition: hpm_mtg_drv.h:55
vel_one_way_mode
define the enum of the hardware force one way mode
Definition: hpm_mtg_drv.h:155
mtg_event_trig_num
define the enum of the event trigger number
Definition: hpm_mtg_drv.h:90
static void mtg_set_time1_adjust_value(MTGV2_Type *base, uint32_t value)
MTG set time1 adjust value.
Definition: hpm_mtgv2_drv.h:512
struct mtg_hardware_force_one_way_mode mtg_hardware_force_one_way_mode_t
define the struct of the hardware force one way mode
hpm_stat_t mtg_setup_tra_limit(MTGV2_Type *base, uint8_t tra_index, mtg_tra_limit_param_t *param)
MTG setup trajectory limit params.
Definition: hpm_mtgv2_drv.c:109
static uint32_t mtg_get_tra_control_status(MTGV2_Type *base, uint8_t tra_index)
MTG get trajectory predictor control register value.
Definition: hpm_mtgv2_drv.h:343
mtg_evnet_object_postion
define the enum of the postion of the observed object
Definition: hpm_mtg_drv.h:35
enum mtg_filter_err_bypass_mode mtg_filter_err_bypass_mode_t
define the enum of the filter first load mode
enum mtg_filter_first_load_mode mtg_filter_first_load_mode_t
define the enum of the filter first load mode
enum mtg_time_input_source mtg_time_input_source_t
define the enum of the trajectory predictor time input source
static void mtg_clear_tra_lock(MTGV2_Type *base, uint8_t tra_index)
MTG clear trajectory predictor lock status.
Definition: hpm_mtgv2_drv.h:378
static uint32_t mtg_get_tra_pos_lock_value(MTGV2_Type *base, uint8_t tra_index)
MTG get trajectory predictor postion lock value.
Definition: hpm_mtgv2_drv.h:402
mtg_filter_ff_mode
define the enum of the filter ff mode
Definition: hpm_mtg_drv.h:188
enum mtg_event_dir mtg_event_dir_t
define the enum of the event detection direction
enum mtg_irq_enable mtg_irq_enable_t
static uint32_t mtg_get_irq_status(MTGV2_Type *ptr)
Get the event irq status.
Definition: hpm_mtgv2_drv.h:663
static void mtg_filter_disable_bypass(MTGV2_Type *base)
MTG disable filter error bypass When difference between input and filter's pos result is bigger than ...
Definition: hpm_mtgv2_drv.h:453
static void mtg_stop_global_reset(MTGV2_Type *base)
MTG stop global reset.
Definition: hpm_mtgv2_drv.h:545
mtg_software_force_one_way_mode
define the enum of the software force one way mode
Definition: hpm_mtg_drv.h:147
struct mtg_time_init_param mtg_time_init_param_t
define the struct of the trajectory predictor time initialization
enum mtg_event_mode mtg_event_mode_t
define the enum of the event detection mode
void mtg_setup_tra_hardware_pos_one_way_mode(MTGV2_Type *base, uint8_t tra_index, mtg_hardware_force_one_way_mode_t *param)
MTG setup trajectory hardware one_way mode.
Definition: hpm_mtgv2_drv.c:138
static uint32_t mtg_get_tra_cmd_control_status(MTGV2_Type *base, uint8_t tra_index, uint8_t cmd_index)
MTG get trajectory predictor commond control register value.
Definition: hpm_mtgv2_drv.h:356
void mtg_disable_tra_pos_one_way_mode(MTGV2_Type *base, uint8_t tra_index)
MTG disable trajectory postion one_way mode.
Definition: hpm_mtgv2_drv.c:147
int32_t mtg_calc_jer_preset(MTGV2_Type *base, clock_name_t clock, uint8_t tra_index, float jer)
MTG link trigger source and trajectory command.
Definition: hpm_mtgv2_drv.c:31
enum mtg_evnet_object_postion mtg_evnet_object_postion_t
define the enum of the postion of the observed object
@ event_object_vel
Definition: hpm_mtgv2_drv.h:79
@ event_object_pos
Definition: hpm_mtgv2_drv.h:81
@ event_object_acc
Definition: hpm_mtgv2_drv.h:80
@ event_object_rev_pos
Definition: hpm_mtgv2_drv.h:78
@ irq_tra0_vel_shift_issue
Definition: hpm_mtgv2_drv.h:40
@ irq_event0
Definition: hpm_mtgv2_drv.h:30
@ irq_event0_object_sudden_change
Definition: hpm_mtgv2_drv.h:29
@ irq_tra1_vel_shift_issue
Definition: hpm_mtgv2_drv.h:32
@ irq_tra0_cmd0
Definition: hpm_mtgv2_drv.h:46
@ irq_tra1_acc_shift_issue
Definition: hpm_mtgv2_drv.h:33
@ irq_event1
Definition: hpm_mtgv2_drv.h:28
@ irq_event3_object_sudden_change
Definition: hpm_mtgv2_drv.h:23
@ irq_filter_mul0_overflow
Definition: hpm_mtgv2_drv.h:22
@ irq_tra1_cmd2
Definition: hpm_mtgv2_drv.h:36
@ irq_filter_mul1_overflow
Definition: hpm_mtgv2_drv.h:21
@ irq_tra1_cmd_conflict
Definition: hpm_mtgv2_drv.h:34
@ irq_tra0_cmd_conflict
Definition: hpm_mtgv2_drv.h:42
@ irq_tra0_cmd2
Definition: hpm_mtgv2_drv.h:44
@ irq_f_i_irq
Definition: hpm_mtgv2_drv.h:47
@ irq_event2
Definition: hpm_mtgv2_drv.h:26
@ irq_tra1_cmd0
Definition: hpm_mtgv2_drv.h:38
@ irq_tra1_cmd3
Definition: hpm_mtgv2_drv.h:35
@ irq_tra0_acc_shift_issue
Definition: hpm_mtgv2_drv.h:41
@ irq_tra0_cmd3
Definition: hpm_mtgv2_drv.h:43
@ irq_tra0_lock
Definition: hpm_mtgv2_drv.h:39
@ irq_i_f_irq0
Definition: hpm_mtgv2_drv.h:48
@ irq_tra0_cmd1
Definition: hpm_mtgv2_drv.h:45
@ irq_event3
Definition: hpm_mtgv2_drv.h:24
@ irq_tra1_cmd1
Definition: hpm_mtgv2_drv.h:37
@ irq_tra1_lock
Definition: hpm_mtgv2_drv.h:31
@ irq_event2_object_sudden_change
Definition: hpm_mtgv2_drv.h:25
@ irq_event1_object_sudden_change
Definition: hpm_mtgv2_drv.h:27
@ cmd_object_acc
Definition: hpm_mtgv2_drv.h:298
@ cmd_object_jer
Definition: hpm_mtgv2_drv.h:299
@ cmd_object_rev
Definition: hpm_mtgv2_drv.h:295
@ cmd_object_pos
Definition: hpm_mtgv2_drv.h:296
@ cmd_object_vel
Definition: hpm_mtgv2_drv.h:297
@ mtg_time_input_from_filter
Definition: hpm_mtgv2_drv.h:254
@ mtg_time_input_from_input
Definition: hpm_mtgv2_drv.h:255
@ event_dir_mode_y1_y0
Definition: hpm_mtgv2_drv.h:108
@ event_dir_mode_dy
Definition: hpm_mtgv2_drv.h:107
@ mtg_filter_err_bypass_mode_hw
Definition: hpm_mtgv2_drv.h:219
@ mtg_filter_err_bypass_mode_sw
Definition: hpm_mtgv2_drv.h:220
@ event_dir_positive
Definition: hpm_mtgv2_drv.h:99
@ event_dir_both
Definition: hpm_mtgv2_drv.h:100
@ event_dir_negative
Definition: hpm_mtgv2_drv.h:98
@ mtg_filter_first_load_mode_without_acc
Definition: hpm_mtgv2_drv.h:211
@ mtg_filter_first_load_mode_include_acc
Definition: hpm_mtgv2_drv.h:212
@ cmd_mode_old_delta
Definition: hpm_mtgv2_drv.h:307
@ cmd_mode_new_value
Definition: hpm_mtgv2_drv.h:306
@ event_over_cmp_mode_smaller
Definition: hpm_mtgv2_drv.h:115
@ event_over_cmp_mode_bigger
Definition: hpm_mtgv2_drv.h:116
@ link_event3
Definition: hpm_mtgv2_drv.h:285
@ link_event_timeout
Definition: hpm_mtgv2_drv.h:288
@ link_hw_trigger
Definition: hpm_mtgv2_drv.h:286
@ link_event2
Definition: hpm_mtgv2_drv.h:284
@ link_event0
Definition: hpm_mtgv2_drv.h:282
@ link_sw_trigger
Definition: hpm_mtgv2_drv.h:287
@ link_event1
Definition: hpm_mtgv2_drv.h:283
@ event_mode_time_match
Definition: hpm_mtgv2_drv.h:91
@ event_mode_over_protect
Definition: hpm_mtgv2_drv.h:90
@ event_mode_hold
Definition: hpm_mtgv2_drv.h:89
@ event_mode_across
Definition: hpm_mtgv2_drv.h:88
@ bigger_or_eq_zero
Definition: hpm_mtgv2_drv.h:187
@ smaller_or_eq_zero
Definition: hpm_mtgv2_drv.h:188
@ event_trig_repeat
Definition: hpm_mtgv2_drv.h:124
@ event_trig_once
Definition: hpm_mtgv2_drv.h:123
@ event_source_tra1_output
Definition: hpm_mtgv2_drv.h:71
@ event_source_tra0_output
Definition: hpm_mtgv2_drv.h:70
@ event_source_before_filter
Definition: hpm_mtgv2_drv.h:68
@ event_source_filter_output
Definition: hpm_mtgv2_drv.h:69
@ mtg_filter_ff_mode_from_register
Definition: hpm_mtgv2_drv.h:203
@ mtg_filter_ff_mode_from_input
Definition: hpm_mtgv2_drv.h:204
@ sw_force_positive
Definition: hpm_mtgv2_drv.h:180
@ sw_force_negative
Definition: hpm_mtgv2_drv.h:179
define the struct of the event setup parameter
Definition: hpm_mtg_drv.h:98
uint32_t error_limit
Definition: hpm_mtg_drv.h:118
struct mtg_event_param::@152::@155 over_protect_param
mtg_event_trig_num_t trig_num
Definition: hpm_mtg_drv.h:107
struct mtg_event_param::@152::@153 cross_param
uint32_t clock_count
Definition: hpm_mtg_drv.h:126
bool enable
Definition: hpm_mtg_drv.h:99
uint32_t hold_value_l
Definition: hpm_mtg_drv.h:117
mtg_event_mode_t mode
Definition: hpm_mtg_drv.h:103
uint32_t limit_value_h
Definition: hpm_mtg_drv.h:122
mtg_event_object_t obj
Definition: hpm_mtg_drv.h:101
uint32_t cross_value_l
Definition: hpm_mtg_drv.h:113
uint32_t hold_value_h
Definition: hpm_mtg_drv.h:116
mtg_event_dir_t dir
Definition: hpm_mtg_drv.h:104
bool irq_en
Definition: hpm_mtg_drv.h:100
struct mtg_event_param::@152::@154 hold_param
struct mtg_event_param::@152::@156 time_param
uint32_t cross_value_h
Definition: hpm_mtg_drv.h:112
uint32_t limit_value_l
Definition: hpm_mtg_drv.h:123
uint32_t preset[4]
Definition: hpm_mtg_drv.h:128
mtg_evnet_object_postion_t obj_postion
Definition: hpm_mtg_drv.h:102
uint32_t hold_clock_cnt
Definition: hpm_mtg_drv.h:119
mtg_event_dir_mode_t dir_mode
Definition: hpm_mtg_drv.h:105
Definition: hpm_mtg_drv.h:193
uint32_t filter_time_constant_tp
Definition: hpm_mtg_drv.h:213
uint32_t filter_stage_shift[2]
Definition: hpm_mtg_drv.h:218
mtg_filter_first_load_mode_t first_load_mode
Definition: hpm_mtgv2_drv.h:236
bool err_bypass_i_f_en
Definition: hpm_mtg_drv.h:200
bool ff_en
Definition: hpm_mtg_drv.h:195
bool acceleration_en
Definition: hpm_mtg_drv.h:203
uint32_t filter_time_shift
Definition: hpm_mtg_drv.h:220
mtg_filter_ff_mode_t ff_mode
Definition: hpm_mtg_drv.h:206
int32_t vel_init_value
Definition: hpm_mtg_drv.h:208
int32_t acc_init_value
Definition: hpm_mtg_drv.h:209
uint32_t filter_time_constant_tz
Definition: hpm_mtg_drv.h:214
bool timeout_en
Definition: hpm_mtg_drv.h:199
bool init_en
Definition: hpm_mtg_drv.h:196
bool err_bypass_en
Definition: hpm_mtg_drv.h:197
uint32_t filter_time_constant_tz_1
Definition: hpm_mtg_drv.h:215
mtg_filter_err_bypass_mode_t err_bypass_mode
Definition: hpm_mtgv2_drv.h:228
bool enable
Definition: hpm_mtg_drv.h:194
bool err_init
Definition: hpm_mtg_drv.h:198
uint32_t filter_ff_shift
Definition: hpm_mtg_drv.h:221
bool err_bypass_f_i_en
Definition: hpm_mtg_drv.h:201
uint32_t filter_param_shift
Definition: hpm_mtg_drv.h:219
uint32_t filter_gain
Definition: hpm_mtg_drv.h:217
bool multi_err_irq_en
Definition: hpm_mtg_drv.h:202
define the struct of the hardware force one way mode
Definition: hpm_mtg_drv.h:163
uint32_t vel_limit_p
Definition: hpm_mtg_drv.h:164
uint32_t vel_limit_n
Definition: hpm_mtg_drv.h:165
define the struct of mtg lock values
Definition: hpm_mtg_drv.h:24
int32_t acc
Definition: hpm_mtg_drv.h:28
uint32_t time_stamp
Definition: hpm_mtg_drv.h:29
uint32_t pos
Definition: hpm_mtg_drv.h:26
int32_t rev
Definition: hpm_mtg_drv.h:25
int32_t vel
Definition: hpm_mtg_drv.h:27
define the struct of the trajectory predictor time initialization
Definition: hpm_mtg_drv.h:237
uint8_t index
Definition: hpm_mtg_drv.h:240
mtg_time_input_source_t source
Definition: hpm_mtg_drv.h:241
bool enable
Definition: hpm_mtg_drv.h:238
uint32_t adjust_value
Definition: hpm_mtg_drv.h:239
define the struct of the trajectory predictor timeout
Definition: hpm_mtg_drv.h:247
bool enable
Definition: hpm_mtg_drv.h:248
uint32_t timeout_clock_count
Definition: hpm_mtg_drv.h:249
define the struct of the trajectory predictor command
Definition: hpm_mtg_drv.h:298
uint32_t rev_preset
Definition: hpm_mtg_drv.h:302
uint32_t pos_preset
Definition: hpm_mtg_drv.h:303
uint32_t vel_preset
Definition: hpm_mtg_drv.h:304
uint32_t jer_preset
Definition: hpm_mtg_drv.h:306
uint32_t acc_preset
Definition: hpm_mtg_drv.h:305
uint32_t object
Definition: hpm_mtg_drv.h:300
mtg_link_cmd_mode_t mode
Definition: hpm_mtg_drv.h:301
uint8_t index
Definition: hpm_mtg_drv.h:299
Definition: hpm_mtg_drv.h:135
bool vel_step_limit_en
Definition: hpm_mtg_drv.h:136
uint32_t pos_step_min
Definition: hpm_mtg_drv.h:141
uint32_t vel_step_max
Definition: hpm_mtg_drv.h:137
uint32_t vel_step_min
Definition: hpm_mtg_drv.h:138
bool pos_step_limit_en
Definition: hpm_mtg_drv.h:139
uint32_t pos_step_max
Definition: hpm_mtg_drv.h:140
define the struct of the trajectory shift struct
Definition: hpm_mtg_drv.h:289
uint8_t vel_shift
Definition: hpm_mtg_drv.h:292
uint8_t acc_shift
Definition: hpm_mtg_drv.h:291
uint8_t jerk_shift
Definition: hpm_mtg_drv.h:290