Software APIs
lc_ctrl_testutils.h
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#ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_LC_CTRL_TESTUTILS_H_
6#define OPENTITAN_SW_DEVICE_LIB_TESTING_LC_CTRL_TESTUTILS_H_
7
8#include <stdbool.h>
9
10#include "sw/device/lib/base/status.h"
12
13/**
14 * Print current life cycle state to the console.
15 *
16 * Reads the life cycle state register and prints the life cycle state as a
17 * human readable string. The function errors out in locked/invalid life
18 * cycle states where the CPU should not be executing code.
19 */
21status_t lc_ctrl_testutils_lc_state_log(const dif_lc_ctrl_state_t *state);
22
23/**
24 * Checks whether Lifecycle Controller state has debug functions enabled.
25 *
26 * There could be implications for tests with debug functions enabled. For
27 * example, SRAM code execution is enabled when Lifecycle Controller is
28 * in one of these states and OTP_IFETCH is disabled.
29 */
31status_t lc_ctrl_testutils_debug_func_enabled(const dif_lc_ctrl_t *lc_ctrl,
32 bool *debug_enabled);
33
34/**
35 * Check if Lifecycle Controller count number is expected.
36 *
37 * This function will read out lc_transition_cnt register and check the value
38 * against exp_lc_count value.
39 */
41status_t lc_ctrl_testutils_check_transition_count(const dif_lc_ctrl_t *lc_ctrl,
42 uint8_t exp_lc_count);
43
44/**
45 * Check if Lifecycle Controller current state is expected.
46 *
47 * This function will read out lc_state register and check the value
48 * against exp_lc_state value.
49 */
51status_t lc_ctrl_testutils_check_lc_state(const dif_lc_ctrl_t *lc_ctrl,
52 dif_lc_ctrl_state_t exp_lc_state);
53
54/**
55 * Checks the device life cycle state to determine if it is in operational
56 * state.
57 *
58 * @param lc_ctrl Life cycle controller instance.
59 * @return OK_STATUS if the device is in PROD, PROD_END or DEV state; otherwise
60 * FAILED_PRECONDITION.
61 */
63status_t lc_ctrl_testutils_operational_state_check(
64 const dif_lc_ctrl_t *lc_ctrl);
65
66#endif // OPENTITAN_SW_DEVICE_LIB_TESTING_LC_CTRL_TESTUTILS_H_