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

Subversion Repositories embedded_risc

[/] [embedded_risc/] [trunk/] [Verilog/] [uart.v] - Blame information for rev 27

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 hosseinami
/*********************************************************
2
 MODULE:                Sub Level UART Device
3
 
4
 FILE NAME:     uart.v
5
 VERSION:       1.0
6
 DATE:          May 14th, 2002
7
 AUTHOR:                Hossein Amidi
8
 COMPANY:
9
 CODE TYPE:     Register Transfer Level
10
 
11
 DESCRIPTION:   This module is the top level RTL code of UART verilog code.
12
 
13
 It will instantiate the following blocks in the ASIC:
14
 
15
 
16
 Hossein Amidi
17
 (C) April 2002
18
 
19
*********************************************************/
20
 
21
// DEFINES
22
`timescale 1ns / 10ps
23
 
24
// TOP MODULE
25
module uart(// Inputs
26
                                reset,
27
                                clk0,
28
                                uart_addr,
29
                                uart_host_addr,
30
                           uart_host_cmd,
31
                                uart_cmd,
32
                                uart_host_datain,
33
                                uart_cs,
34
                                uart_rd,
35
                                uart_wr,
36
                                ser_rxd,
37
                                uart_datain,
38
                                // Outputs
39
                                ser_txd,
40
                                uart_host_dataout,
41
                                uart_dataout
42
                                );
43
 
44
 
45
// Parameter
46
`include        "parameter.v"
47
 
48
// Inputs
49
input reset;
50
input clk0;
51
input [padd_size - 1 : 0]uart_addr;
52
input [padd_size - 1 : 0]uart_host_addr;
53
input [cmd_size - 1 : 0]uart_host_cmd;
54
input [cmd_size - 1 : 0]uart_cmd;
55
input [data_size - 1 : 0]uart_host_datain;
56
input uart_cs;
57
input uart_rd;
58
input uart_wr;
59
input ser_rxd;
60
input [Byte_size - 1 : 0]uart_datain;
61
 
62
// Outputs
63
output ser_txd;
64
output [data_size - 1 : 0]uart_host_dataout;
65
output [Byte_size - 1 : 0]uart_dataout;
66
 
67
 
68
// Signal Declarations
69
wire reset;
70
wire clk0;
71
wire [padd_size - 1 : 0]uart_addr;
72
wire [padd_size - 1 : 0]uart_host_addr;
73
wire [cmd_size - 1 : 0]uart_host_cmd;
74
wire [cmd_size - 1 : 0]uart_cmd;
75
wire [data_size - 1 : 0]uart_host_datain;
76
wire uart_cs;
77
wire uart_rd;
78
wire uart_wr;
79
wire ser_rxd;
80
wire [Byte_size - 1 : 0]uart_datain;
81
 
82
reg ser_txd;
83
reg [data_size - 1 : 0]uart_host_dataout;
84
wire [Byte_size - 1 : 0]uart_dataout;
85
reg [Byte_size - 1 : 0]ruart_dataout;
86
 
87
// Internal Registers
88
reg [Byte_size - 1 : 0]uart_reg_dataout;
89
 
90
 
91
reg [Byte_size -1 : 0]shift_reg_in;
92
reg [Byte_size -1 : 0]shift_reg_out;
93
reg [uart_cnt_size - 1 : 0]serin_cnt;
94
reg [uart_cnt_size - 1 : 0]serout_cnt;
95
 
96
reg byte_in;
97
reg byte_out;
98
 
99
// Assignment statments
100
assign uart_dataout = ruart_dataout;
101
 
102
/***************** Internal Register of Uart configuration *******************/
103
reg [uart_reg_width - 1 : 0] uart_register [uart_reg_depth - 1 : 0];
104
 
105
 
