From 2d329c4a56580e17781febbfe6e42038fc3d9d03 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Fri, 2 Dec 2016 16:40:39 +1100
Subject: [PATCH] extmod/moduselect: Use configurable EVENT_POLL_HOOK instead
 of WFI.

To make moduselect be usable by any port.
---
 cc3200/mpconfigport.h | 1 +
 extmod/moduselect.c   | 4 ++--
 stmhal/mpconfigport.h | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h
index 7a8aa15d5..5b6a035d5 100644
--- a/cc3200/mpconfigport.h
+++ b/cc3200/mpconfigport.h
@@ -194,6 +194,7 @@ typedef long            mp_off_t;
 
 #define MICROPY_BEGIN_ATOMIC_SECTION()              disable_irq()
 #define MICROPY_END_ATOMIC_SECTION(state)           enable_irq(state)
+#define MICROPY_EVENT_POLL_HOOK                     __WFI();
 
 // assembly functions to handle critical sections, interrupt
 // disabling/enabling and sleep mode enter/exit
diff --git a/extmod/moduselect.c b/extmod/moduselect.c
index a19901e17..5b00f6bad 100644
--- a/extmod/moduselect.c
+++ b/extmod/moduselect.c
@@ -172,7 +172,7 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) {
             mp_map_deinit(&poll_map);
             return mp_obj_new_tuple(3, list_array);
         }
-        __WFI();
+        MICROPY_EVENT_POLL_HOOK
     }
 }
 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select);
@@ -264,7 +264,7 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
             }
             return ret_list;
         }
-        __WFI();
+        MICROPY_EVENT_POLL_HOOK
     }
 }
 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_poll_obj, 1, 3, poll_poll);
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index ed9e26f37..81959555c 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -262,6 +262,7 @@ static inline mp_uint_t disable_irq(void) {
 
 #define MICROPY_BEGIN_ATOMIC_SECTION()     disable_irq()
 #define MICROPY_END_ATOMIC_SECTION(state)  enable_irq(state)
+#define MICROPY_EVENT_POLL_HOOK            __WFI();
 
 // There is no classical C heap in bare-metal ports, only Python
 // garbage-collected heap. For completeness, emulate C heap via
-- 
GitLab