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

Subversion Repositories usb2uart

[/] [usb2uart/] [trunk/] [rtl/] [uart_core/] [uart_core.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 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
 
45
     (
46
 
47
        app_reset_n ,
48
        app_clk ,
49
 
50
        // Reg Bus Interface Signal
51
        reg_cs,
52
        reg_wr,
53
        reg_addr,
54
        reg_wdata,
55
        reg_be,
56
 
57
        // Outputs
58
        reg_rdata,
59
        reg_ack,
60
 
61
       // Line Interface
62
        si,
63
        so
64
 
65
     );
66
 
67
 
68
 
69
 
70
parameter W  = 8'd8;
71
parameter DP = 8'd16;
72
parameter AW = (DP == 2)   ? 1 :
73
               (DP == 4)   ? 2 :
74
               (DP == 8)   ? 3 :
75
               (DP == 16)  ? 4 :
76
               (DP == 32)  ? 5 :
77
               (DP == 64)  ? 6 :
78
               (DP == 128) ? 7 :
79
               (DP == 256) ? 8 : 0;
80
 
81
 
82
 
83
input        app_reset_n          ; // application reset
84
input        app_clk              ; // application clock
85
 
86
//---------------------------------
87
// Reg Bus Interface Signal
88
//---------------------------------
89
input             reg_cs         ;
90
input             reg_wr         ;
91
input [3:0]       reg_addr       ;
92
input [31:0]      reg_wdata      ;
93
input [3:0]       reg_be         ;
94
 
95
// Outputs
96
output [31:0]     reg_rdata      ;
97
output            reg_ack     ;
98
 
99
// Line Interface
100
input         si                  ; // uart si
101
output        so                  ; // uart so
102
 
103
// Wire Declaration
104
 
105
wire [W-1: 0]   tx_fifo_rd_data;
106
wire [W-1: 0]   rx_fifo_wr_data;
107
wire [W-1: 0]   app_rxfifo_data;
108
wire [W-1: 0]   app_txfifo_data;
109
wire [1  : 0]   error_ind;
110
 
111
// Wire 
112
wire         cfg_tx_enable        ; // Tx Enable
113
wire         cfg_rx_enable        ; // Rx Enable
114
wire         cfg_stop_bit         ; // 0 -> 1 Stop, 1 -> 2 Stop
115
wire   [1:0] cfg_pri_mod          ; // priority mode, 0 -> nop, 1 -> Even, 2 -> Odd
116
 
117
wire        frm_error_o          ; // framing error
118
wire        par_error_o          ; // par error
119
wire        rx_fifo_full_err_o   ; // rx fifo full error
120
 
121
wire   [11:0] cfg_baud_16x        ; // 16x Baud clock generation
122
 
123
 
124
 
125
uart_cfg u_cfg (
126
 
127
             . mclk          (app_clk),
128
             . reset_n       (app_reset_n),
129
 
130
        // Reg Bus Interface Signal
131
             . reg_cs        (reg_cs),
132
             . reg_wr        (reg_wr),
133
             . reg_addr      (reg_addr),
134
             . reg_wdata     (reg_wdata),
135
             . reg_be        (reg_be),
136
 
137
            // Outputs
138
            . reg_rdata      (reg_rdata),
139
            . reg_ack        (reg_ack),
140
 
141
 
142
       // configuration
143
            . cfg_tx_enable       (cfg_tx_enable),
144
            . cfg_rx_enable       (cfg_rx_enable),
145
            . cfg_stop_bit        (cfg_stop_bit),
146
            . cfg_pri_mod         (cfg_pri_mod),
147
 
148
            . cfg_baud_16x        (cfg_baud_16x),
149
 
150
            . tx_fifo_full        (app_tx_fifo_full),
151
            . tx_fifo_wr_en       (tx_fifo_wr_en),
152
            . tx_fifo_data        (app_txfifo_data),
153
 
154
            . rx_fifo_empty       (app_rxfifo_empty),
155
            . rx_fifo_rd_en       (app_rxfifo_rd_en),
156
            . rx_fifo_data        (app_rxfifo_data) ,
157
 
158
            . frm_error_o         (frm_error_o),
159
            . par_error_o         (par_error_o),
160
            . rx_fifo_full_err_o  (rx_fifo_full_err_o)
161
 
162
        );
163
 
164
 
165
 
166
// 16x Baud clock generation
167
// Example: to generate 19200 Baud clock from 50Mhz Link clock
168
//    50 * 1000 * 1000 / (2 + cfg_baud_16x) = 19200 * 16
169
//    cfg_baud_16x = 0xA0 (160)
170
 
171
wire line_clk_16x;
172
 
173
clk_ctl #(11) u_clk_ctl (
174
   // Outputs
175
       .clk_o          (line_clk_16x),
176
 
177
   // Inputs
178
       .mclk           (app_clk),
179
       .reset_n        (app_reset_n),
180
       .clk_div_ratio  (cfg_baud_16x)
181
   );
182
 
