-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtarget_control_reset.sv
63 lines (49 loc) · 1.26 KB
/
target_control_reset.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Target control module: RESET
* Simply controls the target's reset input
*/
module target_control_reset(
input rst,
input clk,
input trigger, // High to reset target device
output reg target_reset
);
// Cycles of the fast clock.
// At 48MHz, 10ms is 480000 cycles
parameter RESET_CYCLES=480000;
// 1 means "high to reset target"
// 0 means "low to reset target"
parameter ACTIVE_HIGH=1;
// IDLE has the device powered up
// DRAINING has power pin floating
// LOW has power pin forced to ground
// GUARDING has power pin floating
enum reg [1:0] { IDLE, RESETTING } state;
reg [31:0] elapsed_cycles;
always @(posedge clk) begin
if (rst) begin
// Start in the floating state, counting down to power up the target device
state <= IDLE;
elapsed_cycles <= 0;
target_reset <= !ACTIVE_HIGH;
end
else begin
if (state != IDLE) begin
elapsed_cycles <= elapsed_cycles + 1;
end
if (state == IDLE) begin
if (trigger) begin
state <= RESETTING;
elapsed_cycles <= 1;
target_reset <= ACTIVE_HIGH;
end
end
else if (state == RESETTING) begin
if (elapsed_cycles >= RESET_CYCLES) begin
state <= IDLE;
target_reset <= !ACTIVE_HIGH;
end
end
end
end
endmodule