From 25d78c0062908e91b4d0ae241600f4a077a19400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85strand?= Date: Tue, 21 Apr 2020 14:19:44 +0200 Subject: MLBEDSW-1796 Refactor IRQ initialization Turn the IRQ initialization around, to have the application define the interrupt handler and expose the driver routine that is to be called when that happens. Change-Id: Idbfba1b1d1a1eaf6678ee16e9583c496eb2287ed --- include/ethosu_driver.h | 5 +++ src/ethosu_driver.c | 10 +++--- src/irq_driver.h | 83 ------------------------------------------------- 3 files changed, 9 insertions(+), 89 deletions(-) delete mode 100644 src/irq_driver.h diff --git a/include/ethosu_driver.h b/include/ethosu_driver.h index 5d75852..7ab420a 100644 --- a/include/ethosu_driver.h +++ b/include/ethosu_driver.h @@ -92,6 +92,11 @@ int ethosu_invoke(const void *custom_data_ptr, */ void ethosu_abort(void); +/** + * Interrupt handler do be called on IRQ from Ethos-U + */ +void ethosu_irq_handler(void); + #ifdef __cplusplus } #endif diff --git a/src/ethosu_driver.c b/src/ethosu_driver.c index 567c878..3bad2ac 100644 --- a/src/ethosu_driver.c +++ b/src/ethosu_driver.c @@ -20,8 +20,9 @@ #include "ethosu_common.h" #include "ethosu_device.h" -#include "irq_driver.h" + #include +#include #include #include #include @@ -34,7 +35,7 @@ static int abort_inference = false; static volatile bool irq_triggered = false; #if defined(CPU_CORTEX_M3) || defined(CPU_CORTEX_M4) || defined(CPU_CORTEX_M7) || defined(CPU_CORTEX_M33) || \ defined(CPU_CORTEX_M55) -void irq_handler() +void ethosu_irq_handler(void) { uint8_t irq_raised = 0; (void)ethosu_is_irq_raised(&irq_raised); @@ -56,13 +57,12 @@ static inline void wait_for_irq(void) break; } - sleep(); + __WFI(); __enable_irq(); } } #else -#define setup_irq(...) // Just polling the status register static inline void wait_for_irq(void) { @@ -198,8 +198,6 @@ int ethosu_init(void) return -1; } - setup_irq(&irq_handler, EthosuIrq); - return_code = ethosu_dev_init(); return return_code; diff --git a/src/irq_driver.h b/src/irq_driver.h deleted file mode 100644 index 5a853a5..0000000 --- a/src/irq_driver.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2019-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. - */ - -// IRQ -#if defined(CPU_CORTEX_M3) || defined(CPU_CORTEX_M4) || defined(CPU_CORTEX_M7) || defined(CPU_CORTEX_M33) || \ - defined(CPU_CORTEX_M55) -typedef enum irqn_type -{ - Reset = -15, - Nmi = -14, - HardFault = -13, - MemoryManagement = -12, - BusFault = -11, - UsageFault = -10, - SVCall = -5, - DebugMonitor = -4, - PendSV = -2, - SysTick_IRQn = -1, - Irq0 = 0, -#if defined(FPGA) -#if defined(CPU_CORTEX_M55) - EthosuIrq = 55 -#else - EthosuIrq = 67 -#endif -#else - EthosuIrq = Irq0 -#endif -} IRQn_Type; - -#define __CM7_REV 0x0000U -#define __MPU_PRESENT 1 -#define __ICACHE_PRESENT 1 -#define __DCACHE_PRESENT 1 -#define __TCM_PRESENT 0 -#define __NVIC_PRIO_BITS 3 -#define __Vendor_SysTickConfig 0 - -#if defined(CPU_CORTEX_M7) -#include -#elif defined(CPU_CORTEX_M4) -#include -#elif defined(CPU_CORTEX_M3) -#include -#elif defined(CPU_CORTEX_M0) -#include -#elif defined(CPU_CORTEX_M33) -#include -#elif defined(CPU_CORTEX_M55) -#include -#else -#error "Unknown CPU" -#endif - -typedef void (*ExecFuncPtr)(); -static inline void setup_irq(void (*irq_handler)(), enum irqn_type irq_number) -{ - __NVIC_EnableIRQ(irq_number); - ExecFuncPtr *vectorTable = (ExecFuncPtr *)(SCB->VTOR); - vectorTable[irq_number + 16] = irq_handler; -} - -static inline void sleep() -{ - __WFI(); -} - -#endif -- cgit v1.2.1