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.

76 lines
1.6 KiB

5 years ago
#include "common.h"
//#include "../tpc/tpc_uart.h"
#include "../msp/msp_eeprom.h"
#include "../msp/msp_id.h"
struct global_param G;
struct ts_eeprom_param eep_param;
#define EEP_SECTOR_SIZE 0x200
#define EEP_PARAM_ADDR (EEP_SECTOR_SIZE * 0)
#define ENC_KEY 0x01010101
#if 0
void L3_eeprom_read(void)
{
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);
}
}
}
#endif
void L3_eeprom_persist(void)
{
U8 dlen = MCU_ID_KEY_LEN + MCU_ID_LEN;
eep_param.filter = EEPROM_PARAM_FILTER;
eep_param.len = dlen + 2;
Lc_buf_copy_uc((U8*)eep_param.enc_key,(U8*)&G.enc_key,MCU_ID_KEY_LEN);
Lc_buf_copy_uc((U8*)eep_param.enc_val,(U8*)&G.mcu_enc_id,MCU_ID_LEN);
crc16(eep_param.crc, &eep_param, 2+dlen);
L0_Iap_Erase(EEP_PARAM_ADDR);
L0_Iap_Program_array(EEP_PARAM_ADDR, (U8*)&eep_param, 2 + dlen + 2);
}
void L3_chip_encrypt_main(void)
{
U8 i = 0;
//1.获取MCU_ID
L0_id_get_rom(G.mcu_id);
for(i=0;i<MCU_ID_LEN;i++)
{
L0_uart0_uchex(G.mcu_id[i]);
}
//2.ID加密
Lc_encrypt_id(G.mcu_enc_id,G.mcu_id, ENC_KEY, MCU_ID_LEN);
//3.写入EEPROM
L3_eeprom_persist();
L0_uart0_uc('Y');
}
void L3_reg_init(void)
{
G.enc_key[0] = ENC_KEY >> 24 & 0xFF;
G.enc_key[1] = ENC_KEY >> 16 & 0xFF;
G.enc_key[2] = ENC_KEY >> 8 & 0xFF;
G.enc_key[3] = ENC_KEY >> 0 & 0xFF;
//eeprom中读取持久化的值
//L3_eeprom_read();
}