1 |
2 |
motilito |
//---------------------------------------------------------------------------------------
|
2 |
|
|
// uart to internal bus top module
|
3 |
|
|
//
|
4 |
|
|
//---------------------------------------------------------------------------------------
|
5 |
|
|
|
6 |
|
|
module uart2bus_top
|
7 |
|
|
(
|
8 |
|
|
// global signals
|
9 |
|
|
clock, reset,
|
10 |
|
|
// uart serial signals
|
11 |
|
|
ser_in, ser_out,
|
12 |
|
|
// internal bus to register file
|
13 |
|
|
int_address, int_wr_data, int_write,
|
14 |
|
|
int_rd_data, int_read
|
15 |
|
|
);
|
16 |
|
|
//---------------------------------------------------------------------------------------
|
17 |
|
|
// modules inputs and outputs
|
18 |
|
|
input clock; // global clock input
|
19 |
|
|
input reset; // global reset input
|
20 |
|
|
input ser_in; // serial data input
|
21 |
|
|
output ser_out; // serial data output
|
22 |
|
|
output [15:0] int_address; // address bus to register file
|
23 |
|
|
output [7:0] int_wr_data; // write data to register file
|
24 |
|
|
output int_write; // write control to register file
|
25 |
|
|
output int_read; // read control to register file
|
26 |
|
|
input [7:0] int_rd_data; // data read from register file
|
27 |
|
|
|
28 |
|
|
// baud rate configuration, see baud_gen.v for more details.
|
29 |
4 |
motilito |
// baud rate generator parameters for 115200 baud on 40MHz clock
|
30 |
|
|
`define D_BAUD_FREQ 12'h90
|
31 |
|
|
`define D_BAUD_LIMIT 16'h0ba5
|
32 |
2 |
motilito |
// baud rate generator parameters for 115200 baud on 44MHz clock
|
33 |
4 |
motilito |
// `define D_BAUD_FREQ 12'd23
|
34 |
|
|
// `define D_BAUD_LIMIT 16'd527
|
35 |
2 |
motilito |
// baud rate generator parameters for 9600 baud on 66MHz clock
|
36 |
|
|
//`define D_BAUD_FREQ 12'h10
|
37 |
|
|
//`define D_BAUD_LIMIT 16'h1ACB
|
38 |
|
|
|
39 |
|
|
// internal wires
|
40 |
|
|
wire [7:0] tx_data; // data byte to transmit
|
41 |
|
|
wire new_tx_data; // asserted to indicate that there is a new data byte for transmission
|
42 |
|
|
wire tx_busy; // signs that transmitter is busy
|
43 |
|
|
wire [7:0] rx_data; // data byte received
|
44 |
|
|
wire new_rx_data; // signs that a new byte was received
|
45 |
|
|
wire [11:0] baud_freq;
|
46 |
|
|
wire [15:0] baud_limit;
|
47 |
|
|
wire baud_clk;
|
48 |
|
|
|
49 |
|
|
//---------------------------------------------------------------------------------------
|
50 |
|
|
// module implementation
|
51 |
|
|
// uart top module instance
|
52 |
|
|
uart_top uart1
|
53 |
|
|
(
|
54 |
|
|
.clock(clock), .reset(reset),
|
55 |
|
|
.ser_in(ser_in), .ser_out(ser_out),
|
56 |
|
|
.rx_data(rx_data), .new_rx_data(new_rx_data),
|
57 |
|
|
.tx_data(tx_data), .new_tx_data(new_tx_data), .tx_busy(tx_busy),
|
58 |
|
|
.baud_freq(baud_freq), .baud_limit(baud_limit),
|
59 |
|
|
.baud_clk(baud_clk)
|
60 |
|
|
);
|
61 |
|
|
|
62 |
|
|
// assign baud rate default values
|
63 |
|
|
assign baud_freq = `D_BAUD_FREQ;
|
64 |
|
|
assign baud_limit = `D_BAUD_LIMIT;
|
65 |
|
|
|
66 |
|
|
// uart parser instance
|
67 |
|
|
uart_parser #(16) uart_parser1
|
68 |
|
|
(
|
69 |
|
|
.clock(clock), .reset(reset),
|
70 |
|
|
.rx_data(rx_data), .new_rx_data(new_rx_data),
|
71 |
|
|
.tx_data(tx_data), .new_tx_data(new_tx_data), .tx_busy(tx_busy),
|
72 |
|
|
.int_address(int_address), .int_wr_data(int_wr_data), .int_write(int_write),
|
73 |
|
|
.int_rd_data(int_rd_data), .int_read(int_read)
|
74 |
|
|
);
|
75 |
|
|
|
76 |
|
|
endmodule
|
77 |
|
|
//---------------------------------------------------------------------------------------
|
78 |
|
|
// Th.. Th.. Th.. Thats all folks !!!
|
79 |
|
|
//---------------------------------------------------------------------------------------
|