stmhal/moduselect: Implement "oneshot polling" flag.
Similar to recently added feature in unix port: if event triggers for an objects, its polling flags are automatically reset, so it won't be polled until they are set again explicitly.
This commit is contained in:
parent
c5d8ffef58
commit
be3ae9d13c
@ -33,6 +33,9 @@
|
|||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "pybioctl.h"
|
#include "pybioctl.h"
|
||||||
|
|
||||||
|
// Flags for poll()
|
||||||
|
#define FLAG_ONESHOT (1)
|
||||||
|
|
||||||
/// \module select - Provides select function to wait for events on a stream
|
/// \module select - Provides select function to wait for events on a stream
|
||||||
///
|
///
|
||||||
/// This module provides the select function.
|
/// This module provides the select function.
|
||||||
@ -223,13 +226,17 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
|
|||||||
|
|
||||||
// work out timeout (its given already in ms)
|
// work out timeout (its given already in ms)
|
||||||
mp_uint_t timeout = -1;
|
mp_uint_t timeout = -1;
|
||||||
if (n_args == 2) {
|
int flags = 0;
|
||||||
|
if (n_args >= 2) {
|
||||||
if (args[1] != mp_const_none) {
|
if (args[1] != mp_const_none) {
|
||||||
mp_int_t timeout_i = mp_obj_get_int(args[1]);
|
mp_int_t timeout_i = mp_obj_get_int(args[1]);
|
||||||
if (timeout_i >= 0) {
|
if (timeout_i >= 0) {
|
||||||
timeout = timeout_i;
|
timeout = timeout_i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (n_args >= 3) {
|
||||||
|
flags = mp_obj_get_int(args[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t start_tick = mp_hal_ticks_ms();
|
mp_uint_t start_tick = mp_hal_ticks_ms();
|
||||||
@ -249,6 +256,10 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
|
|||||||
if (poll_obj->flags_ret != 0) {
|
if (poll_obj->flags_ret != 0) {
|
||||||
mp_obj_t tuple[2] = {poll_obj->obj, MP_OBJ_NEW_SMALL_INT(poll_obj->flags_ret)};
|
mp_obj_t tuple[2] = {poll_obj->obj, MP_OBJ_NEW_SMALL_INT(poll_obj->flags_ret)};
|
||||||
ret_list->items[n_ready++] = mp_obj_new_tuple(2, tuple);
|
ret_list->items[n_ready++] = mp_obj_new_tuple(2, tuple);
|
||||||
|
if (flags & FLAG_ONESHOT) {
|
||||||
|
// Don't poll next time, until new event flags will be set explicitly
|
||||||
|
poll_obj->flags = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret_list;
|
return ret_list;
|
||||||
@ -256,7 +267,7 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
|
|||||||
__WFI();
|
__WFI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_poll_obj, 1, 2, poll_poll);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_poll_obj, 1, 3, poll_poll);
|
||||||
|
|
||||||
STATIC const mp_map_elem_t poll_locals_dict_table[] = {
|
STATIC const mp_map_elem_t poll_locals_dict_table[] = {
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_register), (mp_obj_t)&poll_register_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_register), (mp_obj_t)&poll_register_obj },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user