8000 py/scheduler: Move mp_keyboard_interrupt from lib/utils to py core. · boris93/micropython@9efb36b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9efb36b

Browse files
committed
py/scheduler: Move mp_keyboard_interrupt from lib/utils to py core.
This function is tightly coupled to the state and behaviour of the scheduler, and is a core part of the runtime: to schedule a pending exception. So move it there.
1 parent 5a91cd9 commit 9efb36b

File tree

6 files changed

+14
-23
lines changed

6 files changed

+14
-23
lines changed

lib/utils/interrupt_char.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,4 @@ void mp_hal_set_interrupt_char(int c) {
3838
mp_interrupt_char = c;
3939
}
4040

41-
void mp_keyboard_interrupt(void) {
42-
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
43-
#if MICROPY_ENABLE_SCHEDULER
44-
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
45-
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
46-
}
47-
#endif
48-
}
49-
5041
#endif

lib/utils/interrupt_char.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@
2828

2929
extern int mp_interrupt_char;
3030
void mp_hal_set_interrupt_char(int c);
31-
void mp_keyboard_interrupt(void);
3231

3332
#endif // MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H

ports/cc3200/telnet/telnet.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
#include <stdint.h>
2828

29-
#include "py/mpconfig.h"
30-
#include "py/obj.h"
29+
#include "py/runtime.h"
3130
#include "py/mphal.h"
3231
#include "lib/utils/interrupt_char.h"
3332
#include "telnet.h"

ports/samd/mphalport.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "py/mpstate.h"
27+
#include "py/runtime.h"
2828
#include "py/mphal.h"
29-
#include "lib/utils/interrupt_char.h"
3029
#include "samd_soc.h"
3130
#include "tusb.h"
3231

@@ -46,15 +45,6 @@ void mp_hal_set_interrupt_char(int c) {
4645
tud_cdc_set_wanted_char(c);
4746
}
4847

49-
void mp_keyboard_interrupt(void) {
50-
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
51-
#if MICROPY_ENABLE_SCHEDULER
52-
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
53-
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
54-
}
55-
#endif
56-
}
57-
5848
#endif
5949

6050
void mp_hal_delay_ms(mp_uint_t ms) {

py/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extern const byte mp_binary_op_method_name[];
6464
void mp_init(void);
6565
void mp_deinit(void);
6666

67+
void mp_keyboard_interrupt(void);
6768
void mp_handle_pending(bool raise_exc);
6869
void mp_handle_pending_tail(mp_uint_t atomic_state);
6970

py/scheduler.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828

2929
#include "py/runtime.h"
3030

31+
#if MICROPY_KBD_EXCEPTION
32+
void mp_keyboard_interrupt(void) {
33+
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
34+
#if MICROPY_ENABLE_SCHEDULER
35+
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
36+
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
37+
}
38+
#endif
39+
}
40+
#endif
41+
3142
#if MICROPY_ENABLE_SCHEDULER
3243

3344
#define IDX_MASK(i) ((i) & (MICROPY_SCHEDULER_DEPTH - 1))

0 commit comments

Comments
 (0)
0