📄 ty514cpu.c
字号:
if((sw1 != ins)&&((sw1+ins) != 0xff))
{
// sw2 = SAM4recvbyte();
// if(STATE_FLAG)
// { command = IFD_ICC_TypeError;return;}
// XBYTE[0] = sw1;XBYTE[1] =sw2;
// length = 2;
// return;
STATE_FLAG = 1;
command = IFD_ICC_TypeError;return;
}
//sw1 == ins
//case3
if(case3)
{
pointer = 5;
Detu(); //方向字符为16 ETU
Detu(); //方向字符为16 ETU
Detu(); //方向字符为16 ETU
while((sw1+ins) == 0xff)
{
temp = XBYTE[pointer];
pointer ++;
SAM4sendbyte(temp);
if (STATE_FLAG)
{ command = temp; return;}
do{
sw1 = SAM4recvbyte();
if (STATE_FLAG)
{ command = IFD_ICC_TypeError; return;}
if(sw1 == 0x60) sPC60();
} while( sw1 == 0x60);
if(--pp3 == 0) break;
}
if(sw1 == ins)
{
while(pp3)
{
temp = XBYTE[pointer];
SAM4sendbyte(temp);
pointer++;
pp3--;
if (STATE_FLAG)
{ command = sw1; return;}
}
while(1)
{
sw1 = SAM4recvbyte();
if(STATE_FLAG)
{ command = IFD_ICC_TypeError;return;}
if(sw1 != 0x60) break;
sPC60();
}
}
sw2 = SAM4recvbyte();
if(STATE_FLAG)
{ command = IFD_ICC_TypeError;return;}
XBYTE[0] = sw1;
XBYTE[1] =sw2;
length = 2;
return;
}
//case1,2
//指针复位
pointer = 0;
while((sw1+ins) == 0xff) // 20040720 add
{
temp = SAM4recvbyte();
if(STATE_FLAG)
{ command = temp;return;}
XBYTE[pointer] = temp;
pointer++;
while(1) // 200407012 modify
{
sw1 = SAM4recvbyte();
if(STATE_FLAG)
{command = IFD_ICC_TypeError;return;}
if(sw1 != 0x60) break;
sPC60();
}
if(--pp3 == 0) break;
}
if(sw1 == ins)
{
do
{
temp = SAM4recvbyte();
if(STATE_FLAG)
{ command = temp;return;}
XBYTE[pointer] = temp;
pointer++;
pp3--;
}while(pp3);
}
// sw1 = SAM4recvbyte();
// if(STATE_FLAG)
// { command = sw1;return;}
while(1) // 200407012 modify
{
sw1 = SAM4recvbyte();
if(STATE_FLAG)
{command = IFD_ICC_TypeError;return;}
if(sw1 != 0x60) break;
sPC60();
}
sw2 = SAM4recvbyte();
if(STATE_FLAG)
{ command = IFD_ICC_TypeError;return;}
XBYTE[pointer] = sw1;
pointer++;
XBYTE[pointer] = sw2;
pointer ++;
length = pointer;
return;
}
//==================================================================================
//card1 T=1通信协议
void trans1_t1(void) //using 0
{
uchar data T1_Bcc; data tempLEN;data LEN1;data tempPCB; data tempPCB1;data tempR;
uchar data j; data k; data i;data m;data n;//data ISquen;
uchar data tempINF;data Inf;
uchar data T;
// uint data Respointer=0; 再同步处理
SendFirb();
k=0;m=0;i=0;j=0;tempPCB1=0x0;tempR=0x0;//ISquen=0;
pointer=0;
if(length>IFSD)
{
if(IFSD>=IFSC)
{
i= length/IFSC;
j=length%IFSC;
if(CPU1_block)
PCB =0x60;
else
PCB = 0x20;
CPU1_block = ~CPU1_block;
LEN = IFSC;
pointer=0;
goto trans1_t1_s;
}
if(IFSD<IFSC)
{
i= length/IFSD;
j=length%IFSD;
if(CPU1_block)
PCB =0x60;
else
PCB = 0x20;
CPU1_block = ~CPU1_block;
LEN = IFSD;
goto trans1_t1_s;
}
}
else if(length<IFSD)
{
if(length>IFSC)
{
i= length/IFSC;
j=length%IFSC;
if(CPU1_block)
PCB =0x60;
else
PCB = 0x20;
CPU1_block = ~CPU1_block;
LEN = IFSC;
goto trans1_t1_s;
}
if(length<=IFSC)
{
LEN = length;
}
}
else if(length == IFSD)
{
if(IFSD>IFSC)
{
i= length/IFSC;
j=length%IFSC;
if(CPU1_block)
PCB =0x60;
else
PCB = 0x20;
pointer=0;
LEN = IFSC;
goto trans1_t1_s;
}
if(IFSD<=IFSC)
{
LEN = IFSD;
}
}
//正常处理
//trans_t1_t:
delay2ms();
delay2ms();
delay2ms();
n=0;
CARD1sendbyte(NAD);//SENDbyte0(NAD);
if(STATE_FLAG)
{
command = SErr;
return;
}
T1_Bcc = NAD;
if(CPU1_block)
PCB =0x40;
else
PCB =0x00;
CPU1_block = ~CPU1_block;
CARD1sendbyte(PCB);//SENDbyte0(pcb)
if(STATE_FLAG)
{
command = SErr;
return;
}
T1_Bcc ^= PCB;
CARD1sendbyte(LEN);//SENDbyte0(Len);
if(STATE_FLAG)
{
command = SErr;
return;
}
T1_Bcc ^= LEN;
tempLEN = LEN;
while(tempLEN)
{
// transbuff[n]= XBYTE[pointer];
temp = XBYTE[pointer];
CARD1sendbyte(temp);
T1_Bcc ^= temp;
if(STATE_FLAG)
{
command = SErr;
return;
}
tempLEN --;
pointer ++;
n++;
}
if((PCB&0xe0)==0xc0)
temp=Inf;
CARD1sendbyte(T1_Bcc);//SENDbyte0(Bcc);//send BCC
if(STATE_FLAG)
{
command = SErr;
return;
}
tempPCB=PCB;
/****************************************************************************************************************************************************************/
//正常接收响应
counter= 0x012c,T1_Bcc=0;
trans1_t1_r:
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;
STATE_FLAG = 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;
STATE_FLAG = 1 ;
CPU1_REST_FLAG=0;
command=0x82;
return;
}
T1_Bcc ^= PCB;
LEN1= CARD1recvbyte();//(uint)(WI*DD)*240);//960/6 //RECVbyte0();//recv Len
if(STATE_FLAG)
{
delay2ms();
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
STATE_FLAG = 1 ;
CPU1_REST_FLAG=0;
command=0x82;
return;
}
T1_Bcc ^= LEN1;
T=LEN1;
//长度超出范围
if(LEN1>0xfe)
{
delay100ms();
delay100ms();
delay100ms();
delay100ms();
delay100ms();
delay100ms();
if(m==2)
{
delay2ms();
IC_RST1=0;
IC_IO1=0;
CLK_CTR=1;
IC_PWR1=1;
STATE_FLAG = 1 ;
CPU1_REST_FLAG=0;
command=0x82;
return;
}
if(PCB&0x80==0x00)
{
if(PCB&0x20)
{
Card1SendR(0x0,tempPCB);
m++;
goto trans1_t1_r;
}
if(PCB&0x40)
{
Card1SendR(0x0,0x92);
m++;
tempPCB1=0x92;
goto trans1_t1_r;
}
else
{
Card1SendR(0x0,0x82);
m++;
tempPCB1=0x82;
goto trans1_t1_r;
}
}
//之前发送的是I块
if((tempPCB&0x80)==0x00)
{
if(tempPCB&0x40)
{
Card1SendR(0x0,0x92);
m++;
tempPCB1=0x92;
goto trans1_t1_r;
}
if(!(tempPCB&0x40))
{
Card1SendR(0x0,0x82);
m++;
tempPCB1=0x82;
goto trans1_t1_r;
}
}
//之前发送的是R块
if((tempPCB&0xc0)==0x80)
{
if(tempPCB==0x80)
{
Card1SendR(0x0,0x80);
m++;
goto trans1_t1_r;
}
if(tempPCB==0x90)
{
Card1SendR(0x0,0x90);
m++;
goto trans1_t1_r;
}
}
}
while(LEN1)//RECV INF
{
temp = CARD1recvbyte();//(uint)(WI*DD)*240);//960/6 //RECVbyte0();
if(STATE_FLAG)
{
delay2ms();
IC_RST1 = 0;
IC_IO1 = 0;
CLK_CTR=1;
IC_PWR1 = 1;
CPU1_REST_FLAG = 0;
command = 0x82;
return;
}
if(!(PCB&0x80))
{
XBYTE[counter] = temp;
T1_Bcc^=temp;
LEN1--;
counter++;
}
else
{
T1_Bcc^=temp;
LEN1--;
}
}
if((PCB==0xc1)||(PCB==0xc3))
tempINF=temp;
temp = CARD1recvbyte();//(uint)(WI*DD)*240);//960/6 //RECVbyte0();//recv Bcc
if(STATE_FLAG)
{
delay2ms();
IC_RST1 = 0;
IC_IO1 = 0;
CLK_CTR=1;
IC_PWR1 = 1;
CPU1_REST_FLAG = 0;
command = 0x82;
return;
}
length = counter-0x012c;
//EDC错误
if((temp!= T1_Bcc)||(parity_bit==1))
{
delay2ms();
parity_bit=0;
if(m==2)
{
IC_RST1=0;
IC_IO1=0;
CPU1_REST_FLAG=0;
IC_PWR1=1;
STATE_FLAG = 1 ;
command = 0x82;
return;
// Card1SendR(0x0,0xc0); 再同步处理
// goto trans1_t1_r;
}
delay2ms();
delay2ms();
if((PCB&0x80)==0x00)
{
if((tempPCB&0xc0)==0x80) //1CF.121
{
Card1SendR(0x0,(tempPCB&0x91));
m++;
counter-=T;
goto trans1_t1_r;
}
if(PCB&0x40)
{
counter-=T;
Card1SendR(0x0,0x91);
tempPCB1=0x91;
m++;
goto trans1_t1_r;
}
if(!(PCB&0x40))
{
counter-=T;
Card1SendR(0x0,0x81);
tempPCB1=0x81;
m++;
goto trans1_t1_r;
}
}
if(!(tempPCB&0x80))
{ //I块EDC错误
if((tempPCB&0x40)==0x00)
{
Card1SendR(0x0,0x81);
tempPCB1=0x81;
m++;
goto trans1_t1_r;
}
//I块EDC错误
if((tempPCB&0x40)==0x40)
{
Card1SendR(0x0,0x91);
tempPCB1=0x91;
m++;
goto trans1_t1_r;
}
}
//S块
if((tempPCB&0xc0)==0xc0)
{
Card1SendR(0x0,0x81);
m++;
tempPCB1=0x81;
goto trans1_t1_r;
}
//R
if((tempPCB&0xc0)==0x80)
{
Card1SendR(0x0,tempPCB);// 5.7.59修改的
m++;
goto trans1_t1_r;
}
}
/* NAD错误 */
if(NAD!=0x00)
{
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&0x80)==0x0)
{
if((tempPCB&0xc0)==0x80)
{
Card1SendR(0x0,tempPCB);
counter-=T;
m++;
goto trans1_t1_r;
}
if(PCB&0x40)
{
Card1SendR(0x0,0x92);
counter-=T;
m++;
tempPCB1=0x92;
goto trans1_t1_r;
}
else
{
Card1SendR(0x0,0x82);
m++;
counter-=T;
tempPCB1=0x82;
goto trans1_t1_r;
}
}
//先前发送块为I块
if((tempPCB&0x80)==0x00)
{
if((tempPCB&0x40)==0x00)
{
Card1SendR(0x0,0x82);
m++;
tempPCB1=0x82;
goto trans1_t1_r;
}
if((tempPCB&0x40)==0x40)
{
Card1SendR(0x0,0x92);
m++;
tempPCB1=0x92;
goto trans1_t1_r;
}
}
//先前块为R块
if((tempPCB&0xc0)==0x80)
{
if(tempPCB==0x80)
{
Card1SendR(0x0,0x82);
m++;
tempPCB1=0x82;
goto trans1_t1_r;
}
if(tempPCB==0x90)
{
Card1SendR(0x0,0x92);
m++;
tempPCB1=0x92;
goto trans1_t1_r;
}
}
//先前块为S块
if((tempPCB&0xe0)==0xc0)
{
Card1SendR(0x0,0x92);
m++;
tempPCB1=0x92;
goto trans1_t1_r;
}
}
/*PCB判断及纠错 */
if(PCB&0x80)//is R_block or S_block(not I_block) -- save NAD.PCB.Len
{
//回复为S请求块
if((PCB&0xe0)==0xc0)
{
if(T!=0x01) //判断S请求块长度是否正确
{
// pointer-=T;
if(m==2) //判断重发次数是否超过
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -