summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-12-14 17:06:56 +1100
committerDamien George <damien@micropython.org>2023-12-18 12:20:47 +1100
commit395886caa3406a25790bd27e74ec63a96d8e5b4d (patch)
treeab08973886ada1953607909ffe4d2ea0561ce3b4
parent0e706a62b168b7c2818f99d8785fe4dd31af9169 (diff)
downloadmicropython-395886caa3406a25790bd27e74ec63a96d8e5b4d.tar.gz
micropython-395886caa3406a25790bd27e74ec63a96d8e5b4d.zip
extmod/modos: Factor os.dupterm_notify() function to common extmod code.
esp8266 doesn't need ets task because the notify is now scheduled (see commits 7d57037906cf0274af08bd2eccbfffabe0ea66e3 and c60caf19951c8326be9c3b6f3b016a4d21f69276 for relevant history). Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--extmod/modos.c16
-rw-r--r--ports/esp32/modos.c18
-rw-r--r--ports/esp8266/esp_mphal.c27
-rw-r--r--ports/esp8266/esp_mphal.h4
-rw-r--r--ports/esp8266/main.c1
-rw-r--r--ports/esp8266/modos.c17
-rw-r--r--ports/mimxrt/modos.c18
-rw-r--r--ports/samd/modos.c18
8 files changed, 27 insertions, 92 deletions
diff --git a/extmod/modos.c b/extmod/modos.c
index da14fd81f8..5a088b5202 100644
--- a/extmod/modos.c
+++ b/extmod/modos.c
@@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
+#include "py/mphal.h"
#include "py/objstr.h"
#include "py/runtime.h"
@@ -128,6 +129,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname);
#endif
+#if MICROPY_PY_OS_DUPTERM_NOTIFY
+STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
+ (void)obj_in;
+ for (;;) {
+ int c = mp_os_dupterm_rx_chr();
+ if (c < 0) {
+ break;
+ }
+ ringbuf_put(&stdin_ringbuf, c);
+ }
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
+#endif
+
STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) },
diff --git a/ports/esp32/modos.c b/ports/esp32/modos.c
index 287f1d9900..5b055eb979 100644
--- a/ports/esp32/modos.c
+++ b/ports/esp32/modos.c
@@ -27,6 +27,9 @@
* THE SOFTWARE.
*/
+// This file is never compiled standalone, it's included directly from
+// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
+
#include "esp_system.h"
#include "py/runtime.h"
@@ -48,18 +51,3 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
return mp_obj_new_bytes_from_vstr(&vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
-
-#if MICROPY_PY_OS_DUPTERM_NOTIFY
-STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
- (void)obj_in;
- for (;;) {
- int c = mp_os_dupterm_rx_chr();
- if (c < 0) {
- break;
- }
- ringbuf_put(&stdin_ringbuf, c);
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
-#endif
diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c
index 956cb2e649..394c9796c8 100644
--- a/ports/esp8266/esp_mphal.c
+++ b/ports/esp8266/esp_mphal.c
@@ -134,33 +134,6 @@ void MP_FASTCODE(mp_hal_signal_input)(void) {
#endif
}
-STATIC void dupterm_task_handler(os_event_t *evt) {
- static byte lock;
- if (lock) {
- return;
- }
- lock = 1;
- while (1) {
- int c = mp_os_dupterm_rx_chr();
- if (c < 0) {
- break;
- }
- ringbuf_put(&stdin_ringbuf, c);
- }
- mp_hal_signal_input();
- lock = 0;
-}
-
-STATIC os_event_t dupterm_evt_queue[4];
-
-void dupterm_task_init() {
- system_os_task(dupterm_task_handler, DUPTERM_TASK_ID, dupterm_evt_queue, MP_ARRAY_SIZE(dupterm_evt_queue));
-}
-
-void mp_hal_signal_dupterm_input(void) {
- system_os_post(DUPTERM_TASK_ID, 0, 0);
-}
-
// this bit is unused in the Xtensa PS register
#define ETS_LOOP_ITER_BIT (12)
diff --git a/ports/esp8266/esp_mphal.h b/ports/esp8266/esp_mphal.h
index 6fea6554b0..e677fa450d 100644
--- a/ports/esp8266/esp_mphal.h
+++ b/ports/esp8266/esp_mphal.h
@@ -41,8 +41,6 @@ extern const struct _mp_print_t mp_debug_print;
extern ringbuf_t stdin_ringbuf;
// Call this after putting data to stdin_ringbuf
void mp_hal_signal_input(void);
-// Call this when data is available in dupterm object
-void mp_hal_signal_dupterm_input(void);
// This variable counts how many times the UART is attached to dupterm
extern int uart_attached_to_dupterm;
@@ -65,9 +63,7 @@ void mp_hal_set_interrupt_char(int c);
uint32_t mp_hal_get_cpu_freq(void);
#define UART_TASK_ID 0
-#define DUPTERM_TASK_ID 1
void uart_task_init();
-void dupterm_task_init();
uint32_t esp_disable_irq(void);
void esp_enable_irq(uint32_t state);
diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c
index d0f52ed566..d774bbd35a 100644
--- a/ports/esp8266/main.c
+++ b/ports/esp8266/main.c
@@ -63,7 +63,6 @@ STATIC void mp_reset(void) {
#endif
pin_init0();
readline_init0();
- dupterm_task_init();
// Activate UART(0) on dupterm slot 1 for the REPL
{
diff --git a/ports/esp8266/modos.c b/ports/esp8266/modos.c
index 0ddcba2a32..32c6a06676 100644
--- a/ports/esp8266/modos.c
+++ b/ports/esp8266/modos.c
@@ -25,16 +25,10 @@
* THE SOFTWARE.
*/
-#include <string.h>
+// This file is never compiled standalone, it's included directly from
+// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
-#include "py/objtuple.h"
-#include "py/objstr.h"
-#include "extmod/misc.h"
#include "extmod/modmachine.h"
-#include "extmod/vfs.h"
-#include "extmod/vfs_fat.h"
-#include "extmod/vfs_lfs.h"
-#include "genhdr/mpversion.h"
#include "user_interface.h"
STATIC const char *mp_os_uname_release(void) {
@@ -60,10 +54,3 @@ void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t s
--uart_attached_to_dupterm;
}
}
-
-STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
- (void)obj_in;
- mp_hal_signal_dupterm_input();
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
diff --git a/ports/mimxrt/modos.c b/ports/mimxrt/modos.c
index ecfc3712d7..2ee8418152 100644
--- a/ports/mimxrt/modos.c
+++ b/ports/mimxrt/modos.c
@@ -28,6 +28,9 @@
* THE SOFTWARE.
*/
+// This file is never compiled standalone, it's included directly from
+// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
+
#include "py/runtime.h"
#include "py/mphal.h"
@@ -108,18 +111,3 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
#endif
-
-#if MICROPY_PY_OS_DUPTERM_NOTIFY
-STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
- (void)obj_in;
- for (;;) {
- int c = mp_os_dupterm_rx_chr();
- if (c < 0) {
- break;
- }
- ringbuf_put(&stdin_ringbuf, c);
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
-#endif
diff --git a/ports/samd/modos.c b/ports/samd/modos.c
index f9df0cd996..16b9eb0841 100644
--- a/ports/samd/modos.c
+++ b/ports/samd/modos.c
@@ -29,6 +29,9 @@
* THE SOFTWARE.
*/
+// This file is never compiled standalone, it's included directly from
+// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
+
#include "py/runtime.h"
#include "py/mphal.h"
#include "modmachine.h"
@@ -96,18 +99,3 @@ bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) {
return type == &machine_uart_type;
}
#endif
-
-#if MICROPY_PY_OS_DUPTERM_NOTIFY
-STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
- (void)obj_in;
- for (;;) {
- int c = mp_os_dupterm_rx_chr();
- if (c < 0) {
- break;
- }
- ringbuf_put(&stdin_ringbuf, c);
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
-#endif