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
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 @@
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;
+}