MLECO-2948: Minor refactoring for platform modules.

Reducing dependency on cmsis-device sources as these will
be removed under MLECO-2944. Also, starting to refactor
to allow HAL to drop NPU and TA init routines - this will
happen in future CRs.

Added platform driver for native, and subsequent patches
will attempt to get rid of the HAL "profile" specific
sources and allow platform stub implementations at a level
below HAL. This will allow platforms drivers to only
override the range of functions that they actually want to
implement and will fall back on stubs for the rest. In this
CR only "utils" have been removed.

Change-Id: I09b4a28e20847a07a956c818c6f47c74aab89063
diff --git a/source/hal/platform/simple/source/platform_drivers.c b/source/hal/platform/simple/source/platform_drivers.c
new file mode 100644
index 0000000..c92a964
--- /dev/null
+++ b/source/hal/platform/simple/source/platform_drivers.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2022 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.
+ */
+
+#include "platform_drivers.h"
+
+#include "uart_stdout.h"
+#include <string.h>
+
+int platform_init(void)
+{
+    SystemCoreClockUpdate();    /* From start up code */
+
+    /* UART init - will enable valid use of printf (stdout
+     * re-directed at this UART (UART0) */
+    UartStdOutInit();
+
+    info("%s: complete\n", __FUNCTION__);
+
+    /** TODO: Add ARM NPU and TA init here */
+    return 0;
+}
+
+void platform_release(void)
+{
+    __disable_irq();
+}
+
+void platform_name(char* name, size_t size)
+{
+    strncpy(name, DESIGN_NAME, size);
+}
diff --git a/source/hal/platform/simple/source/stubs_glcd.c b/source/hal/platform/simple/source/stubs_glcd.c
index 6b60dcd..d843cf4 100644
--- a/source/hal/platform/simple/source/stubs_glcd.c
+++ b/source/hal/platform/simple/source/stubs_glcd.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
  * SPDX-License-Identifier: Apache-2.0
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,9 +31,10 @@
     UNUSED(bitmap);
 }
 
-void GLCD_Image(void *data, const unsigned int width, const unsigned int height,
-    const unsigned int channels, const unsigned int pos_x,
-    const unsigned int pos_y, const unsigned int downsample_factor)
+void GLCD_Image(const void *data, const uint32_t width,
+               const uint32_t height, const uint32_t channels,
+               const uint32_t pos_x, const uint32_t pos_y,
+               const uint32_t downsample_factor)
 {
     UNUSED(data);
     UNUSED(pos_x);
diff --git a/source/hal/platform/simple/source/timer_simple_platform.c b/source/hal/platform/simple/source/timer_simple_platform.c
index 4bcd07b..3d28261 100644
--- a/source/hal/platform/simple/source/timer_simple_platform.c
+++ b/source/hal/platform/simple/source/timer_simple_platform.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
  * SPDX-License-Identifier: Apache-2.0
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,11 +16,26 @@
  */
 #include "timer_simple_platform.h"
 
-#include "irqs.h"
-#include "log_macros.h"
+#include "log_macros.h"     /* Logging macros */
+#include "cmsis.h"          /* For CPU related defintiions */
 
 #include <inttypes.h>
 
+static uint64_t cpu_cycle_count = 0;    /* 64-bit cpu cycle counter */
+extern uint32_t SystemCoreClock;        /* Expected to come from the cmsis-device lib */
+
+/**
+ * @brief   Gets the system tick triggered cycle counter for the CPU.
+ * @return  64-bit counter value.
+ **/
+static uint64_t Get_SysTick_Cycle_Count(void);
+
+/**
+ * SysTick initialisation
+ */
+static int Init_SysTick(void);
+
+
 base_time_counter get_time_counter(void)
 {
     base_time_counter t = {
@@ -56,3 +71,53 @@
 {
     /* Add any custom requirement for this platform here */
 }
+
+
+void SysTick_Handler(void)
+{
+    /* Increment the cycle counter based on load value. */
+    cpu_cycle_count += SysTick->LOAD + 1;
+}
+
+/**
+ * Gets the current SysTick derived counter value
+ */
+static uint64_t Get_SysTick_Cycle_Count(void)
+{
+    uint32_t systick_val;
+
+    NVIC_DisableIRQ(SysTick_IRQn);
+    systick_val = SysTick->VAL & SysTick_VAL_CURRENT_Msk;
+    NVIC_EnableIRQ(SysTick_IRQn);
+
+    return cpu_cycle_count + (SysTick->LOAD - systick_val);
+}
+
+/**
+ * SysTick initialisation
+ */
+static int Init_SysTick(void)
+{
+    const uint32_t ticks_10ms = SystemCoreClock/100 + 1;
+    int err = 0;
+
+    /* Reset CPU cycle count value. */
+    cpu_cycle_count = 0;
+
+    /* Changing configuration for sys tick => guard from being
+     * interrupted. */
+    NVIC_DisableIRQ(SysTick_IRQn);
+
+    /* SysTick init - this will enable interrupt too. */
+    err = SysTick_Config(ticks_10ms);
+
+    /* Enable interrupt again. */
+    NVIC_EnableIRQ(SysTick_IRQn);
+
+    /* Wait for SysTick to kick off */
+    while (!err && !SysTick->VAL) {
+        __NOP();
+    }
+
+    return err;
+}
\ No newline at end of file