Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EventFlags.h Source File

EventFlags.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2019 ARM Limited
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00020  * SOFTWARE.
00021  */
00022 #ifndef EVENT_FLAG_H
00023 #define EVENT_FLAG_H
00024 
00025 #include <cstddef>
00026 #include <stdint.h>
00027 #include "rtos/mbed_rtos_types.h"
00028 #include "rtos/mbed_rtos1_types.h"
00029 #include "rtos/mbed_rtos_storage.h"
00030 
00031 #include "platform/NonCopyable.h"
00032 
00033 namespace rtos {
00034 /** \addtogroup rtos-public-api */
00035 /** @{*/
00036 
00037 /**
00038  * \defgroup rtos_EventFlags EventFlags class
00039  * @{
00040  */
00041 
00042 /** The EventFlags class is used to control event flags or wait for event flags other threads control.
00043 
00044  @note
00045  EventFlags support 31 flags. The MSB flag is ignored. It is used to return an error code (@a osFlagsError).
00046 
00047  @note
00048  Memory considerations: The EventFlags control structures will be created on the current thread's stack, both for the Mbed OS
00049  and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
00050 */
00051 class EventFlags : private mbed::NonCopyable<EventFlags> {
00052 public:
00053     /** Create and initialize an EventFlags object.
00054      *
00055      * @note You cannot call this function from ISR context.
00056     */
00057     EventFlags();
00058 
00059     /** Create and initialize an EventFlags object.
00060 
00061      @param name name to be used for this EventFlags. It has to stay allocated for the lifetime of the thread.
00062 
00063      @note You cannot call this function from ISR context.
00064     */
00065     EventFlags(const char *name);
00066 
00067     /** Set the specified event flags.
00068       @param   flags the flags that will be set.
00069       @return  event flags after setting or error code if highest bit set (see @a osFlagsError for details).
00070 
00071       @note This function may be called from ISR context.
00072      */
00073     uint32_t set(uint32_t flags);
00074 
00075     /** Clear the specified event flags.
00076       @param   flags the flags that will be cleared (default: 0x7fffffff -- all flags).
00077       @return  event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
00078 
00079       @note You may call this function from ISR context.
00080      */
00081     uint32_t clear(uint32_t flags = 0x7fffffff);
00082 
00083     /** Get the currently set event flags.
00084       @return  current event flags.
00085 
00086       @note You may call this function from ISR context.
00087      */
00088     uint32_t get() const;
00089 
00090     /** Wait for all of the specified event flags to become signaled.
00091       @param   flags    the flags to wait for (default: 0 -- no flags).
00092       @param   millisec timeout value (default: osWaitForever).
00093       @param   clear    clear specified event flags after waiting for them (default: true).
00094       @return  event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
00095 
00096       @note You may call this function from ISR context if the millisec parameter is set to 0.
00097      */
00098     uint32_t wait_all(uint32_t flags = 0, uint32_t millisec = osWaitForever, bool clear = true);
00099 
00100     /** Wait for any of the specified event flags to become signaled.
00101       @param   flags    the flags to wait for (default: 0 -- no flags).
00102       @param   millisec timeout value (default: osWaitForever).
00103       @param   clear    clear specified event flags after waiting for them (default: true).
00104       @return  event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
00105 
00106       @note This function may be called from ISR context if the millisec parameter is set to 0.
00107      */
00108     uint32_t wait_any(uint32_t flags = 0, uint32_t millisec = osWaitForever, bool clear = true);
00109 
00110     /** EventFlags destructor.
00111 
00112       @note You cannot call this function from ISR context.
00113     */
00114     ~EventFlags();
00115 
00116 private:
00117     void constructor(const char *name = nullptr);
00118     uint32_t wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool clear);
00119 #if MBED_CONF_RTOS_PRESENT
00120     osEventFlagsId_t                _id;
00121     mbed_rtos_storage_event_flags_t _obj_mem;
00122 #else
00123     uint32_t _flags;
00124 #endif
00125 };
00126 
00127 /** @}*/
00128 /** @}*/
00129 
00130 }
00131 #endif