Software APIs
Typedefs | Enumerations | Functions
dif_clkmgr.h File Reference

(a5c3f339c6)

Clock Manager Device Interface Functions More...

#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_clkmgr_autogen.h"

Go to the source code of this file.

Typedefs

typedef uint32_t dif_clkmgr_gateable_clock_t
 An Index of a "Gateable" Clock. More...
 
typedef uint32_t dif_clkmgr_hintable_clock_t
 An Index of a "Hintable" Clock. More...
 
typedef enum dif_clkmgr_measure_clock dif_clkmgr_measure_clock_t
 
typedef enum dif_clkmgr_recov_err_type dif_clkmgr_recov_err_type_t
 
typedef uint32_t dif_clkmgr_recov_err_codes_t
 A set of recoverable errors. More...
 
typedef enum dif_clkmgr_fatal_err_type dif_clkmgr_fatal_err_type_t
 
typedef uint32_t dif_clkmgr_fatal_err_codes_t
 A set of fatal errors. More...
 

Enumerations

enum  dif_clkmgr_measure_clock {
  kDifClkmgrMeasureClockIoDiv4 ,
  kDifClkmgrMeasureClockMain ,
  kDifClkmgrMeasureClockUsb ,
  kDifClkmgrMeasureClockCount
}
 
enum  dif_clkmgr_recov_err_type
 
enum  dif_clkmgr_fatal_err_type {
  kDifClkmgrFatalErrTypeRegfileIntegrity = 1u << 0 ,
  kDifClkmgrFatalErrTypeIdleCount = 1u << 1 ,
  kDifClkmgrFatalErrTypeShadowStorage = 1u << 2
}
 

Functions

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_jitter_enable_is_locked (const dif_clkmgr_t *clkmgr, bool *is_locked)
 Check if jitter enable is locked. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_lock_jitter_enable (const dif_clkmgr_t *clkmgr)
 Lock jitter enable. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_jitter_get_enabled (const dif_clkmgr_t *clkmgr, dif_toggle_t *state)
 Check if jitter is Enabled. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_jitter_set_enabled (const dif_clkmgr_t *clkmgr, dif_toggle_t new_state)
 Enable of Disable jitter. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_find_gateable_clock (const dif_clkmgr_t *clkmgr, dt_instance_id_t inst_id, dif_clkmgr_gateable_clock_t *clock)
 Obtain the index of a gateable clock for a device. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_gateable_clock_get_enabled (const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock, dif_toggle_t *state)
 Check if a Gateable Clock is Enabled or Disabled. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_gateable_clock_set_enabled (const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock, dif_toggle_t new_state)
 Enable or Disable a Gateable Clock. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_find_hintable_clock (const dif_clkmgr_t *clkmgr, dt_instance_id_t inst_id, dif_clkmgr_hintable_clock_t *clock)
 Obtain the index of a hintable clock for a device. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_hintable_clock_get_enabled (const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock, dif_toggle_t *state)
 Check if a Hintable Clock is Enabled or Disabled. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_hintable_clock_set_hint (const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock, dif_toggle_t new_state)
 Enable or Disable a Hintable Clock. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_hintable_clock_get_hint (const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock, dif_toggle_t *state)
 Read the current Hint for a Hintable Clock. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_control_is_locked (const dif_clkmgr_t *clkmgr, bool *is_locked)
 Check if external clock control is locked. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_lock_external_clock_control (const dif_clkmgr_t *clkmgr)
 Lock external clock control. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_set_enabled (const dif_clkmgr_t *clkmgr, bool is_low_speed)
 Enable chip to use the external clock. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_set_disabled (const dif_clkmgr_t *clkmgr)
 Disable chip to use the external clock. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_is_settled (const dif_clkmgr_t *clkmgr, bool *status)
 Determine if the transition to using external clock is complete. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_ctrl_disable (const dif_clkmgr_t *clkmgr)
 Disable measurement control updates. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_ctrl_get_enable (const dif_clkmgr_t *clkmgr, dif_toggle_t *state)
 Get measurement control state. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_enable_measure_counts (const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock, uint32_t min_threshold, uint32_t max_threshold)
 Configure count measurements. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_disable_measure_counts (const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock)
 Disable count measurements. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_counts_get_enable (const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock, dif_toggle_t *state)
 Get the count measurement enable. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_counts_get_thresholds (const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock, uint32_t *min_threshold, uint32_t *max_threshold)
 Get the count measurement thresholds. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_recov_err_code_get_codes (const dif_clkmgr_t *clkmgr, dif_clkmgr_recov_err_codes_t *codes)
 Read the recoverable error codes. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_recov_err_code_clear_codes (const dif_clkmgr_t *clkmgr, dif_clkmgr_recov_err_codes_t codes)
 Clear selected recoverable error codes. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_fatal_err_code_get_codes (const dif_clkmgr_t *clkmgr, dif_clkmgr_fatal_err_codes_t *codes)
 Read the fatal error codes. More...
 
OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_wait_for_ext_clk_switch (const dif_clkmgr_t *clkmgr)
 Wait for external clock switch to finish. More...
 

Detailed Description

Clock Manager Device Interface Functions

Definition in file dif_clkmgr.h.

Typedef Documentation

◆ dif_clkmgr_fatal_err_codes_t

typedef uint32_t dif_clkmgr_fatal_err_codes_t

A set of fatal errors.

This type is used to read the fatal error codes.

Definition at line 183 of file dif_clkmgr.h.

◆ dif_clkmgr_gateable_clock_t

typedef uint32_t dif_clkmgr_gateable_clock_t

An Index of a "Gateable" Clock.

"Gateable" clocks are under full software control: they can be enabled and disabled by software, which directly starts and stops the identified clock.

Definition at line 32 of file dif_clkmgr.h.

◆ dif_clkmgr_hintable_clock_t

typedef uint32_t dif_clkmgr_hintable_clock_t

An Index of a "Hintable" Clock.

"Hintable" clocks are under partial software control: software can suggest they are stopped, but the clock manager may delay stopping the peripheral, or may ignore the request altogether.

Definition at line 41 of file dif_clkmgr.h.

◆ dif_clkmgr_recov_err_codes_t

typedef uint32_t dif_clkmgr_recov_err_codes_t

A set of recoverable errors.

This type is used to clear and read the recoverable error codes.

Definition at line 161 of file dif_clkmgr.h.

Enumeration Type Documentation

◆ dif_clkmgr_fatal_err_type

Enumerator
kDifClkmgrFatalErrTypeRegfileIntegrity 

A fatal error for regfile integrity.

kDifClkmgrFatalErrTypeIdleCount 

A fatal error for a duplicate idle counter.

kDifClkmgrFatalErrTypeShadowStorage 

A fatal error for a shadow register storage.

Definition at line 163 of file dif_clkmgr.h.

◆ dif_clkmgr_measure_clock

Enumerator
kDifClkmgrMeasureClockIoDiv4 

The Io div4 clock.

kDifClkmgrMeasureClockMain 

The Main clock.

kDifClkmgrMeasureClockUsb 

The Usb clock.

kDifClkmgrMeasureClockCount 

Total number of clock measurements.

Definition at line 43 of file dif_clkmgr.h.

Function Documentation

◆ dif_clkmgr_disable_measure_counts()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_disable_measure_counts ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_measure_clock_t  clock 
)

Disable count measurements.

Does not modify the thresholds.

Parameters
clkmgrClock Manager Handle.
clockA clock to be measured.
Returns
The result of the operation.

Definition at line 459 of file dif_clkmgr.c.

◆ dif_clkmgr_enable_measure_counts()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_enable_measure_counts ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_measure_clock_t  clock,
uint32_t  min_threshold,
uint32_t  max_threshold 
)

Configure count measurements.

Parameters
clkmgrClock Manager Handle.
clockA clock to be measured.
min_thresholdThe smallest permissible cycle count.
max_thresholdThe largest permissible cycle count.
Returns
The result of the operation.

Definition at line 394 of file dif_clkmgr.c.

◆ dif_clkmgr_external_clock_control_is_locked()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_control_is_locked ( const dif_clkmgr_t *  clkmgr,
bool *  is_locked 
)

Check if external clock control is locked.

Parameters
clkmgrClock Manager Handle.
[out]is_lockedwhether external clock control is locked or not.
Returns
The result of the operation.

Definition at line 271 of file dif_clkmgr.c.

◆ dif_clkmgr_external_clock_is_settled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_is_settled ( const dif_clkmgr_t *  clkmgr,
bool *  status 
)

Determine if the transition to using external clock is complete.

Parameters
clkmgrClock Manager Handle.
[out]statusSet to true if the transition is complete.
Returns
The result of the operation once it completes.

Definition at line 74 of file dif_clkmgr.c.

◆ dif_clkmgr_external_clock_set_disabled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_set_disabled ( const dif_clkmgr_t *  clkmgr)

Disable chip to use the external clock.

Parameters
clkmgrClock Manager Handle.
Returns
The result of the operation.

Definition at line 314 of file dif_clkmgr.c.

◆ dif_clkmgr_external_clock_set_enabled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_external_clock_set_enabled ( const dif_clkmgr_t *  clkmgr,
bool  is_low_speed 
)

Enable chip to use the external clock.

Parameters
clkmgrClock Manager Handle.
is_low_speedExternal clock is low speed or high speed.
Returns
The result of the operation. High speed - external clock is close to nominal speeds (e.g. external clock is 96MHz and nominal frequency is 96MHz-100MHz). Low speed - external clock is half of nominal speeds (e.g. external clock is 48MHz and nominal frequency is 96MHz-100MHz).

Definition at line 292 of file dif_clkmgr.c.

◆ dif_clkmgr_fatal_err_code_get_codes()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_fatal_err_code_get_codes ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_fatal_err_codes_t codes 
)

Read the fatal error codes.

Parameters
clkmgrClock Manager Handle.
[out]codesThe fatal error codes.
Returns
The result of the operation.

Definition at line 624 of file dif_clkmgr.c.

◆ dif_clkmgr_find_gateable_clock()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_find_gateable_clock ( const dif_clkmgr_t *  clkmgr,
dt_instance_id_t  inst_id,
dif_clkmgr_gateable_clock_t clock 
)

Obtain the index of a gateable clock for a device.

Given a module instance (identified by its instance ID), return the index of the gateable clock which controls this device and can be used with the clkmgr DIF.

Example (find gateable clock of UART0):

clkmgr, kDtInstanceIdUart0, &clock));
Parameters
clkmgrA clock manager handle.
inst_idAn instance ID.
[out]clockThe index of the clock.
Returns
kDifError if no gateable clock matches the description, kDifOk otherwise.

Definition at line 149 of file dif_clkmgr.c.

◆ dif_clkmgr_find_hintable_clock()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_find_hintable_clock ( const dif_clkmgr_t *  clkmgr,
dt_instance_id_t  inst_id,
dif_clkmgr_hintable_clock_t clock 
)

Obtain the index of a hintable clock for a device.

Given a module instance (identified by its instance ID), return the index of the hintable clock which controls this device and can be used with the clkmgr DIF.

Example (find hintable clock of KMAC):

clkmgr, kDtInstanceIdKmac, &clock));
Parameters
clkmgrA clock manager handle.
inst_idAn instance ID.
[out]clockThe index of the clock.
Returns
kDifError if no hintable clock matches the description, kDifOk otherwise.

Definition at line 204 of file dif_clkmgr.c.

◆ dif_clkmgr_gateable_clock_get_enabled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_gateable_clock_get_enabled ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_gateable_clock_t  clock,
dif_toggle_t state 
)

Check if a Gateable Clock is Enabled or Disabled.

Parameters
clkmgrClock Manager Handle.
clockGateable Clock ID.
[out]is_enabledwhether the clock is enabled or not.
Returns
The result of the operation.

Definition at line 170 of file dif_clkmgr.c.

◆ dif_clkmgr_gateable_clock_set_enabled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_gateable_clock_set_enabled ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_gateable_clock_t  clock,
dif_toggle_t  new_state 
)

Enable or Disable a Gateable Clock.

Parameters
clkmgrClock Manager Handle.
clockGateable Clock ID.
new_statewhether to enable or disable the clock.
Returns
The result of the operation.

Definition at line 184 of file dif_clkmgr.c.

◆ dif_clkmgr_hintable_clock_get_enabled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_hintable_clock_get_enabled ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_hintable_clock_t  clock,
dif_toggle_t state 
)

Check if a Hintable Clock is Enabled or Disabled.

Hintable clocks are not under full software control, but this operation accurately reflects the state of the current clock, regardless of any hint requests made by software.

To read what hint the software has given the hardware, use dif_clkmgr_hintable_clock_get_hint.

Parameters
clkmgrClock Manager Handle.
clockHintable Clock ID.
[out]is_enabledwhether the clock is enabled or not.
Returns
The result of the operation.

Definition at line 225 of file dif_clkmgr.c.

◆ dif_clkmgr_hintable_clock_get_hint()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_hintable_clock_get_hint ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_hintable_clock_t  clock,
dif_toggle_t state 
)

Read the current Hint for a Hintable Clock.

Hintable clocks are not under full software control; this operation accurately reflects the current software hint, not the current state of the clock.

To read whether the clock is currently enabled or disabled, use dif_clkmgr_hintable_clock_get_enabled.

Parameters
clkmgrClock Manager Handle.
clockHintable Clock ID.
[out]hinted_is_enabledthe current software request (hint) for this clock.
Returns
The result of the operation.

Definition at line 257 of file dif_clkmgr.c.

◆ dif_clkmgr_hintable_clock_set_hint()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_hintable_clock_set_hint ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_hintable_clock_t  clock,
dif_toggle_t  new_state 
)

Enable or Disable a Hintable Clock.

This only sets a hint that the clock should be enabled or disabled. The clock manager is in control of whether the clock should actually be enabled or disabled.

To read what hint the software has given the hardware, use dif_clkmgr_hintable_clock_get_hint. To read whether the clock is currently enabled or disabled, use dif_clkmgr_hintable_clock_get_enabled.

Parameters
clkmgrClock Manager Handle.
clockHintable Clock ID.
new_statewhether to enable or disable the clock.
Returns
The result of the operation.

Definition at line 239 of file dif_clkmgr.c.

◆ dif_clkmgr_jitter_enable_is_locked()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_jitter_enable_is_locked ( const dif_clkmgr_t *  clkmgr,
bool *  is_locked 
)

Check if jitter enable is locked.

Parameters
clkmgrClock Manager Handle.
[out]is_lockedwhether jitter is locked or not.
Returns
The result of the operation.

Definition at line 88 of file dif_clkmgr.c.

◆ dif_clkmgr_jitter_get_enabled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_jitter_get_enabled ( const dif_clkmgr_t *  clkmgr,
dif_toggle_t state 
)

Check if jitter is Enabled.

Parameters
clkmgrClock Manager Handle.
[out]is_enabledwhether jitter is enabled or not.
Returns
The result of the operation.

Definition at line 107 of file dif_clkmgr.c.

◆ dif_clkmgr_jitter_set_enabled()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_jitter_set_enabled ( const dif_clkmgr_t *  clkmgr,
dif_toggle_t  new_state 
)

Enable of Disable jitter.

Parameters
clkmgrClock Manager Handle.
new_statewhether to enable or disable jitter.
Returns
The result of the operation.

Definition at line 123 of file dif_clkmgr.c.

◆ dif_clkmgr_lock_external_clock_control()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_lock_external_clock_control ( const dif_clkmgr_t *  clkmgr)

Lock external clock control.

Parameters
clkmgrClock Manager Handle.
Returns
The result of the operation.

Definition at line 282 of file dif_clkmgr.c.

◆ dif_clkmgr_lock_jitter_enable()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_lock_jitter_enable ( const dif_clkmgr_t *  clkmgr)

Lock jitter enable.

Parameters
clkmgrClock Manager Handle.
Returns
The result of the operation.

Definition at line 99 of file dif_clkmgr.c.

◆ dif_clkmgr_measure_counts_get_enable()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_counts_get_enable ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_measure_clock_t  clock,
dif_toggle_t state 
)

Get the count measurement enable.

Parameters
clkmgrClock Manager Handle.
clockA clock to be measured.
[out]stateThe state of control enable.
Returns
The result of the operation.

Definition at line 505 of file dif_clkmgr.c.

◆ dif_clkmgr_measure_counts_get_thresholds()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_counts_get_thresholds ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_measure_clock_t  clock,
uint32_t *  min_threshold,
uint32_t *  max_threshold 
)

Get the count measurement thresholds.

Parameters
clkmgrClock Manager Handle.
clockA clock to be measured.
[out]min_thresholdThe minumum threshold.
[out]max_thresholdThe maximum threshold.
Returns
The result of the operation.

Definition at line 546 of file dif_clkmgr.c.

◆ dif_clkmgr_measure_ctrl_disable()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_ctrl_disable ( const dif_clkmgr_t *  clkmgr)

Disable measurement control updates.

This can only be disabled, and stays disabled until the next POR.

Parameters
clkmgrClock Manager Handle.
Returns
The result of the operation.

Definition at line 337 of file dif_clkmgr.c.

◆ dif_clkmgr_measure_ctrl_get_enable()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_measure_ctrl_get_enable ( const dif_clkmgr_t *  clkmgr,
dif_toggle_t state 
)

Get measurement control state.

Parameters
clkmgrClock Manager Handle.
[out]stateThe state of control enable.
Returns
The result of the operation.

Definition at line 346 of file dif_clkmgr.c.

◆ dif_clkmgr_recov_err_code_clear_codes()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_recov_err_code_clear_codes ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_recov_err_codes_t  codes 
)

Clear selected recoverable error codes.

Parameters
clkmgrClock Manager Handle.
codesThe recoverable error codes to be cleared.
Returns
The result of the operation.

Definition at line 614 of file dif_clkmgr.c.

◆ dif_clkmgr_recov_err_code_get_codes()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_recov_err_code_get_codes ( const dif_clkmgr_t *  clkmgr,
dif_clkmgr_recov_err_codes_t codes 
)

Read the recoverable error codes.

Parameters
clkmgrClock Manager Handle.
[out]codesThe recoverable error codes.
Returns
The result of the operation.

Definition at line 604 of file dif_clkmgr.c.

◆ dif_clkmgr_wait_for_ext_clk_switch()

OT_WARN_UNUSED_RESULT dif_result_t dif_clkmgr_wait_for_ext_clk_switch ( const dif_clkmgr_t *  clkmgr)

Wait for external clock switch to finish.

Parameters
clkmgrClock Manager Handle.
Returns
The result of the operation.

Definition at line 634 of file dif_clkmgr.c.