extmod/utime_mphal: Add MP_THREAD_GIL_EXIT/ENTER warppers for sleep functions.
Ported from unix port.
This commit is contained in:
parent
99ed0f25cb
commit
6a87084019
|
@ -33,14 +33,17 @@
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "py/smallint.h"
|
#include "py/smallint.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
#include "extmod/utime_mphal.h"
|
#include "extmod/utime_mphal.h"
|
||||||
|
|
||||||
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
|
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
|
||||||
|
MP_THREAD_GIL_EXIT();
|
||||||
#if MICROPY_PY_BUILTINS_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
|
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
|
||||||
#else
|
#else
|
||||||
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
|
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
|
||||||
#endif
|
#endif
|
||||||
|
MP_THREAD_GIL_ENTER();
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
|
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
|
||||||
|
@ -48,7 +51,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
|
||||||
STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
|
STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
|
||||||
mp_int_t ms = mp_obj_get_int(arg);
|
mp_int_t ms = mp_obj_get_int(arg);
|
||||||
if (ms > 0) {
|
if (ms > 0) {
|
||||||
|
MP_THREAD_GIL_EXIT();
|
||||||
mp_hal_delay_ms(ms);
|
mp_hal_delay_ms(ms);
|
||||||
|
MP_THREAD_GIL_ENTER();
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +62,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj, time_sleep_ms);
|
||||||
STATIC mp_obj_t time_sleep_us(mp_obj_t arg) {
|
STATIC mp_obj_t time_sleep_us(mp_obj_t arg) {
|
||||||
mp_int_t us = mp_obj_get_int(arg);
|
mp_int_t us = mp_obj_get_int(arg);
|
||||||
if (us > 0) {
|
if (us > 0) {
|
||||||
|
MP_THREAD_GIL_EXIT();
|
||||||
mp_hal_delay_us(us);
|
mp_hal_delay_us(us);
|
||||||
|
MP_THREAD_GIL_ENTER();
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue