|
| 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 to whom it may concern about an event has occured. |
| 37 | + @note |
| 38 | + EventFlags support 31 flags so the MSB flag is ignored, it is used to return error code (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. (default: 0x7fffffff) |
| 56 | + @return event flags after setting or error code if highest bit set (osFlagsError). |
| 57 | + */ |
| 58 | + uint32_t set(uint32_t flags = 0x7fffffff); |
| 59 | + |
| 60 | + /** 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). |
| 63 | + */ |
| 64 | + uint32_t clear(uint32_t flags = 0x7fffffff); |
| 65 | + |
| 66 | + /** Get the current Event Flags. |
| 67 | + @return current event flags. |
| 68 | + */ |
| 69 | + uint32_t get(); |
| 70 | + |
| 71 | + /** Wait for one or more Event Flags to become signaled. |
| 72 | + @param flags specifies the flags to wait for. (default: 0) |
| 73 | + @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. |
| 77 | + */ |
| 78 | + uint32_t wait(uint32_t flags = 0, uint32_t timeout = osWaitForever); |
| 79 | + |
| 80 | + ~EventFlags(); |
| 81 | + |
| 82 | +private: |
| 83 | + void constructor(const char *name = NULL); |
| 84 | + osEventFlagsId_t _id; |
| 85 | + osEventFlagsAttr_t _attr; |
| 86 | + mbed_rtos_storage_event_flags_t _obj_mem; |
| 87 | +}; |
| 88 | + |
| 89 | +} |
| 90 | +#endif |
| 91 | + |
| 92 | +/** @}*/ |
0 commit comments