Software APIs
rv_dm_access_after_hw_reset.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 
6 #include "sw/device/lib/testing/rstmgr_testutils.h"
7 #include "sw/device/lib/testing/test_framework/check.h"
9 #include "sw/device/lib/testing/test_framework/ottf_utils.h"
10 
12 
13 /*
14  - Wait for host to perform debugger tests
15  - Once the host side confirms, do a SW reset of the chip
16  - Print a message to confirm reset to host
17  - Host will attach debugger and perform additional checks
18  */
19 
20 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);
21 
22 static volatile uint8_t kReset = 0;
23 
24 enum {
25  kTestTimeoutMicros = 1000000, // 1 second
26 };
27 
28 static dif_rstmgr_t rstmgr;
29 
30 /**
31  * Resets the chip.
32  */
33 static void chip_sw_reset(void) {
34  CHECK_DIF_OK(dif_rstmgr_software_device_reset(&rstmgr));
35  busy_spin_micros(100);
36  CHECK(false, "Should have reset before this line");
37 }
38 
39 bool test_main(void) {
40  CHECK_DIF_OK(dif_rstmgr_init(
42 
43  // Check if there was a HW reset caused by the software.
45  rst_info = rstmgr_testutils_reason_get();
46  rstmgr_testutils_reason_clear();
47 
48  if (rst_info & kDifRstmgrResetInfoPor) {
49  LOG_INFO("Waiting for commands");
50  OTTF_WAIT_FOR(kReset != 0, kTestTimeoutMicros);
51 
52  chip_sw_reset();
53  return false;
54 
55  } else if (rst_info & kDifRstmgrResetInfoSw) {
56  LOG_INFO("Reset complete");
57  return true;
58 
59  } else {
60  LOG_ERROR("Unexpected reset info %d", rst_info);
61  }
62 
63  return false;
64 }