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