Waiting for different signals?

13 Jul 2013

Hello there,

I just can't figure out how to wait for different signals, which should trigger different events.

I want to use a global 'wait_signal()' and use 'switch (signal){ }' to branch... For me there wouldn't be much sense if you could define which signal (for example '0x1' or '0x2') is to wait for, if there would be only the choice of receiving a signal or not?

Could someone please set me on the right track...?

Thanks,

Michael

13 Jul 2013

My experience with RTOS is quite limitted, but afaik that isn't possible, you will need to use one of the methods of communicating between threads, and then only sending a signal that a message has been sent.

Regarding the reason for different arguments (0x1, etc), I *believe*, never tested it though, that it works bitwise. So you can for example wait on 0x3, which is fulfilled when 0x1 and 0x2 are set. I just tried searching it a bit in the source code, but that ends up with the function

__svcSignalWait()

, which I cannot find again.

14 Jul 2013

Hello Erik,

thanks for your reply. That's what I discovered so far, too. If there's no one who knows more about that, it might be that there are plans to extend the signalling capabilities later, I could imagine. But I still hope one of the other users could give a hint to do the trick. For me it would be great to send signals from different threads to a waiting one with the benefit of knowing which task caused the signal...

Thanks,

Michael

14 Jul 2013

I wouldn't really expect it to change, it is a standard RTOS model, the mbed RTOS has to follow the standard model.

I just verified it is indeed bitwise. For sending information from one thread to the other you simply will have to use on of the other options. You can write your own code that packages a signal + message in one.

20 Aug 2013

From what I can tell, you can wait for multiple signals by passing 0 to "signal_wait" The return value is an osEvent struct, and you can get the signal by examining osEvent.value.signals:

        osEvent evt = Thread::signal_wait(0);
        
        if (evt.value.signals & 0x01)  //do something
        if (evt.value.signals & 0x02)  //do something else

Note that signals are actually a bit mask. So if both 1 and 2 are triggered, you'll get back 0b0011 or 3.

I am using this method to watch for button presses in an ISR, but acting on them in a thread.