summaryrefslogtreecommitdiffstatshomepage
path: root/zephyr
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/.gitignore1
-rw-r--r--zephyr/main.c30
-rw-r--r--zephyr/modutime.c2
-rw-r--r--zephyr/mpconfigport.h3
-rw-r--r--zephyr/mpconfigport_minimal.h1
-rw-r--r--zephyr/mphalport.h8
-rw-r--r--zephyr/src/zephyr_getchar.c6
-rw-r--r--zephyr/uart_core.c12
8 files changed, 35 insertions, 28 deletions
diff --git a/zephyr/.gitignore b/zephyr/.gitignore
new file mode 100644
index 0000000000..00ca089d15
--- /dev/null
+++ b/zephyr/.gitignore
@@ -0,0 +1 @@
+outdir/
diff --git a/zephyr/main.c b/zephyr/main.c
index 9146cfadb6..2c7f3fc477 100644
--- a/zephyr/main.c
+++ b/zephyr/main.c
@@ -67,28 +67,34 @@ int real_main(void) {
// Should be set to stack size in prj.mdef minus fuzz factor
mp_stack_set_limit(3584);
+soft_reset:
#if MICROPY_ENABLE_GC
gc_init(heap, heap + sizeof(heap));
#endif
mp_init();
- MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
+ mp_obj_list_init(mp_sys_path, 0);
+ mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
+ mp_obj_list_init(mp_sys_argv, 0);
+
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("main.py");
#endif
- #if MICROPY_REPL_EVENT_DRIVEN
- pyexec_event_repl_init();
+
for (;;) {
- int c = mp_hal_stdin_rx_chr();
- if (pyexec_event_repl_process_char(c)) {
- break;
+ if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
+ if (pyexec_raw_repl() != 0) {
+ break;
+ }
+ } else {
+ if (pyexec_friendly_repl() != 0) {
+ break;
+ }
}
}
- #else
- pyexec_friendly_repl();
- #endif
- //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
- //do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT);
- mp_deinit();
+
+ printf("soft reboot\n");
+ goto soft_reset;
+
return 0;
}
diff --git a/zephyr/modutime.c b/zephyr/modutime.c
index 8b96a5ab1e..378068bb38 100644
--- a/zephyr/modutime.c
+++ b/zephyr/modutime.c
@@ -40,7 +40,7 @@ STATIC mp_obj_t mod_time_time(void) {
* single precision floats so the fraction component will start to
* lose precision on devices with a long uptime.
*/
- return mp_obj_new_int(sys_tick_get() / sys_clock_ticks_per_sec);
+ return mp_obj_new_int(k_uptime_get() / 1000);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time);
diff --git a/zephyr/mpconfigport.h b/zephyr/mpconfigport.h
index e291faf1d6..26fb1410fe 100644
--- a/zephyr/mpconfigport.h
+++ b/zephyr/mpconfigport.h
@@ -37,6 +37,7 @@
#define MICROPY_ENABLE_GC (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_REPL_AUTO_INDENT (1)
+#define MICROPY_KBD_EXCEPTION (1)
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_PY_ASYNC_AWAIT (0)
#define MICROPY_PY_ATTRTUPLE (0)
@@ -47,7 +48,6 @@
#define MICROPY_PY_BUILTINS_RANGE_ATTRS (0)
#define MICROPY_PY_BUILTINS_REVERSED (0)
#define MICROPY_PY_BUILTINS_SET (0)
-#define MICROPY_PY_BUILTINS_SLICE (0)
#define MICROPY_PY_ARRAY (0)
#define MICROPY_PY_COLLECTIONS (0)
#define MICROPY_PY_CMATH (0)
@@ -94,7 +94,6 @@ typedef long mp_off_t;
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
- mp_obj_t mp_kbd_exception; \
const char *readline_hist[8];
extern const struct _mp_obj_module_t mp_module_machine;
diff --git a/zephyr/mpconfigport_minimal.h b/zephyr/mpconfigport_minimal.h
index 6629ffe9c3..4ecc03afb8 100644
--- a/zephyr/mpconfigport_minimal.h
+++ b/zephyr/mpconfigport_minimal.h
@@ -87,5 +87,4 @@ typedef long mp_off_t;
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
- mp_obj_t mp_kbd_exception; \
const char *readline_hist[8];
diff --git a/zephyr/mphalport.h b/zephyr/mphalport.h
index fafbb9ebe5..e3cca8d37d 100644
--- a/zephyr/mphalport.h
+++ b/zephyr/mphalport.h
@@ -2,20 +2,18 @@
#include "lib/utils/interrupt_char.h"
static inline mp_uint_t mp_hal_ticks_us(void) {
- return sys_tick_get() * sys_clock_us_per_tick;
+ return SYS_CLOCK_HW_CYCLES_TO_NS(k_cycle_get_32()) / 1000;
}
static inline mp_uint_t mp_hal_ticks_ms(void) {
- int64_t us = sys_tick_get() * sys_clock_us_per_tick;
- mp_int_t ms = us / 1000;
- return ms;
+ return k_uptime_get();
}
static inline mp_uint_t mp_hal_ticks_cpu(void) {
// ticks_cpu() is defined as using the highest-resolution timing source
// in the system. This is usually a CPU clock, but doesn't have to be,
// here we just use Zephyr hi-res timer.
- return sys_cycle_get_32();
+ return k_cycle_get_32();
}
static inline void mp_hal_delay_us(mp_uint_t delay) {
diff --git a/zephyr/src/zephyr_getchar.c b/zephyr/src/zephyr_getchar.c
index 0f673c9c80..95912f3df2 100644
--- a/zephyr/src/zephyr_getchar.c
+++ b/zephyr/src/zephyr_getchar.c
@@ -43,12 +43,12 @@ static int console_irq_input_hook(uint8_t ch)
i_put = i_next;
}
//printk("%x\n", ch);
- nano_isr_sem_give(&uart_sem);
+ k_sem_give(&uart_sem);
return 1;
}
uint8_t zephyr_getchar(void) {
- nano_task_sem_take(&uart_sem, TICKS_UNLIMITED);
+ k_sem_take(&uart_sem, K_FOREVER);
unsigned int key = irq_lock();
uint8_t c = uart_ringbuf[i_get++];
i_get &= UART_BUFSIZE - 1;
@@ -57,7 +57,7 @@ uint8_t zephyr_getchar(void) {
}
void zephyr_getchar_init(void) {
- nano_sem_init(&uart_sem);
+ k_sem_init(&uart_sem, 0, UINT_MAX);
uart_console_in_debug_hook_install(console_irq_input_hook);
// All NULLs because we're interested only in the callback above
uart_register_input(NULL, NULL, NULL);
diff --git a/zephyr/uart_core.c b/zephyr/uart_core.c
index 702c97d20a..1e85053cd2 100644
--- a/zephyr/uart_core.c
+++ b/zephyr/uart_core.c
@@ -26,9 +26,8 @@
#include <unistd.h>
#include "py/mpconfig.h"
#include "src/zephyr_getchar.h"
-
-// Stopgap
-extern void printk(const char*, ...);
+// Zephyr headers
+#include <uart.h>
/*
* Core UART functions to implement for a port
@@ -41,7 +40,12 @@ int mp_hal_stdin_rx_chr(void) {
// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+ static struct device *uart_console_dev;
+ if (uart_console_dev == NULL) {
+ uart_console_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME);
+ }
+
while (len--) {
- printk("%c", *str++);
+ uart_poll_out(uart_console_dev, *str++);
}
}