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.
 
 
 
 

50 lines
1.1 KiB

#include "common.h"
//#include "../tpc/tpc_uart.h"
#include "../msp/eeprom.h"
#include "../bsp/chipid.h"
struct global_param G;
struct ts_eeprom_enc eep_enc;
#define EEP_SECTOR_SIZE 0x200
#define EEP_ENC_ADDR (EEP_SECTOR_SIZE * 0)
#define ENC_KEY 0x01010101
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.构造数据结构
Lc_buf_copy_uc((U8*)eep_enc.enc_key,(U8*)&G.enc_key,MCU_ID_KEY_LEN);
Lc_buf_copy_uc((U8*)eep_enc.enc_val,(U8*)&G.mcu_enc_id,MCU_ID_LEN);
//4. 写入EEPROM
if(L1_eep_write_block(D_EEP_ENC_IN_SECTOR, D_EEP_ENC_IN_BLOCK, D_EEP_ENC_BLOCK_SIZE, (U8*)&eep_enc,sizeof(eep_enc),TRUE) == 0)
{
//L0_uart0_sendstr("e2p write success");
return;
}
//L0_uart0_sendstr("e2p write failed");
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;
}