summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-01-21 17:16:35 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-01-21 17:16:35 +0300
commit5298472fee1a83878e4670c1f8c885aefc087765 (patch)
tree20d04d4e103f17d401633d28a24a83eb18367356
parent1459f8142919352b5615751566d443e0c319bc8e (diff)
zephyr: Enable SLIP networking for the default build.
This makes MicroPython app running in QEMU be pingable from the host (by following QEMU networking setup instructions, https://www.zephyrproject.org/doc/samples/net/qemu_setup.html).
-rw-r--r--zephyr/main.c16
-rw-r--r--zephyr/prj.conf13
2 files changed, 29 insertions, 0 deletions
diff --git a/zephyr/main.c b/zephyr/main.c
index d812f9609..6d7fca802 100644
--- a/zephyr/main.c
+++ b/zephyr/main.c
@@ -28,6 +28,12 @@
#include <stdio.h>
#include <string.h>
+#include <zephyr.h>
+#ifdef CONFIG_NETWORKING
+#include <net/net_context.h>
+#include <net/nbuf.h>
+#endif
+
#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
@@ -60,6 +66,14 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
static char *stack_top;
static char heap[MICROPY_HEAP_SIZE];
+void init_zephyr(void) {
+ #ifdef CONFIG_NET_IPV4
+ // TODO: Make address configurable
+ static struct in_addr in4addr_my = { { { 192, 0, 2, 1 } } };
+ net_if_ipv4_addr_add(net_if_get_default(), &in4addr_my, NET_ADDR_MANUAL, 0);
+ #endif
+}
+
int real_main(void) {
int stack_dummy;
stack_top = (char*)&stack_dummy;
@@ -67,6 +81,8 @@ int real_main(void) {
// Make MicroPython's stack limit somewhat smaller than full stack available
mp_stack_set_limit(CONFIG_MAIN_STACK_SIZE - 512);
+ init_zephyr();
+
soft_reset:
#if MICROPY_ENABLE_GC
gc_init(heap, heap + sizeof(heap));
diff --git a/zephyr/prj.conf b/zephyr/prj.conf
index 5d6b353ba..a2fcb64d9 100644
--- a/zephyr/prj.conf
+++ b/zephyr/prj.conf
@@ -4,3 +4,16 @@ CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS=y
CONFIG_NEWLIB_LIBC=y
CONFIG_FLOAT=y
CONFIG_MAIN_STACK_SIZE=4096
+
+# Networking config
+CONFIG_NETWORKING=y
+CONFIG_NET_IPV4=y
+CONFIG_TEST_RANDOM_GENERATOR=y
+CONFIG_NET_NBUF_RX_COUNT=4
+
+# Networking drivers
+# SLIP driver for QEMU
+CONFIG_NET_SLIP_TAP=y
+
+# BOARD-specific config (qemu_x86)
+CONFIG_RAM_SIZE=256