Software APIs
pwrmgr_main_power_glitch_test.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
8 #include "sw/device/lib/testing/rstmgr_testutils.h"
9 #include "sw/device/lib/testing/test_framework/check.h"
11 
13 
14 OTTF_DEFINE_TEST_CONFIG();
15 
16 // When the test first runs the rstmgr's `reset_info` CSR should have the POR
17 // bit set, the code clears reset_info and calls wait_for_interrupt(). The WFI
18 // causes core_sleeping to rise, and that causes the SV side to glitch the main
19 // power rail, causing a pwrmgr internally generated reset. The next time the
20 // test runs is after the power glitch reset, which is confirmed reading the
21 // `reset_info` CSR.
22 bool test_main(void) {
23  dif_rstmgr_t rstmgr;
24 
25  // Initialize rstmgr since this will check some registers.
26  CHECK_DIF_OK(dif_rstmgr_init(
28 
29  // Notice we are clearing rstmgr's RESET_INFO, so after the power glitch there
30  // is only one bit set.
31 
32  if (UNWRAP(rstmgr_testutils_is_reset_info(&rstmgr, kDifRstmgrResetInfoPor))) {
33  LOG_INFO("Powered up for the first time, begin test");
34 
35  CHECK_STATUS_OK(rstmgr_testutils_pre_reset(&rstmgr));
36 
37  // This causes core_sleeping to rise and triggers the injection of the
38  // power glitch. Notice it does not by itself trigger a low power
39  // transition.
41 
42  } else {
43  LOG_INFO("Checking reset status.");
44  CHECK_STATUS_OK(rstmgr_testutils_post_reset(
45  &rstmgr, kDifRstmgrResetInfoPowerUnstable, 0, 0, 0, 0));
46  LOG_INFO("Reset status indicates a main power glitch reset");
47  }
48  return true;
49 }