/ Hardware

How to await several events using CMSIS 4 in-built RTOS

Anyone who uses ARM Cortex processors must beware of CMSIS. For those who are not yet acquainted here is something to read. The latest CMSIS is version 4. When it was introduced, it brought along the RTOS goodness mainly developed from the existing Keil RTOS besides unifying device drivers. What is RTOS? If you are asking that, here is an answer.

Since I do not want to make this post lengthy, please acquaint yourself with RTOS threads [here](https://www.keil.com/pack/doc/CMSIS/RTOS/html/
group__CMSIS__RTOS__ThreadMgmt.html) and also about signal management [here](http://www.keil.com/pack/doc/CMSIS/RTOS/html/ group__cmsis__rtos__signalmgmt.html).

image

To await any signal sent/set to/on a particular thread, inside the while loop you'd use osSignalWait(0x00, osWaitForever);

This saves execution time as the thread appears dead.
What if you want to await more than one different signal forever? The first answer I know you would give is use
osSignalWait(0x00, osWaitForever); then use signal = osSignalGet(tid); Unfortunately, the function
osSignalGet was removed from the CMSIS-RTOS API in V4.7 as shown here. So what now?

I needed this functionality and had to work a way though this. By the way, I still do not understand why it was removed. IMHO it has equal relevance to osSignalSet because one would normally set the signal in a different thread from where you handle it.

Here are the steps I used:

  1. await for any signal to be sent using osSignalWait(0x00, osWaitForever);
  2. once it ends (right below it) you receive an osEvent which you can use to get the signals sent (using osEvent.value.signals)
  3. Ensure the signal is valid. I used the first bit of the data to show that I sent a valid signal. The other bits for the specific signal value.
    Using a switch case handle each signal as you preferred

To signal the thread, the value sent using osSignalSet, I ensured that I set the last bit and then set the other bits with the specific signal.

And boom!!!! You are done. It works