Two event sources, one event listener

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

Two event sources, one event listener

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Two event sources, one event listener

Post 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
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

Re: Two event sources, one event listener

Post by kreyl »

Thanks a lot, Giovanni! Now all works perfectly.
I believe, though, that that arcane knowledge worth adding to EventsExplained text.
Post Reply