forked from lowRISC/opentitan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dif_aon_timer.h
209 lines (187 loc) · 6.89 KB
/
dif_aon_timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_DIF_AON_TIMER_H_
#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_AON_TIMER_H_
/**
* @file
* @brief <a href="/hw/ip/aon_timer/doc/">Always-On Timer</a> Device Interface
* Functions
*/
#include <stdbool.h>
#include <stdint.h>
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_base.h"
#include "sw/device/lib/dif/autogen/dif_aon_timer_autogen.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* Starts Always-On Timer (wake-up timer).
*
* This operation starts the wake-up timer with the provided configuration.
* Note that the timer is stopped and counter cleared, before the timer is
* started with the new configuration.
*
* @param aon An Always-On Timer handle.
* @param threshold Threshold in ticks.
* @param prescaler 12 bit pre-scaler to enable very long timeouts (one tick
* every N + 1 clock cycles, where N is the pre-scaler value).
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_wakeup_start(const dif_aon_timer_t *aon,
uint64_t threshold, uint32_t prescaler);
/** Stops Always-On Timer (wake-up timer).
*
* Stops the timer. Configuration is not touched, and can be restarted via
* `dif_aon_timer_wakeup_restart`.
*
* @param aon An Always-On Timer handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_wakeup_stop(const dif_aon_timer_t *aon);
/** Restarts Always-On Timer (wake-up timer).
*
* Clears the counter and restarts the timer using the existing configuration.
*
* @param aon An Always-On Timer handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_wakeup_restart(const dif_aon_timer_t *aon);
/**
* Checks whether this Always-On Timer (wake-up timer) is enabled.
*
* @param aon An Always-On Timer handle.
* @param[out] is_enabled Out-param for the enabled state.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_wakeup_is_enabled(const dif_aon_timer_t *aon,
bool *is_enabled);
/**
* Gets the wakeup cause.
*
* @param aon An Always-On Timer handle.
* @param[out] cause The current cause state.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_get_wakeup_cause(const dif_aon_timer_t *aon,
bool *cause);
/** Clear Always-On Timer wakeup cause
*
* Clears WKUP_CAUSE register
*
* @param aon An Always-On Timer handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_clear_wakeup_cause(const dif_aon_timer_t *aon);
/** Retrieves Always-On Timer (wake-up timer) tick count.
*
* @param aon An Always-On Timer handle.
* @param[out] count Current timer tick count.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_wakeup_get_count(const dif_aon_timer_t *aon,
uint64_t *count);
/** Starts Always-On Timer (watchdog timer).
*
* This operation starts the watchdog timer with the provided configuration.
* Note that the timer is stopped and counter cleared, before the timer is
* started with the new configuration.
*
* @param aon An Always-On Timer handle.
* @param bark_threshold "Bark" threshold in ticks.
* @param bite_threshold "Bite" threshold in ticks.
* @param pause_in_sleep Watchdog is paused when device is in one of the low
* power modes.
* @param lock Lock access to watchdog configuration registers.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_start(const dif_aon_timer_t *aon,
uint32_t bark_threshold,
uint32_t bite_threshold,
bool pause_in_sleep, bool lock);
/** Stops Always-On Timer (watchdog timer).
*
* Stops the timer. Configuration is not touched, and can be restarted via
* `dif_aon_timer_watchdog_restart`.
*
* @param aon An Always-On Timer handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_stop(const dif_aon_timer_t *aon);
/** Restarts Always-On Timer (watchdog timer).
*
* Clears the counter and restarts the timer using the existing configuration.
*
* @param aon An Always-On Timer handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_restart(const dif_aon_timer_t *aon);
/**
* Checks whether this Always-On Timer (watchdog timer) is enabled.
*
* @param aon An Always-On Timer handle.
* @param[out] is_enabled Out-param for the enabled state.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_is_enabled(const dif_aon_timer_t *aon,
bool *is_enabled);
/** Retrieves Always-On Timer (watchdog timer) tick count.
*
* @param aon An Always-On Timer handle.
* @param[out] count Current timer tick count.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_get_count(const dif_aon_timer_t *aon,
uint32_t *count);
/** Clears Always-On Timer (watchdog timer).
*
* This function must be called periodically to satisfy "Bite" and "Bark"
* thresholds. The semantics of this function are similar to
* `dif_aon_timer_watchdog_restart`, however it does not write to the control
* register, and is guaranteed to succeed even when the watchdog is locked.
*
* @param aon An Always-On Timer handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_pet(const dif_aon_timer_t *aon);
/**
* Locks Always-On Timer (watchdog timer).
*
* The watchdog configuration will be locked until the next reset. This means
* that this timer cannot be stopped, restarted or reconfigured, however the
* count can be cleared via `dif_aon_timer_watchdog_pet`.
*
* @param aon An Always-On Timer handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_lock(const dif_aon_timer_t *aon);
/**
* Checks whether this Always-On Timer (watchdog timer) is locked.
*
* @param aon An Always-On Timer handle.
* @param[out] is_locked Out-param for the locked state.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_watchdog_is_locked(const dif_aon_timer_t *aon,
bool *is_locked);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_AON_TIMER_H_