#ifndef _MC_ERROR_H__
#define _MC_ERROR_H__
#include "os/os_types.h"

#pragma  pack (push,1)
typedef struct {
	u8 idx;
	u8 err_code;
	s16 value1;
	s16 value2;
}err_node_t;

typedef struct {
	u8    idx;
	s16   vbus_x10;
	s16   ibus_x10;
	s16   vacc_x10;
	s16   id_x10;
	s16   iq_x10;
	s16   vd_x10;
	s16   vq_x10;
	s16   id_ref_x10;
	s16   iq_ref_x10;
	s16   torque_ref_x10;
	u8    run_mode;
	s16   rpm;
	u8    b_sensorless;
	u8    b_sensorless_stable;
	s16   sensorless_rpm;
	s16   mos_temp;
	s16   mot_temp;
	u8    enc_error;
}runtime_node_t;

#pragma pack(pop)

typedef struct{
	u8 tail;
	u8 count;
	u16 crc;
	err_node_t node[0];
}err_nv_t;

typedef struct{
	u8 tail;
	u8 count;
	u16 crc;
	runtime_node_t node[0];
}runtime_nv_t;

void mc_err_block_init(void);
void mc_crit_err_add(u8 code, s16 value1, s16 value2);
void mc_crit_err_add_s16(u8 code, s16 value);
void mc_err_block_save(void);
int mc_crit_err_get(s16 offset, u8 *buff, int len);
void mc_err_runtime_add(runtime_node_t *rt);
int mc_err_runtime_get(s16 offset, u8 *buff, int len);

#endif /*_MC_ERROR_H__ */

