Line 17... |
Line 17... |
// There is a synchronous reset line, logic high.
|
// There is a synchronous reset line, logic high.
|
//
|
//
|
// Now for the setup register. The register is 32 bits, so that this
|
// Now for the setup register. The register is 32 bits, so that this
|
// UART may be set up over a 32-bit bus.
|
// UART may be set up over a 32-bit bus.
|
//
|
//
|
|
// i_setup[30] True if we are using hardware flow control. This bit
|
|
// is ignored within this module, as any receive hardware flow
|
|
// control will need to be implemented elsewhere.
|
|
//
|
// i_setup[29:28] Indicates the number of data bits per word. This will
|
// i_setup[29:28] Indicates the number of data bits per word. This will
|
// either be 2'b00 for an 8-bit word, 2'b01 for a 7-bit word, 2'b10
|
// either be 2'b00 for an 8-bit word, 2'b01 for a 7-bit word, 2'b10
|
// for a six bit word, or 2'b11 for a five bit word.
|
// for a six bit word, or 2'b11 for a five bit word.
|
//
|
//
|
// i_setup[27] Indicates whether or not to use one or two stop bits.
|
// i_setup[27] Indicates whether or not to use one or two stop bits.
|
Line 72... |
Line 76... |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for more details.
|
// for more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
|
// target there if the PDF file isn't present.) If not, see
|
// target there if the PDF file isn't present.) If not, see
|
// <http://www.gnu.org/licenses/> for a copy.
|
// <http://www.gnu.org/licenses/> for a copy.
|
//
|
//
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// http://www.gnu.org/licenses/gpl.html
|
// http://www.gnu.org/licenses/gpl.html
|
Line 88... |
Line 92... |
// States: (@ baud counter == 0)
|
// States: (@ baud counter == 0)
|
// 0 First bit arrives
|
// 0 First bit arrives
|
// ..7 Bits arrive
|
// ..7 Bits arrive
|
// 8 Stop bit (x1)
|
// 8 Stop bit (x1)
|
// 9 Stop bit (x2)
|
// 9 Stop bit (x2)
|
/// c break condition
|
// c break condition
|
// d Waiting for the channel to go high
|
// d Waiting for the channel to go high
|
// e Waiting for the reset to complete
|
// e Waiting for the reset to complete
|
// f Idle state
|
// f Idle state
|
`define RXU_BIT_ZERO 4'h0
|
`define RXU_BIT_ZERO 4'h0
|
`define RXU_BIT_ONE 4'h1
|
`define RXU_BIT_ONE 4'h1
|
Line 111... |
Line 115... |
`define RXU_RESET_IDLE 4'he
|
`define RXU_RESET_IDLE 4'he
|
`define RXU_IDLE 4'hf
|
`define RXU_IDLE 4'hf
|
|
|
module rxuart(i_clk, i_reset, i_setup, i_uart_rx, o_wr, o_data, o_break,
|
module rxuart(i_clk, i_reset, i_setup, i_uart_rx, o_wr, o_data, o_break,
|
o_parity_err, o_frame_err, o_ck_uart);
|
o_parity_err, o_frame_err, o_ck_uart);
|
parameter INITIAL_SETUP = 30'd868;
|
parameter [30:0] INITIAL_SETUP = 31'd868;
|
// 8 data bits, no parity, (at least 1) stop bit
|
// 8 data bits, no parity, (at least 1) stop bit
|
input i_clk, i_reset;
|
input i_clk, i_reset;
|
input [29:0] i_setup;
|
input [30:0] i_setup;
|
input i_uart_rx;
|
input i_uart_rx;
|
output reg o_wr;
|
output reg o_wr;
|
output reg [7:0] o_data;
|
output reg [7:0] o_data;
|
output reg o_break;
|
output reg o_break;
|
output reg o_parity_err, o_frame_err;
|
output reg o_parity_err, o_frame_err;
|
Line 130... |
Line 134... |
wire use_parity, parity_even, dblstop, fixd_parity;
|
wire use_parity, parity_even, dblstop, fixd_parity;
|
reg [29:0] r_setup;
|
reg [29:0] r_setup;
|
reg [3:0] state;
|
reg [3:0] state;
|
|
|
assign clocks_per_baud = { 4'h0, r_setup[23:0] };
|
assign clocks_per_baud = { 4'h0, r_setup[23:0] };
|
|
// assign hw_flow_control = !r_setup[30];
|
assign data_bits = r_setup[29:28];
|
assign data_bits = r_setup[29:28];
|
assign dblstop = r_setup[27];
|
assign dblstop = r_setup[27];
|
assign use_parity = r_setup[26];
|
assign use_parity = r_setup[26];
|
assign fixd_parity = r_setup[25];
|
assign fixd_parity = r_setup[25];
|
assign parity_even = r_setup[24];
|
assign parity_even = r_setup[24];
|
Line 212... |
Line 217... |
half_baud_time <= (~ck_uart)&&(chg_counter >= half_baud);
|
half_baud_time <= (~ck_uart)&&(chg_counter >= half_baud);
|
|
|
|
|
// Allow our controlling processor to change our setup at any time
|
// Allow our controlling processor to change our setup at any time
|
// outside of receiving/processing a character.
|
// outside of receiving/processing a character.
|
initial r_setup = INITIAL_SETUP;
|
initial r_setup = INITIAL_SETUP[29:0];
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (state >= `RXU_RESET_IDLE)
|
if (state >= `RXU_RESET_IDLE)
|
r_setup <= i_setup;
|
r_setup <= i_setup[29:0];
|
|
|
|
|
// Our monster state machine. YIKES!
|
// Our monster state machine. YIKES!
|
//
|
//
|
// Yeah, this may be more complicated than it needs to be. The basic
|
// Yeah, this may be more complicated than it needs to be. The basic
|