HPM SDK
HPMicro Software Development Kit
hpm_mtg_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 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_mtg_regs.h"
24 typedef struct mtg_result {
25  int32_t rev; /* revolution */
26  uint32_t pos; /* postion */
27  int32_t vel; /* velocity */
28  int32_t acc; /* acceleration */
29  uint32_t time_stamp; /* time stamp */
31 
36  event_source_before_filter = 1 << 0, /* before filter, also treat as input of mtg */
37  event_source_filter_output = 1 << 1, /* after filter, also treat as input of mtg's time compensation module */
38  event_source_tra0_output = 1 << 2, /* output of mtg's trajectory predictor0 */
39  event_source_tra1_output = 1 << 3, /* output of mtg's trajectory predictor1 */
41 
45 typedef enum mtg_event_object {
46  event_object_rev_pos = 1, /* location, revolution and position */
47  event_object_vel = 2, /* velocity */
48  event_object_acc = 4, /* acceleration */
49  event_object_pos = 8, /* postion, ignore revolution */
51 
55 typedef enum mtg_event_mode {
56  event_mode_across = 1, /* across mode, change from greater than to less than, or opposite */
57  event_mode_hold = 2, /* hold mode, maintain within a range for a period of time */
58  event_mode_over_protect = 4, /* over protect mode, greater than or less than */
59  event_mode_time_match = 8, /* time match mode, when the synt's cnt value is equal to the preset */
61 
65 typedef enum mtg_event_dir {
70 
74 typedef enum mtg_event_dir_mode {
75  event_dir_mode_dy = 0, /* use first derivative of object */
76  event_dir_mode_y1_y0 = 1, /* use difference of current and previous */
78 
86 
90 typedef enum mtg_event_trig_num {
91  event_trig_once = 0, /* event can only be triggered once */
92  event_trig_repeat = 1, /* event can be triggered multiple times */
94 
98 typedef struct mtg_event_param {
99  bool enable;
100  bool irq_en; /* enable or disable the event irq */
108 
109  /* union struct of event presets registers, different meaning when different event mode */
110  union {
111  struct {
112  uint32_t cross_value_h; /* the high 32bit of cross_value, only need set when object is ${event_object_rev_pos} */
113  uint32_t cross_value_l; /* the low 32bit of cross_value */
115  struct {
116  uint32_t hold_value_h; /* the high 32bit of hold_value, only need set when object is ${event_object_rev_pos} */
117  uint32_t hold_value_l; /* the low 32bit of hold_value */
118  uint32_t error_limit; /* the range is between ${hold value - error_limit} and ${hold value + error_limit} */
119  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 */
121  struct {
122  uint32_t limit_value_h; /* the high 32bit of limit_value */
123  uint32_t limit_value_l; /* the low 32bit of limit_value */
125  struct {
126  uint32_t clock_count; /* the event will be triggered when synt clock match the value */
128  uint32_t preset[4];
131 
132 /*
133  * @brief define the struct of the trajectory predictor limit
134  */
135 typedef struct mtg_tra_limit_param {
136  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 */
137  uint32_t vel_step_max; /* velocity step limit value max */
138  uint32_t vel_step_min; /* velocity step limit value min */
139  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 */
140  uint32_t pos_step_max; /* postion step limit value max */
141  uint32_t pos_step_min; /* postion step limit value min */
143 
151 
155 typedef enum vel_one_way_mode {
159 
164  uint32_t vel_limit_p;
165  uint32_t vel_limit_n;
167 
172  rev_init_mode_from_first_input_value = 0, /* the first input value will be used by the mtg filter to initialize the filter */
173  rev_init_mode_from_register = 1, /* the value in the register will be used by the mtg filter to initialize the filter */
175 
184 
188 typedef enum mtg_filter_ff_mode {
192 
193 typedef struct mtg_filter_param {
194  bool enable; /* filter enable */
195  bool ff_en; /* filter feedforward enable */
196  bool init_en; /* filter first value initialization enable */
197  bool err_bypass_en; /* filter error bypass enable. when difference between filter input and output beyond the limit, filter output will be bypassed */
198  bool err_init; /* filter error reset enable. when difference between filter input and output beyond the limit, the filter will reset */
199  bool timeout_en; /* filter timeout enable */
203  bool acceleration_en; /* filter acceleration enable. when enable, the filter will output acceleration value */
207  int32_t rev_init_value; /* the initial value of revolution. only used when init_en == true */
208  int32_t vel_init_value; /* the initial value of velocity. only used when init_en == true */
209  int32_t acc_init_value; /* the initial value of acceleration. only used when init_en == true */
210  uint32_t pos_init_value; /* the initial value of postion. only used when init_en == true */
211  uint32_t filter_mot_sel;
217  uint32_t filter_gain;
218  uint32_t filter_stage_shift[2];
221  uint32_t filter_ff_shift;
225 
229 typedef enum mtg_time_input_source {
230  mtg_time_input_from_filter = 1, /* the value in the filter will be used */
231  mtg_time_input_from_input = 2, /* the value in the input will be used */
233 
237 typedef struct mtg_time_init_param {
238  bool enable;
239  uint32_t adjust_value; /* time compensation clocks */
240  uint8_t index;
243 
247 typedef struct mtg_timeout_param {
248  bool enable;
251 
257 typedef enum mtg_link_cfg {
266 
270 typedef enum {
271  cmd_object_rev = 1 << 0,
272  cmd_object_pos = 1 << 1,
273  cmd_object_vel = 1 << 2,
274  cmd_object_acc = 1 << 3,
275  cmd_object_jer = 1 << 4,
277 
281 typedef enum {
282  cmd_mode_new_value = 0, /* when cmd exec, the preset value will replace the old value */
283  cmd_mode_old_delta = 1, /* when cmd exec, the preset value will be added to the old value */
285 
289 typedef struct mtg_tra_shift {
290  uint8_t jerk_shift;
291  uint8_t acc_shift;
292  uint8_t vel_shift;
294 
298 typedef struct mtg_tra_cmd_cfg {
299  uint8_t index;
300  uint32_t object; /* cmd object, see ${mtg_tra_cmd_object_t} */
302  uint32_t rev_preset;
303  uint32_t pos_preset;
304  uint32_t vel_preset;
305  uint32_t acc_preset;
306  uint32_t jer_preset;
308 
309 #ifdef __cplusplus
310 extern "C" {
311 #endif
312 
319 static inline uint32_t mtg_get_tra_control_status(MTG_Type *base, uint8_t tra_index)
320 {
321  assert(tra_index < 2);
322  return base->TRA[tra_index].CONTROL;
323 }
324 
332 static inline uint32_t mtg_get_tra_cmd_control_status(MTG_Type *base, uint8_t tra_index, uint8_t cmd_index)
333 {
334  assert((tra_index < 2) && (cmd_index < 4));
335  return base->TRA[tra_index].CMD[cmd_index].CONTROL;
336 }
337 
343 static inline void mtg_trig_tra_lock(MTG_Type *base, uint8_t tra_index)
344 {
345  assert(tra_index < 2);
346  base->TRA[tra_index].CONTROL |= MTG_TRA_CONTROL_SW_LOCK_SET(1);
347 }
348 
354 static inline void mtg_clear_tra_lock(MTG_Type *base, uint8_t tra_index)
355 {
356  assert(tra_index < 2);
357  base->TRA[tra_index].CONTROL &= ~MTG_TRA_CONTROL_SW_LOCK_MASK;
358 }
359 
366 static inline int32_t mtg_get_tra_rev_lock_value(MTG_Type *base, uint8_t tra_index)
367 {
368  assert(tra_index < 2);
369  return base->TRA[tra_index].LOCK_REV;
370 }
371 
378 static inline uint32_t mtg_get_tra_pos_lock_value(MTG_Type *base, uint8_t tra_index)
379 {
380  assert(tra_index < 2);
381  return base->TRA[tra_index].LOCK_POS;
382 }
383 
390 static inline int32_t mtg_get_tra_vel_lock_value(MTG_Type *base, uint8_t tra_index)
391 {
392  assert(tra_index < 2);
393  return base->TRA[tra_index].LOCK_VEL;
394 }
395 
402 static inline int32_t mtg_get_tra_acc_lock_value(MTG_Type *base, uint8_t tra_index)
403 {
404  assert(tra_index < 2);
405  return base->TRA[tra_index].LOCK_ACC;
406 }
407 
413 static inline void mtg_filter_set_err_bypass_limit(MTG_Type *base, uint32_t limit)
414 {
415  base->FILTER_ERROR_LIMIT_H = limit;
416 }
417 
425 static inline void mtg_filter_set_bypass_switch_filter_limit(MTG_Type *base, uint32_t limit)
426 {
427  base->FILTER_ERROR_LIMIT_L = limit;
428 }
429 
437 static inline void mtg_filter_enable_bypass(MTG_Type *base)
438 {
441 }
442 
450 static inline void mtg_filter_disable_bypass(MTG_Type *base)
451 {
454 }
455 
460 static inline void mtg_filter_enable_reset_init(MTG_Type *base)
461 {
463 }
464 
469 static inline void mtg_filter_disable_reset_init(MTG_Type *base)
470 {
472 }
473 
482 static inline void mtg_filter_switch_filter_result(MTG_Type *base)
483 {
485 }
486 
496 {
498 }
499 
507 static inline bool mtg_get_err_bypass_status(MTG_Type *base)
508 {
509  return MTG_FILTER_CONTROL_ERR_BYPASS_STATUS_GET(base->FILTER_CONTROL) == 0 ? true : false;
510 }
511 
517 static inline void mtg_set_time0_adjust_value(MTG_Type *base, uint32_t value)
518 {
519  base->FILTER_TIME0_SW_ADJUST = value;
520 }
521 
527 static inline void mtg_set_time1_adjust_value(MTG_Type *base, uint32_t value)
528 {
529  base->FILTER_TIME1_SW_ADJUST = value;
530 }
531 
540 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)
541 {
542  assert(index < 2);
543  base->TRA[index].SHIFT = MTG_TRA_SHIFT_JER_SHIFT_SET(jer_shift) |
544  MTG_TRA_SHIFT_ACC_SHIFT_SET(acc_shift) |
545  MTG_TRA_SHIFT_VEL_SHIFT_SET(vel_shift);
546 }
547 
552 static inline void mtg_set_global_reset(MTG_Type *base)
553 {
554  base->SW_GLB_RESET = 1;
555 }
556 
560 static inline void mtg_stop_global_reset(MTG_Type *base)
561 {
562  base->SW_GLB_RESET = 0;
563 }
564 
571 void mtg_get_tra_lock_result(MTG_Type *base, uint8_t tra_index, mtg_lock_value_t *para);
572 
580 hpm_stat_t mtg_setup_event(MTG_Type *base, uint8_t event_index, mtg_event_param_t *param);
581 
589 hpm_stat_t mtg_setup_tra_limit(MTG_Type *base, uint8_t tra_index, mtg_tra_limit_param_t *param);
590 
599 
608 
614 void mtg_disable_tra_pos_one_way_mode(MTG_Type *base, uint8_t tra_index);
615 
622 void mtg_setup_tra_vel_one_way(MTG_Type *base, uint8_t tra_index, vel_one_way_mode_t mode, bool enable);
623 
630 
636 void mtg_setup_time(MTG_Type *base, mtg_time_init_param_t *param);
637 
643 void mtg_setup_filter(MTG_Type *base, mtg_filter_param_t *param);
644 
651 
659 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);
660 
665 void mtg_soft_event_trigger(MTG_Type *base);
666 
672 
678 static inline bool mtg_get_irq_status(MTG_Type *ptr, uint8_t idx)
679 {
680  return ((MTG_EVENT_CONTROL_EVENT_IRQ_GET(ptr->EVENT[idx].CONTROL) != 0) ? true : false);
681 }
682 
688 static inline void mtg_clear_irq_status(MTG_Type *ptr, uint8_t idx)
689 {
691 }
692 
700 int32_t mtg_calc_vel_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float speed);
701 
709 int32_t mtg_calc_acc_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float acc);
710 
718 int32_t mtg_calc_jer_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float jer);
719 
720 #ifdef __cplusplus
721 }
722 #endif
726 #endif /* HPM_MTG_DRV_H */
enum _clock_name clock_name_t
Peripheral Clock Type Description.
uint32_t hpm_stat_t
Definition: hpm_common.h:123
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
void mtg_setup_tra_hardware_pos_one_way_mode(MTG_Type *base, uint8_t tra_index, mtg_hardware_force_one_way_mode_t *param)
MTG setup trajectory hardware one_way mode.
Definition: hpm_mtg_drv.c:123
struct mtg_tra_limit_param mtg_tra_limit_param_t
struct mtg_result mtg_lock_value_t
define the struct of mtg lock values
static void mtg_clear_irq_status(MTG_Type *ptr, uint8_t idx)
Clear the event irq status.
Definition: hpm_mtg_drv.h:688
mtg_filter_rev_init_mode
define the enum of the filter initialization mode
Definition: hpm_mtg_drv.h:171
void mtg_disable_tra_pos_one_way_mode(MTG_Type *base, uint8_t tra_index)
MTG disable trajectory postion one_way mode.
Definition: hpm_mtg_drv.c:132
static void mtg_trig_tra_lock(MTG_Type *base, uint8_t tra_index)
MTG trigger trajectory predictor lock current values.
Definition: hpm_mtg_drv.h:343
static uint32_t mtg_get_tra_pos_lock_value(MTG_Type *base, uint8_t tra_index)
MTG get trajectory predictor postion lock value.
Definition: hpm_mtg_drv.h:378
enum mtg_event_trig_num mtg_event_trig_num_t
define the enum of the event trigger number
static uint32_t mtg_get_tra_cmd_control_status(MTG_Type *base, uint8_t tra_index, uint8_t cmd_index)
MTG get trajectory predictor commond control register value.
Definition: hpm_mtg_drv.h:332
enum vel_one_way_mode vel_one_way_mode_t
define the enum of the hardware force one way mode
static void mtg_filter_enable_bypass(MTG_Type *base)
MTG enable filter error bypass When difference between input and filter's pos result is bigger than t...
Definition: hpm_mtg_drv.h:437
static int32_t mtg_get_tra_acc_lock_value(MTG_Type *base, uint8_t tra_index)
MTG get trajectory predictor acceleration lock value.
Definition: hpm_mtg_drv.h:402
struct mtg_tra_cmd_cfg mtg_tra_cmd_cfg_t
define the struct of the trajectory predictor command
static void mtg_filter_disable_bypass(MTG_Type *base)
MTG disable filter error bypass When difference between input and filter's pos result is bigger than ...
Definition: hpm_mtg_drv.h:450
mtg_tra_cmd_object_t
define the enum of the trajectory predictor command object
Definition: hpm_mtg_drv.h:270
static void mtg_filter_set_err_bypass_limit(MTG_Type *base, uint32_t limit)
MTG setup filter error bypass limit.
Definition: hpm_mtg_drv.h:413
static void mtg_tra_set_shift(MTG_Type *base, uint8_t index, uint8_t jer_shift, uint8_t acc_shift, uint8_t vel_shift)
MTG set time shift value.
Definition: hpm_mtg_drv.h:540
void mtg_setup_tra_software_pos_one_way_mode(MTG_Type *base, uint8_t tra_index, mtg_software_force_one_way_mode_t param)
MTG setup trajectory software one_way mode.
Definition: hpm_mtg_drv.c:114
static void mtg_filter_disable_reset_init(MTG_Type *base)
MTG reset filter disable error reset.
Definition: hpm_mtg_drv.h:469
static bool mtg_get_irq_status(MTG_Type *ptr, uint8_t idx)
Get the event irq status.
Definition: hpm_mtg_drv.h:678
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
hpm_stat_t mtg_setup_event(MTG_Type *base, uint8_t event_index, mtg_event_param_t *param)
MTG setup event params.
Definition: hpm_mtg_drv.c:54
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
static void mtg_filter_enable_reset_init(MTG_Type *base)
MTG reset filter enable error reset.
Definition: hpm_mtg_drv.h:460
enum mtg_event_over_mode_cmp mtg_event_over_mode_cmp_t
define the enum of the event detection over protect mode
mtg_filter_rev_judge_mode
define the enum of the filter judge mode It affects the judgment conditions for changes in the number...
Definition: hpm_mtg_drv.h:180
enum mtg_event_object mtg_event_object_t
define the enum of the observed object
void mtg_setup_time(MTG_Type *base, mtg_time_init_param_t *param)
MTG setup time compensation module.
Definition: hpm_mtg_drv.c:263
mtg_event_dir_mode
define the enum of the event detection direction calculation mode
Definition: hpm_mtg_drv.h:74
void mtg_setup_tra_vel_one_way(MTG_Type *base, uint8_t tra_index, vel_one_way_mode_t mode, bool enable)
MTG setup trajectory velocity one_way mode.
Definition: hpm_mtg_drv.c:137
mtg_event_dir
define the enum of the event detection direction
Definition: hpm_mtg_drv.h:65
void mtg_get_tra_lock_result(MTG_Type *base, uint8_t tra_index, mtg_lock_value_t *para)
MTG predictor get lock result.
Definition: hpm_mtg_drv.c:43
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_filter_stop_auto_switch_filter_result(MTG_Type *base)
MTG disable hardware switch from bypass status to filter status's limit When the difference between i...
Definition: hpm_mtg_drv.h:495
static int32_t mtg_get_tra_vel_lock_value(MTG_Type *base, uint8_t tra_index)
MTG get trajectory predictor velocity lock value.
Definition: hpm_mtg_drv.h:390
struct mtg_timeout_param mtg_timeout_param_t
define the struct of the trajectory predictor timeout
static int32_t mtg_get_tra_rev_lock_value(MTG_Type *base, uint8_t tra_index)
MTG get trajectory predictor revolution lock value.
Definition: hpm_mtg_drv.h:366
int32_t mtg_calc_jer_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float jer)
MTG link trigger source and trajectory command.
Definition: hpm_mtg_drv.c:31
mtg_link_cmd_mode_t
define the enum of the trajectory predictor command mode
Definition: hpm_mtg_drv.h:281
void mtg_get_default_tra_shift(mtg_tra_shift_t *cfg)
Get default trajectory shift.
Definition: hpm_mtg_drv.c:335
void mtg_setup_timeout(MTG_Type *base, mtg_timeout_param_t *param)
MTG setup timeout.
Definition: hpm_mtg_drv.c:286
static void mtg_stop_global_reset(MTG_Type *base)
MTG stop global reset.
Definition: hpm_mtg_drv.h:560
mtg_event_over_mode_cmp
define the enum of the event detection over protect mode
Definition: hpm_mtg_drv.h:82
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)
MTG link trigger source and trajectory command.
Definition: hpm_mtg_drv.c:296
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 bool mtg_get_err_bypass_status(MTG_Type *base)
MTG setup hardware switch from bypass status to filter status's limit When the difference between inp...
Definition: hpm_mtg_drv.h:507
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
hpm_stat_t mtg_setup_tra_limit(MTG_Type *base, uint8_t tra_index, mtg_tra_limit_param_t *param)
MTG setup trajectory limit params.
Definition: hpm_mtg_drv.c:94
static uint32_t mtg_get_tra_control_status(MTG_Type *base, uint8_t tra_index)
MTG get trajectory predictor control register value.
Definition: hpm_mtg_drv.h:319
static void mtg_set_time0_adjust_value(MTG_Type *base, uint32_t value)
MTG set time0 adjust value.
Definition: hpm_mtg_drv.h:517
struct mtg_hardware_force_one_way_mode mtg_hardware_force_one_way_mode_t
define the struct of the hardware force one way mode
static void mtg_clear_tra_lock(MTG_Type *base, uint8_t tra_index)
MTG clear trajectory predictor lock status.
Definition: hpm_mtg_drv.h:354
void mtg_soft_event_trigger(MTG_Type *base)
MTG software trigger trajectory command.
Definition: hpm_mtg_drv.c:329
mtg_evnet_object_postion
define the enum of the postion of the observed object
Definition: hpm_mtg_drv.h:35
static void mtg_set_time1_adjust_value(MTG_Type *base, uint32_t value)
MTG set time1 adjust value.
Definition: hpm_mtg_drv.h:527
enum mtg_filter_rev_judge_mode mtg_filter_rev_judge_mode_t
define the enum of the filter judge mode It affects the judgment conditions for changes in the number...
enum mtg_time_input_source mtg_time_input_source_t
define the enum of the trajectory predictor time input source
static void mtg_filter_set_bypass_switch_filter_limit(MTG_Type *base, uint32_t limit)
MTG setup hardware switch from bypass status to filter status's limit When the difference between inp...
Definition: hpm_mtg_drv.h:425
static void mtg_set_global_reset(MTG_Type *base)
MTG global reset.
Definition: hpm_mtg_drv.h:552
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
int32_t mtg_calc_acc_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float acc)
calculate the acc preset
Definition: hpm_mtg_drv.c:20
static void mtg_filter_switch_filter_result(MTG_Type *base)
MTG enable hardware switch from bypass status to filter status's limit When the difference between in...
Definition: hpm_mtg_drv.h:482
mtg_software_force_one_way_mode
define the enum of the software force one way mode
Definition: hpm_mtg_drv.h:147
void mtg_setup_filter(MTG_Type *base, mtg_filter_param_t *param)
MTG setup filter.
Definition: hpm_mtg_drv.c:222
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
enum mtg_filter_rev_init_mode mtg_filter_rev_init_mode_t
define the enum of the filter initialization mode
int32_t mtg_calc_vel_preset(MTG_Type *base, clock_name_t clock, uint8_t tra_index, float speed)
calculate the vel preset
Definition: hpm_mtg_drv.c:10
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_mtg_drv.h:47
@ event_object_pos
Definition: hpm_mtg_drv.h:49
@ event_object_acc
Definition: hpm_mtg_drv.h:48
@ event_object_rev_pos
Definition: hpm_mtg_drv.h:46
@ rev_init_mode_from_first_input_value
Definition: hpm_mtg_drv.h:172
@ rev_init_mode_from_register
Definition: hpm_mtg_drv.h:173
@ cmd_object_acc
Definition: hpm_mtg_drv.h:274
@ cmd_object_jer
Definition: hpm_mtg_drv.h:275
@ cmd_object_rev
Definition: hpm_mtg_drv.h:271
@ cmd_object_pos
Definition: hpm_mtg_drv.h:272
@ cmd_object_vel
Definition: hpm_mtg_drv.h:273
@ mtg_time_input_from_filter
Definition: hpm_mtg_drv.h:230
@ mtg_time_input_from_input
Definition: hpm_mtg_drv.h:231
@ mtg_rev_judge_mode_new_sub_old
Definition: hpm_mtg_drv.h:181
@ mtg_rev_judge_mode_encoder_lines
Definition: hpm_mtg_drv.h:182
@ event_dir_mode_y1_y0
Definition: hpm_mtg_drv.h:76
@ event_dir_mode_dy
Definition: hpm_mtg_drv.h:75
@ event_dir_positive
Definition: hpm_mtg_drv.h:67
@ event_dir_both
Definition: hpm_mtg_drv.h:68
@ event_dir_negative
Definition: hpm_mtg_drv.h:66
@ cmd_mode_old_delta
Definition: hpm_mtg_drv.h:283
@ cmd_mode_new_value
Definition: hpm_mtg_drv.h:282
@ event_over_cmp_mode_smaller
Definition: hpm_mtg_drv.h:83
@ event_over_cmp_mode_bigger
Definition: hpm_mtg_drv.h:84
@ link_event3
Definition: hpm_mtg_drv.h:261
@ link_event_timeout
Definition: hpm_mtg_drv.h:264
@ link_hw_trigger
Definition: hpm_mtg_drv.h:262
@ link_event2
Definition: hpm_mtg_drv.h:260
@ link_event0
Definition: hpm_mtg_drv.h:258
@ link_sw_trigger
Definition: hpm_mtg_drv.h:263
@ link_event1
Definition: hpm_mtg_drv.h:259
@ event_mode_time_match
Definition: hpm_mtg_drv.h:59
@ event_mode_over_protect
Definition: hpm_mtg_drv.h:58
@ event_mode_hold
Definition: hpm_mtg_drv.h:57
@ event_mode_across
Definition: hpm_mtg_drv.h:56
@ bigger_or_eq_zero
Definition: hpm_mtg_drv.h:156
@ smaller_or_eq_zero
Definition: hpm_mtg_drv.h:157
@ event_trig_repeat
Definition: hpm_mtg_drv.h:92
@ event_trig_once
Definition: hpm_mtg_drv.h:91
@ event_source_tra1_output
Definition: hpm_mtg_drv.h:39
@ event_source_tra0_output
Definition: hpm_mtg_drv.h:38
@ event_source_before_filter
Definition: hpm_mtg_drv.h:36
@ event_source_filter_output
Definition: hpm_mtg_drv.h:37
@ mtg_filter_ff_mode_from_register
Definition: hpm_mtg_drv.h:189
@ mtg_filter_ff_mode_from_input
Definition: hpm_mtg_drv.h:190
@ sw_force_positive
Definition: hpm_mtg_drv.h:149
@ sw_force_negative
Definition: hpm_mtg_drv.h:148
#define MTG_FILTER_CONTROL_ERR_BYPASS_F_I_EN_MASK
Definition: hpm_mtg_regs.h:726
#define MTG_FILTER_CONTROL_ERR_BYPASS_STATUS_GET(x)
Definition: hpm_mtg_regs.h:720
#define MTG_TRA_SHIFT_ACC_SHIFT_SET(x)
Definition: hpm_mtg_regs.h:185
#define MTG_EVENT_CONTROL_EVENT_IRQ_GET(x)
Definition: hpm_mtg_regs.h:615
#define MTG_TRA_SHIFT_VEL_SHIFT_SET(x)
Definition: hpm_mtg_regs.h:194
#define MTG_EVENT_CONTROL_EVENT_IRQ_MASK
Definition: hpm_mtg_regs.h:612
#define MTG_FILTER_CONTROL_ERR_INI_MASK
Definition: hpm_mtg_regs.h:816
#define MTG_FILTER_CONTROL_ERR_BYPASS_EN_SET(x)
Definition: hpm_mtg_regs.h:827
#define MTG_FILTER_CONTROL_ERR_BYPASS_EN_MASK
Definition: hpm_mtg_regs.h:825
#define MTG_TRA_CONTROL_SW_LOCK_SET(x)
Definition: hpm_mtg_regs.h:130
#define MTG_TRA_SHIFT_JER_SHIFT_SET(x)
Definition: hpm_mtg_regs.h:176
#define MTG_FILTER_CONTROL_ERR_INI_SET(x)
Definition: hpm_mtg_regs.h:818
#define MTG_FILTER_CONTROL_ERR_BYPASS_I_F_EN_MASK
Definition: hpm_mtg_regs.h:735
#define MTG_TRA_CONTROL_SW_LOCK_MASK
Definition: hpm_mtg_regs.h:128
#define MTG_FILTER_CONTROL_ERR_BYPASS_I_F_EN_SET(x)
Definition: hpm_mtg_regs.h:737
#define MTG_FILTER_CONTROL_ERR_BYPASS_F_I_EN_SET(x)
Definition: hpm_mtg_regs.h:728
Definition: hpm_mtg_regs.h:12
__RW uint32_t FILTER_CONTROL
Definition: hpm_mtg_regs.h:55
__W uint32_t SW_GLB_RESET
Definition: hpm_mtg_regs.h:53
__RW uint32_t FILTER_ERROR_LIMIT_H
Definition: hpm_mtg_regs.h:77
__RW uint32_t FILTER_TIME1_SW_ADJUST
Definition: hpm_mtg_regs.h:73
struct MTG_Type::@681::@683 CMD[4]
__R uint32_t LOCK_VEL
Definition: hpm_mtg_regs.h:30
__RW uint32_t CONTROL
Definition: hpm_mtg_regs.h:14
struct MTG_Type::@681 TRA[2]
__R uint32_t LOCK_ACC
Definition: hpm_mtg_regs.h:31
__R uint32_t LOCK_POS
Definition: hpm_mtg_regs.h:29
struct MTG_Type::@682 EVENT[4]
__RW uint32_t FILTER_ERROR_LIMIT_L
Definition: hpm_mtg_regs.h:76
__R uint32_t LOCK_REV
Definition: hpm_mtg_regs.h:28
__RW uint32_t FILTER_TIME0_SW_ADJUST
Definition: hpm_mtg_regs.h:74
__RW uint32_t SHIFT
Definition: hpm_mtg_regs.h:15
define the struct of the event setup parameter
Definition: hpm_mtg_drv.h:98
mtg_event_over_mode_cmp_t cmp_mode
Definition: hpm_mtg_drv.h:106
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
mtg_filter_rev_init_mode_t rev_ini_mode
Definition: hpm_mtg_drv.h:204
uint32_t filter_stage_shift[2]
Definition: hpm_mtg_drv.h:218
int32_t rev_init_value
Definition: hpm_mtg_drv.h:207
bool err_bypass_i_f_en
Definition: hpm_mtg_drv.h:200
bool ff_en
Definition: hpm_mtg_drv.h:195
uint32_t filter_zero_tz_sel
Definition: hpm_mtg_drv.h:216
bool acceleration_en
Definition: hpm_mtg_drv.h:203
uint32_t filter_error_limit_l
Definition: hpm_mtg_drv.h:222
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
mtg_filter_rev_judge_mode_t rev_judge_mode
Definition: hpm_mtg_drv.h:205
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
uint32_t pos_init_value
Definition: hpm_mtg_drv.h:210
bool err_bypass_en
Definition: hpm_mtg_drv.h:197
uint32_t filter_time_constant_tz_1
Definition: hpm_mtg_drv.h:215
bool enable
Definition: hpm_mtg_drv.h:194
bool err_init
Definition: hpm_mtg_drv.h:198
uint32_t filter_stage_sel
Definition: hpm_mtg_drv.h:212
uint32_t filter_error_limit_h
Definition: hpm_mtg_drv.h:223
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_mot_sel
Definition: hpm_mtg_drv.h:211
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