summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2024-02-20 12:41:04 +0100
committerDamien George <damien@micropython.org>2024-03-15 18:11:28 +1100
commit61ee59ad8917d64f4f4a0e7a261fd838c5724014 (patch)
treef49c4b686c306d89510c04bbcf07bfbc60c462d7
parentf6213ffc5cb7ea1cb3c7ec10ccd9032035c12159 (diff)
extmod/libmetal: Add MicroPython platform for libmetal.
Add a MicroPython platform for libmetal, based on the generic platform. The MicroPython platform uses common mp_hal_xxx functions and allows ports to customize default configurations for libmetal. Signed-off-by: Jim Mussared <jim.mussared@gmail.com> Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
-rw-r--r--extmod/libmetal/libmetal.mk51
-rw-r--r--extmod/libmetal/metal/config.h81
-rw-r--r--extmod/libmetal/metal/system/micropython/alloc.h1
-rw-r--r--extmod/libmetal/metal/system/micropython/log.h1
-rw-r--r--extmod/libmetal/metal/system/micropython/sleep.h1
-rw-r--r--extmod/libmetal/metal/system/micropython/sys.h5
6 files changed, 140 insertions, 0 deletions
diff --git a/extmod/libmetal/libmetal.mk b/extmod/libmetal/libmetal.mk
new file mode 100644
index 000000000..852b04289
--- /dev/null
+++ b/extmod/libmetal/libmetal.mk
@@ -0,0 +1,51 @@
+# Makefile directives for libmetal
+
+# libmetal is intended to run through a pre-processor (as part of its CMake-based build system).
+# This replicates the basic functionality of the pre-processor, including adding a "micropython"
+# platform that is almost identical to the built-in "generic" platform with a few small changes
+# provided by the files in extmod/libmetal.
+$(BUILD)/openamp: $(BUILD)
+ $(MKDIR) -p $@
+
+$(BUILD)/openamp/metal: $(BUILD)/openamp
+ $(MKDIR) -p $@
+
+$(BUILD)/openamp/metal/config.h: $(BUILD)/openamp/metal $(TOP)/$(LIBMETAL_DIR)/lib/config.h
+ @$(ECHO) "GEN $@"
+ @for file in $(TOP)/$(LIBMETAL_DIR)/lib/*.c $(TOP)/$(LIBMETAL_DIR)/lib/*.h; do $(SED) -e "s/@PROJECT_SYSTEM@/micropython/g" -e "s/@PROJECT_PROCESSOR@/arm/g" $$file > $(BUILD)/openamp/metal/$$(basename $$file); done
+ $(MKDIR) -p $(BUILD)/openamp/metal/processor/arm
+ @$(CP) $(TOP)/$(LIBMETAL_DIR)/lib/processor/arm/*.h $(BUILD)/openamp/metal/processor/arm
+ $(MKDIR) -p $(BUILD)/openamp/metal/compiler/gcc
+ @$(CP) $(TOP)/$(LIBMETAL_DIR)/lib/compiler/gcc/*.h $(BUILD)/openamp/metal/compiler/gcc
+ $(MKDIR) -p $(BUILD)/openamp/metal/system/micropython
+ @$(CP) $(TOP)/$(LIBMETAL_DIR)/lib/system/generic/*.c $(TOP)/$(LIBMETAL_DIR)/lib/system/generic/*.h $(BUILD)/openamp/metal/system/micropython
+ @$(CP) $(TOP)/extmod/libmetal/metal/system/micropython/* $(BUILD)/openamp/metal/system/micropython
+ @$(CP) $(TOP)/extmod/libmetal/metal/config.h $(BUILD)/openamp/metal/config.h
+
+# libmetal's source files.
+SRC_LIBMETAL_C := $(addprefix $(BUILD)/openamp/metal/,\
+ device.c \
+ dma.c \
+ init.c \
+ io.c \
+ irq.c \
+ log.c \
+ shmem.c \
+ softirq.c \
+ version.c \
+ device.c \
+ system/micropython/condition.c \
+ system/micropython/device.c \
+ system/micropython/io.c \
+ system/micropython/irq.c \
+ system/micropython/shmem.c \
+ system/micropython/time.c \
+ )
+
+# These files are generated by the rule above (along with config.h), so we need to make the .c
+# files depend on that step -- can't use the .o files as the target because the .c files don't
+# exist yet.
+$(SRC_LIBMETAL_C): $(BUILD)/openamp/metal/config.h
+
+# Qstr processing will include the generated libmetal headers, so add them as a qstr requirement.
+QSTR_GLOBAL_REQUIREMENTS += $(BUILD)/openamp/metal/config.h
diff --git a/extmod/libmetal/metal/config.h b/extmod/libmetal/metal/config.h
new file mode 100644
index 000000000..459a2f4ca
--- /dev/null
+++ b/extmod/libmetal/metal/config.h
@@ -0,0 +1,81 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2024 Arduino SA
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * MicroPython libmetal config.
+ */
+#ifndef MICROPY_INCLUDED_METAL_MICROPYTHON_H
+#define MICROPY_INCLUDED_METAL_MICROPYTHON_H
+
+#include <stdlib.h>
+
+// Port-specific config.
+#include "mpmetalport.h"
+
+// Library major version number.
+#define METAL_VER_MAJOR 1
+
+// Library minor version number.
+#define METAL_VER_MINOR 5
+
+// Library patch level.
+#define METAL_VER_PATCH 0
+
+// Library version string.
+#define METAL_VER "1.5.0"
+
+#if METAL_HAVE_STDATOMIC_H
+#define HAVE_STDATOMIC_H
+#endif
+
+#if METAL_HAVE_FUTEX_H
+#define HAVE_FUTEX_H
+#endif
+
+#ifndef METAL_MAX_DEVICE_REGIONS
+#define METAL_MAX_DEVICE_REGIONS 1
+#endif
+
+// generic/log.h
+#if METAL_LOG_HANDLER_ENABLE
+#include "py/mphal.h"
+#undef metal_log
+#define metal_log(level, ...) mp_printf(&mp_plat_print, __VA_ARGS__)
+#endif
+
+static inline void *__metal_allocate_memory(unsigned int size) {
+ return m_tracked_calloc(1, size);
+}
+
+static inline void __metal_free_memory(void *ptr) {
+ m_tracked_free(ptr);
+}
+
+// The following functions must be provided by the port (in mpmetalport.h / mpmetalport.c).
+int __metal_sleep_usec(unsigned int usec);
+void sys_irq_enable(unsigned int vector);
+void sys_irq_disable(unsigned int vector);
+void sys_irq_restore_enable(unsigned int flags);
+unsigned int sys_irq_save_disable(void);
+#endif // MICROPY_INCLUDED_METAL_MICROPYTHON_H
diff --git a/extmod/libmetal/metal/system/micropython/alloc.h b/extmod/libmetal/metal/system/micropython/alloc.h
new file mode 100644
index 000000000..dd0fdb13f
--- /dev/null
+++ b/extmod/libmetal/metal/system/micropython/alloc.h
@@ -0,0 +1 @@
+#include <metal/config.h>
diff --git a/extmod/libmetal/metal/system/micropython/log.h b/extmod/libmetal/metal/system/micropython/log.h
new file mode 100644
index 000000000..dd0fdb13f
--- /dev/null
+++ b/extmod/libmetal/metal/system/micropython/log.h
@@ -0,0 +1 @@
+#include <metal/config.h>
diff --git a/extmod/libmetal/metal/system/micropython/sleep.h b/extmod/libmetal/metal/system/micropython/sleep.h
new file mode 100644
index 000000000..dd0fdb13f
--- /dev/null
+++ b/extmod/libmetal/metal/system/micropython/sleep.h
@@ -0,0 +1 @@
+#include <metal/config.h>
diff --git a/extmod/libmetal/metal/system/micropython/sys.h b/extmod/libmetal/metal/system/micropython/sys.h
new file mode 100644
index 000000000..0f404dcd6
--- /dev/null
+++ b/extmod/libmetal/metal/system/micropython/sys.h
@@ -0,0 +1,5 @@
+#include <metal/config.h>
+
+struct metal_state {
+ struct metal_common_state common;
+};