Skip to content

Commit 395886c

Browse files
committed
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 7d57037 and c60caf1 for relevant history). Signed-off-by: Damien George <damien@micropython.org>
1 parent 0e706a6 commit 395886c

File tree

8 files changed

+27
-92
lines changed

8 files changed

+27
-92
lines changed

extmod/modos.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include "py/mphal.h"
2728
#include "py/objstr.h"
2829
#include "py/runtime.h"
2930

@@ -128,6 +129,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname);
128129

129130
#endif
130131

132+
#if MICROPY_PY_OS_DUPTERM_NOTIFY
133+
STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
134+
(void)obj_in;
135+
for (;;) {
136+
int c = mp_os_dupterm_rx_chr();
137+
if (c < 0) {
138+
break;
139+
}
140+
ringbuf_put(&stdin_ringbuf, c);
141+
}
142+
return mp_const_none;
143+
}
144+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
145+
#endif
146+
131147
STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
132148
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) },
133149

ports/esp32/modos.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
* THE SOFTWARE.
2828
*/
2929

30+
// This file is never compiled standalone, it's included directly from
31+
// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
32+
3033
#include "esp_system.h"
3134

3235
#include "py/runtime.h"
@@ -48,18 +51,3 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
4851
return mp_obj_new_bytes_from_vstr(&vstr);
4952
}
5053
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
51-
52-
#if MICROPY_PY_OS_DUPTERM_NOTIFY
53-
STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
54-
(void)obj_in;
55-
for (;;) {
56-
int c = mp_os_dupterm_rx_chr();
57-
if (c < 0) {
58-
break;
59-
}
60-
ringbuf_put(&stdin_ringbuf, c);
61-
}
62-
return mp_const_none;
63-
}
64-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
65-
#endif

ports/esp8266/esp_mphal.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -134,33 +134,6 @@ void MP_FASTCODE(mp_hal_signal_input)(void) {
134134
#endif
135135
}
136136

137-
STATIC void dupterm_task_handler(os_event_t *evt) {
138-
static byte lock;
139-
if (lock) {
140-
return;
141-
}
142-
lock = 1;
143-
while (1) {
144-
int c = mp_os_dupterm_rx_chr();
145-
if (c < 0) {
146-
break;
147-
}
148-
ringbuf_put(&stdin_ringbuf, c);
149-
}
150-
mp_hal_signal_input();
151-
lock = 0;
152-
}
153-
154-
STATIC os_event_t dupterm_evt_queue[4];
155-
156-
void dupterm_task_init() {
157-
system_os_task(dupterm_task_handler, DUPTERM_TASK_ID, dupterm_evt_queue, MP_ARRAY_SIZE(dupterm_evt_queue));
158-
}
159-
160-
void mp_hal_signal_dupterm_input(void) {
161-
system_os_post(DUPTERM_TASK_ID, 0, 0);
162-
}
163-
164137
// this bit is unused in the Xtensa PS register
165138
#define ETS_LOOP_ITER_BIT (12)
166139

ports/esp8266/esp_mphal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ extern const struct _mp_print_t mp_debug_print;
4141
extern ringbuf_t stdin_ringbuf;
4242
// Call this after putting data to stdin_ringbuf
4343
void mp_hal_signal_input(void);
44-
// Call this when data is available in dupterm object
45-
void mp_hal_signal_dupterm_input(void);
4644

4745
// This variable counts how many times the UART is attached to dupterm
4846
extern int uart_attached_to_dupterm;
@@ -65,9 +63,7 @@ void mp_hal_set_interrupt_char(int c);
6563
uint32_t mp_hal_get_cpu_freq(void);
6664

6765
#define UART_TASK_ID 0
68-
#define DUPTERM_TASK_ID 1
6966
void uart_task_init();
70-
void dupterm_task_init();
7167

7268
uint32_t esp_disable_irq(void);
7369
void esp_enable_irq(uint32_t state);

ports/esp8266/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ STATIC void mp_reset(void) {
6363
#endif
6464
pin_init0();
6565
readline_init0();
66-
dupterm_task_init();
6766

6867
// Activate UART(0) on dupterm slot 1 for the REPL
6968
{

ports/esp8266/modos.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
#include <string.h>
28+
// This file is never compiled standalone, it's included directly from
29+
// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
2930

30-
#include "py/objtuple.h"
31-
#include "py/objstr.h"
32-
#include "extmod/misc.h"
3331
#include "extmod/modmachine.h"
34-
#include "extmod/vfs.h"
35-
#include "extmod/vfs_fat.h"
36-
#include "extmod/vfs_lfs.h"
37-
#include "genhdr/mpversion.h"
3832
#include "user_interface.h"
3933

4034
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
6054
--uart_attached_to_dupterm;
6155
}
6256
}
63-
64-
STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
65-
(void)obj_in;
66-
mp_hal_signal_dupterm_input();
67-
return mp_const_none;
68-
}
69-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);

ports/mimxrt/modos.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
* THE SOFTWARE.
2929
*/
3030

31+
// This file is never compiled standalone, it's included directly from
32+
// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
33+
3134
#include "py/runtime.h"
3235
#include "py/mphal.h"
3336

@@ -108,18 +111,3 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
108111
}
109112
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
110113
#endif
111-
112-
#if MICROPY_PY_OS_DUPTERM_NOTIFY
113-
STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
114-
(void)obj_in;
115-
for (;;) {
116-
int c = mp_os_dupterm_rx_chr();
117-
if (c < 0) {
118-
break;
119-
}
120-
ringbuf_put(&stdin_ringbuf, c);
121-
}
122-
return mp_const_none;
123-
}
124-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
125-
#endif

ports/samd/modos.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
* THE SOFTWARE.
3030
*/
3131

32+
// This file is never compiled standalone, it's included directly from
33+
// extmod/modos.c via MICROPY_PY_OS_INCLUDEFILE.
34+
3235
#include "py/runtime.h"
3336
#include "py/mphal.h"
3437
#include "modmachine.h"
@@ -96,18 +99,3 @@ bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) {
9699
return type == &machine_uart_type;
97100
}
98101
#endif
99-
100-
#if MICROPY_PY_OS_DUPTERM_NOTIFY
101-
STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) {
102-
(void)obj_in;
103-
for (;;) {
104-
int c = mp_os_dupterm_rx_chr();
105-
if (c < 0) {
106-
break;
107-
}
108-
ringbuf_put(&stdin_ringbuf, c);
109-
}
110-
return mp_const_none;
111-
}
112-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify);
113-
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy