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

Subversion Repositories uart16550

[/] [uart16550/] [trunk/] [rtl/] [verilog/] [uart_wb.v] - Blame information for rev 84

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3 33 gorban
////  uart_wb.v                                                   ////
4 27 mohor
////                                                              ////
5
////                                                              ////
6
////  This file is part of the "UART 16550 compatible" project    ////
7
////  http://www.opencores.org/cores/uart16550/                   ////
8
////                                                              ////
9
////  Documentation related to this project:                      ////
10
////  - http://www.opencores.org/cores/uart16550/                 ////
11
////                                                              ////
12
////  Projects compatibility:                                     ////
13
////  - WISHBONE                                                  ////
14
////  RS232 Protocol                                              ////
15
////  16550D uart (mostly supported)                              ////
16
////                                                              ////
17
////  Overview (main Features):                                   ////
18
////  UART core WISHBONE interface.                               ////
19
////                                                              ////
20
////  Known problems (limits):                                    ////
21
////  Inserts one wait state on all transfers.                    ////
22
////  Note affected signals and the way they are affected.        ////
23
////                                                              ////
24
////  To Do:                                                      ////
25
////  Nothing.                                                    ////
26
////                                                              ////
27
////  Author(s):                                                  ////
28
////      - gorban@opencores.org                                  ////
29
////      - Jacob Gorban                                          ////
30 29 mohor
////      - Igor Mohor (igorm@opencores.org)                      ////
31 27 mohor
////                                                              ////
32
////  Created:        2001/05/12                                  ////
33
////  Last Updated:   2001/05/17                                  ////
34
////                  (See log for the revision history)          ////
35
////                                                              ////
36
////                                                              ////
37
//////////////////////////////////////////////////////////////////////
38
////                                                              ////
39 29 mohor
//// Copyright (C) 2000, 2001 Authors                             ////
40 27 mohor
////                                                              ////
41
//// This source file may be used and distributed without         ////
42
//// restriction provided that this copyright statement is not    ////
43
//// removed from the file and that any derivative work contains  ////
44
//// the original copyright notice and the associated disclaimer. ////
45
////                                                              ////
46
//// This source file is free software; you can redistribute it   ////
47
//// and/or modify it under the terms of the GNU Lesser General   ////
48
//// Public License as published by the Free Software Foundation; ////
49
//// either version 2.1 of the License, or (at your option) any   ////
50
//// later version.                                               ////
51
////                                                              ////
52
//// This source is distributed in the hope that it will be       ////
53
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
54
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
55
//// PURPOSE.  See the GNU Lesser General Public License for more ////
56
//// details.                                                     ////
57
////                                                              ////
58
//// You should have received a copy of the GNU Lesser General    ////
59
//// Public License along with this source; if not, download it   ////
60
//// from http://www.opencores.org/lgpl.shtml                     ////
61
////                                                              ////
62
//////////////////////////////////////////////////////////////////////
63
//
64
// CVS Revision History
65
//
66
// $Log: not supported by cvs2svn $
67 84 gorban
// Revision 1.15  2002/07/22 23:02:23  gorban
68
// Bug Fixes:
69
//  * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
70
//   Problem reported by Kenny.Tung.
71
//  * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
72
//
73
// Improvements:
74
//  * Made FIFO's as general inferrable memory where possible.
75
//  So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
76
//  This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
77
//
78
//  * Added optional baudrate output (baud_o).
79
//  This is identical to BAUDOUT* signal on 16550 chip.
80
//  It outputs 16xbit_clock_rate - the divided clock.
81
//  It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
82
//
83 73 gorban
// Revision 1.12  2001/12/19 08:03:34  mohor
84
// Warnings cleared.
85
//
86 64 mohor
// Revision 1.11  2001/12/06 14:51:04  gorban
87
// Bug in LSR[0] is fixed.
88
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
89
//
90 50 gorban
// Revision 1.10  2001/12/03 21:44:29  gorban
91
// Updated specification documentation.
92
// Added full 32-bit data bus interface, now as default.
93
// Address is 5-bit wide in 32-bit data bus mode.
94
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
95
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
96
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
97
// My small test bench is modified to work with 32-bit mode.
98
//
99 48 gorban
// Revision 1.9  2001/10/20 09:58:40  gorban
100
// Small synopsis fixes
101
//
102 33 gorban
// Revision 1.8  2001/08/24 21:01:12  mohor
103
// Things connected to parity changed.
104
// Clock devider changed.
105
//
106 29 mohor
// Revision 1.7  2001/08/23 16:05:05  mohor
107
// Stop bit bug fixed.
108
// Parity bug fixed.
109
// WISHBONE read cycle bug fixed,
110
// OE indicator (Overrun Error) bug fixed.
111
// PE indicator (Parity Error) bug fixed.
112
// Register read bug fixed.
113
//
114 27 mohor
// Revision 1.4  2001/05/31 20:08:01  gorban
115
// FIFO changes and other corrections.
116
//
117
// Revision 1.3  2001/05/21 19:12:01  gorban
118
// Corrected some Linter messages.
119
//
120
// Revision 1.2  2001/05/17 18:34:18  gorban
121
// First 'stable' release. Should be sythesizable now. Also added new header.
122
//
123
// Revision 1.0  2001-05-17 21:27:13+02  jacob
124
// Initial revision
125
//
126
//
127
 
128
// UART core WISHBONE interface 
129
//
130
// Author: Jacob Gorban   (jacob.gorban@flextronicssemi.com)
131
// Company: Flextronics Semiconductor
132
//
133
 
134 33 gorban
// synopsys translate_off
135 27 mohor
`include "timescale.v"
136 33 gorban
// synopsys translate_on
137 84 gorban
`include "uart_defines.v"
138 50 gorban
 
139 48 gorban
module uart_wb (clk, wb_rst_i,
140 50 gorban
        wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_adr_i,
141
        wb_adr_int, wb_dat_i, wb_dat_o, wb_dat8_i, wb_dat8_o, wb_dat32_o, wb_sel_i,
142 27 mohor
        we_o, re_o // Write and read enable output for the core
143 48 gorban
);
144 27 mohor
 
145 48 gorban
input             clk;
146 27 mohor
 
147
// WISHBONE interface   
148 48 gorban
input             wb_rst_i;
149
input             wb_we_i;
150
input             wb_stb_i;
151
input             wb_cyc_i;
152
input [3:0]   wb_sel_i;
153 50 gorban
input [`UART_ADDR_WIDTH-1:0]     wb_adr_i; //WISHBONE address line
154
 
155 48 gorban
`ifdef DATA_BUS_WIDTH_8
156
input [7:0]  wb_dat_i; //input WISHBONE bus 
157
output [7:0] wb_dat_o;
158
reg [7:0]         wb_dat_o;
159
wire [7:0]        wb_dat_i;
160 50 gorban
reg [7:0]         wb_dat_is;
161 48 gorban
`else // for 32 data bus mode
162
input [31:0]  wb_dat_i; //input WISHBONE bus 
163
output [31:0] wb_dat_o;
164
reg [31:0]         wb_dat_o;
165
wire [31:0]   wb_dat_i;
166 50 gorban
reg [31:0]         wb_dat_is;
167
`endif // !`ifdef DATA_BUS_WIDTH_8
168
 
169
output [`UART_ADDR_WIDTH-1:0]    wb_adr_int; // internal signal for address bus
170 48 gorban
input [7:0]   wb_dat8_o; // internal 8 bit output to be put into wb_dat_o
171
output [7:0]  wb_dat8_i;
172
input [31:0]  wb_dat32_o; // 32 bit data output (for debug interface)
173
output            wb_ack_o;
174
output            we_o;
175
output            re_o;
176 27 mohor
 
177 48 gorban
wire                      we_o;
178
reg                       wb_ack_o;
179
reg [7:0]          wb_dat8_i;
180
wire [7:0]         wb_dat8_o;
181 50 gorban
wire [`UART_ADDR_WIDTH-1:0]      wb_adr_int; // internal signal for address bus
182
reg [`UART_ADDR_WIDTH-1:0]       wb_adr_is;
183
reg                                                             wb_we_is;
184
reg                                                             wb_cyc_is;
185
reg                                                             wb_stb_is;
186
reg [3:0]                                                wb_sel_is;
187
wire [3:0]   wb_sel_i;
188
reg                      wre ;// timing control signal for write or read enable
189 27 mohor
 
190 50 gorban
// wb_ack_o FSM
191
reg [1:0]         wbstate;
192
always  @(posedge clk or posedge wb_rst_i)
193
        if (wb_rst_i) begin
194 27 mohor
                wb_ack_o <= #1 1'b0;
195 50 gorban
                wbstate <= #1 0;
196 64 mohor
                wre <= #1 1'b1;
197 50 gorban
        end else
198
                case (wbstate)
199
                        0: begin
200
                                if (wb_stb_is & wb_cyc_is) begin
201
                                        wre <= #1 0;
202
                                        wbstate <= #1 1;
203
                                        wb_ack_o <= #1 1;
204
                                end else begin
205
                                        wre <= #1 1;
206
                                        wb_ack_o <= #1 0;
207
                                end
208
                        end
209
                        1: begin
210
                           wb_ack_o <= #1 0;
211
                                wbstate <= #1 2;
212
                                wre <= #1 0;
213
                        end
214
                        2,3: begin
215
                                wb_ack_o <= #1 0;
216
                                wbstate <= #1 0;
217
                                wre <= #1 0;
218
                        end
219
                endcase
220 27 mohor
 
221 50 gorban
assign we_o =  wb_we_is & wb_stb_is & wb_cyc_is & wre ; //WE for registers      
222
assign re_o = ~wb_we_is & wb_stb_is & wb_cyc_is & wre ; //RE for registers      
223 27 mohor
 
224 50 gorban
// Sample input signals
225
always  @(posedge clk or posedge wb_rst_i)
226
        if (wb_rst_i) begin
227
                wb_adr_is <= #1 0;
228
                wb_we_is <= #1 0;
229
                wb_cyc_is <= #1 0;
230
                wb_stb_is <= #1 0;
231
                wb_dat_is <= #1 0;
232
                wb_sel_is <= #1 0;
233
        end else begin
234
                wb_adr_is <= #1 wb_adr_i;
235
                wb_we_is <= #1 wb_we_i;
236
                wb_cyc_is <= #1 wb_cyc_i;
237
                wb_stb_is <= #1 wb_stb_i;
238
                wb_dat_is <= #1 wb_dat_i;
239
                wb_sel_is <= #1 wb_sel_i;
240
        end
241
 
242 79 gorban
assign wb_adr_int = wb_adr_is;
243
 
244 48 gorban
`ifdef DATA_BUS_WIDTH_8 // 8-bit data bus
245
always @(posedge clk or posedge wb_rst_i)
246
        if (wb_rst_i)
247
                wb_dat_o <= #1 0;
248
        else
249
                wb_dat_o <= #1 wb_dat8_o;
250
 
251 50 gorban
always @(wb_dat_is)
252
        wb_dat8_i = wb_dat_is;
253 48 gorban
 
254
`else // 32-bit bus
255
// put output to the correct byte in 32 bits using select line
256
always @(posedge clk or posedge wb_rst_i)
257
        if (wb_rst_i)
258
                wb_dat_o <= #1 0;
259
        else if (re_o)
260 50 gorban
                case (wb_sel_is)
261 48 gorban
                        4'b0001: wb_dat_o <= #1 {24'b0, wb_dat8_o};
262
                        4'b0010: wb_dat_o <= #1 {16'b0, wb_dat8_o, 8'b0};
263
                        4'b0100: wb_dat_o <= #1 {8'b0, wb_dat8_o, 16'b0};
264
                        4'b1000: wb_dat_o <= #1 {wb_dat8_o, 24'b0};
265
                        4'b1111: wb_dat_o <= #1 wb_dat32_o; // debug interface output
266
                        default: wb_dat_o <= #1 0;
267
                endcase // case(wb_sel_i)
268
 
269 50 gorban
always @(wb_sel_is or wb_dat_is)
270
        case (wb_sel_is)
271
                4'b0001 : wb_dat8_i = wb_dat_is[7:0];
272
                4'b0010 : wb_dat8_i = wb_dat_is[15:8];
273
                4'b0100 : wb_dat8_i = wb_dat_is[23:16];
274
                4'b1000 : wb_dat8_i = wb_dat_is[31:24];
275
                default : wb_dat8_i = wb_dat_is[7:0];
276 48 gorban
        endcase // case(wb_sel_i)
277
 
278
`endif // !`ifdef DATA_BUS_WIDTH_8
279
 
280 27 mohor
endmodule
281 48 gorban
 
282
 
283
 
284
 
285
 
286
 
287
 
288
 
289
 
290
 

powered by: WebSVN 2.1.0

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