nv_storage.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. float s_maxEpmRPMBck;
  36. float s_maxEpmTorqueLimBck;
  37. u8 res[256 - 157 - 24 - 8];
  38. u16 crc16;
  39. }foc_params_t;
  40. typedef struct {
  41. u8 mot_nr;
  42. u8 poles;
  43. float r;
  44. float ld;
  45. float lq;
  46. float flux_linkage;
  47. float offset;
  48. float est_pll_band; //normal工作模式下的pll带宽
  49. float pos_lock_pll_band; //电机锁定模式下的pll带宽
  50. float epm_pll_band;
  51. s16 velocity_weight;//车重, kg
  52. s16 velocity_C; //车轮周长, cm
  53. s16 gear_ratio; //传动比
  54. u8 res[128 - 36 - 6];
  55. u16 crc16;
  56. }motor_params_t;
  57. typedef struct {
  58. s16 enter_pointer;
  59. s16 exit_pointer;
  60. s16 limit_value;
  61. }nv_limter_t;
  62. #define TEMP_LIMITER_NUM 3
  63. typedef struct {
  64. u16 magic;
  65. nv_limter_t motor[TEMP_LIMITER_NUM];
  66. nv_limter_t mos[TEMP_LIMITER_NUM];
  67. nv_limter_t vbus;
  68. u8 res[128 - 46];
  69. u16 crc16;
  70. }mc_limit_t;
  71. #define GEAR_SPEED_TRQ_NUM 10
  72. typedef struct {
  73. u16 n_max_speed; //最大速度, rpm
  74. u16 n_max_trq; //最大扭矩
  75. u16 n_max_idc; //最大母线电流
  76. u16 n_zero_accl; //零速启动扭矩给定时间,防止翘头
  77. u16 n_accl_time; //加速的扭矩斜坡时间
  78. u8 n_torque[GEAR_SPEED_TRQ_NUM]; //1000, 2000, 3000... RPM 最大给定扭矩的百分比(最大扭矩的百分比)
  79. }mc_gear_t;
  80. #define CONFIG_MAX_GEAR_NUM 4
  81. typedef struct {
  82. mc_gear_t gears_48[CONFIG_MAX_GEAR_NUM];
  83. mc_gear_t gears_96[CONFIG_MAX_GEAR_NUM];
  84. u16 magic;
  85. u16 crc16;
  86. }mc_gear_config_t;
  87. #pragma pack(pop)
  88. typedef struct {
  89. u8 sn[32];
  90. u16 len;
  91. u16 crc;
  92. }mc_sn_t;
  93. typedef struct {
  94. u8 index;
  95. u16 crc;
  96. u16 len;
  97. u32 err_mask;
  98. u8 data[0]; //just a tag, no memeory alloc
  99. }mc_err_red_t;
  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. void nv_write_crit_errblock(u8 *data, int len);
  124. void nv_read_crit_errblock(u8 *data, int len);
  125. void nv_write_runtime_block(u8 *data, int len);
  126. void nv_read_runtime_block(u8 *data, int len);
  127. #endif /* _NV_Storage_H__ */