2023-10-06 18:47:05 +08:00
|
|
|
|
#include "board.h"
|
|
|
|
|
#include "bytearray.h"
|
|
|
|
|
#include "mystdlib.h"
|
2023-10-07 18:15:52 +08:00
|
|
|
|
#include "debug.h"
|
2023-10-06 18:47:05 +08:00
|
|
|
|
|
|
|
|
|
#include "elec_det.h"
|
|
|
|
|
#include "base/delay.h"
|
|
|
|
|
#include "base/utility.h"
|
|
|
|
|
#include "hardware/adc_cfg.h"
|
|
|
|
|
#include "hardware/dac_cfg.h"
|
|
|
|
|
#include "hardware/gpio_cfg.h"
|
|
|
|
|
#include "hardware/jw3425iic.h"
|
|
|
|
|
#include "hardware/power.h"
|
|
|
|
|
#include "hardware/timer_cfg.h"
|
|
|
|
|
#include "driver/EWDriver.h"
|
|
|
|
|
#include "driver/JQDriver.h"
|
|
|
|
|
#include "driver/XTDriver.h"
|
|
|
|
|
#include "interface/BaseChecker.h"
|
|
|
|
|
#include "interface/JQChecker.h"
|
|
|
|
|
#include "interface/XTChecker.h"
|
2023-10-08 18:27:10 +08:00
|
|
|
|
#include "interface/EWChecker.h"
|
2023-10-06 18:47:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define PLAN_MAX_TASK 64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct{
|
2023-10-07 18:15:52 +08:00
|
|
|
|
CheckerTask_Info_st* task_info_array[PLAN_MAX_TASK];//方案参数结构体指针
|
|
|
|
|
int scheme_inited;
|
2023-10-06 18:47:05 +08:00
|
|
|
|
}self_def;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static self_def g_self;
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取本机地址
|
2023-10-06 18:47:05 +08:00
|
|
|
|
uint8_t elec_local_addr(void)
|
|
|
|
|
{
|
|
|
|
|
static uint8_t addr=0;
|
|
|
|
|
if(addr==0)
|
|
|
|
|
addr=Gpio_GetDeivceAddr();
|
|
|
|
|
return addr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 设置led1状态
|
2023-10-06 18:47:05 +08:00
|
|
|
|
void elec_led1_power(int power)
|
|
|
|
|
{
|
|
|
|
|
LED1_Out=power?1:0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 设置led2状态
|
2023-10-06 18:47:05 +08:00
|
|
|
|
void elec_led2_power(int power)
|
|
|
|
|
{
|
|
|
|
|
LED2_Out=power?1:0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 获取检测结果
|
2023-10-06 18:47:05 +08:00
|
|
|
|
array_def *elec_check_result(void)
|
|
|
|
|
{
|
|
|
|
|
array_def *r=arr_creat();
|
2023-10-07 18:15:52 +08:00
|
|
|
|
arr_append(r,3);
|
2023-10-06 18:47:05 +08:00
|
|
|
|
return arr_temp(r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 写硬件版本号
|
|
|
|
|
array_def *elec_write_hardversion(int version)
|
2023-10-06 18:47:05 +08:00
|
|
|
|
{
|
2023-10-07 18:15:52 +08:00
|
|
|
|
array_def *r=arr_creat();
|
2023-10-06 18:47:05 +08:00
|
|
|
|
board_st.hard_v=version;
|
2023-10-07 18:15:52 +08:00
|
|
|
|
arr_append(r,0);
|
|
|
|
|
return arr_temp(r);
|
2023-10-06 18:47:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 写电阻校准值
|
|
|
|
|
array_def *elec_write_resistor_cbv(int cbv)
|
2023-10-06 18:47:05 +08:00
|
|
|
|
{
|
2023-10-07 18:15:52 +08:00
|
|
|
|
array_def *r=arr_creat();
|
2023-10-06 18:47:05 +08:00
|
|
|
|
board_st.resistor_diff=cbv;
|
2023-10-07 18:15:52 +08:00
|
|
|
|
arr_append(r,0);
|
2023-10-06 18:47:05 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 测量桥丝阻值
|
2023-10-06 18:47:05 +08:00
|
|
|
|
array_def *elec_check_resistor(void)
|
|
|
|
|
{
|
|
|
|
|
/*
|
2023-10-07 18:15:52 +08:00
|
|
|
|
1 通道1-4通,过桥丝
|
|
|
|
|
2 通道2-3通,过桥丝
|
|
|
|
|
3 通道1-3通,测阻抗
|
|
|
|
|
4 通道2-4通,测阻抗
|
2023-10-06 18:47:05 +08:00
|
|
|
|
*/
|
|
|
|
|
uint16_t aus_sample[5];
|
|
|
|
|
uint16_t us_resistor;
|
|
|
|
|
uint8_t uc_index = 0;
|
|
|
|
|
AD_SampleResistor(aus_sample);
|
|
|
|
|
for(uc_index = 0; uc_index < 5; uc_index++)
|
|
|
|
|
{
|
|
|
|
|
aus_sample[uc_index] -= board_st.resistor_diff;
|
|
|
|
|
}
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 读取方案中测量电阻的模式
|
2023-10-06 18:47:05 +08:00
|
|
|
|
switch(0)
|
|
|
|
|
{
|
|
|
|
|
case 0: us_resistor = aus_sample[0];break;
|
|
|
|
|
case 1: us_resistor = aus_sample[1];break;
|
|
|
|
|
case 2: us_resistor = aus_sample[2];break;
|
|
|
|
|
default : us_resistor = 0;break;
|
|
|
|
|
}
|
|
|
|
|
array_def *r=arr_creat();
|
|
|
|
|
arr_append(r,0);
|
|
|
|
|
arr_append(r,us_resistor&0xff);
|
|
|
|
|
arr_append(r,(us_resistor >> 8) & 0xff);
|
|
|
|
|
return arr_temp(r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 校验方案,返0成功
|
2023-10-06 18:47:05 +08:00
|
|
|
|
static int elec_check_scheme(void)
|
|
|
|
|
{
|
|
|
|
|
uint32_t ul_crc32;
|
|
|
|
|
|
|
|
|
|
ul_crc32 = Crc32Calu((uint32_t*)APP_TEST_PLAN_ADDR,(APP_TEST_PLANINFO_SIZE-4));
|
|
|
|
|
if(ul_crc32 != (*(uint32_t*)(APP_TEST_PLAN_ADDR+APP_TEST_PLANINFO_SIZE-4)))
|
|
|
|
|
{
|
|
|
|
|
board_st.plan_id = ~0;
|
|
|
|
|
LED1_Out_Off;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 加载方案
|
2023-10-06 18:47:05 +08:00
|
|
|
|
static void elec_load_scheme(void)
|
|
|
|
|
{
|
|
|
|
|
self_def *s=&g_self;
|
|
|
|
|
uint8_t uc_index = 0;
|
|
|
|
|
uint32_t ul_len;
|
|
|
|
|
CheckerTask_Info_st* pinfo_st = (CheckerTask_Info_st*)(APP_TEST_PLAN_ADDR+256);
|
|
|
|
|
for(uc_index = 0; uc_index < PLAN_MAX_TASK; uc_index++)
|
|
|
|
|
{
|
|
|
|
|
s->task_info_array[uc_index] = 0;
|
|
|
|
|
}
|
|
|
|
|
uc_index = 0;
|
|
|
|
|
while((pinfo_st->runindex != 0xFF) && (uc_index < PLAN_MAX_TASK))
|
|
|
|
|
{
|
|
|
|
|
s->task_info_array[uc_index++] = pinfo_st;
|
|
|
|
|
ul_len = pinfo_st->param_rtv_count & 0x0F;
|
|
|
|
|
ul_len = (ul_len<<1)+5;
|
|
|
|
|
|
|
|
|
|
pinfo_st = (CheckerTask_Info_st*)((uint8_t*)pinfo_st + ul_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 进行检测
|
2023-10-06 18:47:05 +08:00
|
|
|
|
array_def *elec_check_with_scheme(array_def *uid_psw)
|
|
|
|
|
{
|
|
|
|
|
self_def *s=&g_self;
|
2023-10-09 23:01:28 +08:00
|
|
|
|
const uint8_t* taskid_table = (uint8_t*)(APP_TEST_PLAN_ADDR+4);
|
2023-10-08 18:27:10 +08:00
|
|
|
|
CheckerTask *tasks_fun_table[]={jqtaskArray,xttaskArray,ewtaskArray};
|
2023-10-06 18:47:05 +08:00
|
|
|
|
CheckerTask_Info_st *task_par=0;
|
|
|
|
|
uint8_t chip_type=0;
|
|
|
|
|
uint8_t taskid=0;
|
|
|
|
|
CheckerTask task_fun=0;
|
|
|
|
|
uint8_t res=0;
|
|
|
|
|
array_def *r=arr_creat();
|
|
|
|
|
chip_type=(board_st.plan_id >> 12 ) & 0x0F;
|
2023-10-07 18:15:52 +08:00
|
|
|
|
if(s->scheme_inited==0){
|
2023-10-08 18:27:10 +08:00
|
|
|
|
DBG_WARN("scheme not init.");
|
2023-10-06 18:47:05 +08:00
|
|
|
|
arr_append(r,1);
|
|
|
|
|
return arr_temp(r);
|
|
|
|
|
}
|
2023-10-07 18:15:52 +08:00
|
|
|
|
if(chip_type>=LENGTH(tasks_fun_table)){
|
2023-10-08 18:27:10 +08:00
|
|
|
|
DBG_WARN("unknown chip type.");
|
2023-10-07 18:15:52 +08:00
|
|
|
|
arr_append(r,2);
|
|
|
|
|
return arr_temp(r);
|
|
|
|
|
}
|
2023-10-06 18:47:05 +08:00
|
|
|
|
memset(&checker_runcfg,0,sizeof(Checker_RunCfg_st));
|
|
|
|
|
int task_index=0;
|
|
|
|
|
int err_flag=0;
|
|
|
|
|
LED1_Out_Off;
|
2023-10-09 23:01:28 +08:00
|
|
|
|
while((taskid_table[task_index]!=0xff)&&(task_index<PLAN_MAX_TASK)){
|
2023-10-06 18:47:05 +08:00
|
|
|
|
memset(&checker_runcfg.task_info,0,sizeof(CheckerTask_Info_st));
|
2023-10-09 23:01:28 +08:00
|
|
|
|
taskid=taskid_table[task_index];
|
2023-10-06 18:47:05 +08:00
|
|
|
|
memset(checker_runcfg.params,0,20);
|
2023-10-07 18:15:52 +08:00
|
|
|
|
checker_runcfg.param_count = 0;//参数个数
|
|
|
|
|
checker_runcfg.rtv_count = 0;//返回值个数
|
2023-10-06 18:47:05 +08:00
|
|
|
|
checker_runcfg.excue_rtv = 0;
|
|
|
|
|
checker_runcfg.task_info.retry_time = 0;
|
|
|
|
|
if(taskid>=CHECKER_MAXID_COUNT){
|
2023-10-08 18:27:10 +08:00
|
|
|
|
DBG_WARN("tiskid out of bound.");
|
2023-10-06 18:47:05 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
task_par= s->task_info_array[task_index];
|
|
|
|
|
if(task_par==0){
|
2023-10-08 18:27:10 +08:00
|
|
|
|
DBG_WARN("can not find task params.");
|
2023-10-06 18:47:05 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
task_fun=tasks_fun_table[chip_type][taskid];
|
|
|
|
|
if(task_fun==0){
|
2023-10-08 18:27:10 +08:00
|
|
|
|
DBG_WARN("can not find task fun.");
|
2023-10-06 18:47:05 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 装载参数
|
2023-10-06 18:47:05 +08:00
|
|
|
|
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);
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 执行任务
|
2023-10-06 18:47:05 +08:00
|
|
|
|
for(int i=0;i<1+task_par->retry_time;i++)
|
|
|
|
|
{
|
|
|
|
|
checker_runcfg.excue_rtv=1;
|
|
|
|
|
task_fun();
|
|
|
|
|
Checker_Excueindex(task_index);
|
|
|
|
|
if(checker_runcfg.excue_rtv==0)
|
|
|
|
|
break;
|
2023-10-09 23:01:28 +08:00
|
|
|
|
checker_runcfg.rtv_index-=checker_runcfg.rtv_count;
|
2023-10-06 18:47:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
// 找寻下一个任务
|
2023-10-06 18:47:05 +08:00
|
|
|
|
if((checker_runcfg.excue_rtv != 0)
|
|
|
|
|
&& (checker_runcfg.task_info.error_jumpto != 0)
|
|
|
|
|
&& (checker_runcfg.task_info.error_jumpto != 0xFF)
|
|
|
|
|
)
|
|
|
|
|
{
|
2023-10-07 18:15:52 +08:00
|
|
|
|
uint8_t uc_index = task_index+1;//如果时跳至下一个,直接顺序执行
|
2023-10-06 18:47:05 +08:00
|
|
|
|
task_index = checker_runcfg.task_info.error_jumpto;
|
|
|
|
|
while(uc_index < task_index)
|
|
|
|
|
{
|
2023-10-07 18:15:52 +08:00
|
|
|
|
Checker_MaskResult(1,uc_index);//将跳过的步骤标记未执行
|
|
|
|
|
//调整参数返回值下标,将跳过的步骤里面的返回值存储空间保留
|
2023-10-06 18:47:05 +08:00
|
|
|
|
checker_runcfg.rtv_index += (s->task_info_array[uc_index]->param_rtv_count >> 4) & 0x0F;
|
|
|
|
|
uc_index++;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
2023-10-07 18:15:52 +08:00
|
|
|
|
task_index++;//正常情况直接顺序执行
|
2023-10-06 18:47:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
arr_append(r,0);
|
|
|
|
|
arr_appends(r,checker_runcfg.Task_Result,8);
|
|
|
|
|
arr_appends(r,checker_runcfg.Task_Excute,8);
|
|
|
|
|
arr_appends(r,checker_runcfg.Test_Rtv,checker_runcfg.rtv_index*2);
|
|
|
|
|
return arr_temp(r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-07 18:15:52 +08:00
|
|
|
|
|
|
|
|
|
|