Use new timing adapter driver from core_software

Add basic skeleton to initialize timing adapters.

See core_software/drivers/timing_adapter/include/timing_adapter.h
for description of settings and API.

Change-Id: I0884f8efc5735b1a837d45e0bb7c6612d329ad58
diff --git a/targets/corstone-300/CMakeLists.txt b/targets/corstone-300/CMakeLists.txt
index d41a7d3..7653926 100644
--- a/targets/corstone-300/CMakeLists.txt
+++ b/targets/corstone-300/CMakeLists.txt
@@ -52,6 +52,13 @@
 
 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../common target)
 
+set(ETHOSU_TARGET_NPU_COUNT 1 CACHE INTERNAL "Number of NPUs")
+set(ETHOSU_TARGET_NPU_TA_COUNT 2 CACHE INTERNAL "Number of timing adapters per NPU")
+
+target_compile_definitions(ethosu_target_common INTERFACE
+    ETHOSU_NPU_TA_COUNT=${ETHOSU_TARGET_NPU_TA_COUNT}
+    ETHOSU_NPU_COUNT=${ETHOSU_TARGET_NPU_COUNT})
+
 # Linker script
 ethosu_target_link_options(ethosu_target_link INTERFACE
     LINK_FILE platform
@@ -64,7 +71,7 @@
     target.cpp)
 
 target_compile_definitions(ethosu_core_driver PUBLIC ETHOSU)
-target_link_libraries(ethosu_target_startup INTERFACE ethosu_core_driver)
+target_link_libraries(ethosu_target_startup INTERFACE ethosu_core_driver timing_adapter)
 
 ###############################################################################
 # Applications
diff --git a/targets/corstone-300/target.cpp b/targets/corstone-300/target.cpp
index 7c902d2..d5c44ea 100644
--- a/targets/corstone-300/target.cpp
+++ b/targets/corstone-300/target.cpp
@@ -26,11 +26,13 @@
 #include <ethosu_driver.h>
 #endif
 
+#include <timing_adapter.h>
+
 #include "uart.h"
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <inttypes.h>
 
 using namespace EthosU;
 
@@ -39,8 +41,10 @@
  ****************************************************************************/
 
 #define ETHOSU_BASE_ADDRESS 0x48102000
+#define ETHOSU_IRQ          56
 
-#define ETHOSU_IRQ 56
+#define ETHOSU0_TA0_BASE_ADDRESS 0x48103000
+#define ETHOSU0_TA1_BASE_ADDRESS 0x48103200
 
 /****************************************************************************
  * Variables
@@ -53,6 +57,10 @@
 #define ETHOSU_FAST_MEMORY_SIZE 0
 #endif
 
+static uintptr_t ethosu_ta_base_addrs[ETHOSU_NPU_COUNT][ETHOSU_NPU_TA_COUNT] = {
+    {ETHOSU0_TA0_BASE_ADDRESS, ETHOSU0_TA1_BASE_ADDRESS}};
+struct timing_adapter ethosu_ta[ETHOSU_NPU_COUNT][ETHOSU_NPU_TA_COUNT];
+
 /****************************************************************************
  * Cache maintenance
  ****************************************************************************/
@@ -133,6 +141,15 @@
     // Initialize UART driver
     uart_init();
 
+    // Initialize timing adapter(s)
+    for (int i = 0; i < ETHOSU_NPU_COUNT; i++) {
+        for (int j = 0; j < ETHOSU_NPU_TA_COUNT; j++) {
+            if (ta_init(&ethosu_ta[i][j], ethosu_ta_base_addrs[i][j])) {
+                printf("Failed to initialize timing-adapter %d for NPU %d\n", j, i);
+            }
+        }
+    }
+
 #ifdef ETHOSU
     // Initialize Ethos-U NPU driver
     if (ethosu_init_v3(reinterpret_cast<void *>(ETHOSU_BASE_ADDRESS), ethosu_scratch, ETHOSU_FAST_MEMORY_SIZE, 1, 1)) {