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 3

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

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

powered by: WebSVN 2.1.0

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