Software APIs
aon_timer_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_AON_TIMER_TESTUTILS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_AON_TIMER_TESTUTILS_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/lib/base/status.h"
12 
13 /**
14  * Compute the number of AON cycles corresponding to the given microseconds.
15  *
16  * @param aon_timer An Always-On Timer handle.
17  * @param microseconds The number of microseconds.
18  * @param[out] cycles The number of AON clock cycles as a uint32_t
19  * @return The result of the operation.
20  */
22 status_t aon_timer_testutils_get_aon_cycles_32_from_us(uint64_t microseconds,
23  uint32_t *cycles);
24 
25 /**
26  * Compute the number of AON cycles corresponding to the given microseconds.
27  *
28  * @param aon_timer An Always-On Timer handle.
29  * @param microseconds The number of microseconds.
30  * @param[out] cycles The number of AON clock cycles as a uint64_t
31  * @return The result of the operation.
32  */
34 status_t aon_timer_testutils_get_aon_cycles_64_from_us(uint64_t microseconds,
35  uint64_t *cycles);
36 
37 /**
38  * Compute the number of microseconds corresponding to the given AON cycles.
39  *
40  * @param aon_timer An Always-On Timer handle.
41  * @param cycles The number of AON clock cycles.
42  * @param[out] microseconds The number of microseconds.
43  * @return The result of the operation.
44  */
46 status_t aon_timer_testutils_get_us_from_aon_cycles(uint64_t cycles,
47  uint32_t *microseconds);
48 
49 /**
50  * Configure wakeup counter for a number of AON clock cycles.
51  *
52  * @param aon_timer An Always-On Timer handle.
53  * @param cycles The number of AON clock cycles.
54  * @return The result of the operation.
55  */
57 status_t aon_timer_testutils_wakeup_config(const dif_aon_timer_t *aon_timer,
58  uint64_t cycles);
59 
60 /**
61  * Configure watchdog counter in number of AON clock cycles.
62  *
63  * The watchdog counter is set without locking it, and configured so it doesn't
64  * pause for low power.
65  *
66  * @param aon_timer An Always-On Timer handle.
67  * @param bark_cycles The number of AON clock cycles till barking.
68  * @param bite_cycles The number of AON clock cycles till biting.
69  * @param pause_in_sleep Don't increment while sleeping.
70  * @return The result of the operation.
71  */
73 status_t aon_timer_testutils_watchdog_config(const dif_aon_timer_t *aon_timer,
74  uint32_t bark_cycles,
75  uint32_t bite_cycles,
76  bool pause_in_sleep);
77 
78 /**
79  * Turn off the AON timer peripheral.
80  *
81  * At the end of the simulation, stop the wakeup and watchdog timers so that
82  * the design stops generating events that may affect the simulation from
83  * terminating cleanly. The wakeup and watchdog timer controls are read back
84  * to ensure the written value successfully crossed the AON clock domain.
85  *
86  * @param aon_timer An Always-On Timer handle.
87  * @return The result of the operation.
88  */
90 status_t aon_timer_testutils_shutdown(const dif_aon_timer_t *aon_timer);
91 
92 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_AON_TIMER_TESTUTILS_H_