You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

121 lines
2.7 KiB

#include "common.h"
//#include "../tpc/tpc_uart.h"
#include "../bsp/bsp_cs1232.h"
#include "../msp/msp_eeprom.h"
#include "../msp/msp_id.h"
#include "c_crc.h"
struct global_param G;
struct ts_eeprom_param eep_param;
struct ts_eeprom_enc eep_enc;
#define EEP_SECTOR_SIZE 0x200
#define EEP_PARAM_ADDR (EEP_SECTOR_SIZE * 1)
#define EEP_ENC_ADDR (EEP_SECTOR_SIZE * 0)
U8 L1_eeprom_read(U8 *buf,U8 *len)
{
U8 dlen = 0;
L0_Iap_Read_array(EEP_PARAM_ADDR, (U8*)&eep_param, 2 + EEPROM_PARAM_DATA_MAX + 2);
if(eep_param.filter == EEPROM_PARAM_FILTER)
{
dlen = eep_param.len - 2;
crc16(eep_param.crc,(U8*)&eep_param,2+dlen);
if(eep_param.crc[0] == eep_param.buf[dlen] && eep_param.crc[1] == eep_param.buf[dlen+1])
{
L0_uart0_uc('#');
//Lc_buf_copy_uc((U8*)&G.p,(U8*)eep_param.buf,dlen);
Lc_buf_copy_uc(buf,(U8*)eep_param.buf,dlen);//防止dlen>sizeof(G.P)引起的内存错误
*len = dlen;
return 0;
}
}
return 1;
}
U8 L1_eeprom_write(U8 *buf, U8 len)
{
U8 dlen = len;
eep_param.filter = EEPROM_PARAM_FILTER;
eep_param.len = dlen + 2;
Lc_buf_copy_uc((U8*)eep_param.buf,buf,dlen);
crc16(eep_param.crc, &eep_param, 2+dlen);
eep_param.buf[dlen] = eep_param.crc[0];
eep_param.buf[dlen+1] = eep_param.crc[1];
L0_Iap_Erase(EEP_PARAM_ADDR);
L0_Iap_Program_array(EEP_PARAM_ADDR, (U8*)&eep_param, 2 + dlen + 2);
return 0;
}
int L3_mcu_id_ok(void)
{
U8 i = 0,crc[2];
U32 enc_key;
//1.获取MCU_ID
L0_id_get_rom(G.e.mcu_id);
for(i=0;i<MCU_ID_LEN;i++)
{
L0_uart0_uchex(G.e.mcu_id[i]);
}
//2.读取eeprom中的加密信息
L0_Iap_Read_array(EEP_ENC_ADDR, (U8*)&eep_enc, MCU_ID_KEY_LEN + MCU_ID_LEN + 2);
crc16(crc,(U8*)&eep_enc,MCU_ID_KEY_LEN + MCU_ID_LEN);
if(eep_enc.crc[0] != crc[0] || eep_enc.crc[1] != crc[1])
{
L0_uart0_uc('-');
return 0;
}
//3.根据mcu_id和enc_key计算enc_val
enc_key = ((U32)eep_enc.enc_key[0] << 24) | (eep_enc.enc_key[1] << 16) | (eep_enc.enc_key[2] << 8) |(eep_enc.enc_key[3] << 0);
Lc_encrypt_id((U8*)G.e.mcu_enc_id, (U8*)G.e.mcu_id, enc_key, MCU_ID_LEN);
//4.判断enc_val是否一致
for(i=0;i<MCU_ID_KEY_LEN;i++)
{
if(G.e.mcu_enc_id[i] != eep_enc.enc_val[i])
{
return 0;
}
}
return 1;
}
void L3_param_init(void)
{
int i;
for(i=0;i<D_ch_max_num;i++)
{
G.weight[i] = 0;
}
G.allweight = 0;
G._total_weight = 0;
G._total_zweight = 0;
//L3_eeprom_read_param();
}
#if 0
S32 L3_count_std_weight(S32 weight)
{
U8 i = 0;
U16 ratio = 100;
weight = (weight - G._total_zweight)/10;
for(i=0;i<D_weight_std_num;i++)
{
if(R.p.weight_std[i].weight_range == 0 || (R.p.weight_std[i].weight_range * 100) >= weight)
{
break;
}
}
if(i<D_weight_std_num && R.p.weight_std[i].ratio != 0)
{
ratio = R.p.weight_std[i].ratio;
}
return (S32)(weight * 1.0 * ratio / 100) ;
}
#endif