Skip to content

Commit

Permalink
[sw] Port sysrst_ctrl_outputs_test to device tables
Browse files Browse the repository at this point in the history
Signed-off-by: Amaury Pouly <amaury.pouly@lowrisc.org>
  • Loading branch information
pamaury committed Jan 23, 2025
1 parent f5adbb1 commit 52cab17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion sw/device/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6365,7 +6365,7 @@ opentitan_test(
test_harness = "//sw/host/tests/chip/sysrst_ctrl:sysrst_ctrl_outputs",
),
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//hw/top:dt",
"//sw/device/lib/base:mmio",
"//sw/device/lib/dif:pinmux",
"//sw/device/lib/dif:sysrst_ctrl",
Expand Down
45 changes: 25 additions & 20 deletions sw/device/tests/sysrst_ctrl_outputs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "dt/dt.h" // Generated
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_pinmux.h"
#include "sw/device/lib/dif/dif_sysrst_ctrl.h"
Expand All @@ -13,13 +14,12 @@
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/lib/testing/test_framework/ottf_utils.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

/* We need control flow for the ujson messages exchanged
* with the host in OTTF_WAIT_FOR on real devices. */
OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);

static dif_pinmux_t pinmux;
static const dt_sysrst_ctrl_t *kSysrstCtrlDt = &kDtSysrstCtrl[0];
static dif_sysrst_ctrl_t sysrst_ctrl;
static dif_flash_ctrl_state_t flash;

Expand Down Expand Up @@ -48,11 +48,11 @@ enum {
kOutputNumPads = 0x8,
};

static const dif_pinmux_index_t kPeripheralInputs[] = {
kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey0In,
kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey1In,
kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey2In,
kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonPwrbIn,
static const dt_sysrst_ctrl_periph_io_t kPeripheralInputs[] = {
kDtSysrstCtrlPeriphIoKey0In,
kDtSysrstCtrlPeriphIoKey1In,
kDtSysrstCtrlPeriphIoKey2In,
kDtSysrstCtrlPeriphIoPwrbIn,
};

static const dif_pinmux_index_t kInputPadsDV[] = {
Expand All @@ -69,13 +69,10 @@ static const dif_pinmux_index_t kInputPadsReal[] = {
kTopEarlgreyPinmuxInselIor5,
};

static const dif_pinmux_index_t kPeripheralOutputs[] = {
kTopEarlgreyPinmuxOutselSysrstCtrlAonKey0Out,
kTopEarlgreyPinmuxOutselSysrstCtrlAonKey1Out,
kTopEarlgreyPinmuxOutselSysrstCtrlAonKey2Out,
kTopEarlgreyPinmuxOutselSysrstCtrlAonPwrbOut,
kTopEarlgreyPinmuxOutselSysrstCtrlAonBatDisable,
kTopEarlgreyPinmuxOutselSysrstCtrlAonZ3Wakeup,
static const dt_sysrst_ctrl_periph_io_t kPeripheralOutputs[] = {
kDtSysrstCtrlPeriphIoKey0Out, kDtSysrstCtrlPeriphIoKey1Out,
kDtSysrstCtrlPeriphIoKey2Out, kDtSysrstCtrlPeriphIoPwrbOut,
kDtSysrstCtrlPeriphIoBatDisable, kDtSysrstCtrlPeriphIoZ3Wakeup,
};

static const dif_pinmux_index_t kOutputPadsDV[] = {
Expand Down Expand Up @@ -118,14 +115,24 @@ static void pinmux_setup(void) {
const dif_pinmux_index_t *kInputPads =
kDeviceType == kDeviceSimDV ? kInputPadsDV : kInputPadsReal;
for (int i = 0; i < kNumMioInputs; ++i) {
CHECK_DIF_OK(
dif_pinmux_input_select(&pinmux, kPeripheralInputs[i], kInputPads[i]));
dt_periph_io_t pin =
dt_sysrst_ctrl_periph_io(kSysrstCtrlDt, kPeripheralInputs[i]);
// TODO The following will be replaced by better code when we have the
// "board side" configuration done.
CHECK(dt_periph_io_type(pin) == kDtPeriphIoTypeMio);
CHECK_DIF_OK(dif_pinmux_input_select(
&pinmux, dt_periph_io_mio_periph_input(pin), kInputPads[i]));
}
const dif_pinmux_index_t *kOutputPads =
kDeviceType == kDeviceSimDV ? kOutputPadsDV : kOutputPadsReal;
for (int i = 0; i < kNumMioOutputs; ++i) {
dt_periph_io_t pin =
dt_sysrst_ctrl_periph_io(kSysrstCtrlDt, kPeripheralOutputs[i]);
// TODO The following will be replaced by better code when we have the
// "board side" configuration done.
CHECK(dt_periph_io_type(pin) == kDtPeriphIoTypeMio);
CHECK_DIF_OK(dif_pinmux_output_select(&pinmux, kOutputPads[i],
kPeripheralOutputs[i]));
dt_periph_io_mio_outsel(pin)));
}
}

Expand Down Expand Up @@ -181,9 +188,7 @@ static void set_output_overrides(uint8_t override_value) {
bool test_main(void) {
CHECK_DIF_OK(dif_pinmux_init(
mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR), &pinmux));
CHECK_DIF_OK(dif_sysrst_ctrl_init(
mmio_region_from_addr(TOP_EARLGREY_SYSRST_CTRL_AON_BASE_ADDR),
&sysrst_ctrl));
CHECK_DIF_OK(dif_sysrst_ctrl_init_from_dt(kSysrstCtrlDt, &sysrst_ctrl));
if (kDeviceType == kDeviceSimDV) {
CHECK_STATUS_OK(flash_ctrl_testutils_backdoor_init(&flash));
}
Expand Down

0 comments on commit 52cab17

Please sign in to comment.