extmod/utime_mphal: Add MP_THREAD_GIL_EXIT/ENTER warppers for sleep functions.

Ported from unix port.
This commit is contained in:
Paul Sokolovsky 2016-10-29 13:42:36 +03:00
parent 99ed0f25cb
commit 6a87084019
1 changed files with 7 additions and 0 deletions

View File

@ -33,14 +33,17 @@
#include "py/obj.h"
#include "py/mphal.h"
#include "py/smallint.h"
#include "py/runtime.h"
#include "extmod/utime_mphal.h"
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
MP_THREAD_GIL_EXIT();
#if MICROPY_PY_BUILTINS_FLOAT
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
#else
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
#endif
MP_THREAD_GIL_ENTER();
return mp_const_none;
}
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) {
mp_int_t ms = mp_obj_get_int(arg);
if (ms > 0) {
MP_THREAD_GIL_EXIT();
mp_hal_delay_ms(ms);
MP_THREAD_GIL_ENTER();
}
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) {
mp_int_t us = mp_obj_get_int(arg);
if (us > 0) {
MP_THREAD_GIL_EXIT();
mp_hal_delay_us(us);
MP_THREAD_GIL_ENTER();
}
return mp_const_none;
}