MLECO-3096: Removing "timer" from HAL profile.

Attempting to have timer functionality contained within
the platform drivers "package" as it should (in line with
the refactoring work done so far under HAL). This will
ensure that we don't need two timer implementations under
HAL "profiles" and therefore, this whole directory can be
removed.

This change also addressed issue with the applicatio level
Profiler code knowing about how the PMU has been set up by
the platform code. This link has been removed completely.
This will make it much easier to add/amend the Ethos-U PMU
event counters types and give each platform the capability
of populating their relvant counters. The application level
Profiler doesn't know which metrics it is displaying but
just calculates and maintains statistics for whatever PMU
counters it receives from the HAL level.

A fix for timing adapter issue introduced in the last CR
is also included.

Change-Id: Ia46e03a06e7b8e42b9ed2ba8f2af2dcd2229c110
Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
diff --git a/source/hal/source/platform/native/CMakeLists.txt b/source/hal/source/platform/native/CMakeLists.txt
index 9673fef..e0cc711 100644
--- a/source/hal/source/platform/native/CMakeLists.txt
+++ b/source/hal/source/platform/native/CMakeLists.txt
@@ -43,7 +43,8 @@
 ## Platform sources
 target_sources(${PLATFORM_DRIVERS_TARGET}
     PRIVATE
-    source/platform_drivers.c)
+    source/platform_drivers.c
+    source/timer_native.c)
 
 ## Platform component directory
 if (NOT DEFINED COMPONENTS_DIR)
@@ -57,10 +58,14 @@
 ## Platform component: lcd
 add_subdirectory(${COMPONENTS_DIR}/lcd ${CMAKE_BINARY_DIR}/lcd)
 
+## Platform component: PMU
+add_subdirectory(${COMPONENTS_DIR}/platform_pmu ${CMAKE_BINARY_DIR}/platform_pmu)
+
 # Add dependencies:
 target_link_libraries(${PLATFORM_DRIVERS_TARGET}
     PUBLIC
     log
+    platform_pmu
     stdout
     lcd_stubs)
 
diff --git a/source/hal/source/platform/native/include/platform_drivers.h b/source/hal/source/platform/native/include/platform_drivers.h
index d93e31c..a203618 100644
--- a/source/hal/source/platform/native/include/platform_drivers.h
+++ b/source/hal/source/platform/native/include/platform_drivers.h
@@ -21,6 +21,7 @@
 #include "log_macros.h"     /* Logging related helpers. */
 #include "lcd_img.h"        /* LCD functions */
 #include "user_input.h"     /* User input function */
+#include "timer_native.h"   /* Native platform timer/profiler support */
 
 /**
  * @brief   Initialises the platform components.
diff --git a/source/hal/source/platform/native/include/timer_native.h b/source/hal/source/platform/native/include/timer_native.h
new file mode 100644
index 0000000..c8eeda2
--- /dev/null
+++ b/source/hal/source/platform/native/include/timer_native.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ *     http://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.
+ */
+#ifndef NATIVE_TIMER_H
+#define NATIVE_TIMER_H
+
+#include "platform_pmu.h"
+
+#include <stdint.h>
+#include <time.h>
+
+/**
+ * @brief   Resets the counters.
+ */
+void platform_reset_counters(void);
+
+/**
+ * @brief   Gets the current counter values.
+ * @returns A populated instance of pmu_counters struct.
+ **/
+pmu_counters platform_get_counters(void);
+
+#endif /* NATIVE_TIMER_H */
diff --git a/source/hal/source/platform/native/source/timer_native.c b/source/hal/source/platform/native/source/timer_native.c
new file mode 100644
index 0000000..590975f
--- /dev/null
+++ b/source/hal/source/platform/native/source/timer_native.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ *     http://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.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "timer_native.h"
+
+#include "log_macros.h"
+
+#include <time.h>
+#include <string.h>
+
+#define MILLISECONDS_IN_SECOND      1000
+#define MICROSECONDS_IN_SECOND      1000000
+#define NANOSECONDS_IN_MILLISECOND  1000000
+#define NANOSECONDS_IN_MICROSECOND  1000
+
+void platform_reset_counters() { /* Nothing to do */ }
+
+pmu_counters platform_get_counters(void)
+{
+    struct timespec current_time;
+    pmu_counters platform_counters = {
+        .num_counters = 0,
+        .initialised = true
+    };
+    clock_gettime(1, &current_time);
+    uint64_t microseconds = (current_time.tv_sec * MICROSECONDS_IN_SECOND) +
+                            (current_time.tv_nsec / NANOSECONDS_IN_MICROSECOND);
+
+#if NUM_PMU_COUNTERS > 0
+    platform_counters.counters[0].value = microseconds;
+    platform_counters.counters[0].name = "Duration";
+    platform_counters.counters[0].unit = "microseconds";
+    ++platform_counters.num_counters;
+#endif /* NUM_PMU_COUNTERS > 0 */
+
+    return platform_counters;
+}
+
+#ifdef __cplusplus
+}
+#endif