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