183
wire line_reset_n = app_reset_n; // todo-> create synchronised reset w.r.t line clock
184
 
185
uart_txfsm u_txfsm (
186
               . reset_n           ( line_reset_n      ),
187
               . baud_clk_16x      ( line_clk_16x     ),
188
 
189
               . cfg_tx_enable     ( cfg_tx_enable     ),
190
               . cfg_stop_bit      ( cfg_stop_bit      ),
191
               . cfg_pri_mod       ( cfg_pri_mod       ),
192
 
193
       // FIFO control signal
194
               . fifo_empty        ( tx_fifo_rd_empty  ),
195
               . fifo_rd           ( tx_fifo_rd        ),
196
               . fifo_data         ( tx_fifo_rd_data   ),
197
 
198
          // Line Interface
199
               . so                ( so                )
200
          );
201
 
202
 
203
uart_rxfsm u_rxfsm (
204
               . reset_n           (  line_reset_n     ),
205
               . baud_clk_16x      (  line_clk_16x     ) ,
206
 
207
               . cfg_rx_enable     (  cfg_rx_enable    ),
208
               . cfg_stop_bit      (  cfg_stop_bit     ),
209
               . cfg_pri_mod       (  cfg_pri_mod      ),
210
 
211
               . error_ind         (  error_ind        ),
212
 
213
       // FIFO control signal
214
               .  fifo_aval        ( !rx_fifo_wr_full  ),
215
               .  fifo_wr          ( rx_fifo_wr        ),
216
               .  fifo_data        ( rx_fifo_wr_data   ),
217
 
218
          // Line Interface
219
               .  si               (si_ss              )
220
          );
221
 
222
async_fifo #(W,DP,0,0) u_rxfifo (
223
               .wr_clk             (line_clk_16x       ),
224
               .wr_reset_n         (line_reset_n       ),
225
               .wr_en              (rx_fifo_wr         ),
226
               .wr_data            (rx_fifo_wr_data    ),
227
               .full               (rx_fifo_wr_full    ), // sync'ed to wr_clk
228 7 dinesha
               .afull              (                   ), // sync'ed to wr_clk
229 6 dinesha
               .wr_total_free_space(                   ),
230
 
231
               .rd_clk             (app_clk            ),
232
               .rd_reset_n         (app_reset_n        ),
233
               .rd_en              (app_rxfifo_rd_en   ),
234
               .empty              (app_rxfifo_empty   ),  // sync'ed to rd_clk
235 7 dinesha
               .aempty             (                   ),  // sync'ed to rd_clk
236 6 dinesha
               .rd_total_aval      (                   ),
237
               .rd_data            (app_rxfifo_data    )
238
                   );
239
 
240
async_fifo #(W,DP,0,0) u_txfifo  (
241
               .wr_clk             (app_clk            ),
242
               .wr_reset_n         (app_reset_n        ),
243
               .wr_en              (tx_fifo_wr_en      ),
244
               .wr_data            (app_txfifo_data    ),
245
               .full               (app_tx_fifo_full   ), // sync'ed to wr_clk
246 7 dinesha
               .afull              (                   ), // sync'ed to wr_clk
247 6 dinesha
               .wr_total_free_space(                   ),
248
 
249
               .rd_clk             (line_clk_16x       ),
250
               .rd_reset_n         (line_reset_n       ),
251
               .rd_en              (tx_fifo_rd         ),
252
               .empty              (tx_fifo_rd_empty   ),  // sync'ed to rd_clk
253 7 dinesha
               .aempty             (                   ),  // sync'ed to rd_clk
254 6 dinesha
               .rd_total_aval      (                   ),
255
               .rd_data            (tx_fifo_rd_data    )
256
                   );
257
 
258
 
259
double_sync_low   u_si_sync (
260
               . in_data           ( si                ),
261
               . out_clk           (line_clk_16x       ),
262
               . out_rst_n         (line_reset_n       ),
263
               . out_data          (si_ss              )
264
          );
265
 
266
wire   frm_error          = (error_ind == 2'b01);
267
wire   par_error          = (error_ind == 2'b10);
268
wire   rx_fifo_full_err   = (error_ind == 2'b11);
269
 
270
double_sync_low   u_frm_err (
271
               . in_data           ( frm_error        ),
272
               . out_clk           ( app_clk          ),
273
               . out_rst_n         ( app_reset_n      ),
274
               . out_data          ( frm_error_o      )
275
          );
276
 
277
double_sync_low   u_par_err (
278
               . in_data           ( par_error        ),
279
               . out_clk           ( app_clk          ),
280
               . out_rst_n         ( app_reset_n      ),
281
               . out_data          ( par_error_o      )
282
          );
283
 
284
double_sync_low   u_rxfifo_err (
285
               . in_data           ( rx_fifo_full_err ),
286
               . out_clk           ( app_clk          ),
287
               . out_rst_n         ( app_reset_n      ),
288
               . out_data          ( rx_fifo_full_err_o  )
289
          );
290
 
291
 
292
endmodule

powered by: WebSVN 2.1.0

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