实现大部分小板通信命令
This commit is contained in:
@@ -55,17 +55,17 @@ uint8_t uc_buf[4];
|
||||
|
||||
|
||||
|
||||
#define APP_BEG_ADDR 0x8004000
|
||||
#define APP_END_ADDR 0x8024000
|
||||
// 模块程序地址
|
||||
// 这个地址要和 dev_flash.c 中定义的地址相对应
|
||||
#define MC_CODE_ADDR \
|
||||
(FLASH_BASE+2048*112+128)
|
||||
|
||||
//#define APP_TEST_BOARD_CFG 0x803E800
|
||||
#define MC_CODE_ADDR 0x803B000
|
||||
#define APP_TEST_PLAN_ADDR 0x803F000
|
||||
#define APP_TEST_BOOTFLAG_ADDR 0x803F800
|
||||
|
||||
#define FCM_END_ADDR 0x8040000
|
||||
#define FMC_PAGE_SIZE ((uint16_t)0x800U)
|
||||
// 方案地址
|
||||
// 这个地址要和 dev_flash.c 中定义的地址相对应
|
||||
#define APP_TEST_PLAN_ADDR \
|
||||
(FLASH_BASE+2048*109+128)
|
||||
|
||||
// 方案大小
|
||||
#define APP_TEST_PLANINFO_SIZE 2048
|
||||
|
||||
|
||||
|
@@ -16,7 +16,7 @@ static volatile CurrentSample_Range_eu buscurrent_range = Current_Max;
|
||||
#endif
|
||||
|
||||
#define SMod_Read_Idle_Filter 90
|
||||
#define DMod_Read_Idle_Filter 80
|
||||
#define DMod_Read_Idle_Filter 50
|
||||
|
||||
volatile uint16_t* EW_Read_AD_V = FireBus_ADC_Buf;
|
||||
static volatile uint16_t SMod_Read_Idle_C;
|
||||
@@ -389,16 +389,17 @@ void FireBus_ReadInspect_Data(uint16_t count,uint8_t* buf)
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
#define DMOD_READ_AD_FILTER_COUNT 4
|
||||
static uint8_t SMod_FireBusReadPlus(uint16_t* plus_h, uint16_t* plus_t,uint16_t time_out,uint16_t ad_line,uint16_t* max_ad)
|
||||
{
|
||||
uint32_t ul_ad_sample;
|
||||
uint32_t ul_index = 0;
|
||||
uint16_t us_adc_buf[6];
|
||||
uint16_t us_adc_buf[DMOD_READ_AD_FILTER_COUNT+1];
|
||||
uint32_t ul_count = 0;
|
||||
uint32_t uc_step = 0;
|
||||
uint32_t ul_h_count = 0,ul_l_count = 0;
|
||||
*max_ad = 0;
|
||||
for(ul_count =0; ul_count < 5; ul_count++)
|
||||
for(ul_count =0; ul_count < DMOD_READ_AD_FILTER_COUNT; ul_count++)
|
||||
{
|
||||
us_adc_buf[ul_count++] = ADC_GetCurADCFast();
|
||||
}
|
||||
@@ -415,10 +416,10 @@ static uint8_t SMod_FireBusReadPlus(uint16_t* plus_h, uint16_t* plus_t,uint16_t
|
||||
// PBout(I2IC_SCL_Pin_Nu) = 0;
|
||||
// }
|
||||
us_adc_buf[ul_count++] = ul_ad_sample;
|
||||
ul_count %= 0x06;
|
||||
ul_count %= DMOD_READ_AD_FILTER_COUNT;
|
||||
ul_h_count = 0;
|
||||
ul_l_count = 0;
|
||||
for(ul_index =0; ul_index < 6; ul_index++)
|
||||
for(ul_index =0; ul_index < DMOD_READ_AD_FILTER_COUNT; ul_index++)
|
||||
{
|
||||
if(us_adc_buf[ul_index] > ad_line)
|
||||
{
|
||||
@@ -427,7 +428,7 @@ static uint8_t SMod_FireBusReadPlus(uint16_t* plus_h, uint16_t* plus_t,uint16_t
|
||||
ul_l_count++;
|
||||
}
|
||||
}
|
||||
if(uc_step == 0 && ul_h_count > 5)//启动周期计数
|
||||
if(uc_step == 0 && ul_h_count >(DMOD_READ_AD_FILTER_COUNT-1))//启动周期计数
|
||||
{
|
||||
(*plus_h)++;
|
||||
(*plus_t)++;
|
||||
@@ -437,18 +438,18 @@ static uint8_t SMod_FireBusReadPlus(uint16_t* plus_h, uint16_t* plus_t,uint16_t
|
||||
}
|
||||
if(uc_step == 1)
|
||||
{
|
||||
if(ul_h_count > 5)
|
||||
if(ul_h_count > (DMOD_READ_AD_FILTER_COUNT-1))
|
||||
{
|
||||
PBout(I2IC_SCL_Pin_Nu) = 1 ;
|
||||
(*plus_h)++;
|
||||
uc_step = 1;
|
||||
}else if(ul_l_count > 5) //由高变低
|
||||
}else if(ul_l_count > (DMOD_READ_AD_FILTER_COUNT-1)) //由高变低
|
||||
{
|
||||
PBout(I2IC_SCL_Pin_Nu) = 0;
|
||||
uc_step = 2;
|
||||
}
|
||||
}
|
||||
else if(uc_step == 2 && ul_h_count > 5)//由低变高
|
||||
else if(uc_step == 2 && ul_h_count > (DMOD_READ_AD_FILTER_COUNT-1))//由低变高
|
||||
{
|
||||
PBout(I2IC_SCL_Pin_Nu) = 1 ;
|
||||
break;
|
||||
@@ -483,7 +484,7 @@ uint8_t DMod_FireBusReadDatasV2(uint8_t* buf, uint8_t len, uint32_t time_out)
|
||||
uint16_t ad_max = 0,ad_max_temp = 0;
|
||||
CurrentSample_Range_eu range = buscurrent_range;//档位保存
|
||||
Power_SetSampleCurrentRange(R10_2mA_30mA_MC);
|
||||
ADC_CurChnnelSet(AN_MAL_CH,ADC_SPEED_HIGH);
|
||||
ADC_CurChnnelSet(AN_MAL_CH,ADC_SPEED_HFAST);
|
||||
delay_us(2000);
|
||||
//总线跳转到中电平
|
||||
EW_DIFF_MOD_M;
|
||||
@@ -816,7 +817,14 @@ static void EW_TrimPlusCallback(uint8_t flag)
|
||||
}
|
||||
EW_Trim_Flag = flag;
|
||||
}
|
||||
static void EW_SendTrimSquare(uint16_t cycle,uint16_t duty, uint32_t count)
|
||||
/*
|
||||
@brief 发送校准脉冲
|
||||
@param cycle 周期
|
||||
@param duty 总线高电平时间
|
||||
@param count 脉冲个数
|
||||
|
||||
*/
|
||||
void EW_SendTrimSquare(uint16_t cycle,uint16_t duty, uint32_t count)
|
||||
{
|
||||
FireBus_ClkAmend(cycle,duty,count,EW_TrimPlusCallback);
|
||||
EW_Trim_Flag = 0;
|
||||
@@ -907,7 +915,7 @@ uint8_t EW_WriteMTP(uint16_t addr,uint8_t mtpaddr,uint8_t* buf,uint8_t len)
|
||||
len = 10;
|
||||
}
|
||||
EW_CommBuf[3] = len;
|
||||
memcpy((void*)(EW_CommBuf+4),buf,len);
|
||||
memcpy((void*)EW_CommBuf+4,buf,len);
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,len+4,EW_DMOD_Peroid,uc_readflag);
|
||||
if(uc_readflag == 0)
|
||||
{
|
||||
@@ -947,7 +955,7 @@ uint8_t EW_ReadMTP(uint16_t addr,uint8_t mtpaddr,uint8_t* buf,uint8_t len)
|
||||
len = 10;
|
||||
}
|
||||
EW_CommBuf[3] = len;
|
||||
memcpy((void*)(EW_CommBuf+4),buf,len);
|
||||
memcpy((void*)EW_CommBuf+4,buf,len);
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,len+4,EW_DMOD_Peroid,uc_readflag);
|
||||
if(uc_readflag == 0)
|
||||
{
|
||||
@@ -978,7 +986,7 @@ uint8_t EW_RunBootLoader(uint16_t addr,uint8_t reboot)
|
||||
{
|
||||
ul_bootflag = 0x9966AA55;
|
||||
}
|
||||
memcpy((void*)(EW_CommBuf+2),&ul_bootflag,4);
|
||||
memcpy((void*)EW_CommBuf+2,&ul_bootflag,4);
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,6,EW_DMOD_Peroid,0);
|
||||
return 0;
|
||||
}
|
||||
@@ -1000,7 +1008,7 @@ uint8_t EW_WriteRunCfg(uint16_t addr,RunCfg_un* runcfg)
|
||||
addr = (addr & 0xFFC0) | 20;
|
||||
EW_CommBuf[0] = addr&0xFF;
|
||||
EW_CommBuf[1] = (addr >> 8)&0xFF;
|
||||
memcpy((void*)(EW_CommBuf+2),&runcfg,3);
|
||||
memcpy((void*)EW_CommBuf+2,&runcfg,3);
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,6,EW_DMOD_Peroid,uc_readflag);
|
||||
if(uc_readflag == 0)
|
||||
{
|
||||
@@ -1036,7 +1044,7 @@ uint8_t EW_SetAddrByUID(uint16_t addr,uint8_t* uid,uint8_t uid_len,uint8_t* ack_
|
||||
addr = (addr & 0xFFC0) | 21;
|
||||
EW_CommBuf[0] = addr&0xFF;
|
||||
EW_CommBuf[1] = (addr >> 8)&0xFF;
|
||||
memcpy((void*)(EW_CommBuf+2),uid,uid_len);
|
||||
memcpy((void*)EW_CommBuf+2,uid,uid_len);
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,uid_len+2,EW_DMOD_Peroid,uc_readflag);
|
||||
if(uc_readflag == 0)
|
||||
{
|
||||
@@ -1075,7 +1083,7 @@ uint8_t EW_FastSetByUID(uint16_t addr,uint16_t delay, uint8_t pwd_flag,uint8_t*
|
||||
EW_CommBuf[0] = addr&0xFF;
|
||||
EW_CommBuf[1] = (addr >> 8)&0xFF;
|
||||
EW_CommBuf[2] = pwd_flag;
|
||||
memcpy(((void*)(EW_CommBuf+3)),&delay,2);
|
||||
memcpy(((void*)(EW_CommBuf)+3),&delay,2);
|
||||
memcpy((void*)(EW_CommBuf+5),uid,uid_len);
|
||||
uid_len +=5;
|
||||
DMod_SendBytes(((uint8_t*)(EW_CommBuf)),uid_len,EW_DMOD_Peroid,uc_readflag);
|
||||
@@ -1106,7 +1114,7 @@ uint8_t EW_SetDelay(uint16_t addr,uint16_t delay)
|
||||
addr = (addr & 0xFFC0) | 23;
|
||||
EW_CommBuf[0] = addr&0xFF;
|
||||
EW_CommBuf[1] = (addr >> 8)&0xFF;
|
||||
memcpy((void*)(EW_CommBuf+2),&delay,2);
|
||||
memcpy((void*)EW_CommBuf+2,&delay,2);
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,4,EW_DMOD_Peroid,0);
|
||||
uc_ack = DMod_FireBusReadDatasV2((uint8_t*)EW_CommBuf+2,2,EW_DMOD_READ_Timeout);
|
||||
if(EW_CommBuf[0] != EW_CommBuf[2] || EW_CommBuf[1] != EW_CommBuf[3])
|
||||
@@ -1130,7 +1138,7 @@ uint8_t EW_VerfyPWD(uint16_t addr,uint8_t* pwd,uint8_t pwd_len)
|
||||
addr = (addr & 0xFFC0) | 24;
|
||||
EW_CommBuf[0] = addr&0xFF;
|
||||
EW_CommBuf[1] = (addr >> 8)&0xFF;
|
||||
memcpy((void*)(EW_CommBuf+2),pwd,pwd_len);
|
||||
memcpy((void*)EW_CommBuf+2,pwd,pwd_len);
|
||||
pwd_len += 2;
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,pwd_len,EW_DMOD_Peroid,0);
|
||||
return 0;
|
||||
@@ -1282,7 +1290,7 @@ uint8_t EW_CheckRunCfg(uint16_t addr,uint32_t cfg_mask ,uint16_t cfg_state,uint8
|
||||
EW_CommBuf[0] = addr&0xFF;
|
||||
EW_CommBuf[1] = (addr >> 8)&0xFF;
|
||||
memcpy((uint8_t*)&EW_CommBuf[2],&cfg_mask,3);
|
||||
memcpy((uint8_t*)&EW_CommBuf[5],&cfg_state,2);
|
||||
memcpy((uint8_t*)&EW_CommBuf[5],&cfg_state,3);
|
||||
EW_CommBuf[8] = *rtv;
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,9,EW_DMOD_Peroid,1);
|
||||
delay_ms(5);
|
||||
@@ -1388,7 +1396,6 @@ uint8_t EW_SetReportCfg(uint8_t speed,uint8_t cur)
|
||||
EW_CommBuf[2] = speed;
|
||||
EW_CommBuf[3] = cur;
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,4,EW_DMOD_Peroid,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1408,7 +1415,7 @@ uint8_t EW_UpdateCommAddr(uint8_t addr,uint16_t new_addr)
|
||||
addr = (addr & 0xFFC0) | 36;
|
||||
EW_CommBuf[0] = addr&0xFF;
|
||||
EW_CommBuf[1] = (addr >> 8)&0xFF;
|
||||
memcpy((void*)(EW_CommBuf+2),&new_addr,2);
|
||||
memcpy((void*)EW_CommBuf+2,&new_addr,2);
|
||||
DMod_SendBytes((uint8_t*)EW_CommBuf,4,EW_DMOD_Peroid,uc_readflag);
|
||||
if(uc_readflag == 0)
|
||||
{
|
||||
@@ -1525,6 +1532,4 @@ uint8_t EW_ReadUID(uint16_t addr,uint8_t* uid,uint8_t uid_len)
|
||||
uc_ack = 1;
|
||||
}
|
||||
return uc_ack;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -122,7 +122,14 @@ volatile struct
|
||||
#define EW_BOOTLOADER_RUN 61 //运行bootloader
|
||||
#define EW_RA_REGISTER 62 //读MTP
|
||||
#define EW_WA_REGISTER 63 //写MTP
|
||||
/*
|
||||
@brief 发送校准脉冲
|
||||
@param cycle 周期
|
||||
@param duty 总线高电平时间
|
||||
@param count 脉冲个数
|
||||
|
||||
*/
|
||||
void EW_SendTrimSquare(uint16_t cycle,uint16_t duty, uint32_t count);
|
||||
/*
|
||||
@brief 单端第二版,差分接收数据
|
||||
@param *buf 数据缓存指针
|
||||
|
30
source/elec_det/elec_cmd.c
Normal file
30
source/elec_det/elec_cmd.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "elec_det.h"
|
||||
#include "commend.h"
|
||||
#include "mystring.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// 电子模块相关调试命令
|
||||
|
||||
|
||||
|
||||
static int cmd_check(list_def *argv)
|
||||
{
|
||||
array_def *data=arr_creat();
|
||||
cmd_print("start check.");
|
||||
elec_check_with_scheme(data);
|
||||
arr_delete(data);
|
||||
return 0;
|
||||
}
|
||||
commend_export(check,cmd_check,"start check")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "board.h"
|
||||
#include "bytearray.h"
|
||||
#include "mystdlib.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "elec_det.h"
|
||||
#include "base/delay.h"
|
||||
@@ -23,15 +24,42 @@
|
||||
|
||||
|
||||
typedef struct{
|
||||
CheckerTask_Info_st* task_info_array[PLAN_MAX_TASK];//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
||||
|
||||
CheckerTask_Info_st* task_info_array[PLAN_MAX_TASK];//方案参数结构体指针
|
||||
int scheme_inited;
|
||||
}self_def;
|
||||
|
||||
|
||||
static self_def g_self;
|
||||
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
|
||||
|
||||
// 初始化
|
||||
int elec_init(void)
|
||||
{
|
||||
self_def *s=&g_self;
|
||||
void Ye_BoardInit(void);
|
||||
void Ye_BoardCheck(void);
|
||||
int elec_check_scheme(void);
|
||||
void elec_load_scheme(void);
|
||||
Ye_BoardInit();
|
||||
Ye_BoardCheck();
|
||||
if(elec_check_scheme()!=0){
|
||||
// 方案校验失败
|
||||
DBG_WARN("scheme check failed.");
|
||||
s->scheme_inited=0;
|
||||
return 1;
|
||||
}
|
||||
s->scheme_inited=1;
|
||||
elec_load_scheme();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 获取本机地址
|
||||
uint8_t elec_local_addr(void)
|
||||
{
|
||||
static uint8_t addr=0;
|
||||
@@ -41,13 +69,13 @@ uint8_t elec_local_addr(void)
|
||||
}
|
||||
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>led1״̬
|
||||
// 设置led1状态
|
||||
void elec_led1_power(int power)
|
||||
{
|
||||
LED1_Out=power?1:0;
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>led2״̬
|
||||
// 设置led2状态
|
||||
void elec_led2_power(int power)
|
||||
{
|
||||
LED2_Out=power?1:0;
|
||||
@@ -55,40 +83,44 @@ void elec_led2_power(int power)
|
||||
|
||||
|
||||
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 获取检测结果
|
||||
array_def *elec_check_result(void)
|
||||
{
|
||||
array_def *r=arr_creat();
|
||||
|
||||
arr_append(r,3);
|
||||
return arr_temp(r);
|
||||
}
|
||||
|
||||
|
||||
// дӲ<EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><EFBFBD>
|
||||
int elec_write_hardversion(int version)
|
||||
// 写硬件版本号
|
||||
array_def *elec_write_hardversion(int version)
|
||||
{
|
||||
array_def *r=arr_creat();
|
||||
board_st.hard_v=version;
|
||||
return 0;
|
||||
arr_append(r,0);
|
||||
return arr_temp(r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уֵ
|
||||
int elec_write_resistor_cbv(int cbv)
|
||||
// 写电阻校准值
|
||||
array_def *elec_write_resistor_cbv(int cbv)
|
||||
{
|
||||
array_def *r=arr_creat();
|
||||
board_st.resistor_diff=cbv;
|
||||
arr_append(r,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD>ֵ
|
||||
// 测量桥丝阻值
|
||||
array_def *elec_check_resistor(void)
|
||||
{
|
||||
/*
|
||||
1 ͨ<EFBFBD><EFBFBD>1-4ͨ<34><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿
|
||||
2 ͨ<EFBFBD><EFBFBD>2-3ͨ<33><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿
|
||||
3 ͨ<EFBFBD><EFBFBD>1-3ͨ<33><CDA8><EFBFBD><EFBFBD><EFBFBD>迹
|
||||
4 ͨ<EFBFBD><EFBFBD>2-4ͨ<34><CDA8><EFBFBD><EFBFBD><EFBFBD>迹
|
||||
1 通道1-4通,过桥丝
|
||||
2 通道2-3通,过桥丝
|
||||
3 通道1-3通,测阻抗
|
||||
4 通道2-4通,测阻抗
|
||||
*/
|
||||
uint16_t aus_sample[5];
|
||||
uint16_t us_resistor;
|
||||
@@ -98,7 +130,7 @@ array_def *elec_check_resistor(void)
|
||||
{
|
||||
aus_sample[uc_index] -= board_st.resistor_diff;
|
||||
}
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
// 读取方案中测量电阻的模式
|
||||
switch(0)
|
||||
{
|
||||
case 0: us_resistor = aus_sample[0];break;
|
||||
@@ -117,7 +149,7 @@ array_def *elec_check_resistor(void)
|
||||
|
||||
|
||||
|
||||
// У<EFBFBD>鷽<EFBFBD><EFBFBD>,<2C><>0<EFBFBD>ɹ<EFBFBD>
|
||||
// 校验方案,返0成功
|
||||
static int elec_check_scheme(void)
|
||||
{
|
||||
uint32_t ul_crc32;
|
||||
@@ -135,7 +167,7 @@ static int elec_check_scheme(void)
|
||||
|
||||
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD>
|
||||
// 加载方案
|
||||
static void elec_load_scheme(void)
|
||||
{
|
||||
self_def *s=&g_self;
|
||||
@@ -159,7 +191,7 @@ static void elec_load_scheme(void)
|
||||
}
|
||||
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><EFBFBD><EFBFBD>
|
||||
// 进行检测
|
||||
array_def *elec_check_with_scheme(array_def *uid_psw)
|
||||
{
|
||||
self_def *s=&g_self;
|
||||
@@ -172,10 +204,14 @@ array_def *elec_check_with_scheme(array_def *uid_psw)
|
||||
uint8_t res=0;
|
||||
array_def *r=arr_creat();
|
||||
chip_type=(board_st.plan_id >> 12 ) & 0x0F;
|
||||
if(chip_type>=LENGTH(tasks_fun_table)){
|
||||
if(s->scheme_inited==0){
|
||||
arr_append(r,1);
|
||||
return arr_temp(r);
|
||||
}
|
||||
if(chip_type>=LENGTH(tasks_fun_table)){
|
||||
arr_append(r,2);
|
||||
return arr_temp(r);
|
||||
}
|
||||
memset(&checker_runcfg,0,sizeof(Checker_RunCfg_st));
|
||||
int task_index=0;
|
||||
int err_flag=0;
|
||||
@@ -184,8 +220,8 @@ array_def *elec_check_with_scheme(array_def *uid_psw)
|
||||
memset(&checker_runcfg.task_info,0,sizeof(CheckerTask_Info_st));
|
||||
taskid=ptaskindex[task_index];
|
||||
memset(checker_runcfg.params,0,20);
|
||||
checker_runcfg.param_count = 0;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
checker_runcfg.rtv_count = 0;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
checker_runcfg.param_count = 0;//参数个数
|
||||
checker_runcfg.rtv_count = 0;//返回值个数
|
||||
checker_runcfg.excue_rtv = 0;
|
||||
checker_runcfg.task_info.retry_time = 0;
|
||||
if(taskid>=CHECKER_MAXID_COUNT){
|
||||
@@ -200,13 +236,13 @@ array_def *elec_check_with_scheme(array_def *uid_psw)
|
||||
break;
|
||||
}
|
||||
|
||||
// װ<EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD>
|
||||
// 装载参数
|
||||
rt_memcpy(&checker_runcfg.task_info,task_par,sizeof(CheckerTask_Info_st));
|
||||
checker_runcfg.param_count = checker_runcfg.task_info.param_rtv_count & 0x0F;
|
||||
checker_runcfg.rtv_count = (checker_runcfg.task_info.param_rtv_count >> 4) & 0x0F;
|
||||
rt_memcpy(checker_runcfg.params,checker_runcfg.task_info.params,checker_runcfg.param_count*2);
|
||||
|
||||
// ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 执行任务
|
||||
for(int i=0;i<1+task_par->retry_time;i++)
|
||||
{
|
||||
checker_runcfg.excue_rtv=1;
|
||||
@@ -216,23 +252,23 @@ array_def *elec_check_with_scheme(array_def *uid_psw)
|
||||
break;
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD>Ѱ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 找寻下一个任务
|
||||
if((checker_runcfg.excue_rtv != 0)
|
||||
&& (checker_runcfg.task_info.error_jumpto != 0)
|
||||
&& (checker_runcfg.task_info.error_jumpto != 0xFF)
|
||||
)
|
||||
{
|
||||
uint8_t uc_index = task_index+1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>
|
||||
uint8_t uc_index = task_index+1;//如果时跳至下一个,直接顺序执行
|
||||
task_index = checker_runcfg.task_info.error_jumpto;
|
||||
while(uc_index < task_index)
|
||||
{
|
||||
Checker_MaskResult(1,uc_index);//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δִ<EFBFBD><EFBFBD>
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>±꣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>洢<EFBFBD>ռ䱣<EFBFBD><EFBFBD>
|
||||
Checker_MaskResult(1,uc_index);//将跳过的步骤标记未执行
|
||||
//调整参数返回值下标,将跳过的步骤里面的返回值存储空间保留
|
||||
checker_runcfg.rtv_index += (s->task_info_array[uc_index]->param_rtv_count >> 4) & 0x0F;
|
||||
uc_index++;
|
||||
}
|
||||
}else{
|
||||
task_index++;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>
|
||||
task_index++;//正常情况直接顺序执行
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,3 +282,5 @@ array_def *elec_check_with_scheme(array_def *uid_psw)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -3,10 +3,10 @@
|
||||
|
||||
|
||||
#include "stdint.h"
|
||||
#include "bytearray.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int elec_init(void);
|
||||
|
||||
uint8_t elec_local_addr(void);
|
||||
|
||||
@@ -14,10 +14,15 @@ void elec_led1_power(int power);
|
||||
|
||||
void elec_led2_power(int power);
|
||||
|
||||
array_def *elec_check_result(void);
|
||||
|
||||
array_def *elec_write_hardversion(int version);
|
||||
|
||||
array_def *elec_write_resistor_cbv(int cbv);
|
||||
|
||||
array_def *elec_check_resistor(void);
|
||||
|
||||
array_def *elec_check_with_scheme(array_def *uid_psw);
|
||||
|
||||
|
||||
|
||||
|
@@ -273,7 +273,8 @@
|
||||
#define EW_SINGLE_MOD_M {PCout(OUTBH_Pin_Nu)=0;PBout(OUTAL_Pin_Nu)=0;PBout(OUTAH_Pin_Nu)=0; delay_nop(50); PBout(OUTBL_Pin_Nu)=1;PAout(LAVC_M_Pin_Nu)=1;}
|
||||
#define EW_SINGLE_MOD_H HMOS_SWITCH_W_1
|
||||
|
||||
#define EW_DIFF_MOD_M {PCout(OUTBH_Pin_Nu)=0;PBout(OUTAL_Pin_Nu)=0;PBout(OUTAH_Pin_Nu)=0; delay_nop(50); PBout(OUTBL_Pin_Nu)=1;PAout(LAVC_M_Pin_Nu)=1;}
|
||||
#define EW_DIFF_MOD_M {PCout(OUTBH_Pin_Nu)=0;PBout(OUTAL_Pin_Nu)=0; delay_nop(50); PBout(OUTBL_Pin_Nu)=1;PBout(OUTAH_Pin_Nu)=1;PAout(LAVC_M_Pin_Nu)=1;}
|
||||
|
||||
#define EW_DIFF_MOD_H HMOS_SWITCH_W_1
|
||||
#define EW_DIFF_MOD_L HMOS_SWITCH_W_0
|
||||
#define EW_BUS_OFF HMOS_SWITCH_OFF
|
||||
|
@@ -625,9 +625,14 @@ void MC_IICUpdateMTP(void)
|
||||
if(checker_runcfg.params[0] == 0x1000)
|
||||
{
|
||||
auc_setMTPOperReg_cmd[2] = 0x04;
|
||||
auc_earse_cmd[0]= 0x27;
|
||||
auc_earse_cmd[1]= 0xD8;
|
||||
|
||||
}else{
|
||||
auc_setMTPOperReg_cmd[2] = 0x00;
|
||||
}
|
||||
auc_setAddr_cmd[2] = (checker_runcfg.params[0]>>8) & 0xFF;
|
||||
auc_setAddr_cmd[3] = checker_runcfg.params[0] & 0xFF;
|
||||
uc_ack = 0;
|
||||
uc_ack += I2C_master_write(SLAVE_IIC_ADDR_,auc_enMTP_cmd,sizeof(auc_enMTP_cmd),&ul_sendlen,0);
|
||||
delay_ms(5);
|
||||
@@ -645,8 +650,7 @@ void MC_IICUpdateMTP(void)
|
||||
return;
|
||||
}
|
||||
|
||||
auc_setAddr_cmd[2] = (checker_runcfg.params[0]>>8) & 0xFF;
|
||||
auc_setAddr_cmd[3] = checker_runcfg.params[0] & 0xFF;
|
||||
|
||||
uc_ack = I2C_master_write(SLAVE_IIC_ADDR_,auc_setMTPOperReg_cmd,sizeof(auc_setMTPOperReg_cmd),&ul_sendlen,0);
|
||||
//设置MTP操作范围
|
||||
if(uc_ack != 0)
|
||||
|
259
source/elec_det/interface/EWChecker.c
Normal file
259
source/elec_det/interface/EWChecker.c
Normal file
@@ -0,0 +1,259 @@
|
||||
|
||||
#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"
|
||||
|
||||
|
||||
#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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
delay_ms(50);
|
||||
rt_free(read);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// 升级
|
||||
void EW_Updata(void)
|
||||
{
|
||||
Checker_RunCfg_st *cfg=&checker_runcfg;
|
||||
uint8_t ret=0;
|
||||
uint8_t *data=(uint8_t *)MC_CODE_ADDR;
|
||||
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;
|
||||
ret=EW_Charg();
|
||||
if(ret) {ret=1;goto err;}
|
||||
ret=EW_Erease();
|
||||
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:
|
||||
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;
|
||||
//us_h_v = cfg->params[0];
|
||||
us_h_v = 240;
|
||||
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);
|
||||
}
|
||||
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 //数组结束
|
||||
};
|
||||
|
||||
|
22
source/elec_det/interface/EWChecker.h
Normal file
22
source/elec_det/interface/EWChecker.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef EWChecker_h__
|
||||
#define EWChecker_h__
|
||||
#include "base/define.h"
|
||||
#include "basechecker.h"
|
||||
#include "stdint.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern CheckerTask ewtaskArray[CHECKER_MAXID_COUNT] ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user