Line 61... |
Line 61... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.13 2001/11/08 14:54:23 mohor
|
|
// Comments in Slovene language deleted, few small fixes for better work of
|
|
// old tools. IRQs need to be fix.
|
|
//
|
// Revision 1.12 2001/11/07 17:51:52 gorban
|
// Revision 1.12 2001/11/07 17:51:52 gorban
|
// Heavily rewritten interrupt and LSR subsystems.
|
// Heavily rewritten interrupt and LSR subsystems.
|
// Many bugs hopefully squashed.
|
// Many bugs hopefully squashed.
|
//
|
//
|
// Revision 1.11 2001/10/29 17:00:46 gorban
|
// Revision 1.11 2001/10/29 17:00:46 gorban
|
Line 112... |
Line 116... |
`include "timescale.v"
|
`include "timescale.v"
|
// synopsys translate_on
|
// synopsys translate_on
|
|
|
`include "uart_defines.v"
|
`include "uart_defines.v"
|
|
|
module uart_transmitter (clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, stx_pad_o, state, tf_count, tx_reset, lsr_mask);
|
module uart_transmitter (clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, stx_pad_o, tstate, tf_count, tx_reset, lsr_mask);
|
|
|
input clk;
|
input clk;
|
input wb_rst_i;
|
input wb_rst_i;
|
input [7:0] lcr;
|
input [7:0] lcr;
|
input tf_push;
|
input tf_push;
|
input [7:0] wb_dat_i;
|
input [7:0] wb_dat_i;
|
input enable;
|
input enable;
|
input tx_reset;
|
input tx_reset;
|
input lsr_mask; //reset of fifo
|
input lsr_mask; //reset of fifo
|
output stx_pad_o;
|
output stx_pad_o;
|
output [2:0] state;
|
output [2:0] tstate;
|
output [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
output [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
|
|
reg [2:0] state;
|
reg [2:0] tstate;
|
reg [4:0] counter;
|
reg [4:0] counter;
|
reg [2:0] bit_counter; // counts the bits to be sent
|
reg [2:0] bit_counter; // counts the bits to be sent
|
reg [6:0] shift_out; // output shift register
|
reg [6:0] shift_out; // output shift register
|
reg stx_o_tmp;
|
reg stx_o_tmp;
|
reg parity_xor; // parity of the word
|
reg parity_xor; // parity of the word
|
Line 175... |
Line 179... |
|
|
always @(posedge clk or posedge wb_rst_i)
|
always @(posedge clk or posedge wb_rst_i)
|
begin
|
begin
|
if (wb_rst_i)
|
if (wb_rst_i)
|
begin
|
begin
|
state <= #1 s_idle;
|
tstate <= #1 s_idle;
|
stx_o_tmp <= #1 1'b1;
|
stx_o_tmp <= #1 1'b1;
|
counter <= #1 5'b0;
|
counter <= #1 5'b0;
|
shift_out <= #1 7'b0;
|
shift_out <= #1 7'b0;
|
bit_out <= #1 1'b0;
|
bit_out <= #1 1'b0;
|
parity_xor <= #1 1'b0;
|
parity_xor <= #1 1'b0;
|
Line 187... |
Line 191... |
bit_counter <= #1 3'b0;
|
bit_counter <= #1 3'b0;
|
end
|
end
|
else
|
else
|
if (enable)
|
if (enable)
|
begin
|
begin
|
case (state)
|
case (tstate)
|
s_idle : if (~|tf_count) // if tf_count==0
|
s_idle : if (~|tf_count) // if tf_count==0
|
begin
|
begin
|
state <= #1 s_idle;
|
tstate <= #1 s_idle;
|
stx_o_tmp <= #1 1'b1;
|
stx_o_tmp <= #1 1'b1;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
tf_pop <= #1 1'b0;
|
tf_pop <= #1 1'b0;
|
stx_o_tmp <= #1 1'b1;
|
stx_o_tmp <= #1 1'b1;
|
state <= #1 s_pop_byte;
|
tstate <= #1 s_pop_byte;
|
end
|
end
|
s_pop_byte : begin
|
s_pop_byte : begin
|
tf_pop <= #1 1'b1;
|
tf_pop <= #1 1'b1;
|
case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word
|
case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word
|
2'b00 : begin
|
2'b00 : begin
|
Line 220... |
Line 224... |
bit_counter <= #1 3'b111;
|
bit_counter <= #1 3'b111;
|
parity_xor <= #1 ^tf_data_out[7:0];
|
parity_xor <= #1 ^tf_data_out[7:0];
|
end
|
end
|
endcase
|
endcase
|
{shift_out[6:0], bit_out} <= #1 tf_data_out;
|
{shift_out[6:0], bit_out} <= #1 tf_data_out;
|
state <= #1 s_send_start;
|
tstate <= #1 s_send_start;
|
end
|
end
|
s_send_start : begin
|
s_send_start : begin
|
tf_pop <= #1 1'b0;
|
tf_pop <= #1 1'b0;
|
if (~|counter)
|
if (~|counter)
|
counter <= #1 5'b01111;
|
counter <= #1 5'b01111;
|
else
|
else
|
if (counter == 5'b00001)
|
if (counter == 5'b00001)
|
begin
|
begin
|
counter <= #1 0;
|
counter <= #1 0;
|
state <= #1 s_send_byte;
|
tstate <= #1 s_send_byte;
|
end
|
end
|
else
|
else
|
counter <= #1 counter - 1'b1;
|
counter <= #1 counter - 1'b1;
|
stx_o_tmp <= #1 1'b0;
|
stx_o_tmp <= #1 1'b0;
|
end
|
end
|
Line 246... |
Line 250... |
begin
|
begin
|
if (bit_counter > 3'b0)
|
if (bit_counter > 3'b0)
|
begin
|
begin
|
bit_counter <= #1 bit_counter - 1'b1;
|
bit_counter <= #1 bit_counter - 1'b1;
|
{shift_out[5:0],bit_out } <= #1 {shift_out[6:1], shift_out[0]};
|
{shift_out[5:0],bit_out } <= #1 {shift_out[6:1], shift_out[0]};
|
state <= #1 s_send_byte;
|
tstate <= #1 s_send_byte;
|
end
|
end
|
else // end of byte
|
else // end of byte
|
if (~lcr[`UART_LC_PE])
|
if (~lcr[`UART_LC_PE])
|
begin
|
begin
|
state <= #1 s_send_stop;
|
tstate <= #1 s_send_stop;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
case ({lcr[`UART_LC_EP],lcr[`UART_LC_SP]})
|
case ({lcr[`UART_LC_EP],lcr[`UART_LC_SP]})
|
2'b00: bit_out <= #1 ~parity_xor;
|
2'b00: bit_out <= #1 ~parity_xor;
|
2'b01: bit_out <= #1 1'b1;
|
2'b01: bit_out <= #1 1'b1;
|
2'b10: bit_out <= #1 parity_xor;
|
2'b10: bit_out <= #1 parity_xor;
|
2'b11: bit_out <= #1 1'b0;
|
2'b11: bit_out <= #1 1'b0;
|
endcase
|
endcase
|
state <= #1 s_send_parity;
|
tstate <= #1 s_send_parity;
|
end
|
end
|
counter <= #1 0;
|
counter <= #1 0;
|
end
|
end
|
else
|
else
|
counter <= #1 counter - 1'b1;
|
counter <= #1 counter - 1'b1;
|
Line 276... |
Line 280... |
counter <= #1 5'b01111;
|
counter <= #1 5'b01111;
|
else
|
else
|
if (counter == 5'b00001)
|
if (counter == 5'b00001)
|
begin
|
begin
|
counter <= #1 4'b0;
|
counter <= #1 4'b0;
|
state <= #1 s_send_stop;
|
tstate <= #1 s_send_stop;
|
end
|
end
|
else
|
else
|
counter <= #1 counter - 1'b1;
|
counter <= #1 counter - 1'b1;
|
stx_o_tmp <= #1 bit_out;
|
stx_o_tmp <= #1 bit_out;
|
end
|
end
|
Line 288... |
Line 292... |
if (~|counter)
|
if (~|counter)
|
begin
|
begin
|
casex ({lcr[`UART_LC_SB],lcr[`UART_LC_BITS]})
|
casex ({lcr[`UART_LC_SB],lcr[`UART_LC_BITS]})
|
3'b0xx: counter <= #1 5'b01101; // 1 stop bit ok igor
|
3'b0xx: counter <= #1 5'b01101; // 1 stop bit ok igor
|
3'b100: counter <= #1 5'b10101; // 1.5 stop bit
|
3'b100: counter <= #1 5'b10101; // 1.5 stop bit
|
3'b1xx: counter <= #1 5'b11101; // 2 stop bits
|
default: counter <= #1 5'b11101; // 2 stop bits
|
endcase
|
endcase
|
end
|
end
|
else
|
else
|
if (counter == 5'b00001)
|
if (counter == 5'b00001)
|
begin
|
begin
|
counter <= #1 0;
|
counter <= #1 0;
|
state <= #1 s_idle;
|
tstate <= #1 s_idle;
|
end
|
end
|
else
|
else
|
counter <= #1 counter - 1'b1;
|
counter <= #1 counter - 1'b1;
|
stx_o_tmp <= #1 1'b1;
|
stx_o_tmp <= #1 1'b1;
|
end
|
end
|
|
|
default : // should never get here
|
default : // should never get here
|
state <= #1 s_idle;
|
tstate <= #1 s_idle;
|
endcase
|
endcase
|
end // end if enable
|
end // end if enable
|
end // transmitter logic
|
end // transmitter logic
|
|
|
assign stx_pad_o = lcr[`UART_LC_BC] ? 1'b0 : stx_o_tmp; // Break condition
|
assign stx_pad_o = lcr[`UART_LC_BC] ? 1'b0 : stx_o_tmp; // Break condition
|