Line 1... |
Line 1... |
/*
|
/*
|
Author: Sebastien Riou (acapola)
|
Author: Sebastien Riou (acapola)
|
Creation date: 22:22:43 01/10/2011
|
Creation date: 22:22:43 01/10/2011
|
|
|
$LastChangedDate: 2011-02-13 16:20:10 +0100 (Sun, 13 Feb 2011) $
|
$LastChangedDate: 2011-02-18 15:23:07 +0100 (Fri, 18 Feb 2011) $
|
$LastChangedBy: acapola $
|
$LastChangedBy: acapola $
|
$LastChangedRevision: 15 $
|
$LastChangedRevision: 17 $
|
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/iso7816_3_t0_analyzer.v $
|
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/iso7816_3_t0_analyzer.v $
|
|
|
This file is under the BSD licence:
|
This file is under the BSD licence:
|
Copyright (c) 2011, Sebastien Riou
|
Copyright (c) 2011, Sebastien Riou
|
|
|
Line 221... |
Line 221... |
end
|
end
|
end
|
end
|
reg ppsValidSoFar;
|
reg ppsValidSoFar;
|
reg ppsAccepted;
|
reg ppsAccepted;
|
wire ppsDataMatch = (tpduHeader[(CLA_I-(tempBytesCnt*8))+:8]==dataOut);
|
wire ppsDataMatch = (tpduHeader[(CLA_I-(tempBytesCnt*8))+:8]==dataOut);
|
|
wire [3:0] earlyAtrK = (4'h0==tdiCnt) ? dataOut[3:0] : atrK;
|
always @(posedge isoClk, negedge rxCore_nReset) begin
|
always @(posedge isoClk, negedge rxCore_nReset) begin
|
if(~rxCore_nReset) begin
|
if(~rxCore_nReset) begin
|
ppsValidSoFar<=1'b0;
|
ppsValidSoFar<=1'b0;
|
ppsAccepted<=1'b0;
|
ppsAccepted<=1'b0;
|
fiCode<=4'b0001;
|
fiCode<=4'b0001;
|
Line 234... |
Line 235... |
useT15<=1'b0;
|
useT15<=1'b0;
|
{waitCardTx,waitTermTx}<=2'b00;
|
{waitCardTx,waitTermTx}<=2'b00;
|
fsmState<=ATR_TDI;
|
fsmState<=ATR_TDI;
|
atrHasTck<=1'b0;
|
atrHasTck<=1'b0;
|
tempBytesCnt<=8'h0;
|
tempBytesCnt<=8'h0;
|
tdiStruct<=12'h0;
|
tdiStruct<={4'h0,8'h80};//0x80 as default TDi to consider T0 as a TDi
|
atrCompleted<=1'b0;
|
atrCompleted<=1'b0;
|
atrK<=4'b0;
|
atrK<=4'b0;
|
end else if(isActivated) begin
|
end else if(isActivated) begin
|
if(~tsReceived) begin
|
if(~tsReceived) begin
|
{waitCardTx,waitTermTx}<=2'b10;
|
{waitCardTx,waitTermTx}<=2'b10;
|
end else if(~atrCompleted) begin
|
end else if(~atrCompleted) begin
|
//ATR analysis
|
//ATR analysis
|
case(fsmState)
|
case(fsmState)
|
ATR_TDI: begin
|
ATR_TDI: begin
|
if(endOfRx) begin
|
if(endOfRx) begin
|
if(tempBytesCnt==nIfBytes) begin //TDi bytes
|
if(tempBytesCnt+1==nIfBytes) begin //TDi bytes
|
tempBytesCnt <= 2'h0;
|
|
tdiStruct <= {tdiCnt+1,dataOut};
|
|
if(4'h0==tdiCnt) begin//this is T0
|
if(4'h0==tdiCnt) begin//this is T0
|
atrK <= dataOut[3:0];
|
atrK <= dataOut[3:0];
|
fsmState <= (4'b0!=dataOut[7:4]) ? ATR_TDI :
|
|
(4'b0!=dataOut[3:0]) ? ATR_HISTORICAL : T0_HEADER;
|
|
end else begin//TDi, i from 1 to 15
|
|
fsmState <= (4'b0!=dataOut[7:4]) ? ATR_TDI :
|
|
(4'b0!=atrK) ? ATR_HISTORICAL : T0_HEADER;
|
|
end
|
end
|
|
tempBytesCnt <= 2'h0;
|
|
tdiStruct <= {tdiCnt+1,dataOut};
|
if(12'h0=={dataOut,atrK}) begin
|
if(12'h0=={dataOut,atrK}) begin
|
atrCompleted <= 1'b1;
|
atrCompleted <= 1'b1;
|
{waitCardTx,waitTermTx}<=2'b01;
|
{waitCardTx,waitTermTx}<=2'b01;
|
end
|
end
|
|
if((1'b0==tdiStruct[7]) |//we just received the last interface byte
|
|
(4'b0==dataOut[7:4])) begin //or new TDi indicate no further interface bytes
|
|
fsmState <= (4'b0!=earlyAtrK) ? ATR_HISTORICAL :
|
|
atrHasTck ? ATR_TCK : T0_HEADER;
|
|
end else begin//TDi, i from 1 to 15
|
|
fsmState <= ATR_TDI;
|
|
end
|
|
|
end else begin //TA, TB or TC bytes
|
end else begin //TA, TB or TC bytes
|
//TODO: get relevant info
|
//TODO: get relevant info
|
//check if we just received the last interface byte
|
|
if((tempBytesCnt+1==nIfBytes) & (1'b0==tdiStruct[7])) begin
|
|
tempBytesCnt <= 2'h0;
|
|
fsmState <= (4'b0!=atrK) ? ATR_HISTORICAL : T0_HEADER;
|
|
end else begin
|
|
tempBytesCnt <= tempBytesCnt+1;
|
tempBytesCnt <= tempBytesCnt+1;
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
|
ATR_HISTORICAL: begin
|
ATR_HISTORICAL: begin
|
if(endOfRx) begin
|
if(endOfRx) begin
|
if(tempBytesCnt==(atrK-1)) begin
|
if(tempBytesCnt+1==atrK) begin
|
tempBytesCnt <= 8'h0;
|
tempBytesCnt <= 8'h0;
|
if(atrHasTck) begin
|
if(atrHasTck) begin
|
fsmState <= ATR_TCK;
|
fsmState <= ATR_TCK;
|
end else begin
|
end else begin
|
atrCompleted <= 1'b1;
|
atrCompleted <= 1'b1;
|