输入条件:SysKind=0--->EasmChip的操作,SysKind=1-->CpuCard的操作。
输出项目:RetData=0x00成功,RetData!=0x00:失败。
unsigned char CosReset(bool SysKind) { unsigned char i,j; unsigned short Temp; for(i = 0; i < 3; i ++)//---------------------------------------------------循环复位5次,若均失败则返回0xFF { WDT(); SysErrInfo = 0x00; for(j = 0; j < 13; j++) { CosBuf[j] = 0; } Temp = 1000;//---------------------------------------------------------复位应答超时计数器 if(SysKind) { CpuCardRstDirOut; CpuCardRstLow; for(j=0;j<15;j++)//-------------------------------------------------上电复位延时35个ETU { WDT(); Delay10etu(); } CpuCardRstHig;//----------------------------------------------------完成复位 CpuCardSdaDirIn; while(--Temp)//-----------------------------------------------------超时时400/fi-40000 /fi { WDT(); if(!(CpuCardSdaInSt&BIT5)) { CosBuf[0] = AckRecv(1); if(CosBuf[0] == 0x3b) { CosBuf[1] = ResetReceive(1); if( (CosBuf[1] & 0xf0) != 0x60 ) { SysErrInfo = 0xFF; } else { for(j = 2; j < 4+(CosBuf[1] & 0x0F); j++) { CosBuf[j] = ResetReceive(1); } } } break; } } WDT(); if(Temp == 0)//-----------------------------------------------------复位应答超时处理 { CpuCardRstLow; SysErrInfo = 0xFF; } else { if( (CosBuf[0] == 0x3B) && (CosBuf[1] == 0x69) ) if( (CosBuf[2] == 0x00) && (CosBuf[3] == 0x00) ) break; } } else { EasmChipRstDirOut; EasmChipRstLow; for(j=0;j<15;j++)//-------------------------------------------------上电复位延时35个ETU { WDT(); Delay10etu(); } EasmChipRstHig;//---------------------------------------------------完成复位 EasmChipSdaDirIn; while(--Temp)//-----------------------------------------------------超时时400/fi-40000 /fi { WDT(); if(!(EasmChipSdaInSt&BIT1)) { CosBuf[0] = AckRecv(0); if(CosBuf[0] == 0x3b) { CosBuf[1] = ResetReceive(0); if((CosBuf[1] & 0xf0) != 0x60) { SysErrInfo = 0xFF; } else { for(j = 2; j < 4+(CosBuf[1] & 0x0F); j++) { CosBuf[j] = ResetReceive(0); } } } break; } } if(Temp == 0)//-----------------------------------------------------复位应答超时处理 { EasmChipRstLow;//-----------------------------------------------RESET = 0 SysErrInfo = 0xFF; } else { if( (CosBuf[0] == 0x3B) && (CosBuf[1] == 0x69) ) if( (CosBuf[2] == 0x00) && (CosBuf[3] == 0x00) ) break; } } } if(i < 3) { return 0x00; } else { return 0xff; } }