Browse Source

v1.1

master
zhangsan 5 years ago
parent
commit
40c783dfd0
  1. BIN
      si4/ps5ws.si4project/soft_ps5ws.sip_xm
  2. BIN
      si4/ps5ws.si4project/soft_ps5ws.siwork
  3. 46
      source/app/common.c
  4. 6
      source/app/common.h
  5. 3
      source/app/main.c

BIN
si4/ps5ws.si4project/soft_ps5ws.sip_xm

Binary file not shown.

BIN
si4/ps5ws.si4project/soft_ps5ws.siwork

Binary file not shown.

46
source/app/common.c

@ -4,44 +4,12 @@
#include "../msp/msp_id.h" #include "../msp/msp_id.h"
struct global_param G; struct global_param G;
struct ts_eeprom_param eep_param; struct ts_eeprom_enc eep_enc;
#define EEP_SECTOR_SIZE 0x200 #define EEP_SECTOR_SIZE 0x200
#define EEP_PARAM_ADDR (EEP_SECTOR_SIZE * 0) #define EEP_ENC_ADDR (EEP_SECTOR_SIZE * 0)
#define ENC_KEY 0x01010101 #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) void L3_chip_encrypt_main(void)
{ {
U8 i = 0; U8 i = 0;
@ -57,8 +25,14 @@ void L3_chip_encrypt_main(void)
//2.ID加密 //2.ID加密
Lc_encrypt_id(G.mcu_enc_id,G.mcu_id, ENC_KEY, MCU_ID_LEN); Lc_encrypt_id(G.mcu_enc_id,G.mcu_id, ENC_KEY, MCU_ID_LEN);
//3.写入EEPROM //3.构造数据结构
L3_eeprom_persist(); 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);
crc16(eep_enc.crc, &eep_enc, MCU_ID_KEY_LEN + MCU_ID_LEN);
//4. 写入EEPROM
L0_Iap_Erase(EEP_ENC_ADDR);
L0_Iap_Program_array(EEP_ENC_ADDR, (U8*)&eep_enc, MCU_ID_KEY_LEN + MCU_ID_LEN + 2);
L0_uart0_uc('Y'); L0_uart0_uc('Y');
} }

6
source/app/common.h

@ -27,14 +27,12 @@ enum tp_handle
*/ */
#define EEPROM_PARAM_DATA_MAX 64 #define EEPROM_PARAM_DATA_MAX 64
#define EEPROM_PARAM_FILTER 0xAA #define EEPROM_PARAM_FILTER 0xAA
typedef struct ts_eeprom_param typedef struct ts_eeprom_enc
{ {
U8 filter;
U8 len;
U8 enc_key[MCU_ID_KEY_LEN]; U8 enc_key[MCU_ID_KEY_LEN];
U8 enc_val[MCU_ID_LEN]; U8 enc_val[MCU_ID_LEN];
U8 crc[2]; U8 crc[2];
}EEPROM_PARAM; }EEPROM_ENC;
/** /**
* *

3
source/app/main.c

@ -127,9 +127,8 @@ void main(void)
//----------------------------------------------- //-----------------------------------------------
//系统主循环 //系统主循环
//----------------------------------------------- //-----------------------------------------------
//L0_id_main();
L3_chip_encrypt_main(); L3_chip_encrypt_main();
//L1_Iap_main(); L1_Iap_main();
while(1) while(1)
{ {
if(1 == s_nos_tick.t1s_heatbeart) if(1 == s_nos_tick.t1s_heatbeart)

Loading…
Cancel
Save