Software APIs
dif_clkmgr.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_CLKMGR_H_
6 #define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_CLKMGR_H_
7 
8 /**
9  * @file
10  * @brief <a href="/hw/top_earlgrey/ip_autogen/clkmgr/doc/">Clock Manager</a>
11  * Device Interface Functions
12  */
13 
14 #include <stdint.h>
15 
19 
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif // __cplusplus
25 
26 /**
27  * An Index of a "Gateable" Clock.
28  *
29  * "Gateable" clocks are under full software control: they can be enabled and
30  * disabled by software, which directly starts and stops the identified clock.
31  */
32 typedef uint32_t dif_clkmgr_gateable_clock_t;
33 
34 /**
35  * An Index of a "Hintable" Clock.
36  *
37  * "Hintable" clocks are under partial software control: software can suggest
38  * they are stopped, but the clock manager may delay stopping the peripheral, or
39  * may ignore the request altogether.
40  */
41 typedef uint32_t dif_clkmgr_hintable_clock_t;
42 
44  /**
45  * The Io clock.
46  */
48  /**
49  * The Io_div2 clock.
50  */
52  /**
53  * The Io div4 clock.
54  */
56  /**
57  * The Main clock.
58  */
60  /**
61  * The Usb clock.
62  */
64 } dif_clkmgr_measure_clock_t;
65 
67  /**
68  * A recoverable update error for one of the clocks.
69  */
71  /**
72  * A recoverable measurement error for IO clock.
73  */
75  /**
76  * A recoverable measurement error for IO_DIV2 clock.
77  */
79  /**
80  * A recoverable measurement error for IO_DIV4 clock.
81  */
83  /**
84  * A recoverable measurement error for MAIN clock.
85  */
87  /**
88  * A recoverable measurement error for USB clock.
89  */
91  /**
92  * A recoverable timeout error for IO clock.
93  */
95  /**
96  * A recoverable timeout error for IO_DIV2 clock.
97  */
99  /**
100  * A recoverable timeout error for IO_DIV4 clock.
101  */
103  /**
104  * A recoverable timeout error for MAIN clock.
105  */
107  /**
108  * A recoverable timeout error for USB clock.
109  */
111 } dif_clkmgr_recov_err_type_t;
112 
113 /**
114  * A set of recoverable errors.
115  *
116  * This type is used to clear and read the recoverable error codes.
117  */
119 
121  /**
122  * A fatal error for regfile integrity.
123  */
125  /**
126  * A fatal error for a duplicate idle counter.
127  */
129  /**
130  * A fatal error for a shadow register storage.
131  */
133 } dif_clkmgr_fatal_err_type_t;
134 
135 /**
136  * A set of fatal errors.
137  *
138  * This type is used to read the fatal error codes.
139  */
141 
142 /**
143  * Check if jitter is Enabled.
144  * @param clkmgr Clock Manager Handle.
145  * @param[out] is_enabled whether jitter is enabled or not.
146  * @returns The result of the operation.
147  */
150  dif_toggle_t *state);
151 
152 /**
153  * Enable of Disable jitter.
154  * @param clkmgr Clock Manager Handle.
155  * @param new_state whether to enable or disable jitter.
156  * @returns The result of the operation.
157  */
160  dif_toggle_t new_state);
161 
162 /**
163  * Check if a Gateable Clock is Enabled or Disabled.
164  *
165  * @param clkmgr Clock Manager Handle.
166  * @param clock Gateable Clock ID.
167  * @param[out] is_enabled whether the clock is enabled or not.
168  * @returns The result of the operation.
169  */
172  const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock,
173  dif_toggle_t *state);
174 
175 /**
176  * Enable or Disable a Gateable Clock.
177  *
178  * @param clkmgr Clock Manager Handle.
179  * @param clock Gateable Clock ID.
180  * @param new_state whether to enable or disable the clock.
181  * @returns The result of the operation.
182  */
185  const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock,
186  dif_toggle_t new_state);
187 
188 /**
189  * Check if a Hintable Clock is Enabled or Disabled.
190  *
191  * Hintable clocks are not under full software control, but this operation
192  * accurately reflects the state of the current clock, regardless of any hint
193  * requests made by software.
194  *
195  * To read what hint the software has given the hardware, use
196  * #dif_clkmgr_hintable_clock_get_hint.
197  *
198  * @param clkmgr Clock Manager Handle.
199  * @param clock Hintable Clock ID.
200  * @param[out] is_enabled whether the clock is enabled or not.
201  * @returns The result of the operation.
202  */
205  const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock,
206  dif_toggle_t *state);
207 
208 /**
209  * Enable or Disable a Hintable Clock.
210  *
211  * This only sets a hint that the clock should be enabled or disabled. The clock
212  * manager is in control of whether the clock should actually be enabled or
213  * disabled.
214  *
215  * To read what hint the software has given the hardware, use
216  * #dif_clkmgr_hintable_clock_get_hint. To read whether the clock is currently
217  * enabled or disabled, use #dif_clkmgr_hintable_clock_get_enabled.
218  *
219  * @param clkmgr Clock Manager Handle.
220  * @param clock Hintable Clock ID.
221  * @param new_state whether to enable or disable the clock.
222  * @returns The result of the operation.
223  */
226  const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock,
227  dif_toggle_t new_state);
228 
229 /**
230  * Read the current Hint for a Hintable Clock.
231  *
232  * Hintable clocks are not under full software control; this operation
233  * accurately reflects the current software hint, not the current state of the
234  * clock.
235  *
236  * To read whether the clock is currently enabled or disabled, use
237  * #dif_clkmgr_hintable_clock_get_enabled.
238  *
239  * @param clkmgr Clock Manager Handle.
240  * @param clock Hintable Clock ID.
241  * @param[out] hinted_is_enabled the current software request (hint) for this
242  * clock.
243  * @returns The result of the operation.
244  */
247  const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock,
248  dif_toggle_t *state);
249 
250 /**
251  * Enable chip to use the external clock.
252  *
253  * @param clkmgr Clock Manager Handle.
254  * @param is_low_speed External clock is low speed or high speed.
255  * @returns The result of the operation.
256  * High speed - external clock is close to nominal speeds (e.g. external clock
257  * is 96MHz and nominal frequency is 96MHz-100MHz). Low speed - external clock
258  * is half of nominal speeds (e.g. external clock is 48MHz and nominal frequency
259  * is 96MHz-100MHz).
260  *
261  */
264  bool is_low_speed);
265 
266 /**
267  * Disable chip to use the external clock.
268  *
269  * @param clkmgr Clock Manager Handle.
270  * @returns The result of the operation.
271  */
274 
275 /**
276  * Determine if the transition to using external clock is complete.
277  *
278  * @param clkmgr Clock Manager Handle.
279  * @param[out] status Set to true if the transition is complete.
280  * @returns The result of the operation once it completes.
281  */
284  bool *status);
285 
286 /**
287  * Disable measurement control updates.
288  *
289  * This can only be disabled, and stays disabled until the next POR.
290  *
291  * @param clkmgr Clock Manager Handle.
292  * @returns The result of the operation.
293  */
296 
297 /**
298  * Get measurement control state.
299  *
300  * @param clkmgr Clock Manager Handle.
301  * @param[out] state The state of control enable.
302  * @returns The result of the operation.
303  */
306  dif_toggle_t *state);
307 
308 /**
309  * Configure count measurements.
310  *
311  * @param clkmgr Clock Manager Handle.
312  * @param clock A clock to be measured.
313  * @param min_threshold The smallest permissible cycle count.
314  * @param max_threshold The largest permissible cycle count.
315  * @returns The result of the operation.
316  */
319  dif_clkmgr_measure_clock_t clock,
320  uint32_t min_threshold,
321  uint32_t max_threshold);
322 
323 /**
324  * Disable count measurements.
325  *
326  * Does not modify the thresholds.
327  *
328  * @param clkmgr Clock Manager Handle.
329  * @param clock A clock to be measured.
330  * @returns The result of the operation.
331  */
334  const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock);
335 
336 /**
337  * Get the count measurement enable.
338  *
339  * @param clkmgr Clock Manager Handle.
340  * @param clock A clock to be measured.
341  * @param[out] state The state of control enable.
342  * @returns The result of the operation.
343  */
346  const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock,
347  dif_toggle_t *state);
348 
349 /**
350  * Get the count measurement thresholds.
351  *
352  * @param clkmgr Clock Manager Handle.
353  * @param clock A clock to be measured.
354  * @param[out] min_threshold The minumum threshold.
355  * @param[out] max_threshold The maximum threshold.
356  * @returns The result of the operation.
357  */
360  const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock,
361  uint32_t *min_threshold, uint32_t *max_threshold);
362 
363 /**
364  * Read the recoverable error codes.
365  *
366  * @param clkmgr Clock Manager Handle.
367  * @param[out] codes The recoverable error codes.
368  * @returns The result of the operation.
369  */
372  const dif_clkmgr_t *clkmgr, dif_clkmgr_recov_err_codes_t *codes);
373 
374 /**
375  * Clear selected recoverable error codes.
376  *
377  * @param clkmgr Clock Manager Handle.
378  * @param codes The recoverable error codes to be cleared.
379  * @returns The result of the operation.
380  */
383  const dif_clkmgr_t *clkmgr, dif_clkmgr_recov_err_codes_t codes);
384 
385 /**
386  * Read the fatal error codes.
387  *
388  * @param clkmgr Clock Manager Handle.
389  * @param[out] codes The fatal error codes.
390  * @returns The result of the operation.
391  */
394  const dif_clkmgr_t *clkmgr, dif_clkmgr_fatal_err_codes_t *codes);
395 
396 /**
397  * Wait for external clock switch to finish.
398  *
399  * @param clkmgr Clock Manager Handle.
400  * @returns The result of the operation.
401  */
404 #ifdef __cplusplus
405 } // extern "C"
406 #endif // __cplusplus
407 
408 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_CLKMGR_H_