5#ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_CLKMGR_TESTUTILS_H_
6#define OPENTITAN_SW_DEVICE_LIB_TESTING_CLKMGR_TESTUTILS_H_
8#include "sw/device/lib/base/status.h"
11#include "sw/device/lib/testing/test_framework/check.h"
13#define MODULE_ID MAKE_MODULE_ID('c', 'm', 'h')
23static inline bool clkmgr_testutils_get_trans_clock_status(
27 dif_clkmgr_hintable_clock_get_enabled(clkmgr, clock, &state);
46inline status_t clkmgr_testutils_check_trans_clock_gating(
48 bool exp_clock_enabled, uint32_t timeout_usec) {
49 TRY(dif_clkmgr_hintable_clock_set_hint(clkmgr, clock, 0x0));
55 TRY(dif_clkmgr_hintable_clock_set_hint(clkmgr, clock, 0x1));
71status_t clkmgr_testutils_enable_clock_count(
const dif_clkmgr_t *clkmgr,
72 dif_clkmgr_measure_clock_t clock,
73 uint32_t lo_threshold,
74 uint32_t hi_threshold);
90status_t clkmgr_testutils_enable_clock_counts_with_expected_thresholds(
91 const dif_clkmgr_t *clkmgr,
bool jitter_enabled,
bool external_clk,
107status_t clkmgr_testutils_enable_clock_counts_with_failing_thresholds(
117status_t clkmgr_testutils_check_measurement_counts(
const dif_clkmgr_t *clkmgr);
129status_t clkmgr_testutils_check_measurement_enables(
139status_t clkmgr_testutils_disable_clock_counts(
const dif_clkmgr_t *clkmgr);
149status_t clkmgr_testutils_enable_external_clock_blocking(
160#define CLKMGR_TESTUTILS_CHECK_CLOCK_HINT(clkmgr, clock_id, expected_state) \
162 dif_toggle_t clock_state; \
163 TRY(dif_clkmgr_hintable_clock_get_enabled(&clkmgr, clock_id, \
165 TRY_CHECK(clock_state == expected_state, \
166 "Clock enabled state is (%d) and not as expected (%d).", \
167 clock_state, expected_state); \
187#define CLKMGR_TESTUTILS_SET_AND_CHECK_CLOCK_HINT(clkmgr, clock_id, new_state, \
192 dif_result_t set_res = \
193 dif_clkmgr_hintable_clock_set_hint(&clkmgr, clock_id, new_state); \
194 dif_toggle_t hint_state; \
198 dif_result_t hint_get_res = \
199 dif_clkmgr_hintable_clock_get_hint(&clkmgr, clock_id, &hint_state); \
201 dif_toggle_t clock_state; \
202 dif_result_t get_res = dif_clkmgr_hintable_clock_get_enabled( \
203 &clkmgr, clock_id, &clock_state); \
207 TRY_CHECK(hint_state == new_state, \
208 "Clock hint state is (%d) and not as requested (%d).", \
209 hint_state, new_state); \
210 TRY_CHECK(clock_state == expected_state, \
211 "Clock enabled state is (%d) and not as expected (%d).", \
212 clock_state, expected_state); \