File tree Expand file tree Collapse file tree 5 files changed +40
-5
lines changed
Expand file tree Collapse file tree 5 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
3838static soft_timer_entry_t mp_bluetooth_hci_soft_timer ;
3939static 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.
4244static 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
5557static 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
5964void mp_bluetooth_hci_poll_in_ms (uint32_t ms ) {
@@ -65,7 +70,9 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
6570static 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
Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4949static mp_sched_node_t mp_bluetooth_hci_sched_node ;
5050static soft_timer_entry_t mp_bluetooth_hci_soft_timer ;
5151
52+ static bool mp_bluetooth_hci_poll_active = false;
53+
5254static 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
6567static 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
6974void 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.
7479static 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
Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4545static mp_sched_node_t mp_bluetooth_hci_sched_node ;
4646static soft_timer_entry_t mp_bluetooth_hci_soft_timer ;
4747
48+ static bool mp_bluetooth_hci_poll_active = false;
49+
4850static 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
6163static 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
6570void 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.
7075static 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
Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4545static soft_timer_entry_t mp_bluetooth_hci_soft_timer ;
4646static 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.
4951static 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) {
6870static 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) {
8286mp_obj_t mp_bthci_uart ;
8387
8488static 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
8895int mp_bluetooth_hci_uart_init (uint32_t port , uint32_t baudrate ) {
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
4343// Soft timer for scheduling a HCI poll.
4444static 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.
4749static 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
6062static 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
6469void mp_bluetooth_hci_poll_in_ms_default (uint32_t ms ) {
@@ -75,7 +80,9 @@ static mp_sched_node_t mp_bluetooth_hci_sched_node;
7580static 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
You can’t perform that action at this time.
0 commit comments