MLECO-2919: Restructuring to standardise HAL APIs
* LCD module component created (removed from individual
platform packs).
* retarget.c moved out into its own component that wraps
the uart module. It also have the native stub for
GetLine => paved the way for removing data_acq module
from profiles.
* shortened names for components' dir for npu and ta
* remove peripheral_memmap and peripheral_irqs headers
from platform_drivers.h. There should be no need for
these to be included in the top level now. These should
be private headers.
* cmsis_device moved in as a component.
* Pyenv created by set_up_default_resource.py will also
install packages that CMake's source generator needs.
TODO's:
* Remove timer from profiles (MLECO-3096)
Change-Id: I9d6ea2f4f291788f40a16ed507019563c8d7f205
diff --git a/source/hal/source/components/stdout/CMakeLists.txt b/source/hal/source/components/stdout/CMakeLists.txt
new file mode 100644
index 0000000..f1e26ff
--- /dev/null
+++ b/source/hal/source/components/stdout/CMakeLists.txt
@@ -0,0 +1,110 @@
+#----------------------------------------------------------------------------
+# 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.
+#----------------------------------------------------------------------------
+
+#########################################################
+# Wrapper for enabling stdout and stderr facility #
+#########################################################
+# This is a wrapper around the UART module for CMSDK #
+# and PL011 UART drivers with retarget functions. #
+#########################################################
+
+cmake_minimum_required(VERSION 3.15.6)
+
+project(stdout
+ DESCRIPTION "Standard output and err redirection over UART"
+ LANGUAGES C CXX)
+
+
+set(STDOUT_RETARGET OFF CACHE BOOL "Retarget stdout/err to UART")
+
+# Interface library for standard output:
+set(STDOUT_IFACE_TARGET stdout_iface)
+add_library(${STDOUT_IFACE_TARGET} INTERFACE)
+target_include_directories(${STDOUT_IFACE_TARGET} INTERFACE include)
+
+if (STDOUT_RETARGET)
+
+ set(STDOUT_COMPONENT_CMSDK stdout_retarget_cmsdk)
+ set(STDOUT_COMPONENT_PL011 stdout_retarget_pl011)
+
+ add_library(${STDOUT_COMPONENT_CMSDK} STATIC)
+ add_library(${STDOUT_COMPONENT_PL011} STATIC)
+
+ # Check prerequisites
+ ## Core platform directory is required to add the UART library project.
+ if (NOT DEFINED CORE_PLATFORM_DIR)
+ message(FATAL_ERROR "CORE_PLATFORM_DIR undefined")
+ endif()
+
+ ## UART0_BASE is the base address for UART configuration. The platform
+ ## should define it prior to including this library.
+ if (NOT DEFINED UART0_BASE)
+ message(WARNING "UART0_BASE undefined, default will be used.")
+ endif()
+
+ ## Platform component: UART
+ add_subdirectory(${CORE_PLATFORM_DIR}/drivers/uart ${CMAKE_BINARY_DIR}/uart)
+
+ ## Component sources - public
+ target_sources(${STDOUT_COMPONENT_CMSDK}
+ PUBLIC
+ source/retarget.c)
+
+ ## Component sources - public
+ target_sources(${STDOUT_COMPONENT_PL011}
+ PUBLIC
+ source/retarget.c)
+
+ # Link
+ target_link_libraries(${STDOUT_COMPONENT_CMSDK}
+ PUBLIC
+ ${STDOUT_IFACE_TARGET}
+ ethosu_uart_cmsdk_apb)
+
+ target_link_libraries(${STDOUT_COMPONENT_PL011}
+ PUBLIC
+ ${STDOUT_IFACE_TARGET}
+ ethosu_uart_pl011)
+
+ # Display status
+ message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
+ message(STATUS "*******************************************************")
+ message(STATUS "Library: " ${STDOUT_COMPONENT_CMSDK})
+ message(STATUS "Library: " ${STDOUT_COMPONENT_PL011})
+ message(STATUS "*******************************************************")
+
+else()
+
+ # Create static library for retarget (stdout/err over UART)
+ set(STDOUT_COMPONENT stdout)
+ add_library(${STDOUT_COMPONENT} STATIC)
+
+ ## Component sources - public
+ target_sources(${STDOUT_COMPONENT}
+ PUBLIC
+ source/user_input.c)
+
+ target_link_libraries(${STDOUT_COMPONENT}
+ PUBLIC
+ ${STDOUT_IFACE_TARGET})
+
+ # Display status
+ message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
+ message(STATUS "*******************************************************")
+ message(STATUS "Library: " ${STDOUT_COMPONENT})
+ message(STATUS "*******************************************************")
+endif()
diff --git a/source/hal/source/components/stdout/include/user_input.h b/source/hal/source/components/stdout/include/user_input.h
new file mode 100644
index 0000000..e76b418
--- /dev/null
+++ b/source/hal/source/components/stdout/include/user_input.h
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+#ifndef STDOUT_USER_INPUT_H
+#define STDOUT_USER_INPUT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+unsigned int GetLine(char *user_input, unsigned int size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* STDOUT_USER_INPUT_H */
diff --git a/source/hal/source/components/stdout/source/retarget.c b/source/hal/source/components/stdout/source/retarget.c
new file mode 100644
index 0000000..ac9b282
--- /dev/null
+++ b/source/hal/source/components/stdout/source/retarget.c
@@ -0,0 +1,278 @@
+/*
+ * 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.
+ */
+#if !defined(USE_SEMIHOSTING)
+
+#include "uart_stdout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
+/* Arm compiler re-targeting */
+
+#include <rt_misc.h>
+#include <rt_sys.h>
+
+
+/* Standard IO device handles. */
+#define STDIN 0x8001
+#define STDOUT 0x8002
+#define STDERR 0x8003
+
+#define RETARGET(fun) _sys##fun
+
+#else
+/* GNU compiler re-targeting */
+
+/*
+ * This type is used by the _ I/O functions to denote an open
+ * file.
+ */
+typedef int FILEHANDLE;
+
+/*
+ * Open a file. May return -1 if the file failed to open.
+ */
+extern FILEHANDLE _open(const char * /*name*/, int /*openmode*/);
+
+/* Standard IO device handles. */
+#define STDIN 0x00
+#define STDOUT 0x01
+#define STDERR 0x02
+
+#define RETARGET(fun) fun
+
+#endif
+
+/* Standard IO device name defines. */
+const char __stdin_name[] __attribute__((aligned(4))) = "STDIN";
+const char __stdout_name[] __attribute__((aligned(4))) = "STDOUT";
+const char __stderr_name[] __attribute__((aligned(4))) = "STDERR";
+
+__attribute__((noreturn)) static void UartEndSimulation(int code)
+{
+ UartPutc((char) 0x4); // End of simulation
+ UartPutc((char) code); // Exit code
+ while(1);
+}
+
+void _ttywrch(int ch) {
+ (void)fputc(ch, stdout);
+}
+
+FILEHANDLE RETARGET(_open)(const char *name, int openmode)
+{
+ (void)(openmode);
+
+ if (strcmp(name, __stdin_name) == 0) {
+ return (STDIN);
+ }
+
+ if (strcmp(name, __stdout_name) == 0) {
+ return (STDOUT);
+ }
+
+ if (strcmp(name, __stderr_name) == 0) {
+ return (STDERR);
+ }
+
+ return -1;
+}
+
+int RETARGET(_write)(FILEHANDLE fh, const unsigned char *buf, unsigned int len, int mode)
+{
+ (void)(mode);
+
+ switch (fh) {
+ case STDOUT:
+ case STDERR: {
+ int c;
+
+ while (len-- > 0) {
+ c = fputc(*buf++, stdout);
+ if (c == EOF) {
+ return EOF;
+ }
+ }
+
+ return 0;
+ }
+ default:
+ return EOF;
+ }
+}
+
+int RETARGET(_read)(FILEHANDLE fh, unsigned char *buf, unsigned int len, int mode)
+{
+ (void)(mode);
+
+ switch (fh) {
+ case STDIN: {
+ int c;
+
+ while (len-- > 0) {
+ c = fgetc(stdin);
+ if (c == EOF) {
+ return EOF;
+ }
+
+ *buf++ = (unsigned char)c;
+ }
+
+ return 0;
+ }
+ default:
+ return EOF;
+ }
+}
+
+int RETARGET(_istty)(FILEHANDLE fh)
+{
+ switch (fh) {
+ case STDIN:
+ case STDOUT:
+ case STDERR:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+int RETARGET(_close)(FILEHANDLE fh)
+{
+ if (RETARGET(_istty(fh))) {
+ return 0;
+ }
+
+ return -1;
+}
+
+int RETARGET(_seek)(FILEHANDLE fh, long pos)
+{
+ (void)(fh);
+ (void)(pos);
+
+ return -1;
+}
+
+int RETARGET(_ensure)(FILEHANDLE fh)
+{
+ (void)(fh);
+
+ return -1;
+}
+
+long RETARGET(_flen)(FILEHANDLE fh)
+{
+ if (RETARGET(_istty)(fh)) {
+ return 0;
+ }
+
+ return -1;
+}
+
+int RETARGET(_tmpnam)(char *name, int sig, unsigned int maxlen)
+{
+ (void)(name);
+ (void)(sig);
+ (void)(maxlen);
+
+ return 1;
+}
+
+char *RETARGET(_command_string)(char *cmd, int len)
+{
+ (void)(len);
+
+ return cmd;
+}
+
+void RETARGET(_exit)(int return_code)
+{
+ UartEndSimulation(return_code);
+ while(1);
+}
+
+int system(const char *cmd)
+{
+ (void)(cmd);
+
+ return 0;
+}
+
+time_t time(time_t *timer)
+{
+ time_t current;
+
+ current = 0; // To Do !! No RTC implemented
+
+ if (timer != NULL) {
+ *timer = current;
+ }
+
+ return current;
+}
+
+void _clock_init(void) {}
+
+clock_t clock(void)
+{
+ return (clock_t)-1;
+}
+
+int remove(const char *arg) {
+ (void)(arg);
+
+ return 0;
+}
+
+int rename(const char *oldn, const char *newn)
+{
+ (void)(oldn);
+ (void)(newn);
+
+ return 0;
+}
+
+int fputc(int ch, FILE *f)
+{
+ (void)(f);
+
+ return UartPutc(ch);
+}
+
+int fgetc(FILE *f)
+{
+ (void)(f);
+
+ return UartPutc(UartGetc());
+}
+
+#ifndef ferror
+
+/* arm-none-eabi-gcc with newlib uses a define for ferror */
+int ferror(FILE *f)
+{
+ (void)(f);
+
+ return EOF;
+}
+
+#endif /* #ifndef ferror */
+
+#endif /* !defined(USE_SEMIHOSTING) */
diff --git a/source/hal/source/components/stdout/source/user_input.c b/source/hal/source/components/stdout/source/user_input.c
new file mode 100644
index 0000000..e5fe1b9
--- /dev/null
+++ b/source/hal/source/components/stdout/source/user_input.c
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+
+unsigned int GetLine(char *user_input, unsigned int size)
+{
+ if (NULL != fgets(user_input, size, stdin)) {
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif