Software APIs
watchdog.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_SILICON_CREATOR_LIB_DRIVERS_WATCHDOG_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_WATCHDOG_H_
7 
8 #include <stdint.h>
9 
11 #include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * The following constants represent the expected number of sec_mmio register
19  * writes performed by functions in provided in this module. See
20  * `SEC_MMIO_WRITE_INCREMENT()` for more details.
21  *
22  * Example:
23  * ```
24  * watchdog_init(lc);
25  * SEC_MMIO_WRITE_INCREMENT(kWatchdogSecMmioInit);
26  * ```
27  */
28 enum {
29  kWatchdogSecMmioInit = 4,
30  kWatchdogSecMmioConfigure = 4,
31  kWatchdogSecMmioDisable = 1,
32 };
33 
34 /**
35  * Minimum watchdog threshold. Watchdog will not be enabled if the value in the
36  * OTP is less than this value.
37  */
38 enum {
39  kWatchdogMinThreshold = 1,
40 };
41 
42 /**
43  * Initialize the watchdog timer.
44  *
45  * The watchdog bite threshold will be initialized to a value determined by
46  * the lifecycle state and OTP configuration.
47  *
48  * @param lc_state Current lifecycle state.
49  */
50 void watchdog_init(lifecycle_state_t lc_state);
51 
52 /**
53  * Watchdog configuration.
54  */
55 typedef struct watchdog_config {
56  /**
57  * Bark threshold value in cycles.
58  */
59  uint32_t bark_threshold;
60  /**
61  * Bite threshold value in cycles.
62  */
63  uint32_t bite_threshold;
64  /**
65  * Whether or not to enable the watchdog timer after it is configured.
66  */
69 
70 /**
71  * Configure the watchdog timer with given bite threshold.
72  *
73  * This operation will set the counter value to 0.
74  *
75  * @param config Watchdog configuration.
76  */
77 void watchdog_configure(watchdog_config_t config);
78 
79 /**
80  * Disable the watchdog.
81  *
82  * This will prevent the watchdog from triggering and resetting the chip.
83  */
84 void watchdog_disable(void);
85 
86 /**
87  * Pet the watchdog, thus preventing a watchdog initiated reset.
88  */
89 void watchdog_pet(void);
90 
91 /**
92  * Get the current watchdog counter value.
93  *
94  * @return current watchdog value.
95  */
97 uint32_t watchdog_get(void);
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_WATCHDOG_H_