<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Wait for message and signal simultaneously using CMSIS RTX call</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/41394/wait-for-message-and-signal-simultaneously-using-cmsis-rtx-call</link><description> 
 
Wait for message and signal simultaneously using CMSIS RTX
call 

 
Hi All, 

 
I am using CMSIS RTX V4.80.0. I need to wait for a message and a
signal simultaneously in a single thread. 

 
In the CMSIS RTOS API, I came across a function osWait(</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Wait for message and signal simultaneously using CMSIS RTX call</title><link>https://community.arm.com/thread/65067?ContentTypeID=1</link><pubDate>Wed, 15 Feb 2017 10:27:06 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:558a70b1-7f81-4121-a91a-3a884be3786f</guid><dc:creator>Robert Chapman</dc:creator><description>&lt;p&gt;&lt;p&gt;
You could augment the communications between the two tasks in the
following manner. Task A will wait forever for a signal. Task B can
send a message to task A and then it would also send a &amp;quot;message&amp;quot;
signal. Task A would wake with the &amp;quot;message&amp;quot; signal and then know to
get a message. You could also tie in mail the same way. The other
signals in Task A could be used just for signalling.&lt;/p&gt;

&lt;p&gt;
We&amp;#39;ve implemented this with a health manager task which initially
waits forever for any signals. If any task has an emergency, then it
sends a 911 signal to the health manager which deals with the crisis.
If a task wishes to schedule a regular checkup, then it sends a mail
with the details and sets the &amp;quot;register&amp;quot; signal. The health manager
gets the &amp;quot;register&amp;quot; signal, reads the mail and then schedules an
appointment. The time to the appointment is now used in the signal
timeout as opposed to waiting forever.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wait for message and signal simultaneously using CMSIS RTX call</title><link>https://community.arm.com/thread/108920?ContentTypeID=1</link><pubDate>Sat, 15 Oct 2016 05:22:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a8dbd1e1-3de8-4985-97a9-daeeb1253963</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Just a footnote - if the wait-complex can&amp;#39;t consume all &amp;quot;ready&amp;quot;
event information in a single call, then it should be written
like:&lt;/p&gt;

&lt;pre&gt;
int wait_complex(unsigned timeout) {
    res = wait(summary,timeout);
    if (res != timeout &amp;amp;&amp;amp; res != error) {
        crit(x) {
            if (a &amp;amp;&amp;amp; b) {
                a = false;
                b = false;
                res = EVENT_A_AND_B;
            } else if (c) {
                c = false;
                res = EVENT_C;
            } else if (d) {
                d = false;
                res = EVENT_D;
            } else {
                res = EVENT_EMPTY;
            }
            if (a&amp;amp;&amp;amp;b || c || d) signal(summary); // so next wait() doesn&amp;#39;t hang
        }
    }
    return res;
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
It then needs to &amp;quot;restart&amp;quot; the summary signal, in case there are more
state information ready to process.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wait for message and signal simultaneously using CMSIS RTX call</title><link>https://community.arm.com/thread/93815?ContentTypeID=1</link><pubDate>Sat, 15 Oct 2016 04:45:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:09911a89-762e-40c1-92fe-85dca9a41d10</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Just quick mock-up of a wait_complex() that can wait for one of
multiple events, or for a specific state combination.&lt;/p&gt;

&lt;p&gt;
And the individual state variables doesn&amp;#39;t need to be traditional
signal resources in the OS - but they must contain some form of state
that can be (reasonably cheaply) polled when evaluating if the
summary event should be signalled or not.&lt;br /&gt;
Alas, there is no osMailPoll() and osMessagePoll() to make it easier
to create a wait function that could wait for both mails, messages
and signals.&lt;/p&gt;

&lt;pre&gt;
void signal_a() {
    crit(x) {
        a = true;
        if (a &amp;amp;&amp;amp; b) signal(summary);
    }
}

void signal_b() {
    crit(x) {
        b = true;
        if (a &amp;amp;&amp;amp; b) signal(summary);
     }
}

void signal_c() {
    crit(x) {
        c = true;
        signal(summary);
    }
}

void signal_d() {
    crit(x) {
        d = true;
        signal(summary);
    }
}

/**
 * \brief Wait for event a+b both raised, or for event c or for event d or for timeout.
 */
int wait_complex(unsigned timeout) {
    res = wait(summary,timeout);
    if (res == timeout) return timeout;
    if (res == error) return error;
    crit(x) {
        if (a &amp;amp;&amp;amp; b) {
            a = false;
            b = false;
            return EVENT_A_AND_B;
        }
        if (c) {
            c = false;
            return EVENT_C;
        }
        if (d) {
            d = false;
            return EVENT_D;
        }
    }
    return EVENT_OOPS;
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wait for message and signal simultaneously using CMSIS RTX call</title><link>https://community.arm.com/thread/69678?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2016 04:38:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8b0ed9bd-322f-4bba-851a-0a861881c06d</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Note that you can implement an arbitrarily complex &amp;quot;wait for
multiple&amp;quot; with some own code.&lt;/p&gt;

&lt;p&gt;
Implement code where you in a critical section change one or more
of your n state variables. Then evaluate your wakeup condition - if
it is satisfied then signal this using a &amp;quot;summary&amp;quot; event.&lt;/p&gt;

&lt;p&gt;
So an interested thread waits for this &amp;quot;summary&amp;quot; event. When the
thread wakes up, it enters a critical section to decide if it wants
to reset one or more of all your individual state variables.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>