OpenCores
URL https://opencores.org/ocsvn/iso7816_3_master/iso7816_3_master/trunk

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [sources/] [Uart.v] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 acapola
`timescale 1ns / 1ps
2
`default_nettype none
3 2 acapola
//////////////////////////////////////////////////////////////////////////////////
4
// Company: 
5
// Engineer: Sebastien Riou
6
// 
7
// Create Date:    23:57:02 08/31/2010 
8
// Design Name: 
9
// Module Name:    Uart 
10
// Project Name: 
11
// Target Devices: 
12
// Tool versions: 
13
// Description: Half duplex UART with 1 byte buffer
14
//
15
// Dependencies: 
16
//
17
// Revision: 
18
// Revision 0.01 - File Created
19
// Additional Comments: 
20
//
21
//////////////////////////////////////////////////////////////////////////////////
22
module BasicHalfDuplexUart(
23 4 acapola
    output wire [7:0] rxData,
24
    output wire overrunErrorFlag,       //new data has been received before dataOut was read
25
    output wire dataOutReadyFlag,       //new data available
26
    output wire frameErrorFlag,         //bad parity or bad stop bits
27
    output wire txRun,                                  //tx is started
28
    output wire endOfRx,           //one cycle pulse: 1 during last cycle of last stop bit of rx
29
    output wire rxRun,                                  //rx is definitely started, one of the three flag will be set
30
    output wire rxStartBit,                     //rx is started, but we don't know yet if real rx or just a glitch
31
    output wire txFull,
32
    output wire isTx,              //1 only when tx is ongoing. Indicates the direction of the com line.
33 2 acapola
 
34 4 acapola
         input wire serialIn,                           //signals to merged into a inout signal according to "isTx"
35
         output wire serialOut,
36
         output wire comClk,
37 2 acapola
 
38 4 acapola
    input wire [DIVIDER_WIDTH-1:0] clkPerCycle,
39
         input wire [7:0] txData,
40
         input wire [CLOCK_PER_BIT_WIDTH-1:0] clocksPerBit,
41
         input wire stopBit2,//0: 1 stop bit, 1: 2 stop bits
42
         input wire oddParity, //if 1, parity bit is such that data+parity have an odd number of 1
43
    input wire msbFirst,  //if 1, bits order is: startBit, b7, b6, b5...b0, parity
44
         input wire startTx,
45
         input wire ackFlags,
46
         input wire clk,
47
    input wire nReset
48 2 acapola
    );
49
 
50
//parameters to override
51
parameter DIVIDER_WIDTH = 1;
52
parameter CLOCK_PER_BIT_WIDTH = 13;     //allow to support default speed of ISO7816
53
//invert the polarity of the output or not
54
parameter IN_POLARITY = 1'b0;
55
parameter PARITY_POLARITY = 1'b1;
56
//default conventions
57
parameter START_BIT = 1'b0;
58
parameter STOP_BIT1 = 1'b1;
59
parameter STOP_BIT2 = 1'b1;
60
 
61
//constant definition for states
62
localparam IDLE_STATE =         3'b000;
63
localparam RX_STATE =   3'b001;
64
localparam TX_STATE =   3'b011;
65
 
66
wire rxSerialIn = isTx ? STOP_BIT1 : serialIn;
67
//wire serialOut;
68
wire loadDataIn;
69
 
70
wire txStopBits;
71
 
72
assign isTx = txRun & ~txStopBits;
73
//let this to top level to avoid inout signal
74
//assign serialLine = isTx ? serialOut : 1'bz;
75
 
76
assign loadDataIn = startTx & ~rxStartBit & (~rxRun | endOfRx);
77
 
78
/*//complicated approach... instead we can simply divide the clock at lower levels
79
wire useEarlyComClk = |clkPerCycle ? 1'b1:1'b0;
80
reg dividedClk;
81
wire earlyComClk;//earlier than comClk by 1 cycle of clk (use to make 1 cycle pulse signals)
82
always @(posedge clk)begin
83
        if(useEarlyComClk)
84
                dividedClk <= earlyComClk;
85
end
86
assign comClk=useEarlyComClk ? dividedClk : clk;//clock for communication
87
wire endOfRxComClk;//pulse of 1 cycle of comClk
88
assign endOfRx = useEarlyComClk ? endOfRxComClk & earlyComClk & ~comClk : endOfRxComClk;//pulse of 1 cycle of clk
89
ClkDivider #(.DIVIDER_WIDTH(DIVIDER_WIDTH))
90
        clkDivider(
91
                .nReset(nReset),
92
                .clk(clk),
93
                .divider(clkPerCycle),
94
                .dividedClk(earlyComClk)
95
                );
96
*/
97 5 acapola
wire stopBit;
98 2 acapola
// Instantiate the module
99
RxCoreSelfContained #(
100 7 acapola
                .DIVIDER_WIDTH(DIVIDER_WIDTH),
101
                .CLOCK_PER_BIT_WIDTH(CLOCK_PER_BIT_WIDTH)
102
                )
103 2 acapola
        rxCore (
104
    .dataOut(rxData),
105
    .overrunErrorFlag(overrunErrorFlag),
106
    .dataOutReadyFlag(dataOutReadyFlag),
107
    .frameErrorFlag(frameErrorFlag),
108
    .endOfRx(endOfRx),
109
    .run(rxRun),
110
    .startBit(rxStartBit),
111 5 acapola
         .stopBit(stopBit),
112
    .clkPerCycle(clkPerCycle),
113 2 acapola
    .clocksPerBit(clocksPerBit),
114
    .stopBit2(stopBit2),
115
    .oddParity(oddParity),
116
    .msbFirst(msbFirst),
117
         .ackFlags(ackFlags),
118
    .serialIn(rxSerialIn),
119
    .comClk(comClk),
120
    .clk(clk),
121
    .nReset(nReset)
122
    );
123 7 acapola
TxCore #(.DIVIDER_WIDTH(DIVIDER_WIDTH),
124
                        .CLOCK_PER_BIT_WIDTH(CLOCK_PER_BIT_WIDTH)
125
                )
126 2 acapola
        txCore (
127
        .serialOut(serialOut),
128
        .run(txRun),
129
        .full(txFull),
130
   .stopBits(txStopBits),
131
        .dataIn(txData),
132
        .clkPerCycle(clkPerCycle),
133
        .clocksPerBit(clocksPerBit),
134
        .stopBit2(stopBit2),
135
   .oddParity(oddParity),
136
   .msbFirst(msbFirst),
137
        .loadDataIn(loadDataIn),
138
        .comClk(comClk),
139
   .clk(clk),
140
   .nReset(nReset)
141
);
142
 
143
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.