|
@@ -2,6 +2,7 @@
|
|
|
#include "libs/utils.h"
|
|
#include "libs/utils.h"
|
|
|
#include "libs/crc16.h"
|
|
#include "libs/crc16.h"
|
|
|
#include "app/nv_storage.h"
|
|
#include "app/nv_storage.h"
|
|
|
|
|
+#include "libs/logger.h"
|
|
|
|
|
|
|
|
mc_config conf;
|
|
mc_config conf;
|
|
|
|
|
|
|
@@ -56,7 +57,8 @@ bool mc_conf_finish_recv(u16 crc) {
|
|
|
static u16 crc16;
|
|
static u16 crc16;
|
|
|
bool mc_conf_begin_send(void) {
|
|
bool mc_conf_begin_send(void) {
|
|
|
if (conf_buff) {
|
|
if (conf_buff) {
|
|
|
- return true;
|
|
|
|
|
|
|
+ os_free(conf_buff);
|
|
|
|
|
+ conf_buff = NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
conf_idx = 0;
|
|
conf_idx = 0;
|
|
@@ -65,11 +67,13 @@ bool mc_conf_begin_send(void) {
|
|
|
conf_len = mc_conf_encode_configs(conf_buff);
|
|
conf_len = mc_conf_encode_configs(conf_buff);
|
|
|
crc16 = crc16_get(conf_buff, conf_len);
|
|
crc16 = crc16_get(conf_buff, conf_len);
|
|
|
}
|
|
}
|
|
|
|
|
+ sys_debug("%x, %d, %d\n", conf_buff, conf_len, crc16);
|
|
|
return conf_buff != NULL;
|
|
return conf_buff != NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
int mc_conf_send_data(u8 *buff, int offset, int len) {
|
|
int mc_conf_send_data(u8 *buff, int offset, int len) {
|
|
|
|
|
+ sys_debug("off %d, %d\n", offset, conf_idx);
|
|
|
if (offset == 0 && !mc_conf_begin_send()) {
|
|
if (offset == 0 && !mc_conf_begin_send()) {
|
|
|
return -2;
|
|
return -2;
|
|
|
}
|
|
}
|
|
@@ -105,21 +109,28 @@ void mc_conf_load(void) {
|
|
|
u16 crc16 = crc16_get((u8 *)&temp, (u8 *)&temp.crc - (u8 *)&temp);
|
|
u16 crc16 = crc16_get((u8 *)&temp, (u8 *)&temp.crc - (u8 *)&temp);
|
|
|
bool idx0_success = crc16 == temp.crc;
|
|
bool idx0_success = crc16 == temp.crc;
|
|
|
if (idx0_success) {
|
|
if (idx0_success) {
|
|
|
|
|
+ sys_debug("conf block 0 OK!\n");
|
|
|
memcpy(&conf, &temp, sizeof(temp));
|
|
memcpy(&conf, &temp, sizeof(temp));
|
|
|
}
|
|
}
|
|
|
nv_read_config_block(1, (u8 *)&temp, sizeof(temp));
|
|
nv_read_config_block(1, (u8 *)&temp, sizeof(temp));
|
|
|
crc16 = crc16_get((u8 *)&temp, (u8 *)&temp.crc - (u8 *)&temp);
|
|
crc16 = crc16_get((u8 *)&temp, (u8 *)&temp.crc - (u8 *)&temp);
|
|
|
if (crc16 == temp.crc && !idx0_success) {
|
|
if (crc16 == temp.crc && !idx0_success) {
|
|
|
|
|
+ sys_debug("conf block0 Bad!\n");
|
|
|
|
|
+ sys_debug("conf block 1 OK!\n");
|
|
|
memcpy(&conf, &temp, sizeof(temp));
|
|
memcpy(&conf, &temp, sizeof(temp));
|
|
|
nv_write_config_block(0, (u8 *)&temp, sizeof(temp));
|
|
nv_write_config_block(0, (u8 *)&temp, sizeof(temp));
|
|
|
}else if (crc16 != temp.crc) {
|
|
}else if (crc16 != temp.crc) {
|
|
|
if (idx0_success) {
|
|
if (idx0_success) {
|
|
|
|
|
+ sys_debug("conf block1 Bad!\n");
|
|
|
nv_write_config_block(1, (u8 *)&conf, sizeof(conf));
|
|
nv_write_config_block(1, (u8 *)&conf, sizeof(conf));
|
|
|
}else {
|
|
}else {
|
|
|
|
|
+ sys_debug("conf block0&1 Bad!\n");
|
|
|
mc_conf_default();
|
|
mc_conf_default();
|
|
|
nv_write_config_block(0, (u8 *)&conf, sizeof(conf));
|
|
nv_write_config_block(0, (u8 *)&conf, sizeof(conf));
|
|
|
nv_write_config_block(1, (u8 *)&conf, sizeof(conf));
|
|
nv_write_config_block(1, (u8 *)&conf, sizeof(conf));
|
|
|
}
|
|
}
|
|
|
|
|
+ }else {
|
|
|
|
|
+ sys_debug("conf block 1 OK!\n");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -135,7 +146,7 @@ void mc_conf_load(void) {
|
|
|
Gear_torque(l,5);Gear_torque(l,6);Gear_torque(l,7);Gear_torque(l,8);Gear_torque(l,9); \
|
|
Gear_torque(l,5);Gear_torque(l,6);Gear_torque(l,7);Gear_torque(l,8);Gear_torque(l,9); \
|
|
|
}while(0);
|
|
}while(0);
|
|
|
|
|
|
|
|
-#define GearLow_torque(l, t) conf.g_n[l].torque[t] = CONFIG_GearLow##l##_Torque##t
|
|
|
|
|
|
|
+#define GearLow_torque(l, t) conf.g_l[l].torque[t] = CONFIG_GearLow##l##_Torque##t
|
|
|
#define GearLow_Config_default(l) \
|
|
#define GearLow_Config_default(l) \
|
|
|
do { \
|
|
do { \
|
|
|
conf.g_l[l].max_speed = CONFIG_GearLow##l##_MaxSpeed;\
|
|
conf.g_l[l].max_speed = CONFIG_GearLow##l##_MaxSpeed;\
|
|
@@ -162,11 +173,12 @@ void mc_conf_load(void) {
|
|
|
}while(0);
|
|
}while(0);
|
|
|
|
|
|
|
|
void mc_conf_default(void) {
|
|
void mc_conf_default(void) {
|
|
|
- conf.version = 0;
|
|
|
|
|
|
|
+ conf.version = CONFIG_Version;
|
|
|
conf.m.poles = CONFIG_Motor_Poles;
|
|
conf.m.poles = CONFIG_Motor_Poles;
|
|
|
conf.m.ld = CONFIG_Motor_Ld;
|
|
conf.m.ld = CONFIG_Motor_Ld;
|
|
|
conf.m.lq = CONFIG_Motor_Lq;
|
|
conf.m.lq = CONFIG_Motor_Lq;
|
|
|
conf.m.rs = CONFIG_Motor_Rs;
|
|
conf.m.rs = CONFIG_Motor_Rs;
|
|
|
|
|
+ conf.m.flux = CONFIG_Motor_Flux;
|
|
|
conf.m.nor_pll_band = CONFIG_Motor_PLLBand;
|
|
conf.m.nor_pll_band = CONFIG_Motor_PLLBand;
|
|
|
conf.m.epm_pll_band = CONFIG_Motor_EpmPLL;
|
|
conf.m.epm_pll_band = CONFIG_Motor_EpmPLL;
|
|
|
conf.m.pos_pll_band = CONFIG_Motor_PosPLL;
|
|
conf.m.pos_pll_band = CONFIG_Motor_PosPLL;
|
|
@@ -210,8 +222,8 @@ void mc_conf_default(void) {
|
|
|
conf.c.pid[PID_Vel_ID].kd = CONFIG_Foc_PID_VelCtrl_Kd;
|
|
conf.c.pid[PID_Vel_ID].kd = CONFIG_Foc_PID_VelCtrl_Kd;
|
|
|
|
|
|
|
|
conf.c.pid[PID_AutoHold_ID].kp = CONFIG_Foc_PID_Autohold_Kp;
|
|
conf.c.pid[PID_AutoHold_ID].kp = CONFIG_Foc_PID_Autohold_Kp;
|
|
|
- conf.c.pid[PID_AutoHold_ID].kp = CONFIG_Foc_PID_Autohold_Ki;
|
|
|
|
|
- conf.c.pid[PID_AutoHold_ID].ki = CONFIG_Foc_PID_Autohold_Kd;
|
|
|
|
|
|
|
+ conf.c.pid[PID_AutoHold_ID].ki = CONFIG_Foc_PID_Autohold_Ki;
|
|
|
|
|
+ conf.c.pid[PID_AutoHold_ID].kd = CONFIG_Foc_PID_Autohold_Kd;
|
|
|
|
|
|
|
|
conf.c.pid[PID_IDCLim_ID].kp = CONFIG_Foc_PID_IDCLim_Kp;
|
|
conf.c.pid[PID_IDCLim_ID].kp = CONFIG_Foc_PID_IDCLim_Kp;
|
|
|
conf.c.pid[PID_IDCLim_ID].ki = CONFIG_Foc_PID_IDCLim_Ki;
|
|
conf.c.pid[PID_IDCLim_ID].ki = CONFIG_Foc_PID_IDCLim_Ki;
|
|
@@ -291,7 +303,7 @@ int mc_conf_encode_motor(u8 *buff) {
|
|
|
encode_u16(buff, conf.m.velocity_w);buff += 2;
|
|
encode_u16(buff, conf.m.velocity_w);buff += 2;
|
|
|
encode_u16(buff, conf.m.wheel_c);buff += 2;
|
|
encode_u16(buff, conf.m.wheel_c);buff += 2;
|
|
|
encode_float(buff, conf.m.gear_ratio);buff += 4;
|
|
encode_float(buff, conf.m.gear_ratio);buff += 4;
|
|
|
- encode_u16(buff, conf.m.max_fw_id); buff += 4;
|
|
|
|
|
|
|
+ encode_u16(buff, conf.m.max_fw_id); buff += 2;
|
|
|
return buff - ori;
|
|
return buff - ori;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -419,6 +431,7 @@ int mc_conf_decode_limiter(limiter_t *l, int size, u8 *buff) {
|
|
|
l->enter_pointer = decode_s16(buff);buff += 2;
|
|
l->enter_pointer = decode_s16(buff);buff += 2;
|
|
|
l->exit_pointer = decode_s16(buff);buff += 2;
|
|
l->exit_pointer = decode_s16(buff);buff += 2;
|
|
|
l->limit_value = decode_s16(buff);buff += 2;
|
|
l->limit_value = decode_s16(buff);buff += 2;
|
|
|
|
|
+ l++;
|
|
|
}
|
|
}
|
|
|
return buff - ori;
|
|
return buff - ori;
|
|
|
}
|
|
}
|
|
@@ -429,6 +442,7 @@ int mc_conf_encode_limiter(limiter_t *l, int size, u8 *buff) {
|
|
|
encode_s16(buff, l->enter_pointer);buff += 2;
|
|
encode_s16(buff, l->enter_pointer);buff += 2;
|
|
|
encode_s16(buff, l->exit_pointer);buff += 2;
|
|
encode_s16(buff, l->exit_pointer);buff += 2;
|
|
|
encode_s16(buff, l->limit_value);buff += 2;
|
|
encode_s16(buff, l->limit_value);buff += 2;
|
|
|
|
|
+ l++;
|
|
|
}
|
|
}
|
|
|
return buff - ori;
|
|
return buff - ori;
|
|
|
}
|
|
}
|
|
@@ -505,7 +519,7 @@ int mc_conf_get_gear(u8 mode, u8 *data) {
|
|
|
if (mode == 0) {
|
|
if (mode == 0) {
|
|
|
g = conf.g_l;
|
|
g = conf.g_l;
|
|
|
}
|
|
}
|
|
|
- return mc_conf_decode_gear(g, data);
|
|
|
|
|
|
|
+ return mc_conf_encode_gear(g, data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool mc_conf_set_limter(u8 *data, int len) {
|
|
bool mc_conf_set_limter(u8 *data, int len) {
|
|
@@ -517,8 +531,8 @@ bool mc_conf_set_limter(u8 *data, int len) {
|
|
|
|
|
|
|
|
int mc_conf_get_limter(u8 *data) {
|
|
int mc_conf_get_limter(u8 *data) {
|
|
|
u8 *ori = data;
|
|
u8 *ori = data;
|
|
|
- data += mc_conf_decode_limiter(conf.p_mot, CONFIG_TEMP_PROT_NUM, data);
|
|
|
|
|
- data += mc_conf_decode_limiter(conf.p_mos, CONFIG_TEMP_PROT_NUM, data);
|
|
|
|
|
- data += mc_conf_decode_limiter(&conf.p_vol, 1, data);
|
|
|
|
|
|
|
+ data += mc_conf_encode_limiter(conf.p_mot, CONFIG_TEMP_PROT_NUM, data);
|
|
|
|
|
+ data += mc_conf_encode_limiter(conf.p_mos, CONFIG_TEMP_PROT_NUM, data);
|
|
|
|
|
+ data += mc_conf_encode_limiter(&conf.p_vol, 1, data);
|
|
|
return data-ori;
|
|
return data-ori;
|
|
|
}
|
|
}
|