106
// Circuit for internal Register
107
always @(posedge reset or posedge clk0)
108
begin
109
        if(reset == 1'b1)
110
        begin
111
                uart_host_dataout <= 32'h0;
112
                uart_register[0] <= 32'h0;
113
                uart_register[1] <= 32'h0;
114
                uart_register[2] <= 32'h0;
115
                uart_register[3] <= 32'h0;
116
                uart_register[4] <= 32'h0;
117
                uart_register[5] <= 32'h0;
118
                uart_register[6] <= 32'h0;
119
                uart_register[7] <= 32'h0;
120
        end
121
        else
122
        begin
123
                if(uart_host_cmd == 3'b010)
124
                begin
125
                        case(uart_host_addr)
126
                                24'h080024: uart_register[0] <= uart_host_datain;
127
                                24'h080025: uart_register[1] <= uart_host_datain;
128
                                24'h080026: uart_register[2] <= uart_host_datain;
129
                                24'h080027: uart_register[3] <= uart_host_datain;
130
                                24'h080028: uart_register[4] <= uart_host_datain;
131
                                24'h080029: uart_register[5] <= uart_host_datain;
132
                                24'h08002A: uart_register[6] <= uart_host_datain;
133
                                24'h08002B: uart_register[7] <= uart_host_datain;
134
                        endcase
135
                end
136
                else
137
                if(uart_host_cmd == 3'b001)
138
                begin
139
                        case(uart_host_addr)
140
                                24'h080024: uart_host_dataout <= uart_register[0];
141
                                24'h080025: uart_host_dataout <= uart_register[1];
142
                                24'h080026: uart_host_dataout <= uart_register[2];
143
                                24'h080027: uart_host_dataout <= uart_register[3];
144
                                24'h080028: uart_host_dataout <= uart_register[4];
145
                                24'h080029: uart_host_dataout <= uart_register[5];
146
                                24'h08002A: uart_host_dataout <= uart_register[6];
147
                                24'h08002B: uart_host_dataout <= uart_register[7];
148
                        endcase
149
                end
150
        end
151
 
152
end
153
 
154
 
155
// Circuit for reciever side
156
always @(posedge reset or posedge clk0)
157
begin
158
        if(reset == 1'b1)
159
        begin
160
                shift_reg_in  <= 8'h0;
161
        end
162
        else
163
        if((uart_wr == 1'b1) && (uart_rd == 1'b0) && (byte_in == 1'b0))
164
        begin
165
                shift_reg_in[7] <= shift_reg_in[6];
166
                shift_reg_in[6] <= shift_reg_in[5];
167
                shift_reg_in[5] <= shift_reg_in[4];
168
                shift_reg_in[4] <= shift_reg_in[3];
169
                shift_reg_in[3] <= shift_reg_in[2];
170
                shift_reg_in[2] <= shift_reg_in[1];
171
                shift_reg_in[1] <= shift_reg_in[0];
172
                shift_reg_in[0] <= ser_rxd;
173
        end
174
        else
175
                shift_reg_in <= shift_reg_in;
176
end
177
 
178
 
179
always @(posedge reset or posedge clk0)
180
begin
181
        if(reset == 1'b1)
182
                ruart_dataout <= 8'h0;
183
        else
184
        if((uart_wr == 1'b1) && (uart_rd == 1'b0) && (byte_in == 1'b1))
185
        begin
186
          ruart_dataout[0] <= shift_reg_in[0];
187
          ruart_dataout[1] <= shift_reg_in[1];
188
          ruart_dataout[2] <= shift_reg_in[2];
189
          ruart_dataout[3] <= shift_reg_in[3];
190
          ruart_dataout[4] <= shift_reg_in[4];
191
          ruart_dataout[5] <= shift_reg_in[5];
192
          ruart_dataout[6] <= shift_reg_in[6];
193
          ruart_dataout[7] <= shift_reg_in[7];
194
        end
195
end
196
 
197
 
198
// Circuit for transmitter side
199
always @(posedge reset or posedge clk0)
200
begin
201
        if(reset == 1'b1)
202
        begin
203
                shift_reg_out <= 8'h0;
204
                ser_txd <= 1'b0;
205
        end
206
        else
207
        if((uart_wr == 1'b0) && (uart_rd == 1'b1) && (byte_out == 1'b0))
208
        begin
209
                ser_txd <= shift_reg_out[7];
210
                shift_reg_out[7] <= shift_reg_out[6];
211
                shift_reg_out[6] <= shift_reg_out[5];
212
                shift_reg_out[5] <= shift_reg_out[4];
213
                shift_reg_out[4] <= shift_reg_out[3];
214
                shift_reg_out[3] <= shift_reg_out[2];
215
                shift_reg_out[2] <= shift_reg_out[1];
216
                shift_reg_out[1] <= shift_reg_out[0];
217
        end
218
        else
219
        if((uart_wr == 1'b0) && (uart_rd == 1'b1) && (byte_out == 1'b1))
220
                shift_reg_out <= uart_datain;
221
end
222
 
223
 
224
 
225
// Serial Input Byte Counter
226
always @(posedge reset or posedge clk0)
227
begin
228
        if(reset == 1'b1)
229
        begin
230
                serin_cnt <= 3'b000;
231
                byte_in <= 1'b0;
232
        end
233
        else
234
        if((uart_cs == 1'b1) && (uart_wr == 1'b1) && (uart_rd == 1'b0))
235
                serin_cnt <= serin_cnt + 1;
236
        else
237
        if(serin_cnt == 3'b111)
238
                byte_in <= 1'b1;
239
        else
240
        begin
241
                byte_in <= 1'b0;
242
                serin_cnt <= serin_cnt;
243
        end
244
end
245
 
246
 
247
// Serial Output Byte Counter
248
always @(posedge reset or posedge clk0)
249
begin
250
        if(reset == 1'b1)
251
        begin
252
                serout_cnt <= 3'b000;
253
                byte_out <= 1'b0;
254
        end
255
        else
256
        if((uart_cs == 1'b1) && (uart_wr == 1'b0) && (uart_rd == 1'b1))
257
                serout_cnt <= serout_cnt + 1;
258
        else
259
        if(serout_cnt == 3'b111)
260
                byte_out <= 1'b1;
261
        else
262
        begin
263
                byte_out <= 1'b0;
264
                serout_cnt <= serout_cnt;
265
        end
266
end
267
 
268
endmodule

powered by: WebSVN 2.1.0

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