summaryrefslogtreecommitdiff
path: root/ports/esp8266
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-10-13 20:01:57 +1100
committerDamien George <damien.p.george@gmail.com>2017-10-13 20:01:57 +1100
commit37282f8fc135a16ff36e2afe0de907cbde531ed0 (patch)
treedaabbdc393b9870b5383aee08817df24a396ad98 /ports/esp8266
parente39fcda8eb1bfc1ccc1660079189f9ae39392abe (diff)
extmod/uos_dupterm: Update uos.dupterm() and helper funcs to have index.
The uos.dupterm() signature and behaviour is updated to reflect the latest enhancements in the docs. It has minor backwards incompatibility in that it no longer accepts zero arguments. The dupterm_rx helper function is moved from esp8266 to extmod and generalised to support multiple dupterm slots. A port can specify multiple slots by defining the MICROPY_PY_OS_DUPTERM config macro to an integer, being the number of slots it wants to have; 0 means to disable the dupterm feature altogether. The unix and esp8266 ports are updated to work with the new interface and are otherwise unchanged with respect to functionality.
Diffstat (limited to 'ports/esp8266')
-rw-r--r--ports/esp8266/esp_mphal.c37
-rw-r--r--ports/esp8266/main.c2
-rw-r--r--ports/esp8266/modules/webrepl.py4
3 files changed, 4 insertions, 39 deletions
diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c
index 71d4c5062..9f4f051fd 100644
--- a/ports/esp8266/esp_mphal.c
+++ b/ports/esp8266/esp_mphal.c
@@ -155,41 +155,6 @@ void mp_hal_signal_input(void) {
#endif
}
-static int call_dupterm_read(void) {
- if (MP_STATE_PORT(term_obj) == NULL) {
- return -1;
- }
-
- nlr_buf_t nlr;
- if (nlr_push(&nlr) == 0) {
- mp_obj_t readinto_m[3];
- mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_readinto, readinto_m);
- readinto_m[2] = MP_STATE_PORT(dupterm_arr_obj);
- mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m);
- if (res == mp_const_none) {
- nlr_pop();
- return -2;
- }
- if (res == MP_OBJ_NEW_SMALL_INT(0)) {
- mp_uos_deactivate("dupterm: EOF received, deactivating\n", MP_OBJ_NULL);
- nlr_pop();
- return -1;
- }
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(MP_STATE_PORT(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ);
- nlr_pop();
- if (*(byte*)bufinfo.buf == mp_interrupt_char) {
- mp_keyboard_interrupt();
- return -2;
- }
- return *(byte*)bufinfo.buf;
- } else {
- mp_uos_deactivate("dupterm: Exception in read() method, deactivating: ", nlr.ret_val);
- }
-
- return -1;
-}
-
STATIC void dupterm_task_handler(os_event_t *evt) {
static byte lock;
if (lock) {
@@ -197,7 +162,7 @@ STATIC void dupterm_task_handler(os_event_t *evt) {
}
lock = 1;
while (1) {
- int c = call_dupterm_read();
+ int c = mp_uos_dupterm_rx_chr();
if (c < 0) {
break;
}
diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c
index 7f5dca84e..d1b88a8ce 100644
--- a/ports/esp8266/main.c
+++ b/ports/esp8266/main.c
@@ -51,8 +51,6 @@ STATIC void mp_reset(void) {
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
mp_obj_list_init(mp_sys_argv, 0);
- MP_STATE_PORT(term_obj) = MP_OBJ_NULL;
- MP_STATE_PORT(dupterm_arr_obj) = MP_OBJ_NULL;
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
extern void esp_native_code_init(void);
esp_native_code_init();
diff --git a/ports/esp8266/modules/webrepl.py b/ports/esp8266/modules/webrepl.py
index 5a76e9b26..aa156d148 100644
--- a/ports/esp8266/modules/webrepl.py
+++ b/ports/esp8266/modules/webrepl.py
@@ -31,7 +31,9 @@ def setup_conn(port, accept_handler):
def accept_conn(listen_sock):
global client_s
cl, remote_addr = listen_sock.accept()
- if uos.dupterm():
+ prev = uos.dupterm(None)
+ uos.dupterm(prev)
+ if prev:
print("\nConcurrent WebREPL connection from", remote_addr, "rejected")
cl.close()
return