-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocker.v
More file actions
80 lines (68 loc) · 1.37 KB
/
Copy pathLocker.v
File metadata and controls
80 lines (68 loc) · 1.37 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
module Locker (clk,rst,datain,Enter,locked,unlocked);
input clk,rst,datain,Enter;
output reg locked,unlocked;
parameter idle = 3'b000;
parameter s1 = 3'b001;
parameter s2 = 3'b010;
parameter s3 = 3'b011;
parameter unlockstate = 3'b100;
parameter lockstate = 3'b101;
parameter errorstate = 3'b110;
reg [2:0] ps,ns;
reg [1:0] attempterr;
always@(posedge clk or posedge rst) begin
if(rst) begin ps <= idle; attempterr = 0; end
else begin
ps <= ns;
if(ps == errorstate) attempterr = attempterr + 1;
else if (ps == unlockstate) attempterr = 0;
end
end
always@(*) begin
ns = ps;
locked = 1;
unlocked = 0;
case(ps)
idle : begin
if(datain == 1 && attempterr < 3)
ns = s1;
else
ns = errorstate;
end
s1 : begin
if(datain == 0 && attempterr < 3)
ns = s2;
else
ns = errorstate;
end
s2 : begin
if(datain == 1 && attempterr < 3)
ns = s3;
else
ns = errorstate;
end
s3 : begin
if(datain == 0 && attempterr < 3)
ns = unlockstate;
else
ns = errorstate;
end
unlockstate : begin
unlocked = 1;
locked = 0;
if (Enter)
ns = idle;
else
ns = unlockstate;
end
lockstate : begin
locked = 1;
unlocked = 0;
if(Enter)
ns = idle;
else
ns = errorstate;
end
endcase
end
endmodule