-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuart_tx.v
More file actions
86 lines (80 loc) · 1.64 KB
/
uart_tx.v
File metadata and controls
86 lines (80 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
`define NEGATIVE_RESET
`include "global_config.h"
`include "nettype.h"
`include "stddef.h"
`include "uart.h"
`timescale 1ns/1ns
module uart_tx(clk,reset,tx_start,tx_data,tx_busy,
tx_end,tx);
input clk,reset;
input tx_start;
input[7:0] tx_data;
output tx;
output tx_busy;
output tx_end;
reg tx_end;
reg tx;
reg state;
reg[8:0] div_cnt;
reg[3:0] bit_cnt;
reg[7:0] sh_reg;
assign tx_busy = (state == `UART_STATE_TX) ?
`ENABLE : `DISABLE;
always@(posedge clk or `RESET_EDGE reset)
begin
if(reset == `RESET_ENABLE)
begin
state <= #1 `UART_STATE_IDLE;
div_cnt <= #1 `UART_DIV_RATE;
bit_cnt <= #1 `UART_BIT_CNT_START;
sh_reg <= #1 `BYTE_DATA_W'h0;
tx_end <= #1 `DISABLE;
tx <= #1 `UART_STOP_BIT;
end
else
begin
case(state)
`UART_STATE_IDLE:
begin
if(tx_start == `ENABLE)
begin
state <= #1 `UART_STATE_TX;
sh_reg <= #1 tx_data;
tx <= #1 `UART_START_BIT;
end
tx_end <= #1 `DISABLE;
end
`UART_STATE_TX:
begin
if(div_cnt == {`UART_DIV_CNT_W{1'b0}})
begin
case(bit_cnt)
`UART_BIT_CNT_MSB:
begin
bit_cnt <= #1 `UART_BIT_CNT_STOP;
tx <= #1 `UART_STOP_BIT;
end
`UART_BIT_CNT_STOP:
begin
state <= #1 `UART_STATE_IDLE;
bit_cnt <= #1 `UART_BIT_CNT_START;
tx_end <= #1 `ENABLE;
end
default:
begin
bit_cnt <= #1 bit_cnt + 1;
sh_reg <= #1 sh_reg >> 1'b1;
tx <= #1 sh_reg[`LSB];
end
endcase
div_cnt <= #1 `UART_DIV_RATE;
end
else
begin
div_cnt <= #1 div_cnt - 1;
end
end
endcase
end
end
endmodule