Skip to content

Commit 95593e5

Browse files
committed
all/mpbthciport.c: Don't restart BLE polling if already running.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 79abdad commit 95593e5

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

ports/alif/mpbthciport.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
3838
static soft_timer_entry_t mp_bluetooth_hci_soft_timer;
3939
static mp_sched_node_t mp_bluetooth_hci_sched_node;
4040

41+
static bool mp_bluetooth_hci_poll_active = false;
42+
4143
// This is called by soft_timer and executes at IRQ_PRI_PENDSV.
4244
static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
4345
mp_bluetooth_hci_poll_now();
@@ -53,7 +55,10 @@ void mp_bluetooth_hci_init(void) {
5355
}
5456

5557
static void mp_bluetooth_hci_start_polling(void) {
56-
mp_bluetooth_hci_poll_now();
58+
// Poll now unless it's already running
59+
if (!mp_bluetooth_hci_poll_active) {
60+
mp_bluetooth_hci_poll_now();
61+
}
5762
}
5863

5964
void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
@@ -65,7 +70,9 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
6570
static void run_events_scheduled_task(mp_sched_node_t *node) {
6671
(void)node;
6772
// This will process all buffered HCI UART data, and run any callouts or events.
73+
mp_bluetooth_hci_poll_active = true;
6874
mp_bluetooth_hci_poll();
75+
mp_bluetooth_hci_poll_active = false;
6976
}
7077

7178
// Called periodically (systick) or directly (e.g. UART RX IRQ) in order to

ports/mimxrt/mpbthciport.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4949
static mp_sched_node_t mp_bluetooth_hci_sched_node;
5050
static soft_timer_entry_t mp_bluetooth_hci_soft_timer;
5151

52+
static bool mp_bluetooth_hci_poll_active = false;
53+
5254
static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
5355
mp_bluetooth_hci_poll_now();
5456
}
@@ -63,7 +65,10 @@ void mp_bluetooth_hci_init(void) {
6365
}
6466

6567
static void mp_bluetooth_hci_start_polling(void) {
66-
mp_bluetooth_hci_poll_now();
68+
// Poll now unless it's already running
69+
if (!mp_bluetooth_hci_poll_active) {
70+
mp_bluetooth_hci_poll_now();
71+
}
6772
}
6873

6974
void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
@@ -73,7 +78,9 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
7378
// For synchronous mode, we run all BLE stack code inside a scheduled task.
7479
static void run_events_scheduled_task(mp_sched_node_t *node) {
7580
// This will process all buffered HCI UART data, and run any callouts or events.
81+
mp_bluetooth_hci_poll_active = true;
7682
mp_bluetooth_hci_poll();
83+
mp_bluetooth_hci_poll_active = false;
7784
}
7885

7986
// Called periodically (systick) or directly (e.g. UART RX IRQ) in order to

ports/renesas-ra/mpbthciport.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4545
static mp_sched_node_t mp_bluetooth_hci_sched_node;
4646
static soft_timer_entry_t mp_bluetooth_hci_soft_timer;
4747

48+
static bool mp_bluetooth_hci_poll_active = false;
49+
4850
static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
4951
mp_bluetooth_hci_poll_now();
5052
}
@@ -59,7 +61,10 @@ void mp_bluetooth_hci_init(void) {
5961
}
6062

6163
static void mp_bluetooth_hci_start_polling(void) {
62-
mp_bluetooth_hci_poll_now();
64+
// Poll now unless it's already running
65+
if (!mp_bluetooth_hci_poll_active) {
66+
mp_bluetooth_hci_poll_now();
67+
}
6368
}
6469

6570
void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
@@ -69,7 +74,9 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
6974
// For synchronous mode, we run all BLE stack code inside a scheduled task.
7075
static void run_events_scheduled_task(mp_sched_node_t *node) {
7176
// This will process all buffered HCI UART data, and run any callouts or events.
77+
mp_bluetooth_hci_poll_active = true;
7278
mp_bluetooth_hci_poll();
79+
mp_bluetooth_hci_poll_active = false;
7380
}
7481

7582
// Called periodically (systick) or directly (e.g. UART RX IRQ) in order to

ports/rp2/mpbthciport.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4545
static soft_timer_entry_t mp_bluetooth_hci_soft_timer;
4646
static mp_sched_node_t mp_bluetooth_hci_sched_node;
4747

48+
static bool mp_bluetooth_hci_poll_active = false;
49+
4850
// This is called by soft_timer and executes at PendSV level.
4951
static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
5052
mp_bluetooth_hci_poll_now();
@@ -68,7 +70,9 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
6870
static void run_events_scheduled_task(mp_sched_node_t *node) {
6971
(void)node;
7072
// This will process all buffered HCI UART data, and run any callouts or events.
73+
mp_bluetooth_hci_poll_active = true;
7174
mp_bluetooth_hci_poll();
75+
mp_bluetooth_hci_poll_active = false;
7276
}
7377

7478
// Called periodically (systick) or directly (e.g. UART RX IRQ) in order to
@@ -82,7 +86,10 @@ void mp_bluetooth_hci_poll_now(void) {
8286
mp_obj_t mp_bthci_uart;
8387

8488
static void mp_bluetooth_hci_start_polling(void) {
85-
mp_bluetooth_hci_poll_now();
89+
// Poll now unless it's already running
90+
if (!mp_bluetooth_hci_poll_active) {
91+
mp_bluetooth_hci_poll_now();
92+
}
8693
}
8794

8895
int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) {

ports/stm32/mpbthciport.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4343
// Soft timer for scheduling a HCI poll.
4444
static soft_timer_entry_t mp_bluetooth_hci_soft_timer;
4545

46+
static bool mp_bluetooth_hci_poll_active = false;
47+
4648
// This is called by soft_timer and executes at IRQ_PRI_PENDSV.
4749
static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) {
4850
mp_bluetooth_hci_poll_now();
@@ -58,7 +60,10 @@ void mp_bluetooth_hci_init(void) {
5860
}
5961

6062
static void mp_bluetooth_hci_start_polling(void) {
61-
mp_bluetooth_hci_poll_now();
63+
// Poll now unless it's already running
64+
if (!mp_bluetooth_hci_poll_active) {
65+
mp_bluetooth_hci_poll_now();
66+
}
6267
}
6368

6469
void mp_bluetooth_hci_poll_in_ms_default(uint32_t ms) {
@@ -75,7 +80,9 @@ static mp_sched_node_t mp_bluetooth_hci_sched_node;
7580
static void run_events_scheduled_task(mp_sched_node_t *node) {
7681
// This will process all buffered HCI UART data, and run any callouts or events.
7782
(void)node;
83+
mp_bluetooth_hci_poll_active = true;
7884
mp_bluetooth_hci_poll();
85+
mp_bluetooth_hci_poll_active = false;
7986
}
8087

8188
// Called periodically (systick) or directly (e.g. UART RX IRQ) in order to

0 commit comments

Comments
 (0)