5 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_UTILS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_UTILS_H_
12 #include "sw/device/lib/base/status.h"
13 #include "sw/device/lib/testing/json/command.h"
14 #include "sw/device/lib/testing/test_framework/ujson_ottf.h"
15 #include "sw/device/lib/testing/test_framework/ujson_ottf_commands.h"
27 #define OTTF_WAIT_FOR(cond, timeout_usec) \
29 if (kDeviceType != kDeviceSimDV) { \
30 ujson_t uj = ujson_ottf_console(); \
31 const ibex_timeout_t timeout_ = ibex_timeout_init(timeout_usec); \
32 test_command_t command; \
33 LOG_INFO("SiVal: waiting for commands"); \
35 CHECK(!ibex_timeout_check(&timeout_), \
36 "Timed out after %d usec waiting for " #cond, timeout_usec); \
39 UJSON_WITH_CRC(ujson_deserialize_test_command_t, &uj, &command)); \
40 CHECK_STATUS_OK(ujson_ottf_dispatch(&uj, command)); \
43 IBEX_SPIN_FOR(cond, timeout_usec); \
68 #define OTTF_BACKDOOR_VAR OT_USED OT_SECTION(".data")
74 #define OTTF_BACKDOOR_VAR_DV OT_USED OT_SECTION(".rodata")
76 #if defined(OPENTITAN_IS_EARLGREY)
78 static void ottf_backdoor_flush_read_buffers(
void) {
84 enum { kBufferBytes = 32 };
85 static volatile const uint8_t kFlashFlusher[kBufferBytes];
86 for (
int i = 0; i <
sizeof(kFlashFlusher); ++i) {
87 (void)kFlashFlusher[i];
91 #elif defined(OPENTITAN_IS_DARJEELING)
93 static void ottf_backdoor_flush_read_buffers(
void) {}
96 #error Unsupported top
109 #define OTTF_BACKDOOR_READ(var) \
111 ottf_backdoor_flush_read_buffers(); \
112 typeof(var) _tmp = *(const volatile typeof(var) *)&(var); \
113 atomic_signal_fence(memory_order_acquire); \