From 92947aa0a145c764792de1e1a7e9ce5998f61319 Mon Sep 17 00:00:00 2001 From: Moritz Scherer Date: Fri, 23 Aug 2024 10:40:40 +0200 Subject: [PATCH] Check in soc_ctrl, CMakeLists, testClusterOffload --- targets/chimera-open/include/soc_ctrl.h | 17 +++++++++ tests/chimera-open/CMakeLists.txt | 7 ++++ .../testClusterOffload/CMakeLists.txt | 18 ++++++++++ .../src/testClusterOffload.c | 35 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 targets/chimera-open/include/soc_ctrl.h create mode 100644 tests/chimera-open/CMakeLists.txt create mode 100644 tests/chimera-open/testClusterOffload/CMakeLists.txt create mode 100644 tests/chimera-open/testClusterOffload/src/testClusterOffload.c diff --git a/targets/chimera-open/include/soc_ctrl.h b/targets/chimera-open/include/soc_ctrl.h new file mode 100644 index 0000000..1493fc1 --- /dev/null +++ b/targets/chimera-open/include/soc_ctrl.h @@ -0,0 +1,17 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Moritz Scherer + +#ifndef _OFFLOAD_INCLUDE_GUARD_ +#define _OFFLOAD_INCLUDE_GUARD_ + +#include + +void setupInterruptHandler(void *handler); +void offloadToCluster(void *function, uint8_t clusterId); +void waitClusterBusy(uint8_t clusterId); +uint32_t waitForCluster(uint8_t clusterId); + +#endif diff --git a/tests/chimera-open/CMakeLists.txt b/tests/chimera-open/CMakeLists.txt new file mode 100644 index 0000000..1d90c6f --- /dev/null +++ b/tests/chimera-open/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright 2024 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Moritz Scherer + +add_subdirectory(testClusterOffload) diff --git a/tests/chimera-open/testClusterOffload/CMakeLists.txt b/tests/chimera-open/testClusterOffload/CMakeLists.txt new file mode 100644 index 0000000..4ad9706 --- /dev/null +++ b/tests/chimera-open/testClusterOffload/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright 2024 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Moritz Scherer + +project(chimera-sdk-testClusterOffload LANGUAGES C ASM) + +file(GLOB_RECURSE TEST_SRCS + "src/testClusterOffload.c" +) + +add_chimera_test( + testClusterOffload + ${TEST_SRCS} +) + +target_link_libraries(testClusterOffload PUBLIC chimera-sdk) diff --git a/tests/chimera-open/testClusterOffload/src/testClusterOffload.c b/tests/chimera-open/testClusterOffload/src/testClusterOffload.c new file mode 100644 index 0000000..ca8c445 --- /dev/null +++ b/tests/chimera-open/testClusterOffload/src/testClusterOffload.c @@ -0,0 +1,35 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Moritz Scherer + +#include "soc_ctrl.h" +#include "soc_addr_map.h" +#include +#include + +#define TESTVAL 0x050CCE55 + +static uint32_t *clintPointer = (uint32_t *)CLINT_CTRL_BASE; + +void clusterInterruptHandler() { + uint8_t hartId; + asm("csrr %0, mhartid" : "=r"(hartId)::); + + volatile uint32_t *interruptTarget = clintPointer + hartId; + *interruptTarget = 0; + return; +} + +int32_t testReturn() { + return TESTVAL; +} + +int main() { + setupInterruptHandler(clusterInterruptHandler); + offloadToCluster(testReturn, 0); + uint32_t retVal = waitForCluster(0); + + return (retVal != (TESTVAL | 0x000000001)); +}