Line 1... |
Line 1... |
`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
`default_nettype none
|
`default_nettype none
|
|
|
module Iso7816_3_t0_analyzer(
|
module Iso7816_3_t0_analyzer
|
|
#(parameter DIVIDER_WIDTH = 1)
|
|
(
|
input wire nReset,
|
input wire nReset,
|
input wire clk,
|
input wire clk,
|
input wire [DIVIDER_WIDTH-1:0] clkPerCycle,
|
input wire [DIVIDER_WIDTH-1:0] clkPerCycle,
|
input wire isoReset,
|
input wire isoReset,
|
input wire isoClk,
|
input wire isoClk,
|
input wire isoVdd,
|
input wire isoVdd,
|
input wire isoSio,
|
input wire isoSioTerm,
|
|
input wire isoSioCard,
|
|
input wire useDirectionProbe,//if 1, isoSioTerm and isoSioCard must be connected to Iso7816_directionProbe outputs
|
output reg [3:0] fiCode,
|
output reg [3:0] fiCode,
|
output reg [3:0] diCode,
|
output reg [3:0] diCode,
|
output wire [12:0] fi,
|
output wire [12:0] fi,
|
output wire [7:0] di,
|
output wire [7:0] di,
|
output wire [12:0] cyclesPerEtu,
|
output wire [12:0] cyclesPerEtu,
|
Line 27... |
Line 31... |
output reg useT0,
|
output reg useT0,
|
output reg useT1,
|
output reg useT1,
|
output reg useT15,
|
output reg useT15,
|
output reg waitCardTx,
|
output reg waitCardTx,
|
output reg waitTermTx,
|
output reg waitTermTx,
|
output reg cardTx,
|
output wire cardTx,
|
output reg termTx,
|
output wire termTx,
|
output wire guardTime,
|
output wire guardTime,
|
output wire overrunError,
|
output wire overrunError,
|
output wire frameError,
|
output wire frameError,
|
output reg [7:0] lastByte,
|
output reg [7:0] lastByte,
|
output reg [31:0] bytesCnt
|
output reg [31:0] bytesCnt
|
);
|
);
|
parameter DIVIDER_WIDTH = 1;
|
|
|
wire isoSio = isoSioTerm & isoSioCard;
|
|
|
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
|
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
|
|
|
reg [7:0] buffer[256+5:0];
|
reg [7:0] buffer[256+5:0];
|
localparam CLA_I= 8*4;
|
localparam CLA_I= 8*4;
|
Line 71... |
Line 76... |
//`include "ComRxDriverTasks.v"
|
//`include "ComRxDriverTasks.v"
|
|
|
wire endOfRx;
|
wire endOfRx;
|
|
|
wire stopBit2 = useT0;//1 if com use 2 stop bits --> 12 ETU / byte
|
wire stopBit2 = useT0;//1 if com use 2 stop bits --> 12 ETU / byte
|
|
wire [12:0] clocksPerBit = cyclesPerEtu-1;
|
RxCoreSelfContained #(
|
RxCoreSelfContained #(
|
.DIVIDER_WIDTH(DIVIDER_WIDTH),
|
.DIVIDER_WIDTH(DIVIDER_WIDTH),
|
.CLOCK_PER_BIT_WIDTH(4'd13),
|
.CLOCK_PER_BIT_WIDTH(4'd13),
|
.PRECISE_STOP_BIT(1'b1))
|
.PRECISE_STOP_BIT(1'b1))
|
rxCore (
|
rxCore (
|
Line 86... |
Line 91... |
.endOfRx(endOfRx),
|
.endOfRx(endOfRx),
|
.run(rxRun),
|
.run(rxRun),
|
.startBit(rxStartBit),
|
.startBit(rxStartBit),
|
.stopBit(guardTime),
|
.stopBit(guardTime),
|
.clkPerCycle(clkPerCycle),
|
.clkPerCycle(clkPerCycle),
|
.clocksPerBit(cyclesPerEtu-1),
|
.clocksPerBit(clocksPerBit),
|
.stopBit2(stopBit2),
|
.stopBit2(stopBit2),
|
.oddParity(oddParity),
|
.oddParity(oddParity),
|
.msbFirst(msbFirst),
|
.msbFirst(msbFirst),
|
.ackFlags(ackFlags),
|
.ackFlags(ackFlags),
|
.serialIn(isoSio),
|
.serialIn(isoSio),
|
Line 316... |
Line 321... |
end
|
end
|
end
|
end
|
end
|
end
|
|
|
reg [1:0] txDir;
|
reg [1:0] txDir;
|
always @(*) begin: errorSigDirectionBlock
|
reg proto_cardTx;
|
|
reg proto_termTx;
|
|
always @(*) begin: protoComDirectionCombiBlock
|
if(guardTime & ~isoSio)
|
if(guardTime & ~isoSio)
|
{cardTx, termTx}={txDir[0],txDir[1]};
|
{proto_cardTx, proto_termTx}={txDir[0],txDir[1]};
|
else
|
else
|
{cardTx, termTx}={txDir[1],txDir[0]};
|
{proto_cardTx, proto_termTx}={txDir[1],txDir[0]};
|
end
|
end
|
always @(posedge isoClk, negedge nReset) begin: comDirectionBlock
|
always @(posedge isoClk, negedge nReset) begin: protoComDirectionSeqBlock
|
if(~nReset | ~run) begin
|
if(~nReset | ~run) begin
|
txDir<=2'b00;
|
txDir<=2'b00;
|
end else begin
|
end else begin
|
if(~guardTime) begin //{waitCardTx, waitTermTx} is updated during stop bits so we hold current value here
|
if(~guardTime) begin //{waitCardTx, waitTermTx} is updated during stop bits so we hold current value here
|
case({waitCardTx, waitTermTx})
|
case({waitCardTx, waitTermTx})
|
Line 337... |
Line 344... |
endcase
|
endcase
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
|
reg phy_cardTx;
|
|
reg phy_termTx;
|
|
always @(negedge isoSio, negedge nReset) begin: phyComDirectionBlock
|
|
if(~nReset) begin
|
|
phy_cardTx<=1'b0;
|
|
phy_termTx<=1'b0;
|
|
end else begin
|
|
if(~isoSioTerm) begin
|
|
phy_cardTx<=1'b0;
|
|
phy_termTx<=1'b1;
|
|
end else begin
|
|
phy_cardTx<=1'b1;
|
|
phy_termTx<=1'b0;
|
|
end
|
|
end
|
|
end
|
|
|
|
assign cardTx = useDirectionProbe ? phy_cardTx : proto_cardTx;
|
|
assign termTx = useDirectionProbe ? phy_termTx : proto_termTx;
|
|
|
endmodule
|
endmodule
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|