nv_storage.h 3.3 KB

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