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

Subversion Repositories uart2spi

[/] [uart2spi/] [trunk/] [rtl/] [uart_core/] [uart_core.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Tubo 8051 cores UART Interface Module                       ////
4
////                                                              ////
5
////  This file is part of the Turbo 8051 cores project           ////
6
////  http://www.opencores.org/cores/turbo8051/                   ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Turbo 8051 definitions.                                     ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
module uart_core (
44
        line_reset_n ,
45
        line_clk ,
46
 
47
        // configuration control
48
        cfg_tx_enable  , // Enable Transmit Path
49
        cfg_rx_enable  , // Enable Received Path
50
        cfg_stop_bit   , // 0 -> 1 Start , 1 -> 2 Stop Bits
51
        cfg_pri_mod    , // priority mode, 0 -> nop, 1 -> Even, 2 -> Odd
52
        cfg_baud_16x   ,
53
 
54
    // TXD Information
55
        tx_data_avail,
56
        tx_rd,
57
        tx_data,
58
 
59
 
60
    // RXD Information
61
        rx_ready,
62
        rx_wr,
63
        rx_data,
64
 
65
       // Status information
66
        frm_error,
67
        par_error,
68
 
69
        baud_clk_16x,
70
 
71
       // Line Interface
72
        rxd,
73
        txd
74
 
75
     );
76
 
77
 
78
 
79
//---------------------------------
80
// Global Dec
81
// ---------------------------------
82
 
83
input        line_reset_n         ; // line reset
84
input        line_clk             ; // line clock
85
 
86
//-------------------------------------
87
// Configuration 
88
// -------------------------------------
89
input         cfg_tx_enable        ; // Tx Enable
90
input         cfg_rx_enable        ; // Rx Enable
91
input         cfg_stop_bit         ; // 0 -> 1 Stop, 1 -> 2 Stop
92
input   [1:0] cfg_pri_mod          ; // priority mode, 0 -> nop, 1 -> Even, 2 -> Odd
93
input   [11:0] cfg_baud_16x        ; // 16x Baud clock generation
94
 
95
//--------------------------------------
96
// TXD Path
97
// -------------------------------------
98
input         tx_data_avail        ; // Indicate valid TXD Data 
99
input [7:0]   tx_data              ; // TXD Data to be transmited
100
output        tx_rd                ; // Indicate TXD Data Been Read
101
 
102
 
103
//--------------------------------------
104
// RXD Path
105
// -------------------------------------
106
input         rx_ready            ; // Indicate Ready to accept the Read Data
107
output [7:0]  rx_data             ; // RXD Data 
108
output        rx_wr               ; // Valid RXD Data
109
 
110
 
111
//--------------------------------------
112
// ERROR Indication
113
// -------------------------------------
114
output        frm_error            ; // framing error
115
output        par_error            ; // par error
116
 
117
output        baud_clk_16x         ; // 16x Baud clock
118
 
119
 
120
//-------------------------------------
121
// Line Interface
122
// -------------------------------------
123
input         rxd                  ; // uart rxd
124
output        txd                  ; // uart txd
125
 
126
// Wire Declaration
127
 
128
wire [1  : 0]   error_ind          ;
129
 
130
 
131
// 16x Baud clock generation
132
// Example: to generate 19200 Baud clock from 50Mhz Link clock
133
//    50 * 1000 * 1000 / (2 + cfg_baud_16x) = 19200 * 16
134
//    cfg_baud_16x = 0xA0 (160)
135
 
136
clk_ctl #(11) u_clk_ctl (
137
   // Outputs
138
       .clk_o          (baud_clk_16x),
139
 
140
   // Inputs
141
       .mclk           (line_clk),
142
       .reset_n        (line_reset_n),
143
       .clk_div_ratio  (cfg_baud_16x)
144
   );
145
 
146
 
147
uart_txfsm u_txfsm (
148
               . reset_n           ( line_reset_n      ),
149
               . baud_clk_16x      ( baud_clk_16x      ),
150
 
151
               . cfg_tx_enable     ( cfg_tx_enable     ),
152
               . cfg_stop_bit      ( cfg_stop_bit      ),
153
               . cfg_pri_mod       ( cfg_pri_mod       ),
154
 
155
       // FIFO control signal
156
               . fifo_empty        ( !tx_data_avail    ),
157
               . fifo_rd           ( tx_rd             ),
158
               . fifo_data         ( tx_data           ),
159
 
160
          // Line Interface
161
               . so                ( txd                )
162
          );
163
 
164
 
165
uart_rxfsm u_rxfsm (
166
               . reset_n           (  line_reset_n     ),
167
               . baud_clk_16x      (  baud_clk_16x     ) ,
168
 
169
               . cfg_rx_enable     (  cfg_rx_enable    ),
170
               . cfg_stop_bit      (  cfg_stop_bit     ),
171
               . cfg_pri_mod       (  cfg_pri_mod      ),
172
 
173
               . error_ind         (  error_ind        ),
174
 
175
       // FIFO control signal
176
               .  fifo_aval        ( rx_ready          ),
177
               .  fifo_wr          ( rx_wr             ),
178
               .  fifo_data        ( rx_data           ),
179
 
180
          // Line Interface
181
               .  si               (rxd              )
182
          );
183
 
184
 
185
wire   frm_error          = (error_ind == 2'b01);
186
wire   par_error          = (error_ind == 2'b10);
187
 
188
 
189
 
190
endmodule

powered by: WebSVN 2.1.0

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