Skip to content
Snippets Groups Projects
Verified Commit cac1586b authored by rahix's avatar rahix
Browse files

Merge branch 'rahix/micropyhton'


Signed-off-by: default avatarRahix <rahix@rahix.de>
parents 78dfac6c d748ba4b
No related branches found
No related tags found
No related merge requests found
#!/bin/sh
set -e
# makeversionhdr has to be executed in the micropython subdir
# so it picks up the correct version
OUT="$(realpath "$3")"
OUTDIR="$(dirname "$OUT")"
mkdir -p "$OUTDIR/genhdr"
ln -sfr "$OUT" "$OUTDIR/genhdr/$(basename "$OUT")"
cd "$2/micropython"
"$1" "$2/micropython/py/makeversionhdr.py" "$OUT"
# Scripts
micropython_gen_modules = [
python3,
files('gen-modules.py'),
meson.current_source_dir(),
]
micropython_gen_version = [
files('./gen-version.sh'),
python3,
meson.current_source_dir(),
]
micropython_gen_qstr = [
files('gen-qstr.sh'),
python3,
meson.current_source_dir(),
]
# Sources
micropython_includes = include_directories(
'./micropython/',
'./micropython/lib/utils',
'./micropython/extmod/',
)
micropython_sources = files(
'micropython/py/argcheck.c',
'micropython/py/asmarm.c', 'micropython/py/asmbase.c',
'micropython/py/asmthumb.c',
'micropython/py/asmx64.c',
'micropython/py/asmx86.c',
'micropython/py/asmxtensa.c',
'micropython/py/bc.c',
'micropython/py/binary.c',
'micropython/py/builtinevex.c',
'micropython/py/builtinhelp.c',
'micropython/py/builtinimport.c',
'micropython/py/compile.c',
'micropython/py/emitbc.c',
'micropython/py/emitcommon.c',
'micropython/py/emitglue.c',
'micropython/py/emitinlinethumb.c',
'micropython/py/emitinlinextensa.c',
'micropython/py/emitnarm.c',
'micropython/py/emitnative.c',
'micropython/py/emitnthumb.c',
'micropython/py/emitnx64.c',
'micropython/py/emitnx86.c',
'micropython/py/emitnxtensa.c',
'micropython/py/formatfloat.c',
'micropython/py/frozenmod.c',
'micropython/py/gc.c',
'micropython/py/lexer.c',
'micropython/py/malloc.c',
'micropython/py/map.c',
'micropython/py/modarray.c',
'micropython/py/modbuiltins.c',
'micropython/py/modcmath.c',
'micropython/py/modcollections.c',
'micropython/py/modgc.c',
'micropython/py/modio.c',
'micropython/py/modmath.c',
'micropython/py/modmicropython.c',
'micropython/py/modstruct.c',
'micropython/py/modsys.c',
'micropython/py/modthread.c',
'micropython/py/moduerrno.c',
'micropython/py/mpprint.c',
'micropython/py/mpstate.c',
'micropython/py/mpz.c',
'micropython/py/nativeglue.c',
'micropython/py/nlr.c',
'micropython/py/nlrsetjmp.c',
'micropython/py/nlrthumb.c',
'micropython/py/nlrx64.c',
'micropython/py/nlrx86.c',
'micropython/py/nlrxtensa.c',
'micropython/py/obj.c',
'micropython/py/objarray.c',
'micropython/py/objattrtuple.c',
'micropython/py/objbool.c',
'micropython/py/objboundmeth.c',
'micropython/py/objcell.c',
'micropython/py/objclosure.c',
'micropython/py/objcomplex.c',
'micropython/py/objdeque.c',
'micropython/py/objdict.c',
'micropython/py/objenumerate.c',
'micropython/py/objexcept.c',
'micropython/py/objfilter.c',
'micropython/py/objfloat.c',
'micropython/py/objfun.c',
'micropython/py/objgenerator.c',
'micropython/py/objgetitemiter.c',
'micropython/py/objint.c',
'micropython/py/objint_longlong.c',
'micropython/py/objint_mpz.c',
'micropython/py/objlist.c',
'micropython/py/objmap.c',
'micropython/py/objmodule.c',
'micropython/py/objnamedtuple.c',
'micropython/py/objnone.c',
'micropython/py/objobject.c',
'micropython/py/objpolyiter.c',
'micropython/py/objproperty.c',
'micropython/py/objrange.c',
'micropython/py/objreversed.c',
'micropython/py/objset.c',
'micropython/py/objsingleton.c',
'micropython/py/objslice.c',
'micropython/py/objstr.c',
'micropython/py/objstringio.c',
'micropython/py/objstrunicode.c',
'micropython/py/objtuple.c',
'micropython/py/objtype.c',
'micropython/py/objzip.c',
'micropython/py/opmethods.c',
'micropython/py/parse.c',
'micropython/py/parsenum.c',
'micropython/py/parsenumbase.c',
'micropython/py/persistentcode.c',
'micropython/py/pystack.c',
'micropython/py/qstr.c',
'micropython/py/reader.c',
'micropython/py/repl.c',
'micropython/py/runtime.c',
'micropython/py/runtime_utils.c',
'micropython/py/scheduler.c',
'micropython/py/scope.c',
'micropython/py/sequence.c',
'micropython/py/showbc.c',
'micropython/py/smallint.c',
'micropython/py/stackctrl.c',
'micropython/py/stream.c',
'micropython/py/unicode.c',
'micropython/py/vm.c',
'micropython/py/vstr.c',
'micropython/py/warning.c',
)
micropython_additional_sources = files(
'micropython/lib/utils/stdout_helpers.c',
'micropython/lib/utils/pyexec.c',
'micropython/lib/mp-readline/readline.c',
'micropython/extmod/utime_mphal.c',
)
Subproject commit 62f004ba424920a01e60c7a9a064b8ec9cd69c12
......@@ -32,4 +32,8 @@ python3 = 'python3'
subdir('lib/')
subdir('bootloader/')
subdir('epicardium/')
subdir('pycardium/')
subdir('hw-tests/')
#include "py/runtime.h"
#include "py/gc.h"
#include "lib/utils/pyexec.h"
static char *stack_top;
static char heap[4096];
int main(void)
{
/* TODO: Replace this with a proper heap implementation */
int stack_dummy;
stack_top = (char*)&stack_dummy;
gc_init(heap, heap + sizeof(heap));
mp_init();
pyexec_friendly_repl();
while (1) {
;
}
}
void gc_collect(void)
{
/* TODO: Replace this with a proper heap implementation */
void*dummy;
gc_collect_start();
gc_collect_root(&dummy, ((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t));
gc_collect_end();
}
name = 'pycardium'
modsrc = files(
)
#################################
# MicroPython Generated Headers #
#################################
version_h = custom_target(
'mpversion.h',
output: 'mpversion.h',
command: [micropython_gen_version, '@OUTPUT@'],
)
modules_h = custom_target(
'moduledefs.h',
output: 'moduledefs.h',
input: [micropython_sources, modsrc],
command: [micropython_gen_modules, '@OUTPUT@', '@INPUT@'],
)
qstr_h = custom_target(
'qstrdefs.generated.h',
output: 'qstrdefs.generated.h',
input: [
# 'modules/qstrdefs.h',
'mpconfigport.h',
micropython_sources,
],
depends: [modules_h, version_h],
command: [micropython_gen_qstr, meson.current_source_dir(), '@OUTPUT@', '@INPUT@'],
)
mp_headers = [version_h, modules_h, qstr_h]
###################
# MicroPython Lib #
###################
upy = static_library(
'micropython',
micropython_sources,
micropython_additional_sources,
mp_headers,
include_directories: micropython_includes,
)
executable(
name + '.elf',
'main.c',
'mphalport.c',
modsrc,
mp_headers,
include_directories: micropython_includes,
dependencies: [max32665_startup_core1, board_card10, periphdriver],
link_whole: [max32665_startup_core1_lib, board_card10_lib],
link_with: upy,
link_args: [
'-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map',
],
)
/* Hardware Name */
#define MICROPY_HW_BOARD_NAME "card10"
#define MICROPY_HW_MCU_NAME "max32665"
/* MicroPython Config Options */
/*
* Right now, we do not support importing external modules
* though this might change in the future.
*/
#define MICROPY_ENABLE_EXTERNAL_IMPORT (0)
#define MICROPY_ENABLE_DOC_STRING (1)
#define MICROPY_ENABLE_GC (1)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
#define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
/*
* This port is intended to be 32-bit, but unfortunately, int32_t for
* different targets may be defined in different ways - either as int
* or as long. This requires different printf formatting specifiers
* to print such value. So, we avoid int32_t and use int directly.
*/
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; /* must be pointer size */
typedef unsigned mp_uint_t; /* must be pointer size */
typedef long mp_off_t;
/*
* Make a pointer to RAM callable (eg set lower bit for Thumb code)
* (This scheme won't work if we want to mix Thumb and normal ARM code.)
*/
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
/* We need to provide a declaration/definition of alloca() */
#include <alloca.h>
/* TODO: Document this */
#define MP_STATE_PORT MP_STATE_VM
/* For some reason, we need to define readline history manually */
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[16];
#include <stdint.h>
#include "py/lexer.h"
#include "py/mpconfig.h"
#include "py/mperrno.h"
#include "py/obj.h"
#include "py/runtime.h"
/******************************************************************************
* Serial Communication
*/
/* TODO: Use API boundary instead of direct communication */
#include "uart.h"
extern mxc_uart_regs_t * ConsoleUart;
/* Receive single character */
int mp_hal_stdin_rx_chr(void)
{
return UART_ReadByte(ConsoleUart);
}
/* Send string of given length */
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len)
{
UART_Write(ConsoleUart, (uint8_t*)str, len);
}
/******************************************************************************
* Fatal Errors
*/
void NORETURN nlr_jump_fail(void *val)
{
/* TODO: Report error and restart */
while (1) {
}
}
/******************************************************************************
* Stubs
*/
mp_lexer_t *mp_lexer_new_from_file(const char *filename)
{
/* TODO: Do we need an implementation for this? */
mp_raise_OSError(MP_ENOENT);
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
{
/* TODO: Once fs is implemented, get this working as well */
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
/******************************************************************************
* TODO: Remove
*/
int _getpid(void)
{
;
}
int _kill(int pid, int f)
{
;
}
void _exit(int r)
{
;
}
#include "py/mpconfig.h"
/* TODO: Replace this with a proper implementation */
static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; }
/* TODO: Replace this with a proper implementation */
static inline void mp_hal_set_interrupt_char(char c) {}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment