bluerange-io / bluerange-mesh

BlueRange Mesh (formerly FruityMesh) - The first completely connection-based open source mesh on top of Bluetooth Low Energy (4.1/5.0 or higher)
https://bluerange.io/
Other
288 stars 109 forks source link

Timer tick thread locks when main thread is locked #182

Closed rench9 closed 3 years ago

rench9 commented 3 years ago

Hey, we are performing some encoding of packets and found that until the timer tick is locked until encoding completes. Is there any mechanism to mange threads or priorities with fruity mesh.

mariusheil commented 3 years ago

Hi,

take a look here for some info on which interrupts are used: https://github.com/mwaylabs/fruitymesh/blob/master/src/hal/nrf/FruityHalNrf.cpp#L112

FruityMesh runs directly on the SoftDevice and not using a RTOS so there is no direct Thread concept but only interrupt service routines. For your case, I would recommend that you use the main context handler https://github.com/mwaylabs/fruitymesh/blob/master/src/base/GlobalState.cpp#L107 which allows you to run tasks at the lowest priority possible. This will get interrupted by most of the FruityMesh logic whenever necessary so you have to make sure that you do not access any variables that you also use in other parts such as e.g. the TimerEventHandler in a thread unsafe way.

Most of the FruityMesh logic (timerEventHandler, bleEvents, .....) run in the same interrupt priority to make the processing more straight forward and less error prone.

Marius

siretty commented 3 years ago

Hello, I'll close this as there has not been any more feedback. Feel free to reopen it.