📄 ty514cpu.c
字号:
}
CARD1sendbyte(T1_Bcc);//SENDbyte0(Bcc);//send BCC
if(STATE_FLAG)
{
command = SErr;
return;
}
tempPCB=PCB;
if(i==k)
counter=0x012c;
trans1_t1_r1:
NAD=CARD1BWTrecvbyte();//(uint)(WI*DD)*240);//960/6 //RECVbyte0();//recv NAD
if(STATE_FLAG)
{
delay100ms();
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
CPU1_REST_FLAG=0;
command = 0x82;
return;
}
T1_Bcc = NAD;//BCC
PCB = CARD1recvbyte();//(uint)(WI*DD)*240);//960/6 //RECVbyte0();//recv PCB
if(STATE_FLAG)
{
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
CPU1_REST_FLAG=0;
command = 0x82;
return;
}
if(!(PCB&0x80)&&(k>=i))
counter=0x012c;
T1_Bcc ^= PCB;
LEN1 = CARD1recvbyte();//(uint)(WI*DD)*240);//960/6 //RECVbyte0();//recv Len
if(STATE_FLAG)
{
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
CPU1_REST_FLAG=0;
command = 0x82;
return;
}
T1_Bcc ^= LEN1;
tempLEN=LEN1;
if(LEN1>0xfe)
{
delay100ms();
delay100ms();
delay100ms();
delay100ms();
delay100ms();
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
CPU1_REST_FLAG=0;
command = 0x84;
}
if(PCB&0x40)
{
Card1SendR(0x0,0x92);
m++;
goto trans1_t1_r1;
}
else
{
Card1SendR(0x0,0x82);
m++;
goto trans1_t1_r1;
}
}
while(LEN1)
{
temp=CARD1recvbyte();
if(STATE_FLAG)
{
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
CPU1_REST_FLAG=0;
command = 0x84;
return;
}
if(k>=i)
{
XBYTE[counter]=temp;
counter++;
T1_Bcc^=temp;
LEN1--;
}
else
{
T1_Bcc^=temp;
LEN1--;
}
}
if((PCB&0xc0)==0xc0)
tempINF=temp;
length = counter-0x012c;
temp = CARD1recvbyte();//(uint)(WI*DD)*240);//960/6 //RECVbyte0();//recv Bcc
if(STATE_FLAG)
{
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
CPU1_REST_FLAG=0;
command = 0x82;
return;
}
//EDC错误
if((temp != T1_Bcc)||(parity_bit==1))
{
if(m==2)
{
delay2ms();
IC_RST1=0;
CLK_CTR=1;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
delay2ms();
parity_bit=0;
if(!(PCB&0x80)) //接收到I块
{
if(((tempPCB&0x400)==0x40)&&((PCB&0x20)==0x0))
{
Card1SendR(0x0,0x81);
if(k>=i)
counter-=tempLEN;
m++;
goto trans1_t1_r1;
}
else if(((tempPCB&0x40)==0x0)&&((PCB&0x20)==0x0))
{
Card1SendR(0x0,0x91);
if(k>=i)
counter-=tempLEN;
m++;
goto trans1_t1_r1;
}
if(PCB&0x20) //1CF.121
{
Card1SendR(0x0,0x80);
if(k>=i)
counter-=tempLEN;
m++;
goto trans1_t1_r1;
}
}
//发送I块收到EDC错误
if(!(tempPCB&0x80))
{
delay2ms();
delay2ms();
if(tempPCB&0x40)
{
Card1SendR(0x0,0x91);
m++;
tempPCB1=0x91;
goto trans1_t1_r1;
}
if(!(tempPCB&0x40))
{
Card1SendR(0x0,0x81);
tempPCB1=0x81;
m++;
goto trans1_t1_r1;
}
}
//发送R块收到EDC错误
if((tempPCB&0xc0)==0x80)
{
// pointer-=tempLEN;
delay2ms();
delay2ms();
if(tempPCB==0x80)
{
Card1SendR(0x0,0x81);
m++;
tempPCB=0x81;
goto trans1_t1_r1;
}
if(tempPCB==0x90)
{
Card1SendR(0x0,0x91);
m++;
tempPCB=0x91;
goto trans1_t1_r1;
}
}
}
/* NAD错误 */
if(NAD!=0x00)
{
delay2ms();
delay2ms();
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
if((PCB&0x80)==0x00)
{
if(tempPCB&0x40)
{
if(k>=i)
counter-=tempLEN;
Card1SendR(0x0,0x92);
m++;
goto trans1_t1_r1;
}
else
{
if(k>=i)
counter-=tempLEN;
Card1SendR(0x0,0x82);
m++;
goto trans1_t1_r1;
}
}
// if((PCB&0xc0)==0x80)
// {
//之前发送的是I块
if((tempPCB&0x80)==0x00)
{
delay2ms();
if(tempPCB&0x40)
{
Card1SendR(0x0,0x92);
m++;
tempPCB1=0x92;
goto trans1_t1_r1;
}
if(!(tempPCB&0x40))
{
Card1SendR(0x0,0x82); //接收到错误的R块时
m++;
tempPCB1=0x82;
goto trans1_t1_r1;
}
}
// }
}
/* 收到R块 */
if((PCB&0xc0)==0x80)
{
//r块长度错误
if(tempLEN!=0x0)
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
if(!(tempPCB&0x80))
{
delay2ms();
if(tempPCB&0x40)
Card1SendR(0x0,0x90);
else
Card1SendR(0x0,0x80);
m++;
goto trans1_t1_r1;
}
if((tempPCB&0xc0)==0x80)
{
{
Card1SendR(0x0,tempPCB);
m++;
goto trans1_t1_r1;
}
}
}
//R块格式错误
if(PCB&0x20)
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
delay2ms();
delay2ms();
if(tempPCB&0x40)
{
Card1SendR(0x0,0x92);
m++;
tempPCB1=0x92;
goto trans1_t1_r1;
}
else
{
Card1SendR(0x0,0x82);
m++;
tempPCB1=0x82;
goto trans1_t1_r1;
}
}
//sequence wrong
if(((tempPCB2&0xc0)==0x80)&&(tempPCB2==PCB))
{
delay2ms();
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
if(tempPCB&0x40)
{ //1CF.113.03
Card1SendR(0x0,0x90);
m++;
goto trans1_t1_r1;
}
else
{
Card1SendR(0x0,0x80);
m++;
goto trans1_t1_r1;
}
// Card1sendI(0x0,tempPCB,LEN);
}
//收到指示错误的R块
if((PCB&0x0f)!=0x00)
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
if(!(tempPCB&0x80))
{
delay2ms();
delay2ms();
pointer-=LEN;
Card1sendI(0x0,tempPCB,LEN); //重发I块
m++;
goto trans1_t1_r1;
}
}
if(k>=i) //1CF.122.07
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
delay2ms();
if((PCB==tempR)||(tempR==0))
{
pointer-=LEN;
Card1sendI(0x0,tempPCB,LEN);
}
else
{
if(PCB==0x80)
Card1SendR(0x0,0x92);
else
Card1SendR(0x0,0x82);
}
m++;
tempR=PCB;
goto trans1_t1_r1;
}
if((tempPCB&0x80)&&(tempPCB!=0xe3))
{
delay2ms();
delay2ms();
Card1SendR(0x0,tempPCB); //重发R块
m++;
goto trans1_t1_r1;
}
}
/*收到错误块*/
if(((PCB&0xc0)==0xc0)&&(PCB!=0xc3)&&(PCB!=0xc2))
{
delay2ms();
delay2ms();
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
if(tempPCB&0x40)
{
m++;
Card1SendR(0x0,0x92);
goto trans1_t1_r1;
}
else
{
m++;
Card1SendR(0x0,0x82);
goto trans1_t1_r1;
}
}
/* 返回S请求块 */
if((PCB&0xe0)==0xc0)
{
if(PCB==0xc2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x84;
return;
}
if(tempLEN!=0x01)
{
//判断重发次数是否超过
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
delay2ms();
delay2ms();
// pointer-=tempLEN; 1CF.113.03
if(tempPCB&0x40)
{ //1CF.122.03
Card1SendR(0x0,0x90);
m++;
goto trans1_t1_r1;
}
else
{
Card1SendR(0x0,0x80);
m++;
goto trans1_t1_r1;
}
}
//判断是否请求了等待时间扩展
if(PCB == 0xc3)
{
SendSblock(0x0,0xe3,tempINF);
tempPCB=0xe3;
WTX=tempINF;
goto trans1_t1_r1;
}
else if(PCB==0xc2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x84;
return;
}
else
{
if(tempPCB&0x40)
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
Card1SendR(0x0,0x82);
m++;
goto trans1_t1_r1;
}
else
{
Card1SendR(0x0,0x82);
m++;
goto trans1_t1_r1;
}
}
}
/*返回的是I块*/
if(!(PCB&0x80))
{
if(k<i)
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
CPU1_REST_FLAG=0;
STATE_FLAG =1;
command = 0x84;
return;
}
delay2ms();
if(tempPCB&0x40)
{
Card1SendR(0x0,0x82);
m++;
goto trans1_t1_r1;
}
else
{
Card1SendR(0x0,0x82);
m++;
goto trans1_t1_r1;
}
}
//Qeuence wrong
if(((PCB&0x40)==(ISquen&0x40))&&(Squence_flag==1))
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
delay2ms();
if(PCB&0x40)
Card1SendR(0x0,0x82);
else
Card1SendR(0x0,0x92);
counter-=tempLEN;
goto trans1_t1_r1;
}
if(Squence_flag==0)
{
if((PCB&0x40)==0x40)
{
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x8a;
return;
}
Card1SendR(0x0,0x82);
counter-=tempLEN;
m++;
goto trans1_t1_r;
}
}
}
k++;
if(k<i)
{
if((PCB&0x80)==0x00)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -