Software APIs
rv_dm_delayed_enable.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 "sw/device/lib/base/multibits.h"
10 #include "sw/device/lib/testing/lc_ctrl_testutils.h"
11 #include "sw/device/lib/testing/test_framework/check.h"
13 
15 
16 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);
17 
18 enum {
19  kRvDmEnableVal = kMultiBitBool32True,
20 
21  kDebugEnableDelayMicrosDvSim = 1000, // 1ms
22 
23  // For FPGA and silicon, we need to wait long enough for opentitantoolib to
24  // return an error when trying to perform an operation on the device when
25  // debug mode is not enabled.
26  kDebugEnableDelayMicrosDefault = 1000000, // 1s
27 };
28 
29 static dif_lc_ctrl_t lc_ctrl;
30 static dif_rv_dm_t rv_dm;
31 
32 bool test_main(void) {
33  CHECK_DIF_OK(dif_lc_ctrl_init(
35 
36  CHECK_DIF_OK(dif_rv_dm_init(
38 
39  dif_lc_ctrl_state_t state;
40  CHECK_DIF_OK(dif_lc_ctrl_get_state(&lc_ctrl, &state));
41  CHECK_STATUS_OK(lc_ctrl_testutils_lc_state_log(&state));
42 
43  if (state == kDifLcCtrlStateDev) {
44  bool is_locked;
45  CHECK_DIF_OK(dif_rv_dm_late_debug_is_locked(&rv_dm, &is_locked));
46 
47  // Until we add support for delayed enable to the ROM_EXT, we expect this
48  // feature to be unlocked.
49  CHECK(!is_locked);
50 
51  uint32_t delay_micros = kDebugEnableDelayMicrosDefault;
53  delay_micros = kDebugEnableDelayMicrosDvSim;
54  }
55 
57  LOG_INFO("DEBUG_MODE_DISABLED");
58  busy_spin_micros(delay_micros);
59 
60  // Enable debug mode. Report enablement via UART and busy spin again to
61  // allow the debugger to attach.
63 
64  // The following string is expected in host side of the test.
65  LOG_INFO("DEBUG_MODE_ENABLED");
66  busy_spin_micros(delay_micros);
67  }
68 
69  return true;
70 }