MLECO-3070: Further HAL cleanup.

Cleaning up HAL sources by removing unnecessary redirections
with function pointers. The "platform packages" under HAL are
now streamlined enough to not need any major HAL wrapping (as
was the case before).

This allows us to have a very thin HAL layer that sits on top
of the platform and compnent packs. Also helps in getting rid
of "hal platform" pointer being passed around in the code to
use any HAL functionality.

Change-Id: I04b2057f972aad7a5cfb4a396bcdf147c9f9ef1c
Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
diff --git a/source/hal/source/components/npu/ethosu_profiler.c b/source/hal/source/components/npu/ethosu_profiler.c
index 3ac3497..5d50b09 100644
--- a/source/hal/source/components/npu/ethosu_profiler.c
+++ b/source/hal/source/components/npu/ethosu_profiler.c
@@ -22,6 +22,8 @@
 
 extern struct ethosu_driver ethosu_drv;     /* Default Arm Ethos-U NPU device driver object */
 static ethosu_pmu_counters npu_counters;    /* NPU counter local instance */
+static const char* unit_beats = "beats";
+static const char* unit_cycles = "cycles";
 
 /**
  * @brief Gets the npu counter instance to be used.
@@ -59,29 +61,29 @@
     counters->npu_evt_counters[0].event_type = ETHOSU_PMU_NPU_IDLE;
     counters->npu_evt_counters[0].event_mask = ETHOSU_PMU_CNT1_Msk;
     counters->npu_evt_counters[0].name = "NPU IDLE";
-    counters->npu_evt_counters[0].unit = "cycles";
+    counters->npu_evt_counters[0].unit = unit_cycles;
 
     counters->npu_evt_counters[1].event_type = ETHOSU_PMU_AXI0_RD_DATA_BEAT_RECEIVED;
     counters->npu_evt_counters[1].event_mask = ETHOSU_PMU_CNT2_Msk;
     counters->npu_evt_counters[1].name = "NPU AXI0_RD_DATA_BEAT_RECEIVED";
-    counters->npu_evt_counters[1].unit = "beats";
+    counters->npu_evt_counters[1].unit = unit_beats;
 
     counters->npu_evt_counters[2].event_type = ETHOSU_PMU_AXI0_WR_DATA_BEAT_WRITTEN;
     counters->npu_evt_counters[2].event_mask = ETHOSU_PMU_CNT3_Msk;
     counters->npu_evt_counters[2].name = "NPU AXI0_WR_DATA_BEAT_WRITTEN";
-    counters->npu_evt_counters[2].unit = "beats";
+    counters->npu_evt_counters[2].unit = unit_beats;
 
     counters->npu_evt_counters[3].event_type = ETHOSU_PMU_AXI1_RD_DATA_BEAT_RECEIVED;
     counters->npu_evt_counters[3].event_mask = ETHOSU_PMU_CNT4_Msk;
     counters->npu_evt_counters[3].name = "NPU AXI1_RD_DATA_BEAT_RECEIVED";
-    counters->npu_evt_counters[3].unit = "beats";
+    counters->npu_evt_counters[3].unit = unit_beats;
 #else /* ETHOSU_PMU_NCOUNTERS >= 4 */
     #error "NPU PMU expects a minimum of 4 available event triggered counters!"
 #endif /* ETHOSU_PMU_NCOUNTERS >= 4 */
 
 #if ETHOSU_DERIVED_NCOUNTERS >= 1
     counters->npu_derived_counters[0].name = "NPU ACTIVE";
-    counters->npu_derived_counters[0].unit = "cycles";
+    counters->npu_derived_counters[0].unit = unit_cycles;
 #endif /* ETHOSU_DERIVED_NCOUNTERS >= 1 */
 
     for (i = 0; i < ETHOSU_PMU_NCOUNTERS; ++i) {
diff --git a/source/hal/source/components/npu/include/ethosu_profiler.h b/source/hal/source/components/npu/include/ethosu_profiler.h
index ca95b19..093c07f 100644
--- a/source/hal/source/components/npu/include/ethosu_profiler.h
+++ b/source/hal/source/components/npu/include/ethosu_profiler.h
@@ -29,14 +29,14 @@
     enum ethosu_pmu_event_type event_type;
     uint32_t event_mask;
     uint32_t counter_value;
-    char* unit;
-    char* name;
+    const char* unit;
+    const char* name;
 } npu_evt_counter;
 
 typedef struct npu_derived_counter_ {
     uint32_t counter_value;
-    char* unit;
-    char* name;
+    const char* unit;
+    const char* name;
 } npu_derived_counter;
 
 typedef struct ethosu_pmu_counters_ {
diff --git a/source/hal/source/components/platform_pmu/include/platform_pmu.h b/source/hal/source/components/platform_pmu/include/platform_pmu.h
index 3724e57..b3fd8e8 100644
--- a/source/hal/source/components/platform_pmu/include/platform_pmu.h
+++ b/source/hal/source/components/platform_pmu/include/platform_pmu.h
@@ -50,10 +50,10 @@
 void platform_reset_counters(void);
 
 /**
- * @brief   Gets the current counter values.
- * @returns A populated instance of pmu_counters struct.
+ * @brief       Gets the current counter values.
+ * @param[out]  Pointer to a pmu_counters object.
  **/
-pmu_counters platform_get_counters(void);
+void platform_get_counters(pmu_counters* counters);
 
 #ifdef __cplusplus
 }
diff --git a/source/hal/source/hal.c b/source/hal/source/hal.c
index d6028e7..4651bfd 100644
--- a/source/hal/source/hal.c
+++ b/source/hal/source/hal.c
@@ -19,62 +19,29 @@
 #include "platform_drivers.h"   /* Platform drivers */
 #include "log_macros.h"         /* Logging macros */
 
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-int hal_init(hal_platform* platform, platform_timer* timer)
+bool hal_platform_init(void)
 {
-    platform->timer     = timer;
-    platform->platform_init     = platform_init;
-    platform->platform_release  = platform_release;
-    platform_name(platform->plat_name, sizeof(platform->plat_name));
-
-    return 0;
-}
-
-/**
- * @brief  Local helper function to clean the slate for current platform.
- **/
-static void hal_platform_clear(hal_platform* platform)
-{
-    assert(platform);
-    platform->inited = 0;
-}
-
-int hal_platform_init(hal_platform* platform)
-{
-    int state;
-    assert(platform && platform->platform_init);
-    hal_platform_clear(platform);
-
     /* Initialise platform */
-    if (0 != (state = platform->platform_init())) {
-        printf_err("Failed to initialise platform %s\n", platform->plat_name);
-        return state;
+    if (0 != platform_init()) {
+        printf_err("Failed to initialise platform %s\n", platform_name());
+        return false;
     }
 
     /* Initialise LCD */
-    if (0 != (state = hal_lcd_init())) {
+    if (0 != hal_lcd_init()) {
         printf_err("hal_lcd_init failed\n");
-        return state;
+        return false;
     }
 
-    /* Initialise the timer module */
-    init_timer(platform->timer);
+    /* Initialise PMU */
+    hal_pmu_init();
 
-    info("%s platform initialised\n", platform->plat_name);
-    platform->inited = !state;
-    return state;
+    return true;
 }
 
-void hal_platform_release(hal_platform *platform)
+void hal_platform_release(void)
 {
-    assert(platform && platform->platform_release);
-
-    hal_platform_clear(platform);
-    info("Releasing platform %s\n", platform->plat_name);
-    platform->platform_release();
+    platform_release();
 }
 
 bool hal_get_user_input(char* user_input, int size)
diff --git a/source/hal/source/hal_timer.c b/source/hal/source/hal_pmu.c
similarity index 61%
rename from source/hal/source/hal_timer.c
rename to source/hal/source/hal_pmu.c
index 0488afa..c89128d 100644
--- a/source/hal/source/hal_timer.c
+++ b/source/hal/source/hal_pmu.c
@@ -14,26 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "timer.h"
-#include "log_macros.h"
+#include "hal_pmu.h"
 #include "platform_drivers.h"
 
-#include <assert.h>
-#include <string.h>
-#include <inttypes.h>
-
-/**
- * @brief       Initialiser for HAL timer.
- * @param[in]   timer  Platform timer to initialize.
- **/
-void init_timer(platform_timer* timer)
+void hal_pmu_init(void)
 {
-    assert(timer);
-    memset(timer, 0, sizeof(*timer));
+    platform_reset_counters();
+}
 
-    timer->reset = platform_reset_counters;
-    timer->get_counters = platform_get_counters;
+void hal_pmu_reset(void)
+{
+    platform_reset_counters();
+}
 
-    timer->reset();
-    timer->inited = 1;
+void hal_pmu_get_counters(pmu_counters* counters)
+{
+    platform_get_counters(counters);
 }
diff --git a/source/hal/source/platform/mps3/include/platform_drivers.h b/source/hal/source/platform/mps3/include/platform_drivers.h
index 8b699d5..de03bcd 100644
--- a/source/hal/source/platform/mps3/include/platform_drivers.h
+++ b/source/hal/source/platform/mps3/include/platform_drivers.h
@@ -38,10 +38,9 @@
 void platform_release(void);
 
 /**
- * @brief   Sets the platform name.
- * @param[out] name     Name of the platform to be set
- * @param[in]  size     Size of the input buffer
+ * @brief   Gets the platform name.
+ * @return  Pointer to the name
  */
-void platform_name(char* name, size_t size);
+const char* platform_name(void);
 
 #endif /* PLATFORM_DRIVERS_H */
diff --git a/source/hal/source/platform/mps3/include/timer_mps3.h b/source/hal/source/platform/mps3/include/timer_mps3.h
index b370e89..dcec980 100644
--- a/source/hal/source/platform/mps3/include/timer_mps3.h
+++ b/source/hal/source/platform/mps3/include/timer_mps3.h
@@ -44,10 +44,10 @@
 void platform_reset_counters(void);
 
 /**
- * @brief   Gets the current counter values.
- * @returns A populated instance of pmu_counters struct.
+ * @brief       Gets the current counter values.
+ * @param[out]  Pointer to a pmu_counters object.
  **/
-pmu_counters platform_get_counters(void);
+void platform_get_counters(pmu_counters* counters);
 
 /**
  * @brief  Gets the MPS3 core clock
diff --git a/source/hal/source/platform/mps3/source/platform_drivers.c b/source/hal/source/platform/mps3/source/platform_drivers.c
index 17ccdf2..d1c3da2 100644
--- a/source/hal/source/platform/mps3/source/platform_drivers.c
+++ b/source/hal/source/platform/mps3/source/platform_drivers.c
@@ -48,6 +48,9 @@
  */
 static int verify_platform(void);
 
+/** Platform name */
+static const char* s_platform_name = DESIGN_NAME;
+
 int platform_init(void)
 {
     int err = 0;
@@ -82,8 +85,7 @@
 #endif /* ARM_NPU */
 
     /* Print target design info */
-    info("Target system design: %s\n", DESIGN_NAME);
-
+    info("Target system design: %s\n", s_platform_name);
     return 0;
 }
 
@@ -92,9 +94,9 @@
     __disable_irq();
 }
 
-void platform_name(char* name, size_t size)
+const char* platform_name(void)
 {
-    strncpy(name, DESIGN_NAME, size);
+    return s_platform_name;
 }
 
 #define CREATE_MASK(msb, lsb)           (int)(((1U << ((msb) - (lsb) + 1)) - 1) << (lsb))
diff --git a/source/hal/source/platform/mps3/source/timer_mps3.c b/source/hal/source/platform/mps3/source/timer_mps3.c
index 6330269..7ce3002 100644
--- a/source/hal/source/platform/mps3/source/timer_mps3.c
+++ b/source/hal/source/platform/mps3/source/timer_mps3.c
@@ -20,6 +20,8 @@
 #include "smm_mps3.h"   /* Memory map for MPS3. */
 
 static uint64_t cpu_cycle_count = 0;    /* 64-bit cpu cycle counter */
+static const char* unit_cycles = "cycles";
+static const char* unit_ms = "milliseconds";
 
 /**
  * @brief   Gets the system tick triggered cycle counter for the CPU.
@@ -69,12 +71,10 @@
 #endif /* defined (ARM_NPU) */
 }
 
-pmu_counters platform_get_counters(void)
+void platform_get_counters(pmu_counters* counters)
 {
-    pmu_counters platform_counters = {
-        .num_counters = 0,
-        .initialised = true
-    };
+    counters->num_counters = 0;
+    counters->initialised = true;
     uint32_t i = 0;
 
 #if defined (ARM_NPU)
@@ -84,20 +84,20 @@
             npu_counters.npu_evt_counters[i].counter_value,
             npu_counters.npu_evt_counters[i].name,
             npu_counters.npu_evt_counters[i].unit,
-            &platform_counters);
+            counters);
     }
     for (i = 0; i < ETHOSU_DERIVED_NCOUNTERS; ++i) {
         add_pmu_counter(
             npu_counters.npu_derived_counters[i].counter_value,
             npu_counters.npu_derived_counters[i].name,
             npu_counters.npu_derived_counters[i].unit,
-            &platform_counters);
+            counters);
     }
     add_pmu_counter(
         npu_counters.npu_total_ccnt,
         "NPU TOTAL",
-        "cycles",
-        &platform_counters);
+        unit_cycles,
+        counters);
 #endif /* defined (ARM_NPU) */
 
 #if defined(CPU_PROFILE_ENABLED)
@@ -111,14 +111,14 @@
     add_pmu_counter(
             mps3_counters.counter_systick,
             "CPU TOTAL",
-            "cycles",
-            &platform_counters);
+            unit_cycles,
+            counters);
 
     add_pmu_counter(
             get_tstamp_milliseconds(&mps3_counters),
             "DURATION",
-            "milliseconds",
-            &platform_counters);
+            unit_ms,
+            counters);
 #endif /* defined(CPU_PROFILE_ENABLED) */
 
 #if !defined(CPU_PROFILE_ENABLED)
@@ -129,8 +129,6 @@
     UNUSED(i);
 #endif /* !defined(ARM_NPU) */
 #endif /* !defined(CPU_PROFILE_ENABLED) */
-
-    return platform_counters;
 }
 
 uint32_t get_mps3_core_clock(void)
diff --git a/source/hal/source/platform/native/include/platform_drivers.h b/source/hal/source/platform/native/include/platform_drivers.h
index a203618..50164db 100644
--- a/source/hal/source/platform/native/include/platform_drivers.h
+++ b/source/hal/source/platform/native/include/platform_drivers.h
@@ -35,10 +35,9 @@
 void platform_release(void);
 
 /**
- * @brief   Sets the platform name.
- * @param[out] name     Name of the platform to be set
- * @param[in]  size     Size of the input buffer
+ * @brief   Gets the platform name.
+ * @return  Pointer to the name
  */
-void platform_name(char* name, size_t size);
+const char* platform_name(void);
 
 #endif /* PLATFORM_DRIVERS_H */
diff --git a/source/hal/source/platform/native/include/timer_native.h b/source/hal/source/platform/native/include/timer_native.h
index c8eeda2..da34b30 100644
--- a/source/hal/source/platform/native/include/timer_native.h
+++ b/source/hal/source/platform/native/include/timer_native.h
@@ -28,9 +28,9 @@
 void platform_reset_counters(void);
 
 /**
- * @brief   Gets the current counter values.
- * @returns A populated instance of pmu_counters struct.
+ * @brief       Gets the current counter values.
+ * @param[out]  Pointer to a pmu_counters object.
  **/
-pmu_counters platform_get_counters(void);
+void platform_get_counters(pmu_counters* counters);
 
 #endif /* NATIVE_TIMER_H */
diff --git a/source/hal/source/platform/native/source/platform_drivers.c b/source/hal/source/platform/native/source/platform_drivers.c
index 10db99a..d5b3727 100644
--- a/source/hal/source/platform/native/source/platform_drivers.c
+++ b/source/hal/source/platform/native/source/platform_drivers.c
@@ -19,6 +19,8 @@
 
 #include <string.h>
 
+static const char* s_platform_name = "native";
+
 int platform_init(void)
 {
     return 0;
@@ -27,7 +29,7 @@
 void platform_release(void)
 {}
 
-void platform_name(char* name, size_t size)
+const char* platform_name(void)
 {
-    strncpy(name, "native", size);
+    return s_platform_name;
 }
\ No newline at end of file
diff --git a/source/hal/source/platform/native/source/timer_native.c b/source/hal/source/platform/native/source/timer_native.c
index 590975f..7cd832c 100644
--- a/source/hal/source/platform/native/source/timer_native.c
+++ b/source/hal/source/platform/native/source/timer_native.c
@@ -32,25 +32,21 @@
 
 void platform_reset_counters() { /* Nothing to do */ }
 
-pmu_counters platform_get_counters(void)
+void platform_get_counters(pmu_counters* counters)
 {
     struct timespec current_time;
-    pmu_counters platform_counters = {
-        .num_counters = 0,
-        .initialised = true
-    };
+    counters->num_counters = 0;
+    counters->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;
+    counters->counters[0].value = microseconds;
+    counters->counters[0].name = "Duration";
+    counters->counters[0].unit = "microseconds";
+    ++counters->num_counters;
 #endif /* NUM_PMU_COUNTERS > 0 */
-
-    return platform_counters;
 }
 
 #ifdef __cplusplus
diff --git a/source/hal/source/platform/simple/include/platform_drivers.h b/source/hal/source/platform/simple/include/platform_drivers.h
index 31bb682..7d075e7 100644
--- a/source/hal/source/platform/simple/include/platform_drivers.h
+++ b/source/hal/source/platform/simple/include/platform_drivers.h
@@ -39,10 +39,9 @@
 void platform_release(void);
 
 /**
- * @brief   Sets the platform name.
- * @param[out] name     Name of the platform to be set
- * @param[in]  size     Size of the input buffer
+ * @brief   Gets the platform name.
+ * @return  Pointer to the name
  */
-void platform_name(char* name, size_t size);
+const char* platform_name(void);
 
 #endif /* PLATFORM_DRIVERS_H */
diff --git a/source/hal/source/platform/simple/include/timer_simple_platform.h b/source/hal/source/platform/simple/include/timer_simple_platform.h
index 40acd03..20006cc 100644
--- a/source/hal/source/platform/simple/include/timer_simple_platform.h
+++ b/source/hal/source/platform/simple/include/timer_simple_platform.h
@@ -31,10 +31,10 @@
 void platform_reset_counters(void);
 
 /**
- * @brief   Gets the current counter values.
- * @returns A populated instance of pmu_counters struct.
+ * @brief       Gets the current counter values.
+ * @param[out]  Pointer to a pmu_counters object.
  **/
-pmu_counters platform_get_counters(void);
+void platform_get_counters(pmu_counters* counters);
 
 /**
  * @brief   System tick interrupt handler.
diff --git a/source/hal/source/platform/simple/source/platform_drivers.c b/source/hal/source/platform/simple/source/platform_drivers.c
index 177ba70..3e04323 100644
--- a/source/hal/source/platform/simple/source/platform_drivers.c
+++ b/source/hal/source/platform/simple/source/platform_drivers.c
@@ -40,6 +40,9 @@
 
 #endif /* ARM_NPU */
 
+/* Platform name */
+static const char* s_platform_name = DESIGN_NAME;
+
 int platform_init(void)
 {
     SystemCoreClockUpdate();    /* From start up code */
@@ -72,7 +75,7 @@
 #endif /* ARM_NPU */
 
     /* Print target design info */
-    info("Target system design: %s\n", DESIGN_NAME);
+    info("Target system design: %s\n", s_platform_name);
 
     return 0;
 }
@@ -82,7 +85,7 @@
     __disable_irq();
 }
 
-void platform_name(char* name, size_t size)
+const char* platform_name(void)
 {
-    strncpy(name, DESIGN_NAME, size);
+    return s_platform_name;
 }
diff --git a/source/hal/source/platform/simple/source/timer_simple_platform.c b/source/hal/source/platform/simple/source/timer_simple_platform.c
index 94af308..3bb91d0 100644
--- a/source/hal/source/platform/simple/source/timer_simple_platform.c
+++ b/source/hal/source/platform/simple/source/timer_simple_platform.c
@@ -63,12 +63,10 @@
     debug("system tick config ready\n");
 }
 
-pmu_counters platform_get_counters(void)
+void platform_get_counters(pmu_counters* counters)
 {
-    pmu_counters platform_counters = {
-        .num_counters = 0,
-        .initialised = true
-    };
+    counters->num_counters = 0;
+    counters->initialised = true;
     uint32_t i = 0;
 
 #if defined (ARM_NPU)
@@ -78,20 +76,20 @@
                 npu_counters.npu_evt_counters[i].counter_value,
                 npu_counters.npu_evt_counters[i].name,
                 npu_counters.npu_evt_counters[i].unit,
-                &platform_counters);
+                counters);
     }
     for (i = 0; i < ETHOSU_DERIVED_NCOUNTERS; ++i) {
         add_pmu_counter(
                 npu_counters.npu_derived_counters[i].counter_value,
                 npu_counters.npu_derived_counters[i].name,
                 npu_counters.npu_derived_counters[i].unit,
-                &platform_counters);
+                counters);
     }
     add_pmu_counter(
             npu_counters.npu_total_ccnt,
             "NPU TOTAL",
             "cycles",
-            &platform_counters);
+            counters);
 #endif /* defined (ARM_NPU) */
 
 #if defined(CPU_PROFILE_ENABLED)
@@ -99,7 +97,7 @@
             Get_SysTick_Cycle_Count(),
             "CPU TOTAL",
             "cycles",
-            &platform_counters);
+            counters);
 #endif /* defined(CPU_PROFILE_ENABLED) */
 
 #if !defined(CPU_PROFILE_ENABLED)
@@ -109,8 +107,6 @@
     UNUSED(i);
 #endif /* !defined(ARM_NPU) */
 #endif /* !defined(CPU_PROFILE_ENABLED) */
-
-    return platform_counters;
 }
 
 void SysTick_Handler(void)