1 |
11 |
acapola |
/*
|
2 |
|
|
Author: Sebastien Riou (acapola)
|
3 |
|
|
Creation date: 23:57:02 08/31/2010
|
4 |
|
|
|
5 |
|
|
$LastChangedDate: 2011-01-29 13:16:17 +0100 (Sat, 29 Jan 2011) $
|
6 |
|
|
$LastChangedBy: acapola $
|
7 |
|
|
$LastChangedRevision: 11 $
|
8 |
|
|
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/sources/RxCoreSelfContained.v $
|
9 |
|
|
|
10 |
|
|
This file is under the BSD licence:
|
11 |
|
|
Copyright (c) 2011, Sebastien Riou
|
12 |
|
|
|
13 |
|
|
All rights reserved.
|
14 |
|
|
|
15 |
|
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
16 |
|
|
|
17 |
|
|
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
18 |
|
|
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
19 |
|
|
The names of contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
|
20 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21 |
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22 |
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23 |
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
24 |
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
25 |
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
26 |
|
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
27 |
|
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
28 |
|
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
29 |
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
30 |
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
*/
|
32 |
|
|
`default_nettype none
|
33 |
4 |
acapola |
`timescale 1ns / 1ps
|
34 |
11 |
acapola |
|
35 |
|
|
module RxCoreSelfContained
|
36 |
|
|
#(//parameters to override
|
37 |
|
|
parameter DIVIDER_WIDTH = 1,
|
38 |
|
|
parameter CLOCK_PER_BIT_WIDTH = 13, //allow to support default speed of ISO7816
|
39 |
|
|
parameter PRECISE_STOP_BIT = 0, //if 1, stopBit signal goes high exactly at start of stop bit instead of middle of parity bit
|
40 |
|
|
//default conventions
|
41 |
|
|
parameter START_BIT = 1'b0,
|
42 |
|
|
parameter STOP_BIT1 = 1'b1,
|
43 |
|
|
parameter STOP_BIT2 = 1'b1
|
44 |
|
|
)
|
45 |
|
|
(
|
46 |
4 |
acapola |
output wire [7:0] dataOut,
|
47 |
|
|
output wire overrunErrorFlag, //new data has been received before dataOut was read
|
48 |
|
|
output wire dataOutReadyFlag, //new data available
|
49 |
|
|
output wire frameErrorFlag, //bad parity or bad stop bits
|
50 |
|
|
output wire endOfRx, //one cycle pulse: 1 during last cycle of last stop bit
|
51 |
|
|
output wire run, //rx is definitely started, one of the three flag will be set
|
52 |
|
|
output wire startBit, //rx is started, but we don't know yet if real rx or just a glitch
|
53 |
5 |
acapola |
output wire stopBit, //rx is over but still in stop bits
|
54 |
4 |
acapola |
input wire [DIVIDER_WIDTH-1:0] clkPerCycle,
|
55 |
|
|
input wire [CLOCK_PER_BIT_WIDTH-1:0] clocksPerBit,
|
56 |
|
|
input wire stopBit2,//0: 1 stop bit, 1: 2 stop bits
|
57 |
|
|
input wire oddParity, //if 1, parity bit is such that data+parity have an odd number of 1
|
58 |
|
|
input wire msbFirst, //if 1, bits order is: startBit, b7, b6, b5...b0, parity
|
59 |
|
|
input wire ackFlags,
|
60 |
|
|
input wire serialIn,
|
61 |
|
|
input wire comClk,//not used yet
|
62 |
|
|
input wire clk,
|
63 |
|
|
input wire nReset
|
64 |
2 |
acapola |
);
|
65 |
|
|
|
66 |
|
|
wire [CLOCK_PER_BIT_WIDTH-1:0] bitClocksCounter;
|
67 |
|
|
wire bitClocksCounterEarlyMatch;
|
68 |
|
|
wire bitClocksCounterMatch;
|
69 |
|
|
wire [CLOCK_PER_BIT_WIDTH-1:0] bitClocksCounterCompare;
|
70 |
|
|
wire bitClocksCounterInc;
|
71 |
|
|
wire bitClocksCounterClear;
|
72 |
4 |
acapola |
wire bitClocksCounterInitVal;
|
73 |
|
|
wire dividedClk;
|
74 |
2 |
acapola |
Counter #( .DIVIDER_WIDTH(DIVIDER_WIDTH),
|
75 |
7 |
acapola |
.WIDTH(CLOCK_PER_BIT_WIDTH),
|
76 |
2 |
acapola |
.WIDTH_INIT(1))
|
77 |
|
|
bitClocksCounterModule(
|
78 |
|
|
.counter(bitClocksCounter),
|
79 |
|
|
.earlyMatch(bitClocksCounterEarlyMatch),
|
80 |
4 |
acapola |
.match(bitClocksCounterMatch),
|
81 |
|
|
.dividedClk(dividedClk),
|
82 |
2 |
acapola |
.divider(clkPerCycle),
|
83 |
|
|
.compare(bitClocksCounterCompare),
|
84 |
|
|
.inc(bitClocksCounterInc),
|
85 |
|
|
.clear(bitClocksCounterClear),
|
86 |
|
|
.initVal(bitClocksCounterInitVal),
|
87 |
|
|
.clk(clk),
|
88 |
|
|
.nReset(nReset));
|
89 |
|
|
|
90 |
7 |
acapola |
RxCore #( .CLOCK_PER_BIT_WIDTH(CLOCK_PER_BIT_WIDTH),
|
91 |
|
|
.PRECISE_STOP_BIT(PRECISE_STOP_BIT)
|
92 |
|
|
)
|
93 |
|
|
rxCore (
|
94 |
2 |
acapola |
.dataOut(dataOut),
|
95 |
|
|
.overrunErrorFlag(overrunErrorFlag),
|
96 |
|
|
.dataOutReadyFlag(dataOutReadyFlag),
|
97 |
|
|
.frameErrorFlag(frameErrorFlag),
|
98 |
|
|
.endOfRx(endOfRx),
|
99 |
|
|
.run(run),
|
100 |
5 |
acapola |
.startBit(startBit),
|
101 |
|
|
.stopBit(stopBit),
|
102 |
2 |
acapola |
.clocksPerBit(clocksPerBit),
|
103 |
|
|
.stopBit2(stopBit2),
|
104 |
|
|
.oddParity(oddParity),
|
105 |
|
|
.msbFirst(msbFirst),
|
106 |
|
|
.ackFlags(ackFlags),
|
107 |
|
|
.serialIn(serialIn),
|
108 |
|
|
.clk(clk),
|
109 |
|
|
.nReset(nReset),
|
110 |
|
|
.bitClocksCounterEarlyMatch(bitClocksCounterEarlyMatch),
|
111 |
|
|
.bitClocksCounterMatch(bitClocksCounterMatch),
|
112 |
|
|
.bitClocksCounterCompare(bitClocksCounterCompare),
|
113 |
|
|
.bitClocksCounterInc(bitClocksCounterInc),
|
114 |
|
|
.bitClocksCounterClear(bitClocksCounterClear),
|
115 |
7 |
acapola |
.bitClocksCounterInitVal(bitClocksCounterInitVal),
|
116 |
|
|
.bitClocksCounter(bitClocksCounter)
|
117 |
2 |
acapola |
);
|
118 |
|
|
|
119 |
|
|
endmodule
|
120 |
11 |
acapola |
`default_nettype wire
|