Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zephyr rebase #2

Merged
merged 5 commits into from
Oct 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions zephyr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
outdir/
qemu.pid
82 changes: 47 additions & 35 deletions zephyr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,38 @@ BOARD ?= qemu_x86
OUTDIR_PREFIX = $(BOARD)

# Zephyr (generated) config files - must be defined before include below
Z_DOTCONFIG = outdir/$(OUTDIR_PREFIX)/.config
Z_AUTOCONF_H = outdir/$(OUTDIR_PREFIX)/include/generated/autoconf.h
DQUOTE = "
# "
include z_config_proxy.mk
Z_SYSGEN_H = outdir/$(OUTDIR_PREFIX)/misc/generated/sysgen/sysgen.h
Z_EXPORTS = outdir/$(OUTDIR_PREFIX)/Makefile.export
include $(Z_EXPORTS)

ifdef CONFIG_MBEDTLS
MICROPY_PY_USSL = 1
MICROPY_SSL_MBEDTLS = 1
MICROPY_SSL_MBEDTLS_INCLUDE = $(ZEPHYR_BASE)/ext/lib/crypto/mbedtls/include
endif

FROZEN_DIR = scripts

# Zephyr toolchain config is 2-pass, so included twice
include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)
include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)

CFLAGS_TARGET = $(cflags-y)

include ../py/mkenv.mk
include ../py/py.mk

INC += -I.
INC += -I..
INC += -I$(BUILD)
INC += -I$(ZEPHYR_BASE)/include -I$(ZEPHYR_BASE) \
-I$(ZEPHYR_BASE)/net/ip -I$(ZEPHYR_BASE)/net/ip/contiki -I$(ZEPHYR_BASE)/net/ip/contiki/os \
-Ioutdir/$(OUTDIR_PREFIX)/misc/generated/sysgen \
-I$(dir $(Z_AUTOCONF_H))

SRC_C = main.c \
INC += -I$(ZEPHYR_BASE)/net/ip
INC += -I$(ZEPHYR_BASE)/net/ip/contiki
INC += -I$(ZEPHYR_BASE)/net/ip/contiki/os

ifdef CONFIG_NETWORKING
SRC_MOD += modsocket.c
endif

SRC_C = help.c \
main.c \
modutime.c \
modmachine.c \
modpybpin.c \
uart_core.c \
modsocket.c \
lib/utils/stdout_helpers.c \
lib/utils/printf.c \
lib/utils/pyexec.c \
Expand All @@ -57,23 +57,37 @@ SRC_C = main.c \
$(BUILD)/frozen.c \
$(SRC_MOD)

LIB_SRC_C = $(addprefix lib/,\
utils/pyhelp.c \
)

# List of sources for qstr extraction
SRC_QSTR += $(SRC_C)

OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))

COPT = -Os -DNDEBUG -fdata-sections -ffunction-sections
CFLAGS = -std=gnu99 $(TOOLCHAIN_CFLAGS) $(INC) $(CFLAGS_MOD) $(COPT) $(CFLAGS_TARGET)
CFLAGS = $(KBUILD_CFLAGS) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \
-std=gnu99 -DNDEBUG $(INC)

include ../py/mkrules.mk

$(Z_DOTCONFIG):
$(MAKE) -f Makefile.zephyr BOARD=$(BOARD) initconfig
$(Z_EXPORTS):
$(MAKE) -f Makefile.zephyr BOARD=$(BOARD) initconfig outputexports

GENERIC_TARGETS = all zephyr qemu qemugdb flash debug
KCONFIG_TARGETS = config nconfig menuconfig xconfig gconfig

$(GENERIC_TARGETS) $(KCONFIG_TARGETS): $(LIBMICROPYTHON)
KCONFIG_TARGETS = \
initconfig config nconfig menuconfig xconfig gconfig \
oldconfig silentoldconfig defconfig savedefconfig \
allnoconfig allyesconfig alldefconfig randconfig \
listnewconfig olddefconfig
CLEAN_TARGETS = pristine mrproper

$(GENERIC_TARGETS) : $(LIBMICROPYTHON)
$(CLEAN_TARGETS) : clean

$(GENERIC_TARGETS) $(KCONFIG_TARGETS) $(CLEAN_TARGETS):
$(RM) -f outdir/$(OUTDIR_PREFIX)/zephyr.lnk
$(MAKE) -f Makefile.zephyr BOARD=$(BOARD) $@

# Note: doesn't rebuild binary, just runs qemu against it
Expand All @@ -87,19 +101,17 @@ qemu-net:
# For GDB debugging with QEMU
#-s -S

$(LIBMICROPYTHON): $(Z_AUTOCONF_H)
build/genhdr/qstr.i.last: $(Z_AUTOCONF_H)
$(LIBMICROPYTHON): $(Z_SYSGEN_H)
build/genhdr/qstr.i.last: $(Z_SYSGEN_H)

$(Z_AUTOCONF_H):
$(Z_SYSGEN_H):
rm -f $(LIBMICROPYTHON)
-$(MAKE) -f Makefile.zephyr BOARD=$(BOARD)

zephyr_arch.mk: $(Z_DOTCONFIG)
echo "include $(ZEPHYR_BASE)/arch/$(ARCH)/Makefile" >$@

z_config_proxy.mk:
$(MAKE) -f Makefile.zephyr BOARD=$(BOARD) initconfig
echo "include z_config.mk" >$@
CLEAN_EXTRA = z_config_proxy.mk

# Clean Zephyr things too
CLEAN_EXTRA = outdir z_config_proxy.mk
clean : z_clean

z_clean :
$(MAKE) -f Makefile.zephyr BOARD=$(BOARD) clean
18 changes: 18 additions & 0 deletions zephyr/README
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ To run in QEMU:
To build for a real board (see link above for supported Cortex-M boards):

make BOARD=frdm_k64f

For boards with limited FLASH it may be necessary to disable unnecessary
features. For example to run with BOARD=qemu_cortex_m3 try:

make BOARD=qemu_cortex_m3 initconfig
$ZEPHYR_BASE/scripts/config --file outdir/qemu_cortex_m3/.config \
--disable NETWORKING \
--disable MBEDTLS
make BOARD=qemu_cortex_m3

As before we can run this in QEMU too:

make BOARD=qemu_cortex_m3 qemu

The clean targets (clean, pristine, mrproper) all act like their Zephyr
namesakes. In particular a "clean" will causes a full rebuild but will not
remove the .config file.

56 changes: 56 additions & 0 deletions zephyr/help.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013-2016 Damien P. George
*
* 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.
*/

#include <stdio.h>

#include "lib/utils/pyhelp.h"

STATIC const char *help_text =
"Welcome to MicroPython!\n"
"\n"
"Control commands:\n"
" CTRL-A -- on a blank line, enter raw REPL mode\n"
" CTRL-B -- on a blank line, enter normal REPL mode\n"
" CTRL-C -- interrupt a running program\n"
" CTRL-D -- on a blank line, do a soft reset of the board\n"
" CTRL-E -- on a blank line, enter paste mode\n"
"\n"
"For further help on a specific object, type help(obj)\n"
;

STATIC mp_obj_t builtin_help(uint n_args, const mp_obj_t *args) {
if (n_args == 0) {
// print a general help message
printf("%s", help_text);

} else {
// try to print something sensible about the given object
pyhelp_print_obj(args[0]);
}

return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, builtin_help);
71 changes: 71 additions & 0 deletions zephyr/modmachine.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013-2015 Damien P. George
* Copyright (c) 2016 Paul Sokolovsky
* Copyright (c) 2016 Linaro Limited
*
* 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.
*/

#include <stdint.h>
#include <stdio.h>

#include "py/obj.h"
#include "py/runtime.h"
#include "extmod/machine_mem.h"
#include "extmod/machine_pulse.h"
#include "extmod/machine_i2c.h"
#include "modpyb.h"

#if MICROPY_PY_MACHINE

STATIC mp_obj_t machine_reset(void) {
printf("Warning: %s is not implemented\n", __func__);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);

STATIC mp_obj_t machine_reset_cause(void) {
printf("Warning: %s is not implemented\n", __func__);
return MP_OBJ_NEW_SMALL_INT(42);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);

STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },

{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pyb_pin_type) },

// reset causes
/*{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(REASON_DEFAULT_RST) },*/
};

STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);

const mp_obj_module_t mp_module_machine = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&machine_module_globals,
};

#endif // MICROPY_PY_MACHINE
16 changes: 16 additions & 0 deletions zephyr/modpyb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __MICROPY_INCLUDED_ZEPHYR_MODPYB_H__
#define __MICROPY_INCLUDED_ZEPHYR_MODPYB_H__

#include "py/obj.h"

extern const mp_obj_type_t pyb_pin_type;

MP_DECLARE_CONST_FUN_OBJ(pyb_info_obj);

typedef struct _pyb_pin_obj_t {
mp_obj_base_t base;
struct device *port;
uint32_t pin;
} pyb_pin_obj_t;

#endif // __MICROPY_INCLUDED_ZEPHYR_MODPYB_H__
Loading