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,
101status_t clkmgr_testutils_check_measurement_counts(
const dif_clkmgr_t *clkmgr);
113status_t clkmgr_testutils_check_measurement_enables(
123status_t clkmgr_testutils_disable_clock_counts(
const dif_clkmgr_t *clkmgr);
133status_t clkmgr_testutils_enable_external_clock_blocking(
144#define CLKMGR_TESTUTILS_CHECK_CLOCK_HINT(clkmgr, clock_id, expected_state) \
146 dif_toggle_t clock_state; \
147 TRY(dif_clkmgr_hintable_clock_get_enabled(&clkmgr, clock_id, \
149 TRY_CHECK(clock_state == expected_state, \
150 "Clock enabled state is (%d) and not as expected (%d).", \
151 clock_state, expected_state); \
171#define CLKMGR_TESTUTILS_SET_AND_CHECK_CLOCK_HINT(clkmgr, clock_id, new_state, \
176 dif_result_t set_res = \
177 dif_clkmgr_hintable_clock_set_hint(&clkmgr, clock_id, new_state); \
178 dif_toggle_t hint_state; \
182 dif_result_t hint_get_res = \
183 dif_clkmgr_hintable_clock_get_hint(&clkmgr, clock_id, &hint_state); \
185 dif_toggle_t clock_state; \
186 dif_result_t get_res = dif_clkmgr_hintable_clock_get_enabled( \
187 &clkmgr, clock_id, &clock_state); \
191 TRY_CHECK(hint_state == new_state, \
192 "Clock hint state is (%d) and not as requested (%d).", \
193 hint_state, new_state); \
194 TRY_CHECK(clock_state == expected_state, \
195 "Clock enabled state is (%d) and not as expected (%d).", \
196 clock_state, expected_state); \