-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuart_tx.v
62 lines (55 loc) · 1.27 KB
/
uart_tx.v
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
// 230814
`default_nettype none
module UartTx #(
parameter CLOCK_HZ = 10_000_000,
parameter BAUD = 115200
)(
input wire Clock,
input wire Reset,
input wire Start_i,
input wire [7:0] Data_i,
output wire Busy_o,
output wire Done_o,
output wire Tx_o
);
// Timing
wire NextBit;
localparam TICKS_PER_BIT = CLOCK_HZ / BAUD;
StrobeGeneratorTicks #(
.TICKS(TICKS_PER_BIT)
) StrobeGeneratorTicks_inst(
.Clock(Clock),
.Reset(Reset),
.Enable_i(Busy || Start_i),
.Strobe_o(NextBit)
);
// Shift register
reg Busy;
reg [3:0] Pointer /* synthesis syn_encoding = "sequential" */;
reg [7:0] ByteCopy;
always @(posedge Clock, negedge Reset) begin
if(!Reset) begin
ByteCopy <= 0;
Busy <= 0;
Pointer <= 0;
end else if(Start_i) begin
ByteCopy <= Data_i;
Busy <= 1'b1;
Pointer <= 0;
end else if(NextBit) begin
if(Pointer == 4'd9) begin
Busy <= 1'b0;
Pointer <= 4'd0;
end else begin
Pointer <= Pointer + 1'b1;
end
end
end
wire [9:0] DataToSend;
assign DataToSend = {1'b1, ByteCopy, 1'b0};
// Outputs
assign Tx_o = Busy ? DataToSend[Pointer] : 1'b1;
assign Busy_o = Busy;
assign Done_o = NextBit && (Pointer == 4'd9);
endmodule
`default_nettype wire