can_bootloader/user/DiagBootcode.aardio

130 lines
2.0 KiB
Plaintext
Raw Normal View History

2022-05-14 17:00:49 +08:00
var bootstate = 0;
var bootcount = 0;
var sendstate = 0;
FuncWait = function(sid){
if(RespState == (sid + 0x40)){//正响应
return 0;
}
errsid,errnrc = FuncGetNrc();
FuncClrNrc();
if(errsid == sid){
if(errnrc == 0x78){//等待
bootcount = 0;
return 0xff;
}
else {
FuncDisplay("错误");
boottimer.disable();
return 1; //负响应
}
}
if(stopflag == 1){
FuncDisplay("停止");
boottimer.disable();
return 2;//停止命令
}
bootcount += 1;
if(bootcount >= 400){
FuncDisplay("超时");
boottimer.disable();
return 3;//超时
}
}
FuncStopBoot = function(){
stopflag = 1;
}
FuncClearState = function(){
RespState = 0;
bootcount = 0;
sendstate = 1;
}
FuncInitBootState = function(){
bootstate = 0;
RespState = 0;
bootcount = 0;
sendstate = 0;
}
nextstate = function(val){
if(val == 0){
bootstate += 1;
sendstate = 0;
}
}
FuncBootSeq = function(){
select(bootstate) {
case 0 {
//读取当前会话
if(sendstate == 0){
FuncReadDID(0xF186);
FuncClearState();
}
else {
var ret = FuncWait(0x22);
nextstate(ret);
}
}
case 1 {
if(sendstate == 0){
FuncReadDID(0xF195);//读取软件版本
FuncClearState();
}
else {
var ret = FuncWait(0x22);
nextstate(ret);
}
}
case 2 {
if(sendstate == 0){
FuncReadDID(0xF192);//读取硬件版本
FuncClearState();
}
else {
var ret = FuncWait(0x22);
nextstate(ret);
}
}
case 3 {
if(sendstate == 0){
FuncReq10(0x03);//进入扩展会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
case 4 {
if(sendstate == 0){
FuncReq85(0x02);//进入扩展会话
FuncClearState();
}
else {
var ret = FuncWait(0x85);
nextstate(ret);
}
}
case 5 {
if(sendstate == 0){
FuncReq28(0x01);//进入扩展会话
FuncClearState();
}
else {
var ret = FuncWait(0x28);
nextstate(ret);
}
}
else {
FuncDisplay("停止")
boottimer.disable();
}
}
}