3 * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 parameter csr_addr = 4'h0,
20 parameter clk_freq = 100000000,
21 parameter baud = 115200
29 output reg [31:0] csr_do,
49 uart_transceiver transceiver(
68 /* Generate tx_done signal */
73 always @(posedge sys_clk) begin
81 if(tx_busy_r & ~tx_busy)
87 wire csr_selected = csr_a[13:10] == csr_addr;
89 assign rx_ack = csr_selected & csr_we & (csr_a[1:0] == 2'b00) & csr_di[2];
90 assign tx_data = csr_di[7:0];
91 assign tx_wr = csr_selected & csr_we & (csr_a[1:0] == 2'b01);
92 assign tx_ack = csr_selected & csr_we & (csr_a[1:0] == 2'b00) & csr_di[5];
94 parameter default_divisor = clk_freq/baud/16;
96 always @(posedge sys_clk) begin
98 divisor <= default_divisor;
102 if(csr_selected) begin
104 2'b00: csr_do <= {1'b0, tx_done, tx_busy, 1'b0, rx_error, rx_avail};
105 2'b01: csr_do <= rx_data;
106 2'b10: csr_do <= divisor;
109 if(csr_a[1:0] == 2'b10)
110 divisor <= csr_di[15:0];
117 assign rx_irq = rx_avail|rx_error;
118 assign tx_irq = tx_done;