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

Subversion Repositories oms8051mini

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

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

powered by: WebSVN 2.1.0

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