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>
pull/12961/head
iabdalkader 2024-02-20 12:41:04 +01:00 zatwierdzone przez Damien George
rodzic f6213ffc5c
commit 61ee59ad89
6 zmienionych plików z 140 dodań i 0 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -0,0 +1 @@
#include <metal/config.h>

Wyświetl plik

@ -0,0 +1 @@
#include <metal/config.h>

Wyświetl plik

@ -0,0 +1 @@
#include <metal/config.h>

Wyświetl plik

@ -0,0 +1,5 @@
#include <metal/config.h>
struct metal_state {
struct metal_common_state common;
};