-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsd_resp_rx.v
85 lines (82 loc) · 3.14 KB
/
sd_resp_rx.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
75
76
77
78
79
80
81
82
83
84
85
module sd_resp_rx(clk, reset, en, R2_response, sd_cmd, response, finished, started);
input clk, reset, en, sd_cmd, R2_response;
output reg [133:1] response;
output reg finished, started;
reg [7:0] index;
always @(posedge clk, posedge reset) begin
if (reset) begin
response <= 132'b0;
index <= 8'b0;
finished <= 1'b0;
started <= 1'b0;
end
else begin
// process bits if enabled
if (en) begin
// // wait until sending
// if (sd_cmd === 1'bz) begin
// response <= response;
// index <= index;
// finished <= 1'b0;
// started <= 1'b0;
// end
// process start bit
if (sd_cmd == 1'b0 && index == 8'd0) begin
response <= 132'b0; // reset response
index <= 8'd134;
finished <= 1'b0;
started <= 1'b1;
end
// process transmission bit
else if (sd_cmd == 1'b0 && index == 8'd134) begin
response <= response; // don't add transmission bit
index <= index - 1'b1;
finished <= 1'b0;
started <= 1'b1;
end
else begin
if (R2_response) begin
// process stop bit
if (sd_cmd == 1'b1 && index == 8'd0) begin
response <= response;
index <= 8'd0;
finished <= 1'b1;
started <= 1'b1;
end
// process internal data
else begin
response[index] <= sd_cmd;
index <= index - 1'b1;
finished <= 1'b0;
started <= 1'b1;
end
end
// not R2 response
else begin
// process stop bit
if (sd_cmd == 1'b1 && index == 8'd87) begin
response <= response;
index <= 8'd0;
finished <= 1'b1;
started <= 1'b1;
end
// process internal data
else begin
response[index] <= sd_cmd;
index <= index - 1'b1;
finished <= 1'b0;
started <= 1'b1;
end
end
end
end
// not enabled
else begin
response <= response;
index <= index;
finished <= 1'b0;
started <= 1'b0;
end
end
end
endmodule