Software APIs
pwrmgr_sleep_resets_lib.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_TESTS_PWRMGR_SLEEP_RESETS_LIB_H_
6 #define OPENTITAN_SW_DEVICE_TESTS_PWRMGR_SLEEP_RESETS_LIB_H_
7 
8 #include <stdint.h>
9 
14 
15 /**
16  * Some shared times in microsconds.
17  *
18  * Program the alert handler to escalate on alerts upto phase 2 (i.e. reset) but
19  * the phase 1 (i.e. wipe secrets) should occur and last during the time the
20  * wdog is programed to bark.
21  *
22  * Notice these settings are suitable for sim_dv. For some other platforms
23  * they are uniformly rescaled.
24  */
25 typedef enum pwmgr_sleep_resets_lib_times {
26  kWdogBarkMicros = 3 * 100, // 300 us
27  kWdogBiteMicros = 4 * 100, // 400 us
28  kEscalationPhase0Micros = 1 * 100, // 100 us
29  // The cpu value is slightly larger to avoid flakey results.
30  kEscalationPhase0MicrosCpu = kEscalationPhase0Micros + 20, // 120 us
31  kEscalationPhase1Micros = 5 * 100, // 500 us
32  kEscalationPhase2Micros = 50, // 50 us
33  // Allow a long wait before the reset is received, since the host needs
34  // to read and parse the log message before it changes the pin values.
35  kWaitWhileActiveMicros = 500000, // 500 ms
36 } pwmgr_sleep_resets_lib_times_t;
37 
38 /**
39  * The modes of the tests using this library.
40  */
41 typedef enum pwrmgr_sleep_resets_lib_modes {
42  /**
43  * Deep sleep mode.
44  */
45  kPwrmgrSleepResetsLibModesDeepSleep = 1,
46 
47  /**
48  * Normal sleep mode.
49  */
50  kPwrmgrSleepResetsLibModesNormalSleep = 2,
51 
52  /**
53  * Active mode (no sleep).
54  */
55  kPwrmgrSleepResetsLibModesActive = 3
56 } pwrmgr_sleep_resets_lib_modes_t;
57 
58 /**
59  * Objects to access the peripherals used in this test via dif API.
60  */
61 extern dif_flash_ctrl_state_t *flash_ctrl;
62 extern dif_rv_plic_t *plic;
63 extern dif_rstmgr_t *rstmgr;
64 
65 /**
66  * Initialize the peripherals used in this test.
67  */
68 void init_peripherals(void);
69 
70 /**
71  * Program the alert handler to escalate on alerts upto phase 2 (i.e. reset) but
72  * the phase 1 (i.e. wipe secrets) should occur and last during the time the
73  * wdog is programed to bark.
74  */
75 void config_alert_handler(void);
76 
77 /**
78  * Configure the sysrst to trigger a reset with a combo triggered by key0,
79  * and enable it as a reset source. The pinmux configures pad_pin to connect
80  * to key0.
81  */
82 void config_sysrst(dif_pinmux_index_t pad_pin);
83 
84 /**
85  * Configure the wdog cycle counts and enable it as a reset source.
86  * Enabling it as reset source needs a domain crossing to the aon domain,
87  * so it consumes up to 10 us.
88  */
89 void config_wdog(uint64_t bark_micros, uint64_t bite_micros);
90 
91 /**
92  * Trigger escalation together with a watchdog.
93  *
94  * The watchdog is expected to have no effect when escalation is triggered.
95  */
96 void trigger_escalation(void);
97 
98 /**
99  * Prepare for watchdog reset.
100  *
101  * Enable watchdog reset, and spin wait or enter either normal or deep sleep.
102  */
103 void prepare_for_wdog(pwrmgr_sleep_resets_lib_modes_t mode);
104 
105 /**
106  * Prepare for sysrst reset.
107  *
108  * Enable sysrst reset, and spin wait or enter either normal or deep sleep .
109  */
110 void prepare_for_sysrst(pwrmgr_sleep_resets_lib_modes_t mode);
111 
112 /**
113  * External ISR.
114  *
115  * Handles all peripheral interrupts expected for these tests. It expects
116  * no barks from aon_timer, and phase 0 interrupts from the alert handler.
117  */
118 void ottf_external_isr(uint32_t *exc_info);
119 
120 #endif // OPENTITAN_SW_DEVICE_TESTS_PWRMGR_SLEEP_RESETS_LIB_H_