From 5da4092d07c31acaa3d44ac57fa3b02a3be67182 Mon Sep 17 00:00:00 2001 From: Bhavik Patel Date: Wed, 15 Jul 2020 10:06:43 +0200 Subject: MLBEDSW-2594 Initialize the Ethos-U before every job This includes resetting the Ethos-U and restoring the previosuly saved PMU configuration (if any). Change-Id: Id952fb6fef513468952b6a469e857510f8c0214c --- src/ethosu_device.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/ethosu_device.c') diff --git a/src/ethosu_device.c b/src/ethosu_device.c index 9bda87d..60fc243 100644 --- a/src/ethosu_device.c +++ b/src/ethosu_device.c @@ -551,3 +551,42 @@ void ethosu_write_reg(struct ethosu_device *dev, uint32_t address, uint32_t valu UNUSED(value); #endif } + +enum ethosu_error_codes ethosu_save_pmu_config(struct ethosu_device *dev) +{ +#if !defined(ARM_NPU_STUB) + dev->pmccntr = ETHOSU_PMU_Get_CCNTR(); + for (uint32_t i = 0; i < ETHOSU_PMU_NCOUNTERS; i++) + { + dev->pmu_evcntr[i] = ETHOSU_PMU_Get_EVCNTR(i); + dev->pmu_evtypr[i] = ETHOSU_PMU_Get_EVTYPER(i); + } + if (!dev->restore_pmu_config) + { + dev->restore_pmu_config = true; + } +#else + UNUSED(dev); +#endif + + return ETHOSU_SUCCESS; +} + +enum ethosu_error_codes ethosu_restore_pmu_config(struct ethosu_device *dev) +{ +#if !defined(ARM_NPU_STUB) + if (dev->restore_pmu_config) + { + ETHOSU_PMU_Set_CCNTR(dev->pmccntr); + for (uint32_t i = 0; i < ETHOSU_PMU_NCOUNTERS; i++) + { + ETHOSU_PMU_Set_EVCNTR(i, dev->pmu_evcntr[i]); + ETHOSU_PMU_Set_EVTYPER(i, dev->pmu_evtypr[i]); + } + } +#else + UNUSED(dev); +#endif + + return ETHOSU_SUCCESS; +} -- cgit v1.2.1