rtx_evflags.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * Copyright (c) 2013-2018 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * -----------------------------------------------------------------------------
  19. *
  20. * Project: CMSIS-RTOS RTX
  21. * Title: Event Flags functions
  22. *
  23. * -----------------------------------------------------------------------------
  24. */
  25. #include "rtx_lib.h"
  26. // OS Runtime Object Memory Usage
  27. #if ((defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0)))
  28. osRtxObjectMemUsage_t osRtxEventFlagsMemUsage \
  29. __attribute__((section(".data.os.evflags.obj"))) =
  30. { 0U, 0U, 0U };
  31. #endif
  32. // ==== Helper functions ====
  33. /// Set Event Flags.
  34. /// \param[in] ef event flags object.
  35. /// \param[in] flags specifies the flags to set.
  36. /// \return event flags after setting.
  37. static uint32_t EventFlagsSet (os_event_flags_t *ef, uint32_t flags) {
  38. #if (EXCLUSIVE_ACCESS == 0)
  39. uint32_t primask = __get_PRIMASK();
  40. #endif
  41. uint32_t event_flags;
  42. #if (EXCLUSIVE_ACCESS == 0)
  43. __disable_irq();
  44. ef->event_flags |= flags;
  45. event_flags = ef->event_flags;
  46. if (primask == 0U) {
  47. __enable_irq();
  48. }
  49. #else
  50. event_flags = atomic_set32(&ef->event_flags, flags);
  51. #endif
  52. return event_flags;
  53. }
  54. /// Clear Event Flags.
  55. /// \param[in] ef event flags object.
  56. /// \param[in] flags specifies the flags to clear.
  57. /// \return event flags before clearing.
  58. static uint32_t EventFlagsClear (os_event_flags_t *ef, uint32_t flags) {
  59. #if (EXCLUSIVE_ACCESS == 0)
  60. uint32_t primask = __get_PRIMASK();
  61. #endif
  62. uint32_t event_flags;
  63. #if (EXCLUSIVE_ACCESS == 0)
  64. __disable_irq();
  65. event_flags = ef->event_flags;
  66. ef->event_flags &= ~flags;
  67. if (primask == 0U) {
  68. __enable_irq();
  69. }
  70. #else
  71. event_flags = atomic_clr32(&ef->event_flags, flags);
  72. #endif
  73. return event_flags;
  74. }
  75. /// Check Event Flags.
  76. /// \param[in] ef event flags object.
  77. /// \param[in] flags specifies the flags to check.
  78. /// \param[in] options specifies flags options (osFlagsXxxx).
  79. /// \return event flags before clearing or 0 if specified flags have not been set.
  80. static uint32_t EventFlagsCheck (os_event_flags_t *ef, uint32_t flags, uint32_t options) {
  81. #if (EXCLUSIVE_ACCESS == 0)
  82. uint32_t primask;
  83. #endif
  84. uint32_t event_flags;
  85. if ((options & osFlagsNoClear) == 0U) {
  86. #if (EXCLUSIVE_ACCESS == 0)
  87. primask = __get_PRIMASK();
  88. __disable_irq();
  89. event_flags = ef->event_flags;
  90. if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) ||
  91. (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) {
  92. event_flags = 0U;
  93. } else {
  94. ef->event_flags &= ~flags;
  95. }
  96. if (primask == 0U) {
  97. __enable_irq();
  98. }
  99. #else
  100. if ((options & osFlagsWaitAll) != 0U) {
  101. event_flags = atomic_chk32_all(&ef->event_flags, flags);
  102. } else {
  103. event_flags = atomic_chk32_any(&ef->event_flags, flags);
  104. }
  105. #endif
  106. } else {
  107. event_flags = ef->event_flags;
  108. if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) ||
  109. (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) {
  110. event_flags = 0U;
  111. }
  112. }
  113. return event_flags;
  114. }
  115. // ==== Post ISR processing ====
  116. /// Event Flags post ISR processing.
  117. /// \param[in] ef event flags object.
  118. static void osRtxEventFlagsPostProcess (os_event_flags_t *ef) {
  119. os_thread_t *thread;
  120. os_thread_t *thread_next;
  121. uint32_t event_flags;
  122. if (ef->state == osRtxObjectInactive) {
  123. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  124. return;
  125. }
  126. // Check if Threads are waiting for Event Flags
  127. thread = ef->thread_list;
  128. while (thread != NULL) {
  129. thread_next = thread->thread_next;
  130. event_flags = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options);
  131. if (event_flags != 0U) {
  132. osRtxThreadListRemove(thread);
  133. osRtxThreadWaitExit(thread, event_flags, FALSE);
  134. EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags);
  135. }
  136. thread = thread_next;
  137. }
  138. }
  139. // ==== Service Calls ====
  140. /// Create and Initialize an Event Flags object.
  141. /// \note API identical to osEventFlagsNew
  142. static osEventFlagsId_t svcRtxEventFlagsNew (const osEventFlagsAttr_t *attr) {
  143. os_event_flags_t *ef;
  144. uint8_t flags;
  145. const char *name;
  146. // Process attributes
  147. if (attr != NULL) {
  148. name = attr->name;
  149. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
  150. ef = attr->cb_mem;
  151. if (ef != NULL) {
  152. //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
  153. if ((((uint32_t)ef & 3U) != 0U) || (attr->cb_size < sizeof(os_event_flags_t))) {
  154. EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock);
  155. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  156. return NULL;
  157. }
  158. } else {
  159. if (attr->cb_size != 0U) {
  160. EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock);
  161. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  162. return NULL;
  163. }
  164. }
  165. } else {
  166. name = NULL;
  167. ef = NULL;
  168. }
  169. // Allocate object memory if not provided
  170. if (ef == NULL) {
  171. if (osRtxInfo.mpi.event_flags != NULL) {
  172. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
  173. ef = osRtxMemoryPoolAlloc(osRtxInfo.mpi.event_flags);
  174. } else {
  175. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
  176. ef = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_event_flags_t), 1U);
  177. }
  178. #if (defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0))
  179. if (ef != NULL) {
  180. uint32_t used;
  181. osRtxEventFlagsMemUsage.cnt_alloc++;
  182. used = osRtxEventFlagsMemUsage.cnt_alloc - osRtxEventFlagsMemUsage.cnt_free;
  183. if (osRtxEventFlagsMemUsage.max_used < used) {
  184. osRtxEventFlagsMemUsage.max_used = used;
  185. }
  186. }
  187. #endif
  188. flags = osRtxFlagSystemObject;
  189. } else {
  190. flags = 0U;
  191. }
  192. if (ef != NULL) {
  193. // Initialize control block
  194. ef->id = osRtxIdEventFlags;
  195. ef->state = osRtxObjectActive;
  196. ef->flags = flags;
  197. ef->name = name;
  198. ef->thread_list = NULL;
  199. ef->event_flags = 0U;
  200. // Register post ISR processing function
  201. osRtxInfo.post_process.event_flags = osRtxEventFlagsPostProcess;
  202. EvrRtxEventFlagsCreated(ef, ef->name);
  203. } else {
  204. EvrRtxEventFlagsError(NULL, (int32_t)osErrorNoMemory);
  205. }
  206. return ef;
  207. }
  208. /// Get name of an Event Flags object.
  209. /// \note API identical to osEventFlagsGetName
  210. static const char *svcRtxEventFlagsGetName (osEventFlagsId_t ef_id) {
  211. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  212. // Check parameters
  213. if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) {
  214. EvrRtxEventFlagsGetName(ef, NULL);
  215. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  216. return NULL;
  217. }
  218. // Check object state
  219. if (ef->state == osRtxObjectInactive) {
  220. EvrRtxEventFlagsGetName(ef, NULL);
  221. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  222. return NULL;
  223. }
  224. EvrRtxEventFlagsGetName(ef, ef->name);
  225. return ef->name;
  226. }
  227. /// Set the specified Event Flags.
  228. /// \note API identical to osEventFlagsSet
  229. static uint32_t svcRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
  230. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  231. os_thread_t *thread;
  232. os_thread_t *thread_next;
  233. uint32_t event_flags;
  234. uint32_t event_flags0;
  235. // Check parameters
  236. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  237. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  238. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  239. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  240. return ((uint32_t)osErrorParameter);
  241. }
  242. // Check object state
  243. if (ef->state == osRtxObjectInactive) {
  244. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  245. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  246. return ((uint32_t)osErrorResource);
  247. }
  248. // Set Event Flags
  249. event_flags = EventFlagsSet(ef, flags);
  250. // Check if Threads are waiting for Event Flags
  251. thread = ef->thread_list;
  252. while (thread != NULL) {
  253. thread_next = thread->thread_next;
  254. event_flags0 = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options);
  255. if (event_flags0 != 0U) {
  256. if ((thread->flags_options & osFlagsNoClear) == 0U) {
  257. event_flags = event_flags0 & ~thread->wait_flags;
  258. } else {
  259. event_flags = event_flags0;
  260. }
  261. osRtxThreadListRemove(thread);
  262. osRtxThreadWaitExit(thread, event_flags0, FALSE);
  263. EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags0);
  264. }
  265. thread = thread_next;
  266. }
  267. osRtxThreadDispatch(NULL);
  268. EvrRtxEventFlagsSetDone(ef, event_flags);
  269. return event_flags;
  270. }
  271. /// Clear the specified Event Flags.
  272. /// \note API identical to osEventFlagsClear
  273. static uint32_t svcRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) {
  274. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  275. uint32_t event_flags;
  276. // Check parameters
  277. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  278. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  279. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  280. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  281. return ((uint32_t)osErrorParameter);
  282. }
  283. // Check object state
  284. if (ef->state == osRtxObjectInactive) {
  285. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  286. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  287. return ((uint32_t)osErrorResource);
  288. }
  289. // Clear Event Flags
  290. event_flags = EventFlagsClear(ef, flags);
  291. EvrRtxEventFlagsClearDone(ef, event_flags);
  292. return event_flags;
  293. }
  294. /// Get the current Event Flags.
  295. /// \note API identical to osEventFlagsGet
  296. static uint32_t svcRtxEventFlagsGet (osEventFlagsId_t ef_id) {
  297. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  298. // Check parameters
  299. if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) {
  300. EvrRtxEventFlagsGet(ef, 0U);
  301. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  302. return 0U;
  303. }
  304. // Check object state
  305. if (ef->state == osRtxObjectInactive) {
  306. EvrRtxEventFlagsGet(ef, 0U);
  307. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  308. return 0U;
  309. }
  310. EvrRtxEventFlagsGet(ef, ef->event_flags);
  311. return ef->event_flags;
  312. }
  313. /// Wait for one or more Event Flags to become signaled.
  314. /// \note API identical to osEventFlagsWait
  315. static uint32_t svcRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
  316. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  317. os_thread_t *running_thread;
  318. uint32_t event_flags;
  319. // Check running thread
  320. running_thread = osRtxThreadGetRunning();
  321. if (running_thread == NULL) {
  322. EvrRtxEventFlagsError(ef, osRtxErrorKernelNotRunning);
  323. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  324. return ((uint32_t)osError);
  325. }
  326. // Check parameters
  327. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  328. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  329. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  330. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  331. return ((uint32_t)osErrorParameter);
  332. }
  333. // Check object state
  334. if (ef->state == osRtxObjectInactive) {
  335. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  336. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  337. return ((uint32_t)osErrorResource);
  338. }
  339. // Check Event Flags
  340. event_flags = EventFlagsCheck(ef, flags, options);
  341. if (event_flags != 0U) {
  342. EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags);
  343. } else {
  344. // Check if timeout is specified
  345. if (timeout != 0U) {
  346. EvrRtxEventFlagsWaitPending(ef, flags, options, timeout);
  347. // Store waiting flags and options
  348. running_thread->wait_flags = flags;
  349. running_thread->flags_options = (uint8_t)options;
  350. // Suspend current Thread
  351. if (osRtxThreadWaitEnter(osRtxThreadWaitingEventFlags, timeout)) {
  352. osRtxThreadListPut(osRtxObject(ef), running_thread);
  353. } else {
  354. EvrRtxEventFlagsWaitTimeout(ef);
  355. }
  356. event_flags = (uint32_t)osErrorTimeout;
  357. } else {
  358. EvrRtxEventFlagsWaitNotCompleted(ef, flags, options);
  359. event_flags = (uint32_t)osErrorResource;
  360. }
  361. }
  362. return event_flags;
  363. }
  364. /// Delete an Event Flags object.
  365. /// \note API identical to osEventFlagsDelete
  366. static osStatus_t svcRtxEventFlagsDelete (osEventFlagsId_t ef_id) {
  367. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  368. os_thread_t *thread;
  369. // Check parameters
  370. if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) {
  371. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  372. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  373. return osErrorParameter;
  374. }
  375. // Check object state
  376. if (ef->state == osRtxObjectInactive) {
  377. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  378. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  379. return osErrorResource;
  380. }
  381. // Mark object as inactive
  382. ef->state = osRtxObjectInactive;
  383. // Unblock waiting threads
  384. if (ef->thread_list != NULL) {
  385. do {
  386. thread = osRtxThreadListGet(osRtxObject(ef));
  387. osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, FALSE);
  388. } while (ef->thread_list != NULL);
  389. osRtxThreadDispatch(NULL);
  390. }
  391. // Free object memory
  392. if ((ef->flags & osRtxFlagSystemObject) != 0U) {
  393. if (osRtxInfo.mpi.event_flags != NULL) {
  394. (void)osRtxMemoryPoolFree(osRtxInfo.mpi.event_flags, ef);
  395. } else {
  396. (void)osRtxMemoryFree(osRtxInfo.mem.common, ef);
  397. }
  398. #if (defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0))
  399. osRtxEventFlagsMemUsage.cnt_free++;
  400. #endif
  401. }
  402. EvrRtxEventFlagsDestroyed(ef);
  403. return osOK;
  404. }
  405. // Service Calls definitions
  406. //lint ++flb "Library Begin" [MISRA Note 11]
  407. SVC0_1(EventFlagsNew, osEventFlagsId_t, const osEventFlagsAttr_t *)
  408. SVC0_1(EventFlagsGetName, const char *, osEventFlagsId_t)
  409. SVC0_2(EventFlagsSet, uint32_t, osEventFlagsId_t, uint32_t)
  410. SVC0_2(EventFlagsClear, uint32_t, osEventFlagsId_t, uint32_t)
  411. SVC0_1(EventFlagsGet, uint32_t, osEventFlagsId_t)
  412. SVC0_4(EventFlagsWait, uint32_t, osEventFlagsId_t, uint32_t, uint32_t, uint32_t)
  413. SVC0_1(EventFlagsDelete, osStatus_t, osEventFlagsId_t)
  414. //lint --flb "Library End"
  415. // ==== ISR Calls ====
  416. /// Set the specified Event Flags.
  417. /// \note API identical to osEventFlagsSet
  418. __STATIC_INLINE
  419. uint32_t isrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
  420. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  421. uint32_t event_flags;
  422. // Check parameters
  423. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  424. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  425. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  426. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  427. return ((uint32_t)osErrorParameter);
  428. }
  429. // Check object state
  430. if (ef->state == osRtxObjectInactive) {
  431. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  432. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  433. return ((uint32_t)osErrorResource);
  434. }
  435. // Set Event Flags
  436. event_flags = EventFlagsSet(ef, flags);
  437. // Register post ISR processing
  438. osRtxPostProcess(osRtxObject(ef));
  439. EvrRtxEventFlagsSetDone(ef, event_flags);
  440. return event_flags;
  441. }
  442. /// Wait for one or more Event Flags to become signaled.
  443. /// \note API identical to osEventFlagsWait
  444. __STATIC_INLINE
  445. uint32_t isrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
  446. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  447. uint32_t event_flags;
  448. // Check parameters
  449. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || (timeout != 0U) ||
  450. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  451. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  452. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  453. return ((uint32_t)osErrorParameter);
  454. }
  455. // Check object state
  456. if (ef->state == osRtxObjectInactive) {
  457. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  458. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  459. return ((uint32_t)osErrorResource);
  460. }
  461. // Check Event Flags
  462. event_flags = EventFlagsCheck(ef, flags, options);
  463. if (event_flags != 0U) {
  464. EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags);
  465. } else {
  466. EvrRtxEventFlagsWaitNotCompleted(ef, flags, options);
  467. event_flags = (uint32_t)osErrorResource;
  468. }
  469. return event_flags;
  470. }
  471. // ==== Public API ====
  472. /// Create and Initialize an Event Flags object.
  473. osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr) {
  474. osEventFlagsId_t ef_id;
  475. EvrRtxEventFlagsNew(attr);
  476. if (IsIrqMode() || IsIrqMasked()) {
  477. EvrRtxEventFlagsError(NULL, (int32_t)osErrorISR);
  478. ef_id = NULL;
  479. } else {
  480. ef_id = __svcEventFlagsNew(attr);
  481. }
  482. return ef_id;
  483. }
  484. /// Get name of an Event Flags object.
  485. const char *osEventFlagsGetName (osEventFlagsId_t ef_id) {
  486. const char *name;
  487. if (IsIrqMode() || IsIrqMasked()) {
  488. EvrRtxEventFlagsGetName(ef_id, NULL);
  489. name = NULL;
  490. } else {
  491. name = __svcEventFlagsGetName(ef_id);
  492. }
  493. return name;
  494. }
  495. /// Set the specified Event Flags.
  496. uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
  497. uint32_t event_flags;
  498. EvrRtxEventFlagsSet(ef_id, flags);
  499. if (IsIrqMode() || IsIrqMasked()) {
  500. event_flags = isrRtxEventFlagsSet(ef_id, flags);
  501. } else {
  502. event_flags = __svcEventFlagsSet(ef_id, flags);
  503. }
  504. return event_flags;
  505. }
  506. /// Clear the specified Event Flags.
  507. uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) {
  508. uint32_t event_flags;
  509. EvrRtxEventFlagsClear(ef_id, flags);
  510. if (IsIrqMode() || IsIrqMasked()) {
  511. event_flags = svcRtxEventFlagsClear(ef_id, flags);
  512. } else {
  513. event_flags = __svcEventFlagsClear(ef_id, flags);
  514. }
  515. return event_flags;
  516. }
  517. /// Get the current Event Flags.
  518. uint32_t osEventFlagsGet (osEventFlagsId_t ef_id) {
  519. uint32_t event_flags;
  520. if (IsIrqMode() || IsIrqMasked()) {
  521. event_flags = svcRtxEventFlagsGet(ef_id);
  522. } else {
  523. event_flags = __svcEventFlagsGet(ef_id);
  524. }
  525. return event_flags;
  526. }
  527. /// Wait for one or more Event Flags to become signaled.
  528. uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
  529. uint32_t event_flags;
  530. EvrRtxEventFlagsWait(ef_id, flags, options, timeout);
  531. if (IsIrqMode() || IsIrqMasked()) {
  532. event_flags = isrRtxEventFlagsWait(ef_id, flags, options, timeout);
  533. } else {
  534. event_flags = __svcEventFlagsWait(ef_id, flags, options, timeout);
  535. }
  536. return event_flags;
  537. }
  538. /// Delete an Event Flags object.
  539. osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id) {
  540. osStatus_t status;
  541. EvrRtxEventFlagsDelete(ef_id);
  542. if (IsIrqMode() || IsIrqMasked()) {
  543. EvrRtxEventFlagsError(ef_id, (int32_t)osErrorISR);
  544. status = osErrorISR;
  545. } else {
  546. status = __svcEventFlagsDelete(ef_id);
  547. }
  548. return status;
  549. }