1、Tutorial:ZBus-the lightweight and flexible Zephyr message busRodrigo Peixoto,Edge-UFAL/Citriniorodrigopex1Thread AThread BThread CCallback DCallback ESubscribersListenersAsynchronousSynchronousTimeSpaceSynchronizationDecoupledCoupled ZBusChan 1Chan 2Chan 3Chan N2Bus topologies3ONE-TO-ONEONE-TO-MANYM
2、ANY-TO-MANYExample of use4 ZBUSProposed solution5 APP INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAYLOADCore threadTRANSMISSION DONELoRa threadTimerWQ ZBUSStep 016Main thread ZBUSStep 027PROJECT INFOMain thread ZBUSStep 038PROJECT INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMock
3、 ZBUSStep 049PROJECT INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAYLOADCore thread ZBUSStep 0510PROJECT INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAYLOADCore threadTRANSMISSION DONELoRa thread ZBUSStep 0611PROJECT INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAY
4、LOADCore threadTRANSMISSION DONELoRa threadTimerWQ ZBUSStep 0712PROJECT INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAYLOADCore threadTRANSMISSION DONELoRa threadTimerWQ ZBUSStep 0813 APP INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAYLOADCore threadTRANSMISSION DONELoRa thre
5、adTimerWQ ZBUSStep 0914 APP INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAYLOADCore threadTRANSMISSION DONELoRa threadTimerWQFix execution sequence!ZBUSStep 1015 APP INFOSTART TRIGGERSensor threadMain threadSENSOR DATAMockPAYLOADCore threadTRANSMISSION DONELoRa threadTimerWQTips and tric
6、ks16 Avoid excessive use of them,they are running during the publishing processListeners17 Think of them as an ISR.They must run as quickly as possible Do not sleep inside listeners.It will increase the publishing latencyListeners18 Use zbus_chan_const_msg inside listeners.The channels are already l
7、ocked!Use a work queue or separated thread instead of executing something heavy inside a listener Do not use subscribers when losses and duplications cannot be toleratedSubscribers19 PR with confirmed channels sample submitted Use listeners in conjunction with message queues Take care with publishin
8、g loopsUndesired loops20 Avoid loops on the bus diagram Observer 1Chan AObserver 2Chan BUndesired loops21 Take care with chained publishing loops Observer 1Chan AObserver 3Chan BObserver 2Observer 4Chan CChan D Do not use ZBus functions inside an ISRISR22 Postpone that by using work queues insteadExtras23 The channels can be used as a concurrent property system Isolate the hardware code using channels Use channels as modules interface in/outQuestions&Answers24Thank you!