Line 48... |
Line 48... |
|
|
// Ideally, UART_SETUP is defined somewhere. I commonly like to define
|
// Ideally, UART_SETUP is defined somewhere. I commonly like to define
|
// it to CLKRATE / BAUDRATE, to give me 8N1 performance. 4MB is useful
|
// it to CLKRATE / BAUDRATE, to give me 8N1 performance. 4MB is useful
|
// to me, so 100MHz / 4M = 25 could be the setup. You can also use
|
// to me, so 100MHz / 4M = 25 could be the setup. You can also use
|
// 200MHz / 4MB = 50 ... it all depends upon your clock.
|
// 200MHz / 4MB = 50 ... it all depends upon your clock.
|
`define UART_SETUP 30'd25
|
`define UART_SETUP 31'd25
|
reg [29:0] uart_setup;
|
reg [30:0] uart_setup;
|
initial uart_setup = `UART_SETUP;
|
initial uart_setup = `UART_SETUP;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if ((i_wb_stb)&&(i_wb_addr == `UART_SETUP_ADDR))
|
if ((i_wb_stb)&&(i_wb_addr == `UART_SETUP_ADDR))
|
uart_setup[29:0] <= i_wb_data[29:0];
|
uart_setup[30:0] <= i_wb_data[30:0];
|
|
|
//
|
//
|
// First the UART receiver
|
// First the UART receiver
|
//
|
//
|
wire rx_stb, rx_break, rx_perr, rx_ferr, ck_uart;
|
wire rx_stb, rx_break, rx_perr, rx_ferr, ck_uart;
|
Line 81... |
Line 81... |
r_rx_data[11] <= (rx_break)&& (!i_wb_data[11]);
|
r_rx_data[11] <= (rx_break)&& (!i_wb_data[11]);
|
r_rx_data[10] <= (rx_ferr) && (!i_wb_data[10]);
|
r_rx_data[10] <= (rx_ferr) && (!i_wb_data[10]);
|
r_rx_data[ 9] <= (rx_perr) && (!i_wb_data[ 9]);
|
r_rx_data[ 9] <= (rx_perr) && (!i_wb_data[ 9]);
|
end
|
end
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if(((i_wb_stb)&&(~i_wb_we)&&(i_wb_addr == `UART_RX_ADDR))
|
if(((i_wb_stb)&&(!i_wb_we)&&(i_wb_addr == `UART_RX_ADDR))
|
||(rx_stb))
|
||(rx_stb))
|
r_rx_data[8] <= !rx_stb;
|
r_rx_data[8] <= !rx_stb;
|
assign o_cts = !r_rx_data[8];
|
assign o_cts = !r_rx_data[8];
|
assign rx_data = { 20'h00, r_rx_data };
|
assign rx_data = { 20'h00, r_rx_data };
|
assign rx_int = !r_rx_data[8];
|
assign rx_int = !r_rx_data[8];
|
|
|
|
// Transmit hardware flow control, the rts line
|
|
wire rts;
|
|
// Set this rts value to one if you aren't ever going to use H/W flow
|
|
// control, otherwise set it to the value coming in from the external
|
|
// i_rts pin.
|
|
assign rts = i_rts;
|
|
|
//
|
//
|
// Then the UART transmitter
|
// Then the UART transmitter
|
//
|
//
|
|
//
|
|
//
|
|
// Now onto the transmitter itself
|
wire tx_busy;
|
wire tx_busy;
|
reg [7:0] r_tx_data;
|
reg [7:0] r_tx_data;
|
reg r_tx_stb, r_tx_break;
|
reg r_tx_stb, r_tx_break;
|
wire [31:0] tx_data;
|
wire [31:0] tx_data;
|
txuart #(UART_SETUP) tx(i_clk, 1'b0, uart_setup,
|
txuart #(UART_SETUP) tx(i_clk, 1'b0, uart_setup,
|
r_tx_break, r_tx_stb, r_tx_data,
|
r_tx_break, r_tx_stb, r_tx_data,
|
o_tx, tx_busy);
|
rts, o_tx, tx_busy);
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if ((i_wb_stb)&&(i_wb_addr == 5'h0f))
|
if ((i_wb_stb)&&(i_wb_addr == 5'h0f))
|
begin
|
begin
|
r_tx_stb <= (!r_tx_break)&&(!i_wb_data[8]);
|
r_tx_stb <= (!r_tx_break)&&(!i_wb_data[8]);
|
r_tx_data <= i_wb_data[7:0];
|
r_tx_data <= i_wb_data[7:0];
|
r_tx_break<= i_wb_data[9];
|
r_tx_break<= i_wb_data[9];
|
end else if (~tx_busy)
|
end else if (!tx_busy)
|
begin
|
begin
|
r_tx_stb <= 1'b0;
|
r_tx_stb <= 1'b0;
|
r_tx_data <= 8'h0;
|
r_tx_data <= 8'h0;
|
end
|
end
|
assign tx_data = { 20'h00,
|
assign tx_data = { 16'h00, rts, 3'h0,
|
ck_uart, o_tx, r_tx_break, tx_busy,
|
ck_uart, o_tx, r_tx_break, tx_busy,
|
r_tx_data };
|
r_tx_data };
|
assign tx_int = ~tx_busy;
|
assign tx_int = ~tx_busy;
|
|
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
case(i_wb_addr)
|
case(i_wb_addr)
|
`UART_SETUP_ADDR: o_wb_data <= { 2'b00, uart_setup };
|
`UART_SETUP_ADDR: o_wb_data <= { 1'b0, uart_setup };
|
`UART_RX_ADDR : o_wb_data <= rx_data;
|
`UART_RX_ADDR : o_wb_data <= rx_data;
|
`UART_TX_ADDR : o_wb_data <= tx_data;
|
`UART_TX_ADDR : o_wb_data <= tx_data;
|
//
|
//
|
// The rest of these address slots are left open here for
|
// The rest of these address slots are left open here for
|
// whatever else you might wish to connect to this bus/STB
|
// whatever else you might wish to connect to this bus/STB
|