2023-10-07 18:15:52 +08:00
|
|
|
|
|
|
|
#include "EWChecker.h"
|
|
|
|
#include "driver/EWDriver.h"
|
|
|
|
#include "base/delay.h"
|
|
|
|
#include "hardware/adc_cfg.h"
|
|
|
|
#include "base/utility.h"
|
|
|
|
#include "hardware/power.h"
|
|
|
|
#include "hardware/timer_cfg.h"
|
2023-10-08 18:27:10 +08:00
|
|
|
#include "debug.h"
|
2023-10-07 18:15:52 +08:00
|
|
|
|
|
|
|
#define UPDATA_PACK_LEN 58
|
|
|
|
#define UPDATA_BASE_ADDR 0x1000
|
|
|
|
#define UPDATA_DATA_LEN (12*1024)
|
|
|
|
#define UPDATA_FLAG_ADDR (0x3c7c)
|
|
|
|
//#define UPDATA_FLAG ((uint8_t []){0x99,0x66,0xaa,0x55})
|
|
|
|
#define UPDATA_FLAG ((uint8_t []){0xaa,0xbb,0xcc,0xdd})
|
|
|
|
|
|
|
|
// 擦除
|
|
|
|
static uint8_t EW_Erease(void)
|
|
|
|
{
|
|
|
|
uint8_t data[3]={0xfe,0x00,0x00};
|
|
|
|
uint8_t read[4]={0};
|
|
|
|
uint8_t ret=0;
|
|
|
|
DMod_SendBytesXor(data,2,1);
|
|
|
|
ret=DMod_ReadBytesXor(read,4,100);
|
2023-10-08 18:27:10 +08:00
|
|
|
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
2023-10-07 18:15:52 +08:00
|
|
|
delay_ms(50);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 跳转
|
|
|
|
static uint8_t EW_Jump(void)
|
|
|
|
{
|
|
|
|
uint8_t data[3]={0xf9,0x00,0x00};
|
|
|
|
uint8_t read[4]={0};
|
|
|
|
uint8_t ret=0;
|
|
|
|
DMod_SendBytesXor(data,2,1);
|
|
|
|
ret=DMod_ReadBytesXor(read,4,100);
|
2023-10-08 18:27:10 +08:00
|
|
|
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
2023-10-07 18:15:52 +08:00
|
|
|
delay_ms(50);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 充电
|
|
|
|
static uint8_t EW_Charg(void)
|
|
|
|
{
|
|
|
|
uint8_t data[4]={0xf8,0x01,0x04,0x00};
|
|
|
|
uint8_t read[4]={0};
|
|
|
|
uint8_t ret=0;
|
|
|
|
delay_ms(2000);
|
|
|
|
DMod_SendBytesXor(data,3,1);
|
|
|
|
ret=DMod_ReadBytesXor(read,4,100);
|
2023-10-08 18:27:10 +08:00
|
|
|
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
2023-10-07 18:15:52 +08:00
|
|
|
delay_ms(5000);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 发送数据
|
|
|
|
// len 最长为58字节
|
|
|
|
static uint8_t EW_Write(uint16_t addr,uint8_t *d,uint16_t len)
|
|
|
|
{
|
|
|
|
uint8_t ret=0;
|
|
|
|
uint8_t read[4]={0};
|
|
|
|
uint8_t *buf=rt_malloc(len+2+2+1);
|
|
|
|
if(buf==RT_NULL) return 1;
|
|
|
|
buf[0]=0xfc;
|
|
|
|
buf[1]=2+len;
|
|
|
|
buf[2]=addr&0xff;
|
|
|
|
buf[3]=addr>>8;
|
|
|
|
rt_memcpy(&buf[4],d,len);
|
|
|
|
DMod_SendBytesXor(buf,len+2+2,1);
|
|
|
|
ret=DMod_ReadBytesXor(read,4,100);
|
|
|
|
rt_free(buf);
|
2023-10-08 18:27:10 +08:00
|
|
|
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
2023-10-07 18:15:52 +08:00
|
|
|
delay_ms(50);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 校验
|
|
|
|
static uint8_t EW_CheckCrc(uint16_t adr_start,uint16_t adr_end,uint32_t *crc)
|
|
|
|
{
|
|
|
|
uint8_t ret=0;
|
|
|
|
uint8_t cmd[7]={0xfb,0x04,adr_start&0xff,adr_start>>8,adr_end&0xff,adr_end>>8};
|
|
|
|
uint8_t read[4+4]={0};
|
|
|
|
DMod_SendBytesXor(cmd,6,1);
|
|
|
|
ret=DMod_ReadBytesXor(read,8,100);
|
|
|
|
if(ret==0){
|
|
|
|
if(crc){
|
|
|
|
*crc=(read[3])|(read[4]<<8)|(read[5]<<16)|(read[6]<<24);
|
|
|
|
}
|
|
|
|
}
|
2023-10-08 18:27:10 +08:00
|
|
|
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
2023-10-07 18:15:52 +08:00
|
|
|
delay_ms(50);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 读取
|
|
|
|
static uint8_t EW_Read(uint16_t adr,uint8_t *buf,uint16_t len)
|
|
|
|
{
|
|
|
|
uint8_t ret=0;
|
|
|
|
uint8_t cmd[7]={0xfa,0x03,adr&0xff,adr>>8,len};
|
|
|
|
uint16_t read_len=2+len+1+1;
|
|
|
|
uint8_t *read=rt_malloc(read_len);
|
|
|
|
if(read==RT_NULL) return 1;
|
|
|
|
DMod_SendBytesXor(cmd,6,1);
|
|
|
|
ret=DMod_ReadBytesXor(read,read_len,100);
|
|
|
|
rt_memset(buf,0,len);
|
|
|
|
if(ret==0)
|
|
|
|
{
|
|
|
|
rt_memcpy(buf,&read[3],len);
|
|
|
|
}
|
2023-10-08 18:27:10 +08:00
|
|
|
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
2023-10-07 18:15:52 +08:00
|
|
|
delay_ms(50);
|
|
|
|
rt_free(read);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-08 18:27:10 +08:00
|
|
|
// app:通信测试
|
|
|
|
static void EW_appCommTest(void)
|
|
|
|
{
|
|
|
|
uint8_t data[4]={0x11,0x22};
|
|
|
|
uint8_t ret;
|
|
|
|
ret=EW_CommTest(data,2,300);
|
|
|
|
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,data[0],data[1],data[2],data[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
// 升级
|
|
|
|
void EW_Updata(void)
|
|
|
|
{
|
|
|
|
Checker_RunCfg_st *cfg=&checker_runcfg;
|
|
|
|
uint8_t ret=0;
|
2023-10-07 22:54:36 +08:00
|
|
|
uint8_t *data=(uint8_t *)MC_CODE_ADDR+UPDATA_BASE_ADDR;
|
2023-10-07 18:15:52 +08:00
|
|
|
uint16_t len=UPDATA_DATA_LEN;
|
|
|
|
uint16_t addr=UPDATA_BASE_ADDR;
|
|
|
|
uint8_t pack_len=UPDATA_PACK_LEN;
|
|
|
|
uint32_t crc=0;
|
|
|
|
uint32_t crc_module=0;
|
2023-10-08 18:27:10 +08:00
|
|
|
EW_appCommTest();
|
2023-10-07 18:15:52 +08:00
|
|
|
ret=EW_Charg();
|
|
|
|
if(ret) {ret=1;goto err;}
|
|
|
|
ret=EW_Erease();
|
2023-10-08 18:27:10 +08:00
|
|
|
//ret=EW_Jump();
|
2023-10-07 18:15:52 +08:00
|
|
|
if(ret) {ret=2;goto err;}
|
|
|
|
while(len>0){
|
|
|
|
pack_len=len>UPDATA_PACK_LEN?UPDATA_PACK_LEN:len;
|
|
|
|
ret=EW_Write(addr,data,pack_len);
|
|
|
|
addr+=pack_len;
|
|
|
|
data+=pack_len;
|
|
|
|
len-=pack_len;
|
|
|
|
if(ret) {ret=3;goto err;}
|
|
|
|
}
|
|
|
|
crc=Crc32Calu((uint32_t *)MC_CODE_ADDR,UPDATA_DATA_LEN/4);
|
|
|
|
ret=EW_CheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc_module);
|
|
|
|
if(ret) {ret=4;goto err;}
|
|
|
|
if(crc!=crc_module)
|
|
|
|
{ret=5;goto err;}
|
|
|
|
ret=EW_Jump();
|
|
|
|
if(ret) {ret=6;goto err;}
|
|
|
|
delay_ms(100);
|
|
|
|
ret=EW_EnWriteMTP(0,1);
|
|
|
|
if(ret) {ret=7;goto err;}
|
|
|
|
delay_ms(100);
|
|
|
|
// 数据溢出
|
|
|
|
// ret=EW_WriteMTP(0,(uint8_t)(UPDATA_FLAG_ADDR/4),UPDATA_FLAG,4);
|
|
|
|
if(ret) {ret=8;goto err;}
|
|
|
|
delay_ms(100);
|
|
|
|
|
|
|
|
err:
|
2023-10-08 18:27:10 +08:00
|
|
|
DBG_LOG("ret=%d",ret);
|
2023-10-07 18:15:52 +08:00
|
|
|
Checker_MaskResult(ret,checker_runcfg.task_info.runindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void EW_Test_PowerOFF(void)
|
|
|
|
{
|
|
|
|
uint8_t uc_rtv = 0;
|
|
|
|
delay_os_ms(100);
|
|
|
|
XTBUS_OFF;
|
|
|
|
Checker_MaskResult(uc_rtv,checker_runcfg.task_info.runindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void EW_Empty(void)
|
|
|
|
{
|
|
|
|
Checker_RunCfg_st *cfg=&checker_runcfg;
|
|
|
|
int count=cfg->rtv_count;
|
|
|
|
while(count > 0)
|
|
|
|
{
|
|
|
|
cfg->Test_Rtv[cfg->rtv_index++] = 0;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
Checker_MaskResult(0,cfg->task_info.runindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void EW_Test_SetBusV(void)
|
|
|
|
{
|
|
|
|
Checker_RunCfg_st *cfg=&checker_runcfg;
|
|
|
|
uint8_t uc_rtv = 0;
|
|
|
|
uint16_t us_h_v,us_m_v;
|
2023-10-08 18:27:10 +08:00
|
|
|
uint16_t power_old;
|
|
|
|
us_h_v = cfg->params[0];
|
|
|
|
power_old=us_h_v;
|
2023-10-07 18:15:52 +08:00
|
|
|
if(us_h_v < 55)
|
|
|
|
{
|
|
|
|
uc_rtv = 1;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
us_m_v = 50;
|
|
|
|
uc_rtv |= PowerCalibration_set(us_h_v,us_m_v);
|
|
|
|
XTBUS_ON
|
|
|
|
|
|
|
|
us_m_v = ((us_h_v/80)+2)*60;
|
|
|
|
delay_ms(us_m_v);
|
|
|
|
us_h_v = Power_GetBousV();
|
|
|
|
Checker_SetRtv(&us_h_v,cfg->rtv_count);
|
|
|
|
}
|
2023-10-08 18:27:10 +08:00
|
|
|
if(uc_rtv){
|
|
|
|
DBG_WARN("bus power init failed.h");
|
|
|
|
}
|
|
|
|
if((us_h_v<power_old-10)||(us_h_v>power_old+10)){
|
|
|
|
DBG_WARN("power set fialed,want=%d,reality=%d.",power_old,us_h_v);
|
|
|
|
}
|
2023-10-07 18:15:52 +08:00
|
|
|
Checker_MaskResult(uc_rtv,cfg->task_info.runindex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckerTask ewtaskArray[CHECKER_MAXID_COUNT] ={
|
|
|
|
Checker_PowerPrapare, //0 电源准备
|
|
|
|
EW_Empty, //1 上电充能
|
|
|
|
EW_Test_SetBusV, //2 设置总线电压
|
|
|
|
EW_Empty, //3 获取总线电流
|
|
|
|
EW_Empty, //4 扫描UID
|
|
|
|
EW_Empty, //5 写配置参数
|
|
|
|
EW_Empty, //6 验证配置
|
|
|
|
EW_Empty, //7 模拟注码
|
|
|
|
EW_Empty, //8 充能统计
|
|
|
|
EW_Empty, //9 写现场值 网络id 延时
|
|
|
|
EW_Empty, //10比对现场值
|
|
|
|
EW_Empty, //11 桥丝通断检测
|
|
|
|
EW_Empty, //12 电容容量统计
|
|
|
|
EW_Empty, //13 延时等待
|
|
|
|
EW_Empty, //14 写管壳号/工厂信息
|
|
|
|
EW_Empty, //15 写UID
|
|
|
|
EW_Empty, //16 写密码
|
|
|
|
EW_Empty, //17 写入/检测备份区标志
|
|
|
|
EW_Empty, //18 读取备份区数据
|
|
|
|
EW_Empty, //19 校准
|
|
|
|
EW_Empty, //20 使能通讯末电流采集
|
|
|
|
EW_Empty, //21 获取通讯末电流
|
|
|
|
EW_Empty, //22 放电
|
|
|
|
EW_Empty, //23 在线检测
|
|
|
|
EW_Empty, //24 状态检测
|
|
|
|
EW_Empty, //25 起爆
|
|
|
|
EW_Empty, //26 复位
|
|
|
|
EW_Test_PowerOFF, //27 关总线
|
|
|
|
EW_Empty, //28 芯片锁存
|
|
|
|
EW_Empty, //29 使能赋码设备
|
|
|
|
EW_Empty, //30 在线检测
|
|
|
|
EW_Empty, //31 密码验证
|
|
|
|
EW_Empty, //32 加载芯片配置
|
|
|
|
EW_Empty, //33 电容压差测试
|
|
|
|
Checker_ResistorSample,//34 桥丝电阻测试
|
|
|
|
EW_Empty, //35 检测过程中注码
|
|
|
|
EW_Empty, //36 验证注码
|
|
|
|
EW_Empty, //37 模块在线检测
|
|
|
|
EW_Updata, //38 升级
|
|
|
|
(void*)0 //数组结束
|
|
|
|
};
|
|
|
|
|
|
|
|
|