nv_storage.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_acc_time;
  24. u32 n_dec_time;
  25. u32 n_ebrk_time;
  26. u8 n_FwEnable;
  27. pid_conf_t pid_conf[PID_Max_id];
  28. float f_minThroVol;
  29. float f_maxThroVol;
  30. u8 res[2048 - 161];
  31. u16 crc16;
  32. }foc_params_t;
  33. typedef struct {
  34. u8 mot_nr;
  35. u8 poles;
  36. float r;
  37. float ld;
  38. float lq;
  39. float flux_linkage;
  40. float back_emf;
  41. s32 hall_table[8];
  42. float offset;
  43. float est_pll_band; //normal工作模式下的pll带宽
  44. float pos_lock_pll_band; //电机锁定模式下的pll带宽
  45. u16 crc16;
  46. }motor_params_t;
  47. typedef struct {
  48. u16 u_maxRPM;
  49. u16 u_maxTorque;
  50. u16 u_maxIdc;
  51. u16 u_accTime;//加速曲线
  52. }mc_gear_t;
  53. #define CONFIG_MAX_GEAR_NUM 5
  54. typedef struct {
  55. mc_gear_t gears_48[CONFIG_MAX_GEAR_NUM];
  56. mc_gear_t gears_96[CONFIG_MAX_GEAR_NUM];
  57. u16 crc16;
  58. }mc_gear_config_t;
  59. #define MAX_TRQ_POINTS 20
  60. #define MAX_SPD_POINTS 40
  61. #define TBL_SPD_INTVAL 250
  62. typedef struct trq2dq {
  63. s16 torque;
  64. s16 d;
  65. s16 q;
  66. }trq2dq_t;
  67. typedef struct {
  68. struct trq2dq tdq[MAX_SPD_POINTS][MAX_TRQ_POINTS];
  69. u16 magic;
  70. u16 crc16;
  71. }trq2dq_table_t;
  72. #pragma pack(pop)
  73. typedef struct {
  74. u8 sn[32];
  75. u16 len;
  76. u16 crc;
  77. }mc_sn_t;
  78. #define motorParam_idx_0 3
  79. #define motorParam_idx_1 (motorParam_idx_0 + 1)
  80. #define focParam_idx_0 (motorParam_idx_1 + 1)
  81. #define focParam_idx_1 (focParam_idx_0 + 1)
  82. #define trq_Tbl_size (4)
  83. #define trq_Tbl_idx0 (focParam_idx_1 + 1)
  84. #define trq_Tbl_idx1 (trq_Tbl_idx0 + trq_Tbl_size)
  85. #define gear_config_idx_0 (trq_Tbl_idx1 + trq_Tbl_size)
  86. #define gear_config_idx_1 (gear_config_idx_0 + 1)
  87. #define sn_idx_back (gear_config_idx_1 + 1)
  88. void nv_storage_init(void);
  89. motor_params_t *nv_get_motor_params(void);
  90. foc_params_t *nv_get_foc_params(void);
  91. mc_gear_config_t *nv_get_gear_configs(void);
  92. void nv_save_angle_offset(float offset);
  93. void nv_save_motor_params(void);
  94. void nv_read_motor_params(void);
  95. void nv_save_foc_params(void);
  96. void nv_read_foc_params(void);
  97. void nv_save_hall_table(s32 *hall_table);
  98. void nv_set_pid(u8 id, pid_conf_t *pid);
  99. void nv_get_pid(u8 id, pid_conf_t *pid);
  100. void nv_set_hwbrake_mode(u8 mode);
  101. void nv_set_throttle_vol(float min, float max);
  102. bool nv_set_gear_config(u8 mode4896, u8 gear, u16 rpm, u16 torque, u16 idc, u16 acc);
  103. bool nv_get_gear_config(u8 mode4896, u8 gear, u16 *rpm, u16 *torque, u16 *idc, u16 *acc);
  104. trq2dq_table_t *nv_get_trq2dq_table(void);
  105. void nv_write_trq_table_begin(int index);
  106. int nv_write_trq_table_continue(uint8_t *data, int len);
  107. int nv_write_trq_table_check(u8 *data, int len, int index);
  108. int nv_write_sn(u8 *data, int len);
  109. int nv_read_sn(u8 *data, int len);
  110. #endif /* _NV_Storage_H__ */