stm32/mpbthciport: Switch scheduling callback to use node scheduler.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-03-23 17:22:53 +11:00
parent 75506e496f
commit 8045ac07f5
2 changed files with 6 additions and 24 deletions

View File

@ -42,20 +42,12 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
// Soft timer for scheduling a HCI poll. // Soft timer for scheduling a HCI poll.
STATIC soft_timer_entry_t mp_bluetooth_hci_soft_timer; STATIC soft_timer_entry_t mp_bluetooth_hci_soft_timer;
#if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS
// Prevent double-enqueuing of the scheduled task.
STATIC volatile bool events_task_is_scheduled;
#endif
// This is called by soft_timer and executes at IRQ_PRI_PENDSV. // This is called by soft_timer and executes at IRQ_PRI_PENDSV.
STATIC void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) { STATIC void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
mp_bluetooth_hci_poll_now(); mp_bluetooth_hci_poll_now();
} }
void mp_bluetooth_hci_init(void) { void mp_bluetooth_hci_init(void) {
#if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS
events_task_is_scheduled = false;
#endif
soft_timer_static_init( soft_timer_static_init(
&mp_bluetooth_hci_soft_timer, &mp_bluetooth_hci_soft_timer,
SOFT_TIMER_MODE_ONE_SHOT, SOFT_TIMER_MODE_ONE_SHOT,
@ -65,9 +57,6 @@ void mp_bluetooth_hci_init(void) {
} }
STATIC void mp_bluetooth_hci_start_polling(void) { STATIC void mp_bluetooth_hci_start_polling(void) {
#if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS
events_task_is_scheduled = false;
#endif
mp_bluetooth_hci_poll_now(); mp_bluetooth_hci_poll_now();
} }
@ -77,29 +66,21 @@ void mp_bluetooth_hci_poll_in_ms_default(uint32_t ms) {
#if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS #if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS
STATIC mp_sched_node_t mp_bluetooth_hci_sched_node;
// For synchronous mode, we run all BLE stack code inside a scheduled task. // For synchronous mode, we run all BLE stack code inside a scheduled task.
// This task is scheduled periodically via a soft timer, or // This task is scheduled periodically via a soft timer, or
// immediately on HCI UART RXIDLE. // immediately on HCI UART RXIDLE.
STATIC void run_events_scheduled_task(mp_sched_node_t *node) {
STATIC mp_obj_t run_events_scheduled_task(mp_obj_t none_in) {
(void)none_in;
events_task_is_scheduled = false;
// This will process all buffered HCI UART data, and run any callouts or events. // This will process all buffered HCI UART data, and run any callouts or events.
(void)node;
mp_bluetooth_hci_poll(); mp_bluetooth_hci_poll();
return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(run_events_scheduled_task_obj, run_events_scheduled_task);
// Called periodically (systick) or directly (e.g. UART RX IRQ) in order to // Called periodically (systick) or directly (e.g. UART RX IRQ) in order to
// request that processing happens ASAP in the scheduler. // request that processing happens ASAP in the scheduler.
void mp_bluetooth_hci_poll_now_default(void) { void mp_bluetooth_hci_poll_now_default(void) {
if (!events_task_is_scheduled) { mp_sched_schedule_node(&mp_bluetooth_hci_sched_node, run_events_scheduled_task);
events_task_is_scheduled = mp_sched_schedule(MP_OBJ_FROM_PTR(&run_events_scheduled_task_obj), mp_const_none);
if (!events_task_is_scheduled) {
// The schedule queue is full, set callback to try again soon.
mp_bluetooth_hci_poll_in_ms(5);
}
}
} }
#else // !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS #else // !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS

View File

@ -75,6 +75,7 @@
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#endif #endif
#define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_SCHEDULER_STATIC_NODES (1)
#define MICROPY_SCHEDULER_DEPTH (8) #define MICROPY_SCHEDULER_DEPTH (8)
#define MICROPY_VFS (1) #define MICROPY_VFS (1)