nv_storage.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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[256 - 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 offset;
  46. float est_pll_band; //normal工作模式下的pll带宽
  47. float pos_lock_pll_band; //电机锁定模式下的pll带宽
  48. float epm_pll_band;
  49. s16 velocity_weight;//车重, kg
  50. s16 velocity_C; //车轮周长, cm
  51. s16 gear_ratio; //传动比
  52. u8 res[128 - 36 - 6];
  53. u16 crc16;
  54. }motor_params_t;
  55. typedef struct {
  56. s16 enter_pointer;
  57. s16 exit_pointer;
  58. s16 limit_value;
  59. }nv_limter_t;
  60. #define TEMP_LIMITER_NUM 3
  61. typedef struct {
  62. u16 magic;
  63. nv_limter_t motor[TEMP_LIMITER_NUM];
  64. nv_limter_t mos[TEMP_LIMITER_NUM];
  65. nv_limter_t vbus;
  66. u8 res[128 - 46];
  67. u16 crc16;
  68. }mc_limit_t;
  69. #define GEAR_SPEED_TRQ_NUM 10
  70. typedef struct {
  71. u16 n_max_speed; //最大速度, rpm
  72. u16 n_max_trq; //最大扭矩
  73. u16 n_max_idc; //最大母线电流
  74. u16 n_zero_accl; //零速启动扭矩给定时间,防止翘头
  75. u16 n_accl_time; //加速的扭矩斜坡时间
  76. u8 n_torque[GEAR_SPEED_TRQ_NUM]; //1000, 2000, 3000... RPM 最大给定扭矩的百分比(最大扭矩的百分比)
  77. }mc_gear_t;
  78. #define CONFIG_MAX_GEAR_NUM 4
  79. typedef struct {
  80. mc_gear_t gears_48[CONFIG_MAX_GEAR_NUM];
  81. mc_gear_t gears_96[CONFIG_MAX_GEAR_NUM];
  82. u16 magic;
  83. u16 crc16;
  84. }mc_gear_config_t;
  85. #pragma pack(pop)
  86. typedef struct {
  87. u8 sn[32];
  88. u16 len;
  89. u16 crc;
  90. }mc_sn_t;
  91. #define motorParam_idx_0 3
  92. #define motorParam_idx_1 (motorParam_idx_0 + 1)
  93. #define focParam_idx_0 (motorParam_idx_1 + 1)
  94. #define focParam_idx_1 (focParam_idx_0 + 1)
  95. #define trq_Tbl_size (4)
  96. #define trq_Tbl_idx0 (focParam_idx_1 + 1)
  97. #define trq_Tbl_idx1 (trq_Tbl_idx0 + trq_Tbl_size)
  98. #define gear_config_idx_0 (trq_Tbl_idx1 + trq_Tbl_size)
  99. #define gear_config_idx_1 (gear_config_idx_0 + 1)
  100. #define sn_idx_back (gear_config_idx_1 + 1)
  101. #define limiter_cfg_idx_0 (sn_idx_back + 1)
  102. #define limiter_cfg_idx_1 (limiter_cfg_idx_0 + 1)
  103. void nv_storage_init(void);
  104. motor_params_t *nv_get_motor_params(void);
  105. foc_params_t *nv_get_foc_params(void);
  106. mc_gear_config_t *nv_get_gear_configs(void);
  107. mc_limit_t *nv_get_limter(void);
  108. void nv_save_angle_offset(float offset);
  109. void nv_save_motor_params(void);
  110. void nv_read_motor_params(void);
  111. void nv_save_foc_params(void);
  112. void nv_read_foc_params(void);
  113. void nv_save_hall_table(s32 *hall_table);
  114. void nv_set_pid(u8 id, pid_conf_t *pid);
  115. void nv_get_pid(u8 id, pid_conf_t *pid);
  116. void nv_set_hwbrake_mode(u8 mode);
  117. void nv_set_throttle_vol(float min, float max);
  118. int nv_write_sn(u8 *data, int len);
  119. int nv_read_sn(u8 *data, int len);
  120. bool nv_set_limit_config(u8 *config, int len);
  121. void nv_save_limit_config(void);
  122. void* nv_get_limit_config(int *len);
  123. bool nv_set_gear_config(u8 mode96, u8 *config, int len);
  124. void nv_save_gear_configs(void);
  125. void* nv_get_gear_config(u8 mode96, int *len);
  126. #endif /* _NV_Storage_H__ */