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

Subversion Repositories oms8051mini

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

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

powered by: WebSVN 2.1.0

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