-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver.v
74 lines (67 loc) · 1.62 KB
/
receiver.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
63
64
65
66
67
68
69
70
71
72
73
74
`default_nettype none
module receiver(
i_clk,
i_rx,
i_rst,
o_data,
ready
);
input wire i_clk;
input wire i_rx;
input wire i_rst;
output reg ready;
output reg[7:0] o_data;
reg continue_rx;
reg prev;
reg rx_steady_val;
reg [1:0] steady;
reg[7:0] s_data;
reg[3:0] bit_counter;
wire baud_clk;
wire internal_clk;
clock #(.N(78)) internal_clk_gen(
.i_clk(i_clk),
.i_rst(i_rst),
.o_clk(internal_clk)
);
clock baud_gen(
.i_clk(i_clk),
.i_rst(i_rst),
.o_clk(baud_clk)
);
always @ (posedge internal_clk) begin
if (steady == 2'b11) begin
rx_steady_val <= prev;
steady <= 0;
end else if (prev == i_rx) begin
steady <= steady + 1;
end else begin
steady <= 0;
prev <= i_rx;
end
end
always @ (posedge baud_clk, posedge i_rst) begin
if (i_rst) begin
continue_rx <= 0;
bit_counter <= 0;
s_data <= 0;
o_data <= 0;
ready <= 0;
end else if (continue_rx) begin
if (bit_counter < 8) begin
s_data <= {rx_steady_val, s_data[7:1]};
bit_counter <= bit_counter + 1;
ready <= 0;
end else begin
continue_rx <= 0;
o_data <= s_data;
ready <= 1;
end
end else if (~rx_steady_val) begin
continue_rx <= 1;
bit_counter <= 0;
s_data <= 0;
ready <= 0;
end
end
endmodule