| 1 |
2 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: uartdev.v
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: XuLA2 board
|
| 6 |
|
|
//
|
| 7 |
7 |
dgisselq |
// Purpose: This is a simple wrapper around the txuart and rxuart
|
| 8 |
|
|
// modules. The purpose is to make both of those modules
|
| 9 |
|
|
// configurable from a single wishbone address, and capable of receiving
|
| 10 |
|
|
// (or transmitting) via reads (writes) from two other addresses.
|
| 11 |
2 |
dgisselq |
//
|
| 12 |
7 |
dgisselq |
// It also generates interrupts: a receive interrupt strobe on the clock
|
| 13 |
|
|
// when data is made available, and a transmit not busy level interrupt
|
| 14 |
|
|
// which is held high as long as the transmitter is idle. Both should be
|
| 15 |
|
|
// able to work nicely with the programmable interrupt controllers found
|
| 16 |
|
|
// in the ZipCPU project.
|
| 17 |
2 |
dgisselq |
//
|
| 18 |
7 |
dgisselq |
//
|
| 19 |
2 |
dgisselq |
// Creator: Dan Gisselquist, Ph.D.
|
| 20 |
|
|
// Gisselquist Technology, LLC
|
| 21 |
|
|
//
|
| 22 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 23 |
|
|
//
|
| 24 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
| 25 |
|
|
//
|
| 26 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 27 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 28 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 29 |
|
|
// your option) any later version.
|
| 30 |
|
|
//
|
| 31 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 32 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 33 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 34 |
|
|
// for more details.
|
| 35 |
|
|
//
|
| 36 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 37 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 38 |
|
|
//
|
| 39 |
|
|
//
|
| 40 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 41 |
|
|
//
|
| 42 |
|
|
//
|
| 43 |
|
|
module uartdev(i_clk, i_rx_uart, o_tx_uart,
|
| 44 |
|
|
i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
| 45 |
|
|
o_wb_ack, o_wb_stall, o_wb_data,
|
| 46 |
74 |
dgisselq |
o_rx_int, o_tx_int, o_debug);
|
| 47 |
57 |
dgisselq |
parameter DEFAULT_SETUP = { 2'b00, 1'b0, 1'b0, 2'b00, 24'd8333 };
|
| 48 |
2 |
dgisselq |
input i_clk, i_rx_uart;
|
| 49 |
|
|
output wire o_tx_uart;
|
| 50 |
|
|
input i_wb_cyc, i_wb_stb, i_wb_we;
|
| 51 |
|
|
input [1:0] i_wb_addr;
|
| 52 |
|
|
input [31:0] i_wb_data;
|
| 53 |
|
|
output reg o_wb_ack;
|
| 54 |
|
|
output wire o_wb_stall;
|
| 55 |
|
|
output reg [31:0] o_wb_data;
|
| 56 |
|
|
output wire o_rx_int, o_tx_int;
|
| 57 |
74 |
dgisselq |
output wire [31:0] o_debug;
|
| 58 |
2 |
dgisselq |
|
| 59 |
|
|
reg [29:0] r_setup;
|
| 60 |
|
|
reg r_tx_stb, rx_rdy;
|
| 61 |
|
|
reg [7:0] r_tx_data;
|
| 62 |
|
|
initial r_setup = DEFAULT_SETUP;
|
| 63 |
|
|
always @(posedge i_clk)
|
| 64 |
113 |
dgisselq |
if ((i_wb_stb)&&(i_wb_we)&&(~i_wb_addr[1]))
|
| 65 |
9 |
dgisselq |
r_setup <= i_wb_data[29:0];
|
| 66 |
|
|
|
| 67 |
|
|
initial r_tx_stb = 1'b0;
|
| 68 |
|
|
always @(posedge i_clk)
|
| 69 |
113 |
dgisselq |
if ((i_wb_stb)&&(i_wb_we)&&(i_wb_addr == 2'b11))
|
| 70 |
2 |
dgisselq |
begin
|
| 71 |
9 |
dgisselq |
// Note: there's no check for overflow here.
|
| 72 |
|
|
// You're on your own: verify that the device
|
| 73 |
|
|
// isn't busy first.
|
| 74 |
|
|
r_tx_data <= i_wb_data[7:0];
|
| 75 |
|
|
r_tx_stb <= 1'b1;
|
| 76 |
2 |
dgisselq |
end else
|
| 77 |
|
|
r_tx_stb <= 1'b0;
|
| 78 |
|
|
|
| 79 |
9 |
dgisselq |
wire rx_stb, rx_break, rx_parity_err, rx_frame_err;
|
| 80 |
2 |
dgisselq |
wire [7:0] rx_data;
|
| 81 |
|
|
rxuart rxmod(i_clk, 1'b0, r_setup, i_rx_uart,
|
| 82 |
|
|
rx_stb, rx_data, rx_break,
|
| 83 |
9 |
dgisselq |
rx_parity_err, rx_frame_err);
|
| 84 |
2 |
dgisselq |
|
| 85 |
|
|
wire tx_break, tx_busy;
|
| 86 |
|
|
assign tx_break = 1'b0;
|
| 87 |
|
|
txuart txmod(i_clk, 1'b0, r_setup, tx_break, r_tx_stb, r_tx_data,
|
| 88 |
|
|
o_tx_uart, tx_busy);
|
| 89 |
|
|
|
| 90 |
|
|
reg [7:0] r_data;
|
| 91 |
|
|
always @(posedge i_clk)
|
| 92 |
|
|
if (rx_stb)
|
| 93 |
|
|
r_data <= rx_data;
|
| 94 |
9 |
dgisselq |
|
| 95 |
|
|
initial o_wb_data = 32'h00;
|
| 96 |
2 |
dgisselq |
always @(posedge i_clk)
|
| 97 |
|
|
begin
|
| 98 |
|
|
if (rx_stb)
|
| 99 |
|
|
rx_rdy <= (rx_rdy | rx_stb);
|
| 100 |
|
|
|
| 101 |
|
|
case(i_wb_addr)
|
| 102 |
|
|
2'b00: o_wb_data <= { 2'b00, r_setup };
|
| 103 |
|
|
2'b01: o_wb_data <= { 2'b00, r_setup };
|
| 104 |
57 |
dgisselq |
2'b10: begin
|
| 105 |
113 |
dgisselq |
if ((i_wb_stb)&&(~i_wb_we))
|
| 106 |
9 |
dgisselq |
rx_rdy <= rx_stb;
|
| 107 |
2 |
dgisselq |
o_wb_data <= { 20'h00, rx_break, rx_frame_err, rx_parity_err, ~rx_rdy, r_data };
|
| 108 |
|
|
end
|
| 109 |
57 |
dgisselq |
2'b11: o_wb_data <= { 31'h00,tx_busy };
|
| 110 |
2 |
dgisselq |
endcase
|
| 111 |
113 |
dgisselq |
o_wb_ack <= (i_wb_stb); // Read or write, we ack
|
| 112 |
2 |
dgisselq |
end
|
| 113 |
|
|
|
| 114 |
|
|
assign o_wb_stall = 1'b0;
|
| 115 |
|
|
assign o_rx_int = rx_stb;
|
| 116 |
|
|
assign o_tx_int = ~tx_busy;
|
| 117 |
74 |
dgisselq |
|
| 118 |
|
|
assign o_debug = { (~i_rx_uart)||(~o_tx_uart), tx_busy, i_wb_addr,
|
| 119 |
|
|
rx_break, rx_frame_err, rx_parity_err, rx_rdy,
|
| 120 |
|
|
i_wb_cyc, i_wb_stb, i_wb_we, o_wb_ack,
|
| 121 |
|
|
rx_stb, rx_data,
|
| 122 |
|
|
r_tx_stb, r_tx_data,
|
| 123 |
|
|
i_rx_uart, o_tx_uart };
|
| 124 |
2 |
dgisselq |
endmodule
|