|
|
@@ -5,6 +5,26 @@
|
|
|
#include "foc/motor/motor_param.h"
|
|
|
#include "foc/foc_config.h"
|
|
|
|
|
|
+#define motorParam_idx_0 (sn_page_index + 1)
|
|
|
+#define motorParam_idx_1 (motorParam_idx_0 + 1)
|
|
|
+#define focParam_idx_0 (motorParam_idx_1 + 1)
|
|
|
+#define focParam_idx_1 (focParam_idx_0 + 1)
|
|
|
+
|
|
|
+#define trq_Tbl_size (4)
|
|
|
+#define trq_Tbl_idx0 (focParam_idx_1 + 1)
|
|
|
+#define trq_Tbl_idx1 (trq_Tbl_idx0 + trq_Tbl_size)
|
|
|
+
|
|
|
+#define gear_config_idx_0 (trq_Tbl_idx1 + trq_Tbl_size)
|
|
|
+#define gear_config_idx_1 (gear_config_idx_0 + 1)
|
|
|
+
|
|
|
+#define sn_idx_back (gear_config_idx_1 + 1)
|
|
|
+
|
|
|
+#define limiter_cfg_idx_0 (sn_idx_back + 1)
|
|
|
+#define limiter_cfg_idx_1 (limiter_cfg_idx_0 + 1)
|
|
|
+
|
|
|
+#define mc_err_red_idx_0 (limiter_cfg_idx_1 + 1)
|
|
|
+#define mc_err_red_idx_1 (mc_err_red_idx_0 + 1)
|
|
|
+
|
|
|
static motor_params_t m_params;
|
|
|
static foc_params_t foc_params;
|
|
|
static mc_gear_config_t gear_config;
|
|
|
@@ -475,7 +495,93 @@ int nv_read_sn(u8 *data, int len) {
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+static int _mc_err_r_id = mc_err_red_idx_0;
|
|
|
+static u8 _mc_err_r_idx = 0;
|
|
|
+static void mc_err_block_init(void) {
|
|
|
+ mc_err_red_t me0, me1;
|
|
|
+ fmc_read_data(mc_err_red_idx_0, (u8 *)&me0, sizeof(mc_err_red_t));
|
|
|
+ if (me0.len > (one_page_size - sizeof(mc_err_red_t))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ fmc_read_data(mc_err_red_idx_1, (u8 *)&me1, sizeof(mc_err_red_t));
|
|
|
+ if (me1.len > (one_page_size - sizeof(mc_err_red_t))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (me0.index > me1.index) {
|
|
|
+ if (me0.index == 255 && me1.index == 0) {
|
|
|
+ _mc_err_r_id = mc_err_red_idx_0;
|
|
|
+ _mc_err_r_idx = 1;
|
|
|
+ }else {
|
|
|
+ _mc_err_r_id = mc_err_red_idx_1;
|
|
|
+ _mc_err_r_idx = (me0.index + 1) % 255;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (me0.index == 0 && me1.index == 255) {
|
|
|
+ _mc_err_r_id = mc_err_red_idx_1;
|
|
|
+ _mc_err_r_idx = 1;
|
|
|
+ }else {
|
|
|
+ _mc_err_r_id = mc_err_red_idx_0;
|
|
|
+ _mc_err_r_idx = (me1.index + 1) % 255;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void mc_err_block_write(u32 err_mask, u8 *data, int len) {
|
|
|
+ mc_err_red_t me;
|
|
|
+ me.index = _mc_err_r_idx;
|
|
|
+ me.len = (u16)len;
|
|
|
+ if (me.len > (one_page_size - sizeof(mc_err_red_t))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ me.err_mask = err_mask;
|
|
|
+ me.crc = crc16_get(data, me.len);
|
|
|
+ fmc_write_data(_mc_err_r_id, data, len);
|
|
|
+ _mc_err_r_idx = (me.index + 1) % 255;
|
|
|
+ if (_mc_err_r_id == mc_err_red_idx_0) {
|
|
|
+ _mc_err_r_id = mc_err_red_idx_1;
|
|
|
+ }else {
|
|
|
+ _mc_err_r_id = mc_err_red_idx_0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int mc_error_block_read(int block, u32 *err_mask, u8 *data, int len) {
|
|
|
+ mc_err_red_t me;
|
|
|
+ int index = block?mc_err_red_idx_1:mc_err_red_idx_0;
|
|
|
+ fmc_read_data(index, (u8 *)&me, sizeof(mc_err_red_t));
|
|
|
+ fmc_read_data_with_offset(index, sizeof(mc_err_red_t), data, len);
|
|
|
+ if (me.crc != crc16_get(data, len)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (err_mask) {
|
|
|
+ *err_mask = me.err_mask;
|
|
|
+ }
|
|
|
+ return me.index;
|
|
|
+}
|
|
|
|
|
|
+int mc_error_curr_block_read(u32 *err_mask, u8 *data, int len) {
|
|
|
+ int idx0 = mc_error_block_read(0, err_mask, data, len);
|
|
|
+ int idx1 = mc_error_block_read(1, err_mask, data, len);
|
|
|
+ if (idx0 == -1 && idx1 == -1) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (idx0 == -1) {
|
|
|
+ return idx1;
|
|
|
+ }
|
|
|
+ if (idx1 == -1) {
|
|
|
+ return mc_error_block_read(0, err_mask, data, len);
|
|
|
+ }
|
|
|
+ if (idx0 == 255 && idx1 == 0) {
|
|
|
+ return idx1;
|
|
|
+ }
|
|
|
+ if (idx0 == 0 && idx1 == 255) {
|
|
|
+ return mc_error_block_read(0, err_mask, data, len);
|
|
|
+ }
|
|
|
+ if (idx0 > idx1) {
|
|
|
+ return mc_error_block_read(0, err_mask, data, len);
|
|
|
+ }
|
|
|
+ return idx1;
|
|
|
+}
|
|
|
|
|
|
void nv_storage_init(void) {
|
|
|
nv_read_motor_params();
|
|
|
@@ -503,6 +609,8 @@ void nv_storage_init(void) {
|
|
|
#if CONFIG_MOT_TYPE==MOTOR_BLUESHARK_A1
|
|
|
m_params.offset = 0.0f; //编码器做了零位置校准
|
|
|
#endif
|
|
|
- sys_debug("%f -- %f, flux: %f, %d\n", foc_params.n_currentBand, m_params.ld, m_params.flux_linkage, sizeof(m_params));
|
|
|
+ mc_err_block_init();
|
|
|
+ //sys_debug("%f -- %f, flux: %f, %d\n", foc_params.n_currentBand, m_params.ld, m_params.flux_linkage, sizeof(m_params));
|
|
|
+ sys_debug("mc err %d, %d\n", _mc_err_r_id, _mc_err_r_idx);
|
|
|
}
|
|
|
|