Page 1 of 1

Two event sources, one event listener

Posted: Tue Apr 23, 2013 5:28 pm
by kreyl
stm32f205VE, Discovery, ChibiOs 2.5.1
I have a thread which works with radio transmission and reception. There are two EventSource objects, IEvtSrcRadioRx and IEvtSrcRadioTxEnd; first is broadcasted when reception is completed, and second - when transmission.
Also, I have a thread intended to serve the events. It registers to them with single EvtListener object, and waits for any of them. After that the thread does something depending on EventMask.
When I register for only one event (any of above) - all works perfectly. But when I register for both - I have HardFaultVector at attempt of chEvtBroadcast of second event.
Debugging shows that something bad occurs inside chEvtSignalI - mask it receives looks like trash.
Here is code of serving thread:

Code: Select all

static EventListener EvtLstnrApp;
static WORKING_AREA(waAppThread, 128);
static msg_t AppThread(void *arg) {
    (void)arg;
    chRegSetThreadName("App");
    // Register Radio evts
    uint32_t EvtMsk;
    rLevel1.RegisterEvtRx(&EvtLstnrApp, EVTMASK_RADIO_RX);
    rLevel1.RegisterEvtTx(&EvtLstnrApp, EVTMASK_RADIO_TX);

    while(1) {
        EvtMsk = chEvtWaitAny(EVTMASK_RADIO_RX | EVTMASK_RADIO_TX);
        // Serve event
        if(EvtMsk & EVTMASK_RADIO_RX) {
            while(rLevel1.GetReceivedPkt(&SRxPkt) == OK)
                Uart.Cmd(RPL_RRX, (uint8_t*)&SRxPkt, (sizeof(SRxPkt.rID) + sizeof(SRxPkt.Length) + SRxPkt.Length));
        } // if evtmsk

        if(EvtMsk & EVTMASK_RADIO_TX) {
            while(rLevel1.GetTransmittedState(&PktState) == OK) {
                Uart.Cmd(RPL_RTX, (uint8_t*)&PktState, sizeof(rPktIDState_t));
            }
        }
    } // while 1
}


If I am doing something in wrong way - suggestions are greatly appreciated.
Thank you!

Re: Two event sources, one event listener

Posted: Tue Apr 23, 2013 5:35 pm
by Giovanni
Hi,

The EventSource <-> EventListener is a 1-to-N relation, you need to use two listeners, one for each source and each initialized with a different mask (1 and 2 for example). The thread would wait for both.

Giovanni

Re: Two event sources, one event listener

Posted: Tue Apr 23, 2013 5:56 pm
by kreyl
Thanks a lot, Giovanni! Now all works perfectly.
I believe, though, that that arcane knowledge worth adding to EventsExplained text.