#ifndef _NV_Storage_H__ #define _NV_Storage_H__ #include "os/os_types.h" #include "foc/core/PMSM_FOC_Core.h" #include "foc/commands.h" #pragma pack (push,1) typedef struct { float s_PhaseCurrLim; float s_maxDCVol; float s_minDCVol; float s_maxRPM; float s_maxEpmRPM; float s_maxEpmTorqueLim; float s_maxTorque; float s_TorqueBrkLim; float s_iDCeBrkLim; float s_LimitiDC; float n_currentBand; //电流环带宽 float n_startThroVol; float n_endThroVol; u8 n_brkShutPower; u8 n_autoHold; u32 n_dec_time; u32 n_ebrk_time; u8 n_FwEnable; pid_conf_t pid_conf[PID_Max_id]; float f_minThroVol; float f_maxThroVol; float f_adrc_vel_lim_Wo; float f_adrc_vel_lim_Wcv; float f_adrc_vel_lim_B0; float f_adrc_vel_Wo; float f_adrc_vel_Wcv; float f_adrc_vel_B0; float s_maxEpmRPMBck; float s_maxEpmTorqueLimBck; u8 res[256 - 157 - 24 - 8]; u16 crc16; }foc_params_t; typedef struct { u8 mot_nr; u8 poles; float r; float ld; float lq; float flux_linkage; float offset; float est_pll_band; //normal工作模式下的pll带宽 float pos_lock_pll_band; //电机锁定模式下的pll带宽 float epm_pll_band; s16 velocity_weight;//车重, kg s16 velocity_C; //车轮周长, cm s16 gear_ratio; //传动比 u8 res[128 - 36 - 6]; u16 crc16; }motor_params_t; typedef struct { s16 enter_pointer; s16 exit_pointer; s16 limit_value; }nv_limter_t; #define TEMP_LIMITER_NUM 3 typedef struct { u16 magic; nv_limter_t motor[TEMP_LIMITER_NUM]; nv_limter_t mos[TEMP_LIMITER_NUM]; nv_limter_t vbus; u8 res[128 - 46]; u16 crc16; }mc_limit_t; #define GEAR_SPEED_TRQ_NUM 10 typedef struct { u16 n_max_speed; //最大速度, rpm u16 n_max_trq; //最大扭矩 u16 n_max_idc; //最大母线电流 u16 n_zero_accl; //零速启动扭矩给定时间,防止翘头 u16 n_accl_time; //加速的扭矩斜坡时间 u8 n_torque[GEAR_SPEED_TRQ_NUM]; //1000, 2000, 3000... RPM 最大给定扭矩的百分比(最大扭矩的百分比) }mc_gear_t; #define CONFIG_MAX_GEAR_NUM 4 typedef struct { mc_gear_t gears_48[CONFIG_MAX_GEAR_NUM]; mc_gear_t gears_96[CONFIG_MAX_GEAR_NUM]; u16 magic; u16 crc16; }mc_gear_config_t; #pragma pack(pop) typedef struct { u8 sn[32]; u16 len; u16 crc; }mc_sn_t; typedef struct { u8 index; u16 crc; u16 len; u32 err_mask; u8 data[0]; //just a tag, no memeory alloc }mc_err_red_t; void nv_storage_init(void); motor_params_t *nv_get_motor_params(void); foc_params_t *nv_get_foc_params(void); mc_gear_config_t *nv_get_gear_configs(void); mc_limit_t *nv_get_limter(void); void nv_save_angle_offset(float offset); void nv_save_motor_params(void); void nv_read_motor_params(void); void nv_save_foc_params(void); void nv_read_foc_params(void); void nv_save_hall_table(s32 *hall_table); void nv_set_pid(u8 id, pid_conf_t *pid); void nv_get_pid(u8 id, pid_conf_t *pid); void nv_set_hwbrake_mode(u8 mode); void nv_set_throttle_vol(float min, float max); int nv_write_sn(u8 *data, int len); int nv_read_sn(u8 *data, int len); bool nv_set_limit_config(u8 *config, int len); void nv_save_limit_config(void); void* nv_get_limit_config(int *len); bool nv_set_gear_config(u8 mode96, u8 *config, int len); void nv_save_gear_configs(void); void* nv_get_gear_config(u8 mode96, int *len); void nv_write_crit_errblock(u8 *data, int len); void nv_read_crit_errblock(u8 *data, int len); void nv_write_runtime_block(u8 *data, int len); void nv_read_runtime_block(u8 *data, int len); #endif /* _NV_Storage_H__ */