-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp136.sv
48 lines (45 loc) · 1.23 KB
/
p136.sv
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
module top_module(
input clk,
input in,
input reset, // Synchronous reset
output reg [7:0] out_byte,
output reg done
);
enum {IDLE, RECEIVE, STOP, CLEANUP} state;
reg [3:0] counter = 0;
always @(posedge clk) begin
if (reset) begin
state <= IDLE;
done <= 1'b0;
counter <= 0;
end else begin
case (state)
IDLE: begin
done = 1'b0;
if (!in)
state <= RECEIVE;
end
RECEIVE: begin
counter <= counter + 1;
out_byte[counter] = in;
if (counter == 7) begin
state <= STOP;
counter <= 0;
end
end
STOP: begin
if (in) begin
done <= 1'b1;
state <= IDLE;
end
else
state <= CLEANUP;
end
CLEANUP: begin
if (in)
state <= IDLE;
end
endcase
end
end
endmodule