9 #include "sw/device/lib/runtime/irq.h"
11 #include "sw/device/lib/testing/rv_plic_testutils.h"
12 #include "sw/device/lib/testing/test_framework/check.h"
13 #include "sw/device/lib/testing/test_framework/ottf_console.h"
15 #include "sw/device/lib/testing/test_framework/ottf_utils.h"
18 #include "pattgen_regs.h"
33 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control =
true);
36 kTestCmdTimeoutUsec = 5000000,
41 #define DEFINE_BACKDOOR_VAR(type, name, default_val) \
43 OTTF_BACKDOOR_VAR_DV type name##DV = default_val; \
45 OTTF_BACKDOOR_VAR type name##Real = default_val;
47 #define BACKDOOR_VAR(name) \
48 (kDeviceType == kDeviceSimDV ? OTTF_BACKDOOR_READ(name##DV) : name##Real)
53 DEFINE_BACKDOOR_VAR(uint8_t, kChannelEnable, 3)
56 DEFINE_BACKDOOR_VAR(uint8_t, kPattInactiveLevelPda0, 0)
57 DEFINE_BACKDOOR_VAR(uint8_t, kPattInactiveLevelPcl0, 0)
58 DEFINE_BACKDOOR_VAR(uint32_t, kPattDiv0, 0)
59 DEFINE_BACKDOOR_VAR(uint32_t, kPattLower0, 0x76543210)
60 DEFINE_BACKDOOR_VAR(uint32_t, kPattUpper0, 0x76543210)
61 DEFINE_BACKDOOR_VAR(uint8_t, kPattLen0, 40)
62 DEFINE_BACKDOOR_VAR(uint16_t, kPattRep0, 3)
65 DEFINE_BACKDOOR_VAR(uint8_t, kPattInactiveLevelPda1, 0)
66 DEFINE_BACKDOOR_VAR(uint8_t, kPattInactiveLevelPcl1, 0)
67 DEFINE_BACKDOOR_VAR(uint32_t, kPattDiv1, 0)
68 DEFINE_BACKDOOR_VAR(uint32_t, kPattLower1, 0x76543210)
69 DEFINE_BACKDOOR_VAR(uint32_t, kPattUpper1, 0x76543210)
70 DEFINE_BACKDOOR_VAR(uint8_t, kPattLen1, 40)
71 DEFINE_BACKDOOR_VAR(uint16_t, kPattRep1, 3)
75 kTestCmdConfigure = 1,
82 uint8_t test_cmd = kTestCmdWait;
85 static const uint8_t kPattOuts = 4;
106 static dif_rv_plic_t plic;
107 static dif_pattgen_t pattgen;
108 static volatile uint8_t channel_fired = 0;
113 void ottf_external_isr(uint32_t *exc_info) {
121 ottf_console_flow_control_isr(exc_info)) {
125 LOG_INFO(
"IRQ detected %d", irq_id);
131 channel_fired |= 1 << 0;
133 CHECK_DIF_OK(dif_pattgen_irq_is_pending(&pattgen, kDifPattgenIrqDoneCh0,
135 CHECK(is_pending ==
true);
137 dif_pattgen_irq_acknowledge(&pattgen, kDifPattgenIrqDoneCh0));
140 channel_fired |= 1 << 1;
143 CHECK_DIF_OK(dif_pattgen_irq_is_pending(&pattgen, kDifPattgenIrqDoneCh1,
145 CHECK(is_pending ==
true);
147 dif_pattgen_irq_acknowledge(&pattgen, kDifPattgenIrqDoneCh1));
150 LOG_FATAL(
"IRQ: unknown irq %d", irq_id);
158 static void run_test(
void);
165 irq_global_ctrl(
true);
166 irq_external_ctrl(
true);
168 CHECK_DIF_OK(dif_pattgen_init(
174 CHECK_DIF_OK(dif_rv_plic_init(
176 rv_plic_testutils_irq_range_enable(&plic, kPlicTarget,
182 CHECK_DIF_OK(dif_pinmux_init(
188 for (uint8_t i = 0; i < kPattOuts; ++i) {
202 test_cmd = kTestCmdWait;
203 OTTF_WAIT_FOR(test_cmd != kTestCmdWait, kTestCmdTimeoutUsec);
204 if (test_cmd == kTestCmdStop) {
207 CHECK(test_cmd == kTestCmdConfigure);
213 static void run_test(
void) {
215 CHECK_DIF_OK(dif_pattgen_irq_set_enabled(&pattgen, kDifPattgenIrqDoneCh0,
217 CHECK_DIF_OK(dif_pattgen_irq_set_enabled(&pattgen, kDifPattgenIrqDoneCh1,
223 if (BACKDOOR_VAR(kChannelEnable) & 0x1) {
224 patt_cfg.
polarity = BACKDOOR_VAR(kPattPol0);
236 if (BACKDOOR_VAR(kChannelEnable) & 0x2) {
237 patt_cfg.
polarity = BACKDOOR_VAR(kPattPol1);
252 OTTF_WAIT_FOR(test_cmd == kTestCmdRun, kTestCmdTimeoutUsec);
256 if (BACKDOOR_VAR(kChannelEnable) & 0x1) {
260 if (BACKDOOR_VAR(kChannelEnable) & 0x2) {
268 ATOMIC_WAIT_FOR_INTERRUPT(channel_fired == BACKDOOR_VAR(kChannelEnable));