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 2

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

powered by: WebSVN 2.1.0

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