| // Copyright lowRISC contributors. | |
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | |
| // SPDX-License-Identifier: Apache-2.0 | |
| #include "hw/top_matcha/sw/autogen/top_matcha.h" | |
| #include "sw/device/lib/arch/device.h" | |
| #include "sw/device/lib/dif/dif_smc_ctrl.h" | |
| #include "sw/device/lib/dif/dif_uart.h" | |
| #include "sw/device/lib/runtime/hart.h" | |
| #include "sw/device/lib/runtime/log.h" | |
| #include "sw/device/lib/runtime/print.h" | |
| #include "sw/device/lib/testing/test_framework/check.h" | |
| #include "sw/device/lib/testing/test_framework/ottf_test_config.h" | |
| #include "sw/device/lib/testing/test_framework/status.h" | |
| #include "sw/device/lib/testing/test_framework/test_util.h" | |
| OTTF_DEFINE_TEST_CONFIG(); | |
| static dif_uart_t uart; | |
| static dif_smc_ctrl_t smc_ctrl; | |
| void _ottf_main(void) { | |
| uint32_t en_result, regwen_result; | |
| // Initialize the UART to enable logging for non-DV simulation platforms. | |
| if (kDeviceType != kDeviceSimDV) { | |
| init_uart(TOP_MATCHA_UART0_BASE_ADDR, &uart); | |
| } | |
| LOG_INFO("Hello Shodan!"); | |
| // Start testing | |
| test_status_set(kTestStatusInTest); | |
| CHECK_DIF_OK(dif_smc_ctrl_init( | |
| mmio_region_from_addr(TOP_MATCHA_SMC_CTRL_BASE_ADDR), &smc_ctrl)); | |
| CHECK_DIF_OK(dif_smc_ctrl_read_en(&smc_ctrl, &en_result)); | |
| CHECK(en_result == 0, "smc_ctrl is not initilized: expected : 0 | actual: %d", | |
| en_result); | |
| CHECK_DIF_OK(dif_smc_ctrl_set_en(&smc_ctrl), "Set CTRL_EN failed"); | |
| CHECK_DIF_OK(dif_smc_ctrl_read_en(&smc_ctrl, &en_result)); | |
| CHECK(en_result == 1, "ctrl_en is not set: expected : 1 | actual: %d", | |
| en_result); | |
| CHECK_DIF_OK(dif_smc_ctrl_read_regwen(&smc_ctrl, ®wen_result)); | |
| CHECK(regwen_result == 1, | |
| "regwen is not initialized: expected : 1 | actual: %d", regwen_result); | |
| CHECK_DIF_OK(dif_smc_ctrl_clear_regwen(&smc_ctrl), "Clear REGWEN failed"); | |
| CHECK_DIF_OK(dif_smc_ctrl_read_regwen(&smc_ctrl, ®wen_result)); | |
| CHECK(regwen_result == 0, "regwen is not cleared: expected : 0 | actual: %d", | |
| regwen_result); | |
| CHECK_DIF_OK(dif_smc_ctrl_clear_en(&smc_ctrl), | |
| "Clear CTRL_EN with REGWEN as 0 failed"); | |
| CHECK_DIF_OK(dif_smc_ctrl_read_en(&smc_ctrl, &en_result)); | |
| CHECK(en_result == 1, | |
| "ctrl_en should not be cleared: expected : 1 | actual: %d", en_result); | |
| test_status_set(kTestStatusPassed); | |
| } |