nv_storage.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef _NV_Storage_H__
  2. #define _NV_Storage_H__
  3. #include "os/os_types.h"
  4. #include "foc/core/PMSM_FOC_Core.h"
  5. #include "foc/commands.h"
  6. #pragma pack (push,1)
  7. typedef struct {
  8. float s_PhaseCurrLim;
  9. float s_maxDCVol;
  10. float s_minDCVol;
  11. float s_maxRPM;
  12. float s_maxEpmRPM;
  13. float s_maxEpmTorqueLim;
  14. float s_maxTorque;
  15. float s_TorqueBrkLim;
  16. float s_iDCeBrkLim;
  17. float s_LimitiDC;
  18. float n_currentBand; //电流环带宽
  19. float n_startThroVol;
  20. float n_endThroVol;
  21. u8 n_brkShutPower;
  22. u8 n_autoHold;
  23. u32 n_dec_time;
  24. u32 n_ebrk_time;
  25. u8 n_FwEnable;
  26. pid_conf_t pid_conf[PID_Max_id];
  27. float f_minThroVol;
  28. float f_maxThroVol;
  29. float f_adrc_vel_lim_Wo;
  30. float f_adrc_vel_lim_Wcv;
  31. float f_adrc_vel_lim_B0;
  32. float f_adrc_vel_Wo;
  33. float f_adrc_vel_Wcv;
  34. float f_adrc_vel_B0;
  35. u8 res[2048 - 157 - 24];
  36. u16 crc16;
  37. }foc_params_t;
  38. typedef struct {
  39. u8 mot_nr;
  40. u8 poles;
  41. float r;
  42. float ld;
  43. float lq;
  44. float flux_linkage;
  45. float back_emf;
  46. s32 hall_table[8];
  47. float offset;
  48. float est_pll_band; //normal工作模式下的pll带宽
  49. float pos_lock_pll_band; //电机锁定模式下的pll带宽
  50. u16 crc16;
  51. }motor_params_t;
  52. typedef struct {
  53. s16 enter_pointer;
  54. s16 exit_pointer;
  55. s16 limit_value;
  56. }nv_limter_t;
  57. #define TEMP_LIMITER_NUM 3
  58. typedef struct {
  59. u16 magic;
  60. nv_limter_t motor[TEMP_LIMITER_NUM];
  61. nv_limter_t mos[TEMP_LIMITER_NUM];
  62. nv_limter_t vbus;
  63. u8 res[2048 - 46];
  64. u16 crc16;
  65. }mc_limit_t;
  66. #define GEAR_SPEED_TRQ_NUM 10
  67. typedef struct {
  68. u16 n_max_speed; //最大速度, rpm
  69. u16 n_max_trq; //最大扭矩
  70. u16 n_max_idc; //最大母线电流
  71. u16 n_zero_accl; //零速启动扭矩给定时间,防止翘头
  72. u16 n_accl_time; //加速的扭矩斜坡时间
  73. u8 n_torque[GEAR_SPEED_TRQ_NUM]; //1000, 2000, 3000... RPM 最大给定扭矩的百分比(最大扭矩的百分比)
  74. }mc_gear_t;
  75. #define CONFIG_MAX_GEAR_NUM 4
  76. typedef struct {
  77. mc_gear_t gears_48[CONFIG_MAX_GEAR_NUM];
  78. mc_gear_t gears_96[CONFIG_MAX_GEAR_NUM];
  79. u16 magic;
  80. u16 crc16;
  81. }mc_gear_config_t;
  82. #pragma pack(pop)
  83. typedef struct {
  84. u8 sn[32];
  85. u16 len;
  86. u16 crc;
  87. }mc_sn_t;
  88. #define motorParam_idx_0 3
  89. #define motorParam_idx_1 (motorParam_idx_0 + 1)
  90. #define focParam_idx_0 (motorParam_idx_1 + 1)
  91. #define focParam_idx_1 (focParam_idx_0 + 1)
  92. #define trq_Tbl_size (4)
  93. #define trq_Tbl_idx0 (focParam_idx_1 + 1)
  94. #define trq_Tbl_idx1 (trq_Tbl_idx0 + trq_Tbl_size)
  95. #define gear_config_idx_0 (trq_Tbl_idx1 + trq_Tbl_size)
  96. #define gear_config_idx_1 (gear_config_idx_0 + 1)
  97. #define sn_idx_back (gear_config_idx_1 + 1)
  98. #define limiter_cfg_idx_0 (sn_idx_back + 1)
  99. #define limiter_cfg_idx_1 (limiter_cfg_idx_0 + 1)
  100. void nv_storage_init(void);
  101. motor_params_t *nv_get_motor_params(void);
  102. foc_params_t *nv_get_foc_params(void);
  103. mc_gear_config_t *nv_get_gear_configs(void);
  104. mc_limit_t *nv_get_limter(void);
  105. void nv_save_angle_offset(float offset);
  106. void nv_save_motor_params(void);
  107. void nv_read_motor_params(void);
  108. void nv_save_foc_params(void);
  109. void nv_read_foc_params(void);
  110. void nv_save_hall_table(s32 *hall_table);
  111. void nv_set_pid(u8 id, pid_conf_t *pid);
  112. void nv_get_pid(u8 id, pid_conf_t *pid);
  113. void nv_set_hwbrake_mode(u8 mode);
  114. void nv_set_throttle_vol(float min, float max);
  115. int nv_write_sn(u8 *data, int len);
  116. int nv_read_sn(u8 *data, int len);
  117. bool nv_set_limit_config(u8 *config, int len);
  118. void nv_save_limit_config(void);
  119. void* nv_get_limit_config(int *len);
  120. bool nv_set_gear_config(u8 mode96, u8 *config, int len);
  121. void nv_save_gear_configs(void);
  122. void* nv_get_gear_config(u8 mode96, int *len);
  123. #endif /* _NV_Storage_H__ */