|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2006-2017 ARM Limited |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | + * SOFTWARE. |
| 21 | + */ |
| 22 | +#ifndef EVENT_FLAG_H |
| 23 | +#define EVENT_FLAG_H |
| 24 | + |
| 25 | +#include <stdint.h> |
| 26 | +#include "cmsis_os2.h" |
| 27 | +#include "mbed_rtos1_types.h" |
| 28 | +#include "mbed_rtos_storage.h" |
| 29 | + |
| 30 | +#include "platform/NonCopyable.h" |
| 31 | + |
| 32 | +namespace rtos { |
| 33 | +/** \addtogroup rtos */ |
| 34 | +/** @{*/ |
| 35 | + |
| 36 | +/** The EventFlags class is used to signal or wait for an arbitrary event or events. |
| 37 | + @note |
| 38 | + EventFlags support 31 flags so the MSB flag is ignored, it is used to return an error code (@a osFlagsError) |
| 39 | + @note |
| 40 | + Memory considerations: The EventFlags control structures will be created on current thread's stack, both for the mbed OS |
| 41 | + and underlying RTOS objects (static or dynamic RTOS memory pools are not being used). |
| 42 | +*/ |
| 43 | +class EventFlags : private mbed::NonCopyable<EventFlags> { |
| 44 | +public: |
| 45 | + /** Create and Initialize a EventFlags object */ |
| 46 | + EventFlags(); |
| 47 | + |
| 48 | + /** Create and Initialize a EventFlags object |
| 49 | +
|
| 50 | + @param name name to be used for this EventFlags. It has to stay allocated for the lifetime of the thread. |
| 51 | + */ |
| 52 | + EventFlags(const char *name); |
| 53 | + |
| 54 | + /** Set the specified Event Flags. |
| 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). |
| 57 | + */ |
| 58 | + uint32_t set(uint32_t flags); |
| 59 | + |
| 60 | + /** Clear the specified Event Flags. |
| 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). |
| 63 | + */ |
| 64 | + uint32_t clear(uint32_t flags = 0x7fffffff); |
| 65 | + |
| 66 | + /** Get the currently set Event Flags. |
| 67 | + @return set event flags. |
| 68 | + */ |
| 69 | + uint32_t get() const; |
| 70 | + |
| 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. |
| 80 | + @param flags specifies the flags to wait for. (default: 0) |
| 81 | + @param timeout timeout value or 0 in case of no time-out. (default: osWaitForever) |
| 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). |
| 84 | + */ |
| 85 | + uint32_t wait_any(uint32_t flags = 0, uint32_t timeout = osWaitForever, bool clear = true); |
| 86 | + |
| 87 | + ~EventFlags(); |
| 88 | + |
| 89 | +private: |
| 90 | + void constructor(const char *name = NULL); |
| 91 | + uint32_t wait(uint32_t flags, uint32_t opt, uint32_t timeout, bool clear); |
| 92 | + osEventFlagsId_t _id; |
| 93 | + osEventFlagsAttr_t _attr; |
| 94 | + mbed_rtos_storage_event_flags_t _obj_mem; |
| 95 | +}; |
| 96 | + |
| 97 | +} |
| 98 | +#endif |
| 99 | + |
| 100 | +/** @}*/ |
0 commit comments