-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjoy_control.v
executable file
·68 lines (60 loc) · 1.05 KB
/
joy_control.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
// When sndRec is 1, gets 5 bytes from joy_interface and outputs them in DOUT
module joy_control(
input CLK,
input sndRec,
input BUSY,
input [7:0] RxData,
output SS,
output reg getByte,
output reg [39:0] DOUT
);
reg SS = 1;
reg [2:0] pState = 0;
reg [2:0] byteCnt = 0;
reg [39:0] tmpSR = 0;
always @(negedge CLK)
begin
case(pState)
// Idle
0 : begin
SS <= 1;
getByte <= 0;
tmpSR <= 0;
byteCnt <= 0;
pState <= sndRec ? 1 : 0;
end
// Init
1 : begin
SS <= 0;
getByte <= 1;
if(BUSY)
begin
pState <= 2;
byteCnt <= byteCnt + 1;
end
else
pState <= 1;
end
// Wait
2 : begin
SS <= 0;
getByte <= 0;
pState <= BUSY ? 2 : 3;
end
// Check
3 : begin
SS <= 0;
getByte <= 0;
tmpSR <= {tmpSR[31:0], RxData};
pState <= byteCnt == 5 ? 4 : 1;
end
// Done
4 : begin
SS <= 1;
getByte <= 0;
DOUT[39:0] <= tmpSR[39:0];
pState <= sndRec ? 4 : 0;
end
endcase
end
endmodule