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

Subversion Repositories iso7816_3_master

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

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

Line No. Rev Author Line
1 2 acapola
`timescale 1ns / 1ps
2 4 acapola
`default_nettype none
3 2 acapola
//////////////////////////////////////////////////////////////////////////////////
4
// Company: 
5
// Engineer: 
6
// 
7
// Create Date:    19:57:35 10/31/2010 
8
// Design Name: 
9
// Module Name:    HalfDuplexUartIf 
10
// Project Name: 
11
// Target Devices: 
12
// Tool versions: 
13
// Description: 
14
//
15
// Dependencies: 
16
//
17
// Revision: 
18
// Revision 0.01 - File Created
19
// Additional Comments: 
20
//
21
//////////////////////////////////////////////////////////////////////////////////
22
module HalfDuplexUartIf(
23 4 acapola
    input wire nReset,
24
    input wire clk,
25
    input wire [DIVIDER_WIDTH-1:0] clkPerCycle,
26
         input wire [7:0] dataIn,
27
    input wire nWeDataIn,
28 7 acapola
    input wire [CLOCK_PER_BIT_WIDTH-1:0] clocksPerBit,
29 4 acapola
    output wire [7:0] dataOut,
30
    input wire nCsDataOut,
31
    output wire [7:0] statusOut,
32
    input wire nCsStatusOut,
33
    input wire serialIn,
34
         output wire serialOut,
35
         output wire comClk
36 2 acapola
    );
37
//parameters to override
38 7 acapola
parameter DIVIDER_WIDTH = 1;
39
parameter CLOCK_PER_BIT_WIDTH = 13;     //allow to support default speed of ISO7816
40 2 acapola
 
41
   reg [7:0] dataReg;
42
 
43
        // Inputs
44
        wire [7:0] txData;
45 7 acapola
        //wire [12:0] clocksPerBit;
46 2 acapola
        wire stopBit2=1;
47
        wire oddParity=0; //if 1, parity bit is such that data+parity have an odd number of 1
48
   wire msbFirst=0;  //if 1, bits will be send in the order startBit, b7, b6, b5...b0, parity
49
        reg txPending;
50
        wire ackFlags;
51
 
52
        // Outputs
53
        wire [7:0] rxData;
54
        wire overrunErrorFlag;
55
        wire dataOutReadyFlag;
56
        wire frameErrorFlag;
57
        wire txRun;
58
   wire endOfRx;
59
        wire rxRun;
60
        wire rxStartBit;
61
        wire txFull;
62 3 acapola
        wire isTx;
63 2 acapola
 
64
   wire rxFlagsSet = dataOutReadyFlag | overrunErrorFlag | frameErrorFlag;
65
   reg bufferFull;
66
   reg [1:0] flagsReg;
67
 
68
   assign txData = dataReg;
69 7 acapola
   //assign clocksPerBit = 7;
70 2 acapola
 
71
   assign dataOut=dataReg;
72
   assign statusOut[7:0]={txRun, txPending, rxRun, rxStartBit, isTx, flagsReg, bufferFull};
73
 
74
reg waitTxFull0;//internal reg for managing bufferFull bit in Tx
75
 
76
assign ackFlags=~txPending & ~txRun & rxFlagsSet & ((bufferFull & ~nCsDataOut)| ~bufferFull);
77
 
78
always @(posedge clk, negedge nReset) begin
79
   if(~nReset) begin
80
      bufferFull <= 1'b0;
81
      flagsReg <= 1'b0;
82
      txPending <= 1'b0;
83
   end else begin
84
      if(ackFlags) begin
85
         dataReg <= rxData;
86
         flagsReg <= {overrunErrorFlag, frameErrorFlag};
87
         if(rxFlagsSet)
88
            bufferFull <= 1'b1;
89
         else
90
            bufferFull <= 1'b0;
91
      end else if(txPending) begin
92
         if(waitTxFull0) begin
93
            if(~txFull)
94
               waitTxFull0 <= 1'b0;
95
         end else if(txFull) begin//tx actually started, clear txPending and free buffer
96
            txPending <= 1'b0;
97
            bufferFull <= 1'b0; //buffer is empty
98
         end
99
      end else if(~nCsDataOut) begin
100
         bufferFull <= 1'b0;
101
      end else if(~nWeDataIn) begin
102
         dataReg <= dataIn;
103
         bufferFull <= 1'b1;
104
         txPending <= 1'b1;
105
         waitTxFull0 <= txFull;
106
      end
107
   end
108
end
109
 
110 7 acapola
        BasicHalfDuplexUart #(
111
                .DIVIDER_WIDTH(DIVIDER_WIDTH),
112
                .CLOCK_PER_BIT_WIDTH(CLOCK_PER_BIT_WIDTH)
113
                )
114 2 acapola
        uart (
115
                .rxData(rxData),
116
                .overrunErrorFlag(overrunErrorFlag),
117
                .dataOutReadyFlag(dataOutReadyFlag),
118
                .frameErrorFlag(frameErrorFlag),
119
                .txRun(txRun),
120
                .endOfRx(endOfRx),
121
      .rxRun(rxRun),
122
                .rxStartBit(rxStartBit),
123
                .txFull(txFull),
124
                .isTx(isTx),
125
                .serialIn(serialIn),
126
                .serialOut(serialOut),
127 3 acapola
                .comClk(comClk),
128 2 acapola
                .txData(txData),
129
                .clocksPerBit(clocksPerBit),
130
                .stopBit2(stopBit2),
131
                .oddParity(oddParity),
132
      .msbFirst(msbFirst),
133
           .startTx(txPending),
134
                .ackFlags(ackFlags),
135
                .clkPerCycle(clkPerCycle),
136
                .clk(clk),
137
                .nReset(nReset)
138
        );
139
 
140
endmodule

powered by: WebSVN 2.1.0

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