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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [uart/] [uart_core.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OMS 8051 cores UART Interface Module                        ////
4
////                                                              ////
5
////  This file is part of the OMS 8051 cores project             ////
6
////  http://www.opencores.org/cores/oms8051mini/                 ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  OMS 8051 definitions.                                       ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18 11 dinesha
////  Revision :                                                  
19
////     v-0.0 : NOV 26, 2016                                     
20
////        1. initial version picked from                        
21
////          http://www.opencores.org/cores/turbo8051/           
22
////     v-0.1 : NOV 28, 2016                                     
23
////        1.  Register access correction                        
24
////     v-0.2 : NOV 28, 2016                                     
25
////        1.  Register access changed from 32 bit to 8bit       
26
////                                                              
27
//////////////////////////////////////////////////////////////////////
28 2 dinesha
////                                                              ////
29
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
30
////                                                              ////
31
//// This source file may be used and distributed without         ////
32
//// restriction provided that this copyright statement is not    ////
33
//// removed from the file and that any derivative work contains  ////
34
//// the original copyright notice and the associated disclaimer. ////
35
////                                                              ////
36
//// This source file is free software; you can redistribute it   ////
37
//// and/or modify it under the terms of the GNU Lesser General   ////
38
//// Public License as published by the Free Software Foundation; ////
39
//// either version 2.1 of the License, or (at your option) any   ////
40
//// later version.                                               ////
41
////                                                              ////
42
//// This source is distributed in the hope that it will be       ////
43
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
44
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
45
//// PURPOSE.  See the GNU Lesser General Public License for more ////
46
//// details.                                                     ////
47
////                                                              ////
48
//// You should have received a copy of the GNU Lesser General    ////
49
//// Public License along with this source; if not, download it   ////
50
//// from http://www.opencores.org/lgpl.shtml                     ////
51
////                                                              ////
52
//////////////////////////////////////////////////////////////////////
53
module uart_core
54
 
55
     (
56
 
57
        app_reset_n ,
58
        app_clk ,
59
 
60
        // Reg Bus Interface Signal
61
        reg_cs,
62
        reg_wr,
63
        reg_addr,
64
        reg_wdata,
65
        reg_be,
66
 
67
        // Outputs
68
        reg_rdata,
69
        reg_ack,
70
 
71
       // Line Interface
72
        si,
73
        so
74
 
75
     );
76
 
77
 
78
 
79
 
80
parameter W  = 8'd8;
81
parameter DP = 8'd16;
82
parameter AW = (DP == 2)   ? 1 :
83
               (DP == 4)   ? 2 :
84
               (DP == 8)   ? 3 :
85
               (DP == 16)  ? 4 :
86
               (DP == 32)  ? 5 :
87
               (DP == 64)  ? 6 :
88
               (DP == 128) ? 7 :
89
               (DP == 256) ? 8 : 0;
90
 
91
 
92
 
93
input        app_reset_n          ; // application reset
94
input        app_clk              ; // application clock
95
 
96
//---------------------------------
97
// Reg Bus Interface Signal
98
//---------------------------------
99
input             reg_cs         ;
100
input             reg_wr         ;
101
input [3:0]       reg_addr       ;
102 11 dinesha
input [7:0]       reg_wdata      ;
103
input             reg_be         ;
104 2 dinesha
 
105
// Outputs
106 11 dinesha
output [7:0]      reg_rdata      ;
107
output            reg_ack        ;
108 2 dinesha
 
109
// Line Interface
110
input         si                  ; // uart si
111
output        so                  ; // uart so
112
 
113
// Wire Declaration
114
 
115
wire [W-1: 0]   tx_fifo_rd_data;
116
wire [W-1: 0]   rx_fifo_wr_data;
117 6 dinesha
wire [W-1: 0]   app_rxfifo_data;
118
wire [W-1: 0]   app_txfifo_data;
119 2 dinesha
wire [1  : 0]   error_ind;
120
 
121
// Wire 
122
wire         cfg_tx_enable        ; // Tx Enable
123
wire         cfg_rx_enable        ; // Rx Enable
124
wire         cfg_stop_bit         ; // 0 -> 1 Stop, 1 -> 2 Stop
125
wire   [1:0] cfg_pri_mod          ; // priority mode, 0 -> nop, 1 -> Even, 2 -> Odd
126
 
127
wire        frm_error_o          ; // framing error
128
wire        par_error_o          ; // par error
129
wire        rx_fifo_full_err_o   ; // rx fifo full error
130 6 dinesha
 
131
wire   [11:0] cfg_baud_16x        ; // 16x Baud clock generation
132 2 dinesha
wire        rx_fifo_wr_full      ;
133
wire        app_rxfifo_empty     ;
134
 
135
 
136
uart_cfg u_cfg (
137
 
138
             . mclk          (app_clk),
139
             . reset_n       (app_reset_n),
140
 
141
        // Reg Bus Interface Signal
142
             . reg_cs        (reg_cs),
143
             . reg_wr        (reg_wr),
144
             . reg_addr      (reg_addr),
145
             . reg_wdata     (reg_wdata),
146
             . reg_be        (reg_be),
147
 
148
            // Outputs
149
            . reg_rdata      (reg_rdata),
150
            . reg_ack        (reg_ack),
151
 
152
 
153
       // configuration
154
            . cfg_tx_enable       (cfg_tx_enable),
155
            . cfg_rx_enable       (cfg_rx_enable),
156
            . cfg_stop_bit        (cfg_stop_bit),
157
            . cfg_pri_mod         (cfg_pri_mod),
158
 
159 6 dinesha
            . cfg_baud_16x        (cfg_baud_16x),
160
 
161
            . tx_fifo_full        (app_tx_fifo_full),
162
            . tx_fifo_wr_en       (tx_fifo_wr_en),
163
            . tx_fifo_data        (app_txfifo_data),
164
 
165
            . rx_fifo_empty       (app_rxfifo_empty),
166
            . rx_fifo_rd_en       (app_rxfifo_rd_en),
167
            . rx_fifo_data        (app_rxfifo_data) ,
168
 
169 2 dinesha
            . frm_error_o         (frm_error_o),
170
            . par_error_o         (par_error_o),
171
            . rx_fifo_full_err_o  (rx_fifo_full_err_o)
172
 
173
        );
174
 
175
 
176
 
177 6 dinesha
// 16x Baud clock generation
178
// Example: to generate 19200 Baud clock from 50Mhz Link clock
179
//    50 * 1000 * 1000 / (2 + cfg_baud_16x) = 19200 * 16
180
//    cfg_baud_16x = 0xA0 (160)
181 2 dinesha
 
182 6 dinesha
wire line_clk_16x;
183 2 dinesha
 
184 6 dinesha
clk_ctl #(11) u_clk_ctl (
185
   // Outputs
186
       .clk_o          (line_clk_16x),
187
 
188
   // Inputs
189
       .mclk           (app_clk),
190
       .reset_n        (app_reset_n),
191
       .clk_div_ratio  (cfg_baud_16x)
192
   );
193
 
194
wire line_reset_n = app_reset_n; // todo-> create synchronised reset w.r.t line clock
195
 
196 2 dinesha
uart_txfsm u_txfsm (
197
               . reset_n           ( line_reset_n      ),
198
               . baud_clk_16x      ( line_clk_16x      ),
199
 
200
               . cfg_tx_enable     ( cfg_tx_enable     ),
201
               . cfg_stop_bit      ( cfg_stop_bit      ),
202
               . cfg_pri_mod       ( cfg_pri_mod       ),
203
 
204
       // FIFO control signal
205
               . fifo_empty        ( tx_fifo_rd_empty  ),
206
               . fifo_rd           ( tx_fifo_rd        ),
207
               . fifo_data         ( tx_fifo_rd_data   ),
208
 
209
          // Line Interface
210
               . so                ( so                )
211
          );
212
 
213
 
214
uart_rxfsm u_rxfsm (
215
               . reset_n           (  line_reset_n     ),
216
               . baud_clk_16x      (  line_clk_16x     ) ,
217
 
218
               . cfg_rx_enable     (  cfg_rx_enable    ),
219
               . cfg_stop_bit      (  cfg_stop_bit     ),
220
               . cfg_pri_mod       (  cfg_pri_mod      ),
221
 
222
               . error_ind         (  error_ind        ),
223
 
224
       // FIFO control signal
225
               .  fifo_aval        ( !rx_fifo_wr_full  ),
226
               .  fifo_wr          ( rx_fifo_wr        ),
227
               .  fifo_data        ( rx_fifo_wr_data   ),
228
 
229
          // Line Interface
230
               .  si               (si_ss              )
231
          );
232
 
233
async_fifo #(W,DP,0,0) u_rxfifo (
234
               .wr_clk             (line_clk_16x       ),
235
               .wr_reset_n         (line_reset_n       ),
236
               .wr_en              (rx_fifo_wr         ),
237
               .wr_data            (rx_fifo_wr_data    ),
238
               .full               (rx_fifo_wr_full    ), // sync'ed to wr_clk
239
               .wr_total_free_space(                   ),
240
 
241
               .rd_clk             (app_clk            ),
242
               .rd_reset_n         (app_reset_n        ),
243 6 dinesha
               .rd_en              (app_rxfifo_rd_en   ),
244 2 dinesha
               .empty              (app_rxfifo_empty   ),  // sync'ed to rd_clk
245
               .rd_total_aval      (                   ),
246 6 dinesha
               .rd_data            (app_rxfifo_data    )
247 2 dinesha
                   );
248
 
249
async_fifo #(W,DP,0,0) u_txfifo  (
250
               .wr_clk             (app_clk            ),
251
               .wr_reset_n         (app_reset_n        ),
252 6 dinesha
               .wr_en              (tx_fifo_wr_en      ),
253
               .wr_data            (app_txfifo_data    ),
254
               .full               (app_tx_fifo_full   ), // sync'ed to wr_clk
255 2 dinesha
               .wr_total_free_space(                   ),
256
 
257
               .rd_clk             (line_clk_16x       ),
258
               .rd_reset_n         (line_reset_n       ),
259
               .rd_en              (tx_fifo_rd         ),
260
               .empty              (tx_fifo_rd_empty   ),  // sync'ed to rd_clk
261
               .rd_total_aval      (                   ),
262
               .rd_data            (tx_fifo_rd_data    )
263
                   );
264
 
265
 
266
double_sync_low   u_si_sync (
267
               . in_data           ( si                ),
268
               . out_clk           (line_clk_16x       ),
269
               . out_rst_n         (line_reset_n       ),
270
               . out_data          (si_ss              )
271
          );
272
 
273
wire   frm_error          = (error_ind == 2'b01);
274
wire   par_error          = (error_ind == 2'b10);
275
wire   rx_fifo_full_err   = (error_ind == 2'b11);
276
 
277
double_sync_low   u_frm_err (
278
               . in_data           ( frm_error        ),
279
               . out_clk           ( app_clk          ),
280
               . out_rst_n         ( app_reset_n      ),
281
               . out_data          ( frm_error_o      )
282
          );
283
 
284
double_sync_low   u_par_err (
285
               . in_data           ( par_error        ),
286
               . out_clk           ( app_clk          ),
287
               . out_rst_n         ( app_reset_n      ),
288
               . out_data          ( par_error_o      )
289
          );
290
 
291
double_sync_low   u_rxfifo_err (
292
               . in_data           ( rx_fifo_full_err ),
293
               . out_clk           ( app_clk          ),
294
               . out_rst_n         ( app_reset_n      ),
295
               . out_data          ( rx_fifo_full_err_o  )
296
          );
297
 
298
 
299
endmodule

powered by: WebSVN 2.1.0

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