kopia lustrzana https://github.com/micropython/micropython
rp2/mpbthciport: Rework HCI polling timer to use soft_timer.
Signed-off-by: Damien George <damien@micropython.org>pull/12901/head
rodzic
c9a9b2e682
commit
633c604722
|
@ -30,36 +30,37 @@
|
||||||
#include "extmod/modbluetooth.h"
|
#include "extmod/modbluetooth.h"
|
||||||
#include "extmod/modmachine.h"
|
#include "extmod/modmachine.h"
|
||||||
#include "extmod/mpbthci.h"
|
#include "extmod/mpbthci.h"
|
||||||
|
#include "shared/runtime/softtimer.h"
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
#include "mpbthciport.h"
|
#include "mpbthciport.h"
|
||||||
#include "pico/stdlib.h"
|
|
||||||
|
|
||||||
#if MICROPY_PY_BLUETOOTH
|
#if MICROPY_PY_BLUETOOTH
|
||||||
|
|
||||||
#define debug_printf(...) // mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
|
#define debug_printf(...) // mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
|
||||||
#define error_printf(...) mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
|
#define error_printf(...) mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
|
||||||
|
|
||||||
// Poll timer ID.
|
|
||||||
static alarm_id_t poll_timer_id = 0;
|
|
||||||
|
|
||||||
uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
|
uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
|
||||||
|
|
||||||
|
// Soft timer and scheduling node for scheduling a HCI poll.
|
||||||
|
static soft_timer_entry_t mp_bluetooth_hci_soft_timer;
|
||||||
static mp_sched_node_t mp_bluetooth_hci_sched_node;
|
static mp_sched_node_t mp_bluetooth_hci_sched_node;
|
||||||
|
|
||||||
void mp_bluetooth_hci_init(void) {
|
// This is called by soft_timer and executes at PendSV level.
|
||||||
|
static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
|
||||||
|
mp_bluetooth_hci_poll_now();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t mp_bluetooth_hci_timer_callback(alarm_id_t id, void *user_data) {
|
void mp_bluetooth_hci_init(void) {
|
||||||
poll_timer_id = 0;
|
soft_timer_static_init(
|
||||||
mp_bluetooth_hci_poll_now();
|
&mp_bluetooth_hci_soft_timer,
|
||||||
return 0;
|
SOFT_TIMER_MODE_ONE_SHOT,
|
||||||
|
0,
|
||||||
|
mp_bluetooth_hci_soft_timer_callback
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
|
void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
|
||||||
if (poll_timer_id != 0) {
|
soft_timer_reinsert(&mp_bluetooth_hci_soft_timer, ms);
|
||||||
cancel_alarm(poll_timer_id);
|
|
||||||
}
|
|
||||||
poll_timer_id = add_alarm_in_ms(ms, mp_bluetooth_hci_timer_callback, NULL, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -110,10 +111,8 @@ int mp_bluetooth_hci_uart_deinit(void) {
|
||||||
debug_printf("mp_bluetooth_hci_uart_deinit\n");
|
debug_printf("mp_bluetooth_hci_uart_deinit\n");
|
||||||
|
|
||||||
// If a poll callback is set cancel it now.
|
// If a poll callback is set cancel it now.
|
||||||
if (poll_timer_id > 0) {
|
soft_timer_remove(&mp_bluetooth_hci_soft_timer);
|
||||||
cancel_alarm(poll_timer_id);
|
|
||||||
}
|
|
||||||
poll_timer_id = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,9 +69,8 @@ void mp_bluetooth_hci_poll(void) {
|
||||||
// --- Port-specific helpers for the generic NimBLE bindings. -----------------
|
// --- Port-specific helpers for the generic NimBLE bindings. -----------------
|
||||||
|
|
||||||
void mp_bluetooth_nimble_hci_uart_wfi(void) {
|
void mp_bluetooth_nimble_hci_uart_wfi(void) {
|
||||||
#if defined(__WFI)
|
best_effort_wfe_or_timeout(make_timeout_time_ms(1));
|
||||||
__WFI();
|
|
||||||
#endif
|
|
||||||
// This is called while NimBLE is waiting in ble_npl_sem_pend, i.e. waiting for an HCI ACK.
|
// This is called while NimBLE is waiting in ble_npl_sem_pend, i.e. waiting for an HCI ACK.
|
||||||
// Do not need to run events here (it must not invoke Python code), only processing incoming HCI data.
|
// Do not need to run events here (it must not invoke Python code), only processing incoming HCI data.
|
||||||
mp_bluetooth_nimble_hci_uart_process(false);
|
mp_bluetooth_nimble_hci_uart_process(false);
|
||||||
|
|
Ładowanie…
Reference in New Issue