Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignition: Make (reset) button acts as power button when system power off #101

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions hdl/ignition/IgnitionTarget.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface Target;
method Bool system_power_request_in_progress();
method Bool system_power_off_in_progress();
method Bool system_power_on_in_progress();
method Bool system_power_aborted();
endinterface

typedef enum {
Expand Down Expand Up @@ -494,11 +495,13 @@ module mkTarget #(Parameters parameters) (Target);
initialized &&
button_pressed &&
!request_in_progress);
// If a system power abort happened, issue a power on request
// rather than a system reset request.
let request_ = system_power_abort ?
SystemPowerOn :
SystemReset;
// If the system is powered off, act as a power button rather
// than a reset button. The system power transition logic will
// clear the abort flag is this power off was in response to a
// system power fault/abort.
let request_ = system_power_off ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual change is here. The remaining fluff is to make the tests work.

SystemPowerOn :
SystemReset;

reset_button_released <= False;
request.wset(request_);
Expand Down Expand Up @@ -705,6 +708,7 @@ module mkTarget #(Parameters parameters) (Target);
method system_power_request_in_progress = request_in_progress;
method system_power_off_in_progress = system_powering_off;
method system_power_on_in_progress = system_powering_on;
method system_power_aborted = system_power_abort;
endmodule

endpackage: IgnitionTarget
1 change: 1 addition & 0 deletions hdl/ignition/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ bluesim_tests('TargetTests',
'mkSystemResetRequestTest',
'mkSystemResetShortButtonPressTest',
'mkSystemResetLongButtonPressTest',
'mkSystemPowerOnWhenResetButtonPressTest',
'mkSystemPowerAbortOnA2FaultTest',
'mkSystemPowerAbortOnA3FaultTest',
'mkSystemPowerAbortOnA3FaultTimeoutTest',
Expand Down
18 changes: 12 additions & 6 deletions hdl/ignition/test/TargetBench.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface TargetBench;
method Action await_ticks_elapsed(Integer n);
method Action pet_watchdog();

method Action await_system_power_request_complete();
method Action await_system_power_off_complete();
method Stmt await_system_power_request_complete();
method Stmt await_system_power_off_complete();
method Stmt assert_system_powering_on(LinkStatus expected_link0_status);
endinterface

Expand Down Expand Up @@ -83,11 +83,17 @@ module mkTargetBench #(
await(ticks_elapsed_ >= fromInteger(tick_duration * n));
method pet_watchdog = wd.send;

method Action await_system_power_request_complete() =
await(!_target.system_power_request_in_progress);
method Stmt await_system_power_request_complete() =
seq
await(_target.system_power_request_in_progress);
await(!_target.system_power_request_in_progress);
endseq;

method Action await_system_power_off_complete() =
await(!_target.system_power_off_in_progress);
method Stmt await_system_power_off_complete() =
seq
await(_target.system_power_request_in_progress);
await(!_target.system_power_off_in_progress);
endseq;

method Stmt assert_system_powering_on(LinkStatus expected_link0_status) =
seq
Expand Down
51 changes: 45 additions & 6 deletions hdl/ignition/test/TargetTests.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,44 @@ module mkSystemResetLongButtonPressTest (Empty);
endseq);
endmodule

// Test that the system powers on when the system is powered off and the (reset)
// button is pressed.
module mkSystemPowerOnWhenResetButtonPressTest (Empty);
TargetBench bench <- mkTargetBench(
parameters,
4 * parameters.system_power_toggle_cool_down);

let tx = tpl_2(bench.link.message);

mkAutoFSM(seq
assert_eq(
parameters.button_behavior,
ResetButton,
"expected Target configured with reset button");
// Assert that the system initially powers on.
bench.link.set_connected(False, True);
bench.await_system_power_request_complete();
assert_eq(bench.target.system_power, On, "expected system power on");

// Send Hello's and wait for the controller to be marked present.
repeat(3) tx.put(tagged Hello);
repeat(2) bench.await_tick();

// Send a SystemPowerOff request and wait for the request to complete.
tx.put(tagged Request SystemPowerOff);
bench.await_system_power_request_complete();
assert_eq(bench.target.system_power, Off, "expected system power off");

// Press the (reset) button and assert the system powered on.
bench.target.button_event(True);
bench.target.button_event(False);
bench.await_system_power_request_complete();
assert_eq(
bench.target.system_power, On,
"expected system power on");
endseq);
endmodule

module mkSystemPowerAbortOnA2FaultTest (Empty);
TargetBench bench <- mkTargetBench(
parameters,
Expand Down Expand Up @@ -670,22 +708,23 @@ module mkPowerButtonRestartAfterSystemPowerAbortTest (Empty);

TargetBench bench <- mkTargetBench(
parameters_,
4 * parameters.system_power_toggle_cool_down);
4 * parameters_.system_power_toggle_cool_down);

mkAutoFSM(seq
// Set an A2 power fault while a system powers on, triggering an
// emergency power off.
bench.set_faults(system_faults_power_a2);
bench.link.set_connected(False, True);
bench.target.button_event(True);

bench.await_system_power_request_complete();
assert_eq(bench.target.system_power, Off, "expected system power off");
assert_true(
bench.target.system_power_aborted,
"expected system power abort");

// Resolve A2 power fault.
// Resolve A2 power fault and press the button again.
bench.set_faults(system_faults_none);

// Press the button.
bench.target.button_event(True);
bench.target.button_event(False);

bench.await_system_power_request_complete();
assert_eq(
Expand Down