| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- /*
- * Copyright (c) 2013-2023 Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * -----------------------------------------------------------------------------
- *
- * Project: CMSIS-RTOS RTX
- * Title: Event Flags functions
- *
- * -----------------------------------------------------------------------------
- */
- #include "rtx_lib.h"
- // OS Runtime Object Memory Usage
- #ifdef RTX_OBJ_MEM_USAGE
- osRtxObjectMemUsage_t osRtxEventFlagsMemUsage \
- __attribute__((section(".data.os.evflags.obj"))) =
- { 0U, 0U, 0U };
- #endif
- // ==== Helper functions ====
- /// Set Event Flags.
- /// \param[in] ef event flags object.
- /// \param[in] flags specifies the flags to set.
- /// \return event flags after setting.
- static uint32_t EventFlagsSet (os_event_flags_t *ef, uint32_t flags) {
- #if (EXCLUSIVE_ACCESS == 0)
- uint32_t primask = __get_PRIMASK();
- #endif
- uint32_t event_flags;
- #if (EXCLUSIVE_ACCESS == 0)
- __disable_irq();
- ef->event_flags |= flags;
- event_flags = ef->event_flags;
- if (primask == 0U) {
- __enable_irq();
- }
- #else
- event_flags = atomic_set32(&ef->event_flags, flags);
- #endif
- return event_flags;
- }
- /// Clear Event Flags.
- /// \param[in] ef event flags object.
- /// \param[in] flags specifies the flags to clear.
- /// \return event flags before clearing.
- static uint32_t EventFlagsClear (os_event_flags_t *ef, uint32_t flags) {
- #if (EXCLUSIVE_ACCESS == 0)
- uint32_t primask = __get_PRIMASK();
- #endif
- uint32_t event_flags;
- #if (EXCLUSIVE_ACCESS == 0)
- __disable_irq();
- event_flags = ef->event_flags;
- ef->event_flags &= ~flags;
- if (primask == 0U) {
- __enable_irq();
- }
- #else
- event_flags = atomic_clr32(&ef->event_flags, flags);
- #endif
- return event_flags;
- }
- /// Check Event Flags.
- /// \param[in] ef event flags object.
- /// \param[in] flags specifies the flags to check.
- /// \param[in] options specifies flags options (osFlagsXxxx).
- /// \return event flags before clearing or 0 if specified flags have not been set.
- static uint32_t EventFlagsCheck (os_event_flags_t *ef, uint32_t flags, uint32_t options) {
- #if (EXCLUSIVE_ACCESS == 0)
- uint32_t primask;
- #endif
- uint32_t event_flags;
- if ((options & osFlagsNoClear) == 0U) {
- #if (EXCLUSIVE_ACCESS == 0)
- primask = __get_PRIMASK();
- __disable_irq();
- event_flags = ef->event_flags;
- if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) ||
- (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) {
- event_flags = 0U;
- } else {
- ef->event_flags &= ~flags;
- }
- if (primask == 0U) {
- __enable_irq();
- }
- #else
- if ((options & osFlagsWaitAll) != 0U) {
- event_flags = atomic_chk32_all(&ef->event_flags, flags);
- } else {
- event_flags = atomic_chk32_any(&ef->event_flags, flags);
- }
- #endif
- } else {
- event_flags = ef->event_flags;
- if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) ||
- (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) {
- event_flags = 0U;
- }
- }
- return event_flags;
- }
- /// Verify that Event Flags object pointer is valid.
- /// \param[in] ef event flags object.
- /// \return true - valid, false - invalid.
- static bool_t IsEventFlagsPtrValid (const os_event_flags_t *ef) {
- #ifdef RTX_OBJ_PTR_CHECK
- //lint --e{923} --e{9078} "cast from pointer to unsigned int" [MISRA Note 7]
- uint32_t cb_start = (uint32_t)&__os_evflags_cb_start__;
- uint32_t cb_length = (uint32_t)&__os_evflags_cb_length__;
- // Check the section boundaries
- if (((uint32_t)ef - cb_start) >= cb_length) {
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return FALSE;
- }
- // Check the object alignment
- if ((((uint32_t)ef - cb_start) % sizeof(os_event_flags_t)) != 0U) {
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return FALSE;
- }
- #else
- // Check NULL pointer
- if (ef == NULL) {
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return FALSE;
- }
- #endif
- return TRUE;
- }
- // ==== Library functions ====
- /// Destroy an Event Flags object.
- /// \param[in] ef event flags object.
- static void osRtxEventFlagsDestroy (os_event_flags_t *ef) {
- // Mark object as invalid
- ef->id = osRtxIdInvalid;
- // Free object memory
- if ((ef->flags & osRtxFlagSystemObject) != 0U) {
- #ifdef RTX_OBJ_PTR_CHECK
- (void)osRtxMemoryPoolFree(osRtxInfo.mpi.event_flags, ef);
- #else
- if (osRtxInfo.mpi.event_flags != NULL) {
- (void)osRtxMemoryPoolFree(osRtxInfo.mpi.event_flags, ef);
- } else {
- (void)osRtxMemoryFree(osRtxInfo.mem.common, ef);
- }
- #endif
- #ifdef RTX_OBJ_MEM_USAGE
- osRtxEventFlagsMemUsage.cnt_free++;
- #endif
- }
- EvrRtxEventFlagsDestroyed(ef);
- }
- #ifdef RTX_SAFETY_CLASS
- /// Delete an Event Flags safety class.
- /// \param[in] safety_class safety class.
- /// \param[in] mode safety mode.
- void osRtxEventFlagsDeleteClass (uint32_t safety_class, uint32_t mode) {
- os_event_flags_t *ef;
- os_thread_t *thread;
- uint32_t length;
- //lint --e{923} --e{9078} "cast from pointer to unsigned int" [MISRA Note 7]
- ef = (os_event_flags_t *)(uint32_t)&__os_evflags_cb_start__;
- length = (uint32_t)&__os_evflags_cb_length__;
- while (length >= sizeof(os_event_flags_t)) {
- if ( (ef->id == osRtxIdEventFlags) &&
- ((((mode & osSafetyWithSameClass) != 0U) &&
- ((ef->attr >> osRtxAttrClass_Pos) == (uint8_t)safety_class)) ||
- (((mode & osSafetyWithLowerClass) != 0U) &&
- ((ef->attr >> osRtxAttrClass_Pos) < (uint8_t)safety_class)))) {
- while (ef->thread_list != NULL) {
- thread = osRtxThreadListGet(osRtxObject(ef));
- osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, FALSE);
- }
- osRtxEventFlagsDestroy(ef);
- }
- length -= sizeof(os_event_flags_t);
- ef++;
- }
- }
- #endif
- // ==== Post ISR processing ====
- /// Event Flags post ISR processing.
- /// \param[in] ef event flags object.
- static void osRtxEventFlagsPostProcess (os_event_flags_t *ef) {
- os_thread_t *thread;
- os_thread_t *thread_next;
- uint32_t event_flags;
- // Check if Threads are waiting for Event Flags
- thread = ef->thread_list;
- while (thread != NULL) {
- thread_next = thread->thread_next;
- event_flags = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options);
- if (event_flags != 0U) {
- osRtxThreadListRemove(thread);
- osRtxThreadWaitExit(thread, event_flags, FALSE);
- EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags);
- }
- thread = thread_next;
- }
- }
- // ==== Service Calls ====
- /// Create and Initialize an Event Flags object.
- /// \note API identical to osEventFlagsNew
- static osEventFlagsId_t svcRtxEventFlagsNew (const osEventFlagsAttr_t *attr) {
- os_event_flags_t *ef;
- #ifdef RTX_SAFETY_CLASS
- const os_thread_t *thread = osRtxThreadGetRunning();
- uint32_t attr_bits;
- #endif
- uint8_t flags;
- const char *name;
- // Process attributes
- if (attr != NULL) {
- name = attr->name;
- #ifdef RTX_SAFETY_CLASS
- attr_bits = attr->attr_bits;
- #endif
- //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
- ef = attr->cb_mem;
- #ifdef RTX_SAFETY_CLASS
- if ((attr_bits & osSafetyClass_Valid) != 0U) {
- if ((thread != NULL) &&
- ((thread->attr >> osRtxAttrClass_Pos) <
- (uint8_t)((attr_bits & osSafetyClass_Msk) >> osSafetyClass_Pos))) {
- EvrRtxEventFlagsError(NULL, (int32_t)osErrorSafetyClass);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return NULL;
- }
- }
- #endif
- if (ef != NULL) {
- if (!IsEventFlagsPtrValid(ef) || (attr->cb_size != sizeof(os_event_flags_t))) {
- EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return NULL;
- }
- } else {
- if (attr->cb_size != 0U) {
- EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return NULL;
- }
- }
- } else {
- name = NULL;
- #ifdef RTX_SAFETY_CLASS
- attr_bits = 0U;
- #endif
- ef = NULL;
- }
- // Allocate object memory if not provided
- if (ef == NULL) {
- if (osRtxInfo.mpi.event_flags != NULL) {
- //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
- ef = osRtxMemoryPoolAlloc(osRtxInfo.mpi.event_flags);
- #ifndef RTX_OBJ_PTR_CHECK
- } else {
- //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
- ef = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_event_flags_t), 1U);
- #endif
- }
- #ifdef RTX_OBJ_MEM_USAGE
- if (ef != NULL) {
- uint32_t used;
- osRtxEventFlagsMemUsage.cnt_alloc++;
- used = osRtxEventFlagsMemUsage.cnt_alloc - osRtxEventFlagsMemUsage.cnt_free;
- if (osRtxEventFlagsMemUsage.max_used < used) {
- osRtxEventFlagsMemUsage.max_used = used;
- }
- }
- #endif
- flags = osRtxFlagSystemObject;
- } else {
- flags = 0U;
- }
- if (ef != NULL) {
- // Initialize control block
- ef->id = osRtxIdEventFlags;
- ef->flags = flags;
- ef->attr = 0U;
- ef->name = name;
- ef->thread_list = NULL;
- ef->event_flags = 0U;
- #ifdef RTX_SAFETY_CLASS
- if ((attr_bits & osSafetyClass_Valid) != 0U) {
- ef->attr |= (uint8_t)((attr_bits & osSafetyClass_Msk) >>
- (osSafetyClass_Pos - osRtxAttrClass_Pos));
- } else {
- // Inherit safety class from the running thread
- if (thread != NULL) {
- ef->attr |= (uint8_t)(thread->attr & osRtxAttrClass_Msk);
- }
- }
- #endif
- // Register post ISR processing function
- osRtxInfo.post_process.event_flags = osRtxEventFlagsPostProcess;
- EvrRtxEventFlagsCreated(ef, ef->name);
- } else {
- EvrRtxEventFlagsError(NULL, (int32_t)osErrorNoMemory);
- }
- return ef;
- }
- /// Get name of an Event Flags object.
- /// \note API identical to osEventFlagsGetName
- static const char *svcRtxEventFlagsGetName (osEventFlagsId_t ef_id) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags)) {
- EvrRtxEventFlagsGetName(ef, NULL);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return NULL;
- }
- EvrRtxEventFlagsGetName(ef, ef->name);
- return ef->name;
- }
- /// Set the specified Event Flags.
- /// \note API identical to osEventFlagsSet
- static uint32_t svcRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- os_thread_t *thread;
- os_thread_t *thread_next;
- uint32_t event_flags;
- uint32_t event_flags0;
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags) ||
- ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorParameter);
- }
- #ifdef RTX_SAFETY_CLASS
- // Check running thread safety class
- thread = osRtxThreadGetRunning();
- if ((thread != NULL) &&
- ((thread->attr >> osRtxAttrClass_Pos) < (ef->attr >> osRtxAttrClass_Pos))) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorSafetyClass);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorSafetyClass);
- }
- #endif
- // Set Event Flags
- event_flags = EventFlagsSet(ef, flags);
- // Check if Threads are waiting for Event Flags
- thread = ef->thread_list;
- while (thread != NULL) {
- thread_next = thread->thread_next;
- event_flags0 = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options);
- if (event_flags0 != 0U) {
- if ((thread->flags_options & osFlagsNoClear) == 0U) {
- event_flags = event_flags0 & ~thread->wait_flags;
- } else {
- event_flags = event_flags0;
- }
- osRtxThreadListRemove(thread);
- osRtxThreadWaitExit(thread, event_flags0, FALSE);
- EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags0);
- }
- thread = thread_next;
- }
- osRtxThreadDispatch(NULL);
- EvrRtxEventFlagsSetDone(ef, event_flags);
- return event_flags;
- }
- /// Clear the specified Event Flags.
- /// \note API identical to osEventFlagsClear
- static uint32_t svcRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- #ifdef RTX_SAFETY_CLASS
- const os_thread_t *thread;
- #endif
- uint32_t event_flags;
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags) ||
- ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorParameter);
- }
- #ifdef RTX_SAFETY_CLASS
- // Check running thread safety class
- thread = osRtxThreadGetRunning();
- if ((thread != NULL) &&
- ((thread->attr >> osRtxAttrClass_Pos) < (ef->attr >> osRtxAttrClass_Pos))) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorSafetyClass);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorSafetyClass);
- }
- #endif
- // Clear Event Flags
- event_flags = EventFlagsClear(ef, flags);
- EvrRtxEventFlagsClearDone(ef, event_flags);
- return event_flags;
- }
- /// Get the current Event Flags.
- /// \note API identical to osEventFlagsGet
- static uint32_t svcRtxEventFlagsGet (osEventFlagsId_t ef_id) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags)) {
- EvrRtxEventFlagsGet(ef, 0U);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return 0U;
- }
- EvrRtxEventFlagsGet(ef, ef->event_flags);
- return ef->event_flags;
- }
- /// Wait for one or more Event Flags to become signaled.
- /// \note API identical to osEventFlagsWait
- static uint32_t svcRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- os_thread_t *thread;
- uint32_t event_flags;
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags) ||
- ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorParameter);
- }
- #ifdef RTX_SAFETY_CLASS
- // Check running thread safety class
- thread = osRtxThreadGetRunning();
- if ((thread != NULL) &&
- ((thread->attr >> osRtxAttrClass_Pos) < (ef->attr >> osRtxAttrClass_Pos))) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorSafetyClass);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorSafetyClass);
- }
- #endif
- // Check Event Flags
- event_flags = EventFlagsCheck(ef, flags, options);
- if (event_flags != 0U) {
- EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags);
- } else {
- // Check if timeout is specified
- if (timeout != 0U) {
- EvrRtxEventFlagsWaitPending(ef, flags, options, timeout);
- // Suspend current Thread
- if (osRtxThreadWaitEnter(osRtxThreadWaitingEventFlags, timeout)) {
- thread = osRtxThreadGetRunning();
- osRtxThreadListPut(osRtxObject(ef), thread);
- // Store waiting flags and options
- thread->wait_flags = flags;
- thread->flags_options = (uint8_t)options;
- } else {
- EvrRtxEventFlagsWaitTimeout(ef);
- }
- event_flags = (uint32_t)osErrorTimeout;
- } else {
- EvrRtxEventFlagsWaitNotCompleted(ef, flags, options);
- event_flags = (uint32_t)osErrorResource;
- }
- }
- return event_flags;
- }
- /// Delete an Event Flags object.
- /// \note API identical to osEventFlagsDelete
- static osStatus_t svcRtxEventFlagsDelete (osEventFlagsId_t ef_id) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- os_thread_t *thread;
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags)) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return osErrorParameter;
- }
- #ifdef RTX_SAFETY_CLASS
- // Check running thread safety class
- thread = osRtxThreadGetRunning();
- if ((thread != NULL) &&
- ((thread->attr >> osRtxAttrClass_Pos) < (ef->attr >> osRtxAttrClass_Pos))) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorSafetyClass);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return osErrorSafetyClass;
- }
- #endif
- // Unblock waiting threads
- if (ef->thread_list != NULL) {
- do {
- thread = osRtxThreadListGet(osRtxObject(ef));
- osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, FALSE);
- } while (ef->thread_list != NULL);
- osRtxThreadDispatch(NULL);
- }
- osRtxEventFlagsDestroy(ef);
- return osOK;
- }
- // Service Calls definitions
- //lint ++flb "Library Begin" [MISRA Note 11]
- SVC0_1(EventFlagsNew, osEventFlagsId_t, const osEventFlagsAttr_t *)
- SVC0_1(EventFlagsGetName, const char *, osEventFlagsId_t)
- SVC0_2(EventFlagsSet, uint32_t, osEventFlagsId_t, uint32_t)
- SVC0_2(EventFlagsClear, uint32_t, osEventFlagsId_t, uint32_t)
- SVC0_1(EventFlagsGet, uint32_t, osEventFlagsId_t)
- SVC0_4(EventFlagsWait, uint32_t, osEventFlagsId_t, uint32_t, uint32_t, uint32_t)
- SVC0_1(EventFlagsDelete, osStatus_t, osEventFlagsId_t)
- //lint --flb "Library End"
- // ==== ISR Calls ====
- /// Set the specified Event Flags.
- /// \note API identical to osEventFlagsSet
- __STATIC_INLINE
- uint32_t isrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- uint32_t event_flags;
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags) ||
- ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorParameter);
- }
- // Set Event Flags
- event_flags = EventFlagsSet(ef, flags);
- // Register post ISR processing
- osRtxPostProcess(osRtxObject(ef));
- EvrRtxEventFlagsSetDone(ef, event_flags);
- return event_flags;
- }
- /// Wait for one or more Event Flags to become signaled.
- /// \note API identical to osEventFlagsWait
- __STATIC_INLINE
- uint32_t isrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
- os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
- uint32_t event_flags;
- // Check parameters
- if (!IsEventFlagsPtrValid(ef) || (ef->id != osRtxIdEventFlags) || (timeout != 0U) ||
- ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
- EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
- //lint -e{904} "Return statement before end of function" [MISRA Note 1]
- return ((uint32_t)osErrorParameter);
- }
- // Check Event Flags
- event_flags = EventFlagsCheck(ef, flags, options);
- if (event_flags != 0U) {
- EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags);
- } else {
- EvrRtxEventFlagsWaitNotCompleted(ef, flags, options);
- event_flags = (uint32_t)osErrorResource;
- }
- return event_flags;
- }
- // ==== Public API ====
- /// Create and Initialize an Event Flags object.
- osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr) {
- osEventFlagsId_t ef_id;
- EvrRtxEventFlagsNew(attr);
- if (IsException() || IsIrqMasked()) {
- EvrRtxEventFlagsError(NULL, (int32_t)osErrorISR);
- ef_id = NULL;
- } else {
- ef_id = __svcEventFlagsNew(attr);
- }
- return ef_id;
- }
- /// Get name of an Event Flags object.
- const char *osEventFlagsGetName (osEventFlagsId_t ef_id) {
- const char *name;
- if (IsException() || IsIrqMasked()) {
- name = svcRtxEventFlagsGetName(ef_id);
- } else {
- name = __svcEventFlagsGetName(ef_id);
- }
- return name;
- }
- /// Set the specified Event Flags.
- uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
- uint32_t event_flags;
- EvrRtxEventFlagsSet(ef_id, flags);
- if (IsException() || IsIrqMasked()) {
- event_flags = isrRtxEventFlagsSet(ef_id, flags);
- } else {
- event_flags = __svcEventFlagsSet(ef_id, flags);
- }
- return event_flags;
- }
- /// Clear the specified Event Flags.
- uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) {
- uint32_t event_flags;
- EvrRtxEventFlagsClear(ef_id, flags);
- if (IsException() || IsIrqMasked()) {
- event_flags = svcRtxEventFlagsClear(ef_id, flags);
- } else {
- event_flags = __svcEventFlagsClear(ef_id, flags);
- }
- return event_flags;
- }
- /// Get the current Event Flags.
- uint32_t osEventFlagsGet (osEventFlagsId_t ef_id) {
- uint32_t event_flags;
- if (IsException() || IsIrqMasked()) {
- event_flags = svcRtxEventFlagsGet(ef_id);
- } else {
- event_flags = __svcEventFlagsGet(ef_id);
- }
- return event_flags;
- }
- /// Wait for one or more Event Flags to become signaled.
- uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
- uint32_t event_flags;
- EvrRtxEventFlagsWait(ef_id, flags, options, timeout);
- if (IsException() || IsIrqMasked()) {
- event_flags = isrRtxEventFlagsWait(ef_id, flags, options, timeout);
- } else {
- event_flags = __svcEventFlagsWait(ef_id, flags, options, timeout);
- }
- return event_flags;
- }
- /// Delete an Event Flags object.
- osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id) {
- osStatus_t status;
- EvrRtxEventFlagsDelete(ef_id);
- if (IsException() || IsIrqMasked()) {
- EvrRtxEventFlagsError(ef_id, (int32_t)osErrorISR);
- status = osErrorISR;
- } else {
- status = __svcEventFlagsDelete(ef_id);
- }
- return status;
- }
|