Skip to content

Commit 34e4424

Browse files
nbdd0121jwnrt
authored andcommitted
[multitop] port sleep_pin_mio_dio_val_test to devicetables
Signed-off-by: Gary Guo <[email protected]>
1 parent 40eaf7d commit 34e4424

File tree

2 files changed

+43
-75
lines changed

2 files changed

+43
-75
lines changed

sw/device/tests/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7332,14 +7332,11 @@ opentitan_test(
73327332
# in CI/nightlies.
73337333
verilator = verilator_params(tags = ["manual"]),
73347334
deps = [
7335-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
7336-
"//sw/device/lib/base:mmio",
73377335
"//sw/device/lib/dif:pinmux",
73387336
"//sw/device/lib/dif:pwrmgr",
73397337
"//sw/device/lib/dif:rv_plic",
73407338
"//sw/device/lib/runtime:irq",
73417339
"//sw/device/lib/runtime:log",
7342-
"//sw/device/lib/testing:isr_testutils",
73437340
"//sw/device/lib/testing:pwrmgr_testutils",
73447341
"//sw/device/lib/testing:rand_testutils",
73457342
"//sw/device/lib/testing:rv_plic_testutils",

sw/device/tests/sleep_pin_mio_dio_val_test.c

Lines changed: 43 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5-
#include "sw/device/lib/base/mmio.h"
65
#include "sw/device/lib/dif/dif_pinmux.h"
76
#include "sw/device/lib/dif/dif_pwrmgr.h"
87
#include "sw/device/lib/dif/dif_rv_plic.h"
@@ -14,9 +13,6 @@
1413
#include "sw/device/lib/testing/test_framework/check.h"
1514
#include "sw/device/lib/testing/test_framework/ottf_main.h"
1615

17-
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
18-
#include "sw/device/lib/testing/autogen/isr_testutils.h"
19-
2016
OTTF_DEFINE_TEST_CONFIG();
2117

2218
/**
@@ -38,59 +34,41 @@ OTTF_DEFINE_TEST_CONFIG();
3834
* the expected and measured values.
3935
*/
4036

41-
/* NUM_MIO_PADS */
42-
/* NUM_DIO_PADS */
43-
44-
enum { kNumOptOutDio = 2 };
45-
static const uint8_t kOptOutDio[kNumOptOutDio] = {
46-
kTopEarlgreyDirectPadsSpiDeviceSck,
47-
kTopEarlgreyDirectPadsSpiDeviceCsb,
37+
enum { kNumOptOut = 2 };
38+
static const dt_pad_t kOptOut[] = {
39+
kDtPadSpiDeviceSck,
40+
kDtPadSpiDeviceCsb,
4841
};
4942

50-
/**
51-
* If certain MIOs need to be skipped due to tied functionality, specify here.
52-
*/
53-
enum { kNumOptOutMio = 0 };
54-
55-
static uint8_t kMioPads[NUM_MIO_PADS] = {0};
56-
static uint8_t kDioPads[NUM_DIO_PADS] = {0};
43+
static uint8_t kPads[kDtPadCount] = {0};
5744

5845
// PLIC structures
5946
static dif_pwrmgr_t pwrmgr;
6047
static dif_pinmux_t pinmux;
6148
static dif_rv_plic_t plic;
6249

63-
static plic_isr_ctx_t plic_ctx = {.rv_plic = &plic,
64-
.hart_id = kTopEarlgreyPlicTargetIbex0};
65-
66-
static pwrmgr_isr_ctx_t pwrmgr_isr_ctx = {
67-
.pwrmgr = &pwrmgr,
68-
.plic_pwrmgr_start_irq_id = kTopEarlgreyPlicIrqIdPwrmgrAonWakeup,
69-
.expected_irq = kDifPwrmgrIrqWakeup,
70-
.is_only_irq = true};
71-
7250
/**
7351
* External interrupt handler.
7452
*/
75-
void ottf_external_isr(uint32_t *exc_info) {
76-
dif_pwrmgr_irq_t irq_id;
77-
top_earlgrey_plic_peripheral_t peripheral;
78-
79-
isr_testutils_pwrmgr_isr(plic_ctx, pwrmgr_isr_ctx, &peripheral, &irq_id);
53+
bool ottf_handle_irq(uint32_t *exc_info, dt_instance_id_t devid,
54+
dif_rv_plic_irq_id_t irq_id) {
55+
if (devid != dt_pwrmgr_instance_id(kDtPwrmgrAon)) {
56+
return false;
57+
}
8058

81-
// Check that both the peripheral and the irq id is correct
82-
CHECK(peripheral == kTopEarlgreyPlicPeripheralPwrmgrAon,
83-
"IRQ peripheral: %d is incorrect", peripheral);
84-
CHECK(irq_id == kDifPwrmgrIrqWakeup, "IRQ ID: %d is incorrect", irq_id);
59+
dt_pwrmgr_irq_t irq = dt_pwrmgr_irq_from_plic_id(kDtPwrmgrAon, irq_id);
60+
CHECK(irq == kDtPwrmgrIrqWakeup, "IRQ ID: %d is incorrect", irq);
61+
CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(&pwrmgr, irq));
62+
return true;
8563
}
8664

8765
/** Configure pinmux retention value.
8866
*
8967
* Each gen32 can cover 16 PADs randomization. When each pad ret val draws
9068
* **3**, the code calls gen32_range to choose from 0 to 2.
9169
*/
92-
void draw_pinmux_ret(const uint32_t num_pins, uint8_t *arr,
93-
const uint8_t *optout, const uint8_t num_optout) {
70+
void draw_pinmux_ret(uint32_t num_pins, uint8_t *arr, const dt_pad_t *optout,
71+
size_t num_optout) {
9472
for (uint32_t i = 0; i < num_pins; i += 16) {
9573
uint32_t val = rand_testutils_gen32();
9674
uint32_t min_idx = (i + 16 < num_pins) ? i + 16 : num_pins;
@@ -106,7 +84,6 @@ void draw_pinmux_ret(const uint32_t num_pins, uint8_t *arr,
10684

10785
// OptOut processing after draw.
10886
for (int i = 0; i < num_optout; i++) {
109-
CHECK(optout != NULL, "optout must be non-NULL");
11087
arr[optout[i]] = 2; // High-Z always
11188
}
11289
}
@@ -120,12 +97,18 @@ void draw_pinmux_ret(const uint32_t num_pins, uint8_t *arr,
12097
*/
12198
void print_chosen_values(void) {
12299
LOG_INFO("BEGIN Chosen Retention Types");
123-
for (int i = 0; i < NUM_MIO_PADS; ++i) {
124-
LOG_INFO("MIO [%d]: %x", i, kMioPads[i]);
125-
}
126-
for (int i = 0; i < NUM_DIO_PADS; ++i) {
127-
LOG_INFO("DIO [%d]: %x", i, kDioPads[i]);
100+
101+
for (dt_pad_t pad = 0; pad < kDtPadCount; ++pad) {
102+
dif_pinmux_index_t index;
103+
dif_pinmux_pad_kind_t type;
104+
CHECK_DIF_OK(dif_pinmux_pad_from_dt_pad(pad, &index, &type));
105+
if (type == kDifPinmuxPadKindDio) {
106+
LOG_INFO("DIO [%d]: %x", index, kPads[pad]);
107+
} else {
108+
LOG_INFO("MIO [%d]: %x", index, kPads[pad]);
109+
}
128110
}
111+
129112
LOG_INFO("END Chosen Retention Types");
130113
}
131114

@@ -135,22 +118,13 @@ void print_chosen_values(void) {
135118
* @param pinmux Pinmux handle.
136119
*/
137120
void configure_pad_retention_types(dif_pinmux_t *pinmux) {
138-
uint8_t io; // 1 for DIO, 0 for MIO
139-
uint32_t max_pads;
140-
dif_pinmux_pad_kind_t pad_kind;
141-
dif_pinmux_sleep_mode_t pad_mode;
142121
LOG_INFO("Configuring PADs retention types in PINMUX...");
143122

144-
// TODO: for loop of writing values to PINMUX CSRs.
145-
for (io = 0; io < 2; io++) {
146-
max_pads = (io) ? NUM_DIO_PADS : NUM_MIO_PADS;
147-
pad_kind = (io) ? kDifPinmuxPadKindDio : kDifPinmuxPadKindMio;
148-
for (int i = 0; i < max_pads; i++) {
149-
pad_mode = (io) ? (dif_pinmux_sleep_mode_t)(kDioPads[i])
150-
: (dif_pinmux_sleep_mode_t)(kMioPads[i]);
151-
CHECK_DIF_OK(dif_pinmux_pad_sleep_enable(pinmux, (dif_pinmux_index_t)i,
152-
pad_kind, pad_mode));
153-
}
123+
for (dt_pad_t pad = 0; pad < kDtPadCount; pad++) {
124+
dif_pinmux_index_t index;
125+
dif_pinmux_pad_kind_t type;
126+
CHECK_DIF_OK(dif_pinmux_pad_from_dt_pad(pad, &index, &type));
127+
CHECK_DIF_OK(dif_pinmux_pad_sleep_enable(pinmux, index, type, kPads[pad]));
154128
}
155129

156130
LOG_INFO("PADs retention modes are configured.");
@@ -162,8 +136,7 @@ bool lowpower_prep(dif_pwrmgr_t *pwrmgr, dif_pinmux_t *pinmux, bool deepsleep) {
162136

163137
LOG_INFO("Selecting PADs retention modes...");
164138

165-
draw_pinmux_ret(NUM_DIO_PADS, kDioPads, kOptOutDio, kNumOptOutDio);
166-
draw_pinmux_ret(NUM_MIO_PADS, kMioPads, NULL, kNumOptOutMio);
139+
draw_pinmux_ret(kDtPadCount, kPads, kOptOut, kNumOptOut);
167140

168141
print_chosen_values();
169142

@@ -192,12 +165,9 @@ bool test_main(void) {
192165
irq_global_ctrl(true);
193166
irq_external_ctrl(true);
194167

195-
CHECK_DIF_OK(dif_pwrmgr_init(
196-
mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR), &pwrmgr));
197-
CHECK_DIF_OK(dif_pinmux_init(
198-
mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR), &pinmux));
199-
CHECK_DIF_OK(dif_rv_plic_init(
200-
mmio_region_from_addr(TOP_EARLGREY_RV_PLIC_BASE_ADDR), &plic));
168+
CHECK_DIF_OK(dif_pwrmgr_init_from_dt(kDtPwrmgrAon, &pwrmgr));
169+
CHECK_DIF_OK(dif_pinmux_init_from_dt(kDtPinmuxAon, &pinmux));
170+
CHECK_DIF_OK(dif_rv_plic_init_from_dt(kDtRvPlic, &plic));
201171

202172
if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0)) == true) {
203173
uint32_t deep_powerdown_en = rand_testutils_gen32_range(0, 1);
@@ -207,15 +177,16 @@ bool test_main(void) {
207177
// disabled for this test. Remove this later.
208178
dif_pinmux_pad_attr_t out_attr;
209179
dif_pinmux_pad_attr_t in_attr = {0};
210-
CHECK_DIF_OK(dif_pinmux_pad_write_attrs(&pinmux, kTopEarlgreyMuxedPadsIoc3,
211-
kDifPinmuxPadKindMio, in_attr,
212-
&out_attr));
180+
CHECK_DIF_OK(
181+
dif_pinmux_pad_write_attrs_dt(&pinmux, kDtPadIoc3, in_attr, &out_attr));
213182

214183
if (!deepsleep) {
215184
// Enable all the AON interrupts used in this test.
216-
rv_plic_testutils_irq_range_enable(&plic, kTopEarlgreyPlicTargetIbex0,
217-
kTopEarlgreyPlicIrqIdPwrmgrAonWakeup,
218-
kTopEarlgreyPlicIrqIdPwrmgrAonWakeup);
185+
static const uint32_t kPlicTarget = 0;
186+
rv_plic_testutils_irq_range_enable(
187+
&plic, kPlicTarget,
188+
dt_pwrmgr_irq_to_plic_id(kDtPwrmgrAon, kDtPwrmgrIrqWakeup),
189+
dt_pwrmgr_irq_to_plic_id(kDtPwrmgrAon, kDtPwrmgrIrqWakeup));
219190
// Enable pwrmgr interrupt
220191
CHECK_DIF_OK(dif_pwrmgr_irq_set_enabled(&pwrmgr, 0, kDifToggleEnabled));
221192
}

0 commit comments

Comments
 (0)