Skip to content

Commit b0ad73e

Browse files
committed
RTOS: Changes to the EvenFlags API, doxy and tests
1 parent dfbcbdd commit b0ad73e

File tree

3 files changed

+76
-36
lines changed

3 files changed

+76
-36
lines changed

TESTS/mbedmicro-rtos-mbed/event_flags/main.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
#include "mbed.h"
219
#include "greentea-client/test_env.h"
320
#include "rtos.h"
@@ -10,37 +27,33 @@
1027

1128
#define EVENT_SET_VALUE 0x01
1229
const int EVENT_TO_EMIT = 100;
13-
const int EVENT_HANDLE_DELEY = 25;
30+
const int EVENT_HANDLE_DELAY = 25;
1431

1532
DigitalOut led(LED1);
16-
EventFlags event_flags();
33+
EventFlags event_flags;
1734

1835
int events_counter = 0;
1936

2037
void led_thread() {
2138
while (true) {
22-
// events flags that are reported as event are automatically cleared.
23-
event_flags.wait(EVENT_SET_VALUE);
39+
event_flags.wait_all(EVENT_SET_VALUE);
2440
led = !led;
2541
events_counter++;
2642
}
2743
}
2844

2945
int main (void) {
30-
GREENTEA_SETUP(20, "default_auto");
46+
GREENTEA_SETUP(10, "default_auto");
3147

3248
Thread thread(osPriorityNormal, TEST_STACK_SIZE);
3349
thread.start(led_thread);
3450

3551
bool result = false;
3652

37-
printf("Handling %d events...\r\n", EVENT_TO_EMIT);
38-
3953
while (true) {
40-
Thread::wait(2 * EVENT_HANDLE_DELEY);
54+
Thread::wait(2 * EVENT_HANDLE_DELAY);
4155
event_flags.set(EVENT_SET_VALUE);
4256
if (events_counter == EVENT_TO_EMIT) {
43-
printf("Handled %d events\r\n", events_counter);
4457
result = true;
4558
break;
4659
}

rtos/EventFlags.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@
2626

2727
namespace rtos {
2828

29-
EventFlags::EventFlags() {
29+
EventFlags::EventFlags()
30+
{
3031
constructor();
3132
}
3233

33-
EventFlags::EventFlags(const char *name) {
34+
EventFlags::EventFlags(const char *name)
35+
{
3436
constructor(name);
3537
}
3638

37-
void EventFlags::constructor(const char *name) {
39+
void EventFlags::constructor(const char *name)
40+
{
3841
memset(&_obj_mem, 0, sizeof(_obj_mem));
3942
memset(&_attr, 0, sizeof(_attr));
4043
_attr.name = name ? name : "application_unnamed_event_flags";
@@ -44,27 +47,43 @@ void EventFlags::constructor(const char *name) {
4447
MBED_ASSERT(_id);
4548
}
4649

47-
uint32_t EventFlags::set(uint32_t flags) {
50+
uint32_t EventFlags::set(uint32_t flags)
51+
{
4852
return osEventFlagsSet(_id, flags);
4953
}
5054

51-
uint32_t EventFlags::clear(uint32_t flags) {
55+
uint32_t EventFlags::clear(uint32_t flags)
56+
{
5257
return osEventFlagsClear(_id, flags);
5358
}
5459

55-
uint32_t EventFlags::get() {
60+
uint32_t EventFlags::get() const
61+
{
5662
return osEventFlagsGet(_id);
5763
}
5864

59-
uint32_t EventFlags::wait(uint32_t flags, uint32_t timeout) {
60-
if(flags == 0) {
61-
return osEventFlagsWait(_id, 0x7fffffff, osFlagsWaitAny | osFlagsNoClear, timeout);
62-
}
63-
return osEventFlagsWait(_id, flags, osFlagsWaitAll, timeout);
65+
uint32_t EventFlags::wait_all(uint32_t flags, uint32_t timeout, bool clear)
66+
{
67+
return wait(flags, osFlagsWaitAll, timeout, clear);
68+
}
69+
70+
uint32_t EventFlags::wait_any(uint32_t flags, uint32_t timeout, bool clear)
71+
{
72+
return wait(flags, osFlagsWaitAny, timeout, clear);
6473
}
6574

66-
EventFlags::~EventFlags() {
75+
EventFlags::~EventFlags()
76+
{
6777
osEventFlagsDelete(_id);
6878
}
6979

80+
uint32_t EventFlags::wait(uint32_t flags, uint32_t opt, uint32_t timeout, bool clear)
81+
{
82+
if (clear == false) {
83+
opt |= osFlagsNoClear;
84+
}
85+
86+
return osEventFlagsWait(_id, flags, opt, timeout);
87+
}
88+
7089
}

rtos/EventFlags.h

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ namespace rtos {
3333
/** \addtogroup rtos */
3434
/** @{*/
3535

36-
/** The EventFlags class is used to signal to whom it may concern about an event has occured.
36+
/** The EventFlags class is used to signal or wait for an arbitrary event or events.
3737
@note
38-
EventFlags support 31 flags so the MSB flag is ignored, it is used to return error code (osFlagsError)
38+
EventFlags support 31 flags so the MSB flag is ignored, it is used to return an error code (@a osFlagsError)
3939
@note
4040
Memory considerations: The EventFlags control structures will be created on current thread's stack, both for the mbed OS
4141
and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
@@ -52,35 +52,43 @@ class EventFlags : private mbed::NonCopyable<EventFlags> {
5252
EventFlags(const char *name);
5353

5454
/** Set the specified Event Flags.
55-
@param flags specifies the flags that shall be set. (default: 0x7fffffff)
56-
@return event flags after setting or error code if highest bit set (osFlagsError).
55+
@param flags specifies the flags that shall be set.
56+
@return event flags after setting or error code if highest bit set (@a osFlagsError).
5757
*/
58-
uint32_t set(uint32_t flags = 0x7fffffff);
58+
uint32_t set(uint32_t flags);
5959

6060
/** Clear the specified Event Flags.
61-
@param flags specifies the flags that shall be cleared. (default: 0x7fffffff0)
62-
@return event flags before clearing or error code if highest bit set (osFlagsError).
61+
@param flags specifies the flags that shall be cleared. (default: 0x7fffffff - all flags)
62+
@return event flags before clearing or error code if highest bit set (@a osFlagsError).
6363
*/
6464
uint32_t clear(uint32_t flags = 0x7fffffff);
6565

66-
/** Get the current Event Flags.
67-
@return current event flags.
66+
/** Get the currently set Event Flags.
67+
@return set event flags.
6868
*/
69-
uint32_t get();
69+
uint32_t get() const;
7070

71-
/** Wait for one or more Event Flags to become signaled.
71+
/** Wait for all of the specified event flags to become signaled.
72+
@param flags specifies the flags to wait for.
73+
@param timeout timeout value or 0 in case of no time-out. (default: osWaitForever)
74+
@param clear specifies wether to clear the flags after waiting for them. (default: true)
75+
@return event flags before clearing or error code if highest bit set (@a osFlagsError).
76+
*/
77+
uint32_t wait_all(uint32_t flags = 0, uint32_t timeout = osWaitForever, bool clear = true);
78+
79+
/** Wait for any of the specified event flags to become signaled.
7280
@param flags specifies the flags to wait for. (default: 0)
7381
@param timeout timeout value or 0 in case of no time-out. (default: osWaitForever)
74-
@return event flags before clearing or error code if highest bit set (osFlagsError).
75-
@note incase of flags 0 the function will wait to any flag and will not clear the flags,
76-
the user must clear the flags. otherwise the function to wait all specified flags and clear them.
82+
@param clear specifies wether to clear the flags after waiting for them. (default: true)
83+
@return event flags before clearing or error code if highest bit set (@a osFlagsError).
7784
*/
78-
uint32_t wait(uint32_t flags = 0, uint32_t timeout = osWaitForever);
85+
uint32_t wait_any(uint32_t flags = 0, uint32_t timeout = osWaitForever, bool clear = true);
7986

8087
~EventFlags();
8188

8289
private:
8390
void constructor(const char *name = NULL);
91+
uint32_t wait(uint32_t flags, uint32_t opt, uint32_t timeout, bool clear);
8492
osEventFlagsId_t _id;
8593
osEventFlagsAttr_t _attr;
8694
mbed_rtos_storage_event_flags_t _obj_mem;

0 commit comments

Comments
 (0)