Software APIs
reset_reasons_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 
5 #include <stdbool.h>
6 
8 #include "sw/device/silicon_creator/lib/drivers/rstmgr.h"
9 #include "sw/device/silicon_creator/lib/manifest_def.h"
10 
11 OTTF_DEFINE_TEST_CONFIG();
12 
13 enum {
14  kPor = 1 << kRstmgrReasonPowerOn,
15  kSwReset = 1 << kRstmgrReasonSoftwareRequest,
16 };
17 
18 bool test_main(void) {
19  uint32_t reasons = rstmgr_reason_get();
20  LOG_INFO("reset_reasons = %08x", reasons);
21  if (reasons == kPor) {
22  // If the reasons are only POR, then reset to accumulate reasons and
23  // re-enter the test program.
24  rstmgr_reset();
25  } else if (reasons == (kPor | kSwReset)) {
26  // If the reasons are exactly POR|SW, then we're in the second iteration of
27  // this test and the ROM did not clear the reset reason (as instructed by
28  // OTP).
29  return true;
30  }
31  return false;
32 }