From f62c3d756917295146d415fcba7b5208c13874f7 Mon Sep 17 00:00:00 2001 From: Kristofer Jonsson Date: Thu, 21 Jan 2021 17:39:03 +0100 Subject: Build system refactoring The source tree is configured for a specific target as defined in the targets directory. The common target components are defined in targets/common. Targets for real platform should include this directory to get the default target libraries setup. Change-Id: I7fced4bfacec97432cbbd4125bd5b4cdd21122e3 --- targets/corstone-300/target.cpp | 109 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 targets/corstone-300/target.cpp (limited to 'targets/corstone-300/target.cpp') diff --git a/targets/corstone-300/target.cpp b/targets/corstone-300/target.cpp new file mode 100644 index 0000000..3d18680 --- /dev/null +++ b/targets/corstone-300/target.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** + * Includes + ****************************************************************************/ + +#include "target.hpp" + +#ifdef ETHOSU +#include +#endif + +#include "uart.h" + +#include + +using namespace EthosU; + +/**************************************************************************** + * Defines + ****************************************************************************/ + +#define ETHOSU_BASE_ADDRESS 0x48102000 + +#define ETHOSU_IRQ 56 + +/**************************************************************************** + * Variables + ****************************************************************************/ + +#if defined(ETHOSU_FAST_MEMORY_SIZE) && ETHOSU_FAST_MEMORY_SIZE > 0 +__attribute__((aligned(16), section(".bss.ethosu_scratch"))) uint8_t ethosu_scratch[ETHOSU_FAST_MEMORY_SIZE]; +#else +#define ethosu_scratch 0 +#define ETHOSU_FAST_MEMORY_SIZE 0 +#endif + +/**************************************************************************** + * Cache maintenance + ****************************************************************************/ + +#if defined(CPU_CACHE_ENABLE) && defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) +extern "C" { +void ethosu_flush_dcache(uint32_t *p, size_t bytes) { + if (p) + SCB_CleanDCache_by_Addr(p, bytes); + else + SCB_CleanDCache(); +} + +void ethosu_invalidate_dcache(uint32_t *p, size_t bytes) { + if (p) + SCB_InvalidateDCache_by_Addr(p, bytes); + else + SCB_InvalidateDCache(); +} +} +#endif + +/**************************************************************************** + * Init + ****************************************************************************/ + +namespace { + +#ifdef ETHOSU +void ethosuIrqHandler() { + ethosu_irq_handler(); +} +#endif + +} // namespace + +namespace EthosU { + +void targetSetup() { + // Initialize UART driver + uart_init(); + +#ifdef ETHOSU + // Initialize Ethos-U NPU driver + if (ethosu_init_v3(reinterpret_cast(ETHOSU_BASE_ADDRESS), ethosu_scratch, ETHOSU_FAST_MEMORY_SIZE, 1, 1)) { + printf("Failed to initialize NPU.\n"); + return; + } + + /* Assumes SCB->VTOR point to RW memory */ + NVIC_SetVector(static_cast(ETHOSU_IRQ), (uint32_t)ðosuIrqHandler); + NVIC_EnableIRQ(static_cast(ETHOSU_IRQ)); +#endif +} + +} // namespace EthosU -- cgit v1.2.1