← index #16577PR #6438
Related · medium · value 0.469
QUERY · ISSUE

docs: BLE Event handling seems to contradict general guidelines for IRQ handling

openby 32BTopened 2025-01-13updated 2025-11-06
docs

Documentation URL

https://docs.micropython.org/en/latest/library/bluetooth.html#event-handling

Description

In BLE event handling a suggestion is given to create copies of the ringbuffer parameters. This however, would violate the general guidelines given for interrupt routines which specifically warn against instantiating objects.
https://github.com/micropython/micropython/blob/99ac8193ea299e6d836b076149f561e58226ede6/docs/reference/isr_rules.rst?plain=1#L102

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

extmod/nimble: Run the eventq in micropython.schedule.

closedby andrewleechopened 2020-09-13updated 2020-11-13
extmod

This PR changes the background nimble processing to run the nimble eventq handler via schedule() and remove the ringbuffer system.

This change basically ensures that the python IRQ callback for any BLE operation is run to completion before the next BLE operation is handled.

I've only tested the peripheral mode running my application on reader so far, but it appears to be running very reliably - I've had no transmission sync/order/race issues for many hours where previously I'd have a glitch at least every 10-20 minutes.

I'm looking at how to achieve the same in btstack and it appears far less straightforward there. I can't find anything that looks like a similar functional boundary to split across to schedule().
Event callbacks in btstack_packet_handler() are typically run during the processing of mp_bluetooth_hci_poll_h4(), not going via any sort of event queue.

Perhaps I just need to run the entire mp_bluetooth_hci_poll() function via schedule?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied