diff --git a/drivers/interrupt_controller/intc_plic.c b/drivers/interrupt_controller/intc_plic.c index 20422f2343..51ce176939 100644 --- a/drivers/interrupt_controller/intc_plic.c +++ b/drivers/interrupt_controller/intc_plic.c @@ -45,6 +45,12 @@ #define PLIC_REG_SIZE 32 #define PLIC_REG_MASK BIT_MASK(LOG2(PLIC_REG_SIZE)) +#ifdef CONFIG_TEST_INTC_PLIC +#define INTC_PLIC_STATIC +#else +#define INTC_PLIC_STATIC static inline +#endif + typedef void (*riscv_plic_irq_config_func_t)(void); struct plic_config { mem_addr_t prio; @@ -59,12 +65,12 @@ struct plic_config { static uint32_t save_irq; static const struct device *save_dev; -static inline uint32_t local_irq_to_reg_index(uint32_t local_irq) +INTC_PLIC_STATIC uint32_t local_irq_to_reg_index(uint32_t local_irq) { return local_irq >> LOG2(PLIC_REG_SIZE); } -static inline uint32_t local_irq_to_reg_offset(uint32_t local_irq) +INTC_PLIC_STATIC uint32_t local_irq_to_reg_offset(uint32_t local_irq) { return local_irq_to_reg_index(local_irq) * sizeof(uint32_t); } diff --git a/tests/drivers/interrupt_controller/intc_plic/CMakeLists.txt b/tests/drivers/interrupt_controller/intc_plic/CMakeLists.txt new file mode 100644 index 0000000000..59fd0a3bb2 --- /dev/null +++ b/tests/drivers/interrupt_controller/intc_plic/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(intc_plic) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/interrupt_controller/intc_plic/Kconfig b/tests/drivers/interrupt_controller/intc_plic/Kconfig new file mode 100644 index 0000000000..53ccc57348 --- /dev/null +++ b/tests/drivers/interrupt_controller/intc_plic/Kconfig @@ -0,0 +1,10 @@ +# Copyright (c) 2023 Antmicro +# SPDX-License-Identifier: Apache-2.0 + +config TEST_INTC_PLIC + bool + default y + help + Declare some intc_plic.c functions in the global scope for verification. + +source "Kconfig" diff --git a/tests/drivers/interrupt_controller/intc_plic/prj.conf b/tests/drivers/interrupt_controller/intc_plic/prj.conf new file mode 100644 index 0000000000..9467c29268 --- /dev/null +++ b/tests/drivers/interrupt_controller/intc_plic/prj.conf @@ -0,0 +1 @@ +CONFIG_ZTEST=y diff --git a/tests/drivers/interrupt_controller/intc_plic/src/main.c b/tests/drivers/interrupt_controller/intc_plic/src/main.c new file mode 100644 index 0000000000..631e0e8915 --- /dev/null +++ b/tests/drivers/interrupt_controller/intc_plic/src/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Antmicro + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +uint32_t local_irq_to_reg_index(uint32_t local_irq); +uint32_t local_irq_to_reg_offset(uint32_t local_irq); + +ZTEST_SUITE(intc_plic, NULL, NULL, NULL, NULL, NULL); + +/* Test calculating the register index from a local IRQ number */ +ZTEST(intc_plic, test_local_irq_to_reg_index) +{ + zassert_equal(0, local_irq_to_reg_index(0x1f)); + zassert_equal(1, local_irq_to_reg_index(0x20)); + zassert_equal(1, local_irq_to_reg_index(0x3f)); + zassert_equal(2, local_irq_to_reg_index(0x40)); +} + +/* Test calculating the register offset from a local IRQ number */ +ZTEST(intc_plic, test_local_irq_to_reg_offset) +{ + zassert_equal(0, local_irq_to_reg_offset(0x1f)); + zassert_equal(4, local_irq_to_reg_offset(0x20)); + zassert_equal(4, local_irq_to_reg_offset(0x3f)); + zassert_equal(8, local_irq_to_reg_offset(0x40)); +} diff --git a/tests/drivers/interrupt_controller/intc_plic/testcase.yaml b/tests/drivers/interrupt_controller/intc_plic/testcase.yaml new file mode 100644 index 0000000000..11c1f74fa3 --- /dev/null +++ b/tests/drivers/interrupt_controller/intc_plic/testcase.yaml @@ -0,0 +1,7 @@ +tests: + drivers.interrupt_controller.intc_plic: + tags: + - drivers + - interrupt + - plic + platform_allow: qemu_riscv64