rtx_evflags.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. // Check if Threads are waiting for Event Flags
  123. thread = ef->thread_list;
  124. while (thread != NULL) {
  125. thread_next = thread->thread_next;
  126. event_flags = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options);
  127. if (event_flags != 0U) {
  128. osRtxThreadListRemove(thread);
  129. osRtxThreadWaitExit(thread, event_flags, FALSE);
  130. EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags);
  131. }
  132. thread = thread_next;
  133. }
  134. }
  135. // ==== Service Calls ====
  136. /// Create and Initialize an Event Flags object.
  137. /// \note API identical to osEventFlagsNew
  138. static osEventFlagsId_t svcRtxEventFlagsNew (const osEventFlagsAttr_t *attr) {
  139. os_event_flags_t *ef;
  140. uint8_t flags;
  141. const char *name;
  142. // Process attributes
  143. if (attr != NULL) {
  144. name = attr->name;
  145. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
  146. ef = attr->cb_mem;
  147. if (ef != NULL) {
  148. //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
  149. if ((((uint32_t)ef & 3U) != 0U) || (attr->cb_size < sizeof(os_event_flags_t))) {
  150. EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock);
  151. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  152. return NULL;
  153. }
  154. } else {
  155. if (attr->cb_size != 0U) {
  156. EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock);
  157. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  158. return NULL;
  159. }
  160. }
  161. } else {
  162. name = NULL;
  163. ef = NULL;
  164. }
  165. // Allocate object memory if not provided
  166. if (ef == NULL) {
  167. if (osRtxInfo.mpi.event_flags != NULL) {
  168. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
  169. ef = osRtxMemoryPoolAlloc(osRtxInfo.mpi.event_flags);
  170. } else {
  171. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
  172. ef = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_event_flags_t), 1U);
  173. }
  174. #if (defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0))
  175. if (ef != NULL) {
  176. uint32_t used;
  177. osRtxEventFlagsMemUsage.cnt_alloc++;
  178. used = osRtxEventFlagsMemUsage.cnt_alloc - osRtxEventFlagsMemUsage.cnt_free;
  179. if (osRtxEventFlagsMemUsage.max_used < used) {
  180. osRtxEventFlagsMemUsage.max_used = used;
  181. }
  182. }
  183. #endif
  184. flags = osRtxFlagSystemObject;
  185. } else {
  186. flags = 0U;
  187. }
  188. if (ef != NULL) {
  189. // Initialize control block
  190. ef->id = osRtxIdEventFlags;
  191. ef->state = osRtxObjectActive;
  192. ef->flags = flags;
  193. ef->name = name;
  194. ef->thread_list = NULL;
  195. ef->event_flags = 0U;
  196. // Register post ISR processing function
  197. osRtxInfo.post_process.event_flags = osRtxEventFlagsPostProcess;
  198. EvrRtxEventFlagsCreated(ef, ef->name);
  199. } else {
  200. EvrRtxEventFlagsError(NULL, (int32_t)osErrorNoMemory);
  201. }
  202. return ef;
  203. }
  204. /// Get name of an Event Flags object.
  205. /// \note API identical to osEventFlagsGetName
  206. static const char *svcRtxEventFlagsGetName (osEventFlagsId_t ef_id) {
  207. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  208. // Check parameters
  209. if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) {
  210. EvrRtxEventFlagsGetName(ef, NULL);
  211. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  212. return NULL;
  213. }
  214. // Check object state
  215. if (ef->state == osRtxObjectInactive) {
  216. EvrRtxEventFlagsGetName(ef, NULL);
  217. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  218. return NULL;
  219. }
  220. EvrRtxEventFlagsGetName(ef, ef->name);
  221. return ef->name;
  222. }
  223. /// Set the specified Event Flags.
  224. /// \note API identical to osEventFlagsSet
  225. static uint32_t svcRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
  226. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  227. os_thread_t *thread;
  228. os_thread_t *thread_next;
  229. uint32_t event_flags;
  230. uint32_t event_flags0;
  231. // Check parameters
  232. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  233. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  234. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  235. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  236. return ((uint32_t)osErrorParameter);
  237. }
  238. // Check object state
  239. if (ef->state == osRtxObjectInactive) {
  240. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  241. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  242. return ((uint32_t)osErrorResource);
  243. }
  244. // Set Event Flags
  245. event_flags = EventFlagsSet(ef, flags);
  246. // Check if Threads are waiting for Event Flags
  247. thread = ef->thread_list;
  248. while (thread != NULL) {
  249. thread_next = thread->thread_next;
  250. event_flags0 = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options);
  251. if (event_flags0 != 0U) {
  252. if ((thread->flags_options & osFlagsNoClear) == 0U) {
  253. event_flags = event_flags0 & ~thread->wait_flags;
  254. } else {
  255. event_flags = event_flags0;
  256. }
  257. osRtxThreadListRemove(thread);
  258. osRtxThreadWaitExit(thread, event_flags0, FALSE);
  259. EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags0);
  260. }
  261. thread = thread_next;
  262. }
  263. osRtxThreadDispatch(NULL);
  264. EvrRtxEventFlagsSetDone(ef, event_flags);
  265. return event_flags;
  266. }
  267. /// Clear the specified Event Flags.
  268. /// \note API identical to osEventFlagsClear
  269. static uint32_t svcRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) {
  270. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  271. uint32_t event_flags;
  272. // Check parameters
  273. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  274. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  275. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  276. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  277. return ((uint32_t)osErrorParameter);
  278. }
  279. // Check object state
  280. if (ef->state == osRtxObjectInactive) {
  281. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  282. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  283. return ((uint32_t)osErrorResource);
  284. }
  285. // Clear Event Flags
  286. event_flags = EventFlagsClear(ef, flags);
  287. EvrRtxEventFlagsClearDone(ef, event_flags);
  288. return event_flags;
  289. }
  290. /// Get the current Event Flags.
  291. /// \note API identical to osEventFlagsGet
  292. static uint32_t svcRtxEventFlagsGet (osEventFlagsId_t ef_id) {
  293. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  294. // Check parameters
  295. if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) {
  296. EvrRtxEventFlagsGet(ef, 0U);
  297. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  298. return 0U;
  299. }
  300. // Check object state
  301. if (ef->state == osRtxObjectInactive) {
  302. EvrRtxEventFlagsGet(ef, 0U);
  303. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  304. return 0U;
  305. }
  306. EvrRtxEventFlagsGet(ef, ef->event_flags);
  307. return ef->event_flags;
  308. }
  309. /// Wait for one or more Event Flags to become signaled.
  310. /// \note API identical to osEventFlagsWait
  311. static uint32_t svcRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
  312. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  313. os_thread_t *running_thread;
  314. uint32_t event_flags;
  315. // Check running thread
  316. running_thread = osRtxThreadGetRunning();
  317. if (running_thread == NULL) {
  318. EvrRtxEventFlagsError(ef, osRtxErrorKernelNotRunning);
  319. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  320. return ((uint32_t)osError);
  321. }
  322. // Check parameters
  323. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  324. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  325. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  326. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  327. return ((uint32_t)osErrorParameter);
  328. }
  329. // Check object state
  330. if (ef->state == osRtxObjectInactive) {
  331. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  332. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  333. return ((uint32_t)osErrorResource);
  334. }
  335. // Check Event Flags
  336. event_flags = EventFlagsCheck(ef, flags, options);
  337. if (event_flags != 0U) {
  338. EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags);
  339. } else {
  340. // Check if timeout is specified
  341. if (timeout != 0U) {
  342. EvrRtxEventFlagsWaitPending(ef, flags, options, timeout);
  343. // Store waiting flags and options
  344. running_thread->wait_flags = flags;
  345. running_thread->flags_options = (uint8_t)options;
  346. // Suspend current Thread
  347. if (osRtxThreadWaitEnter(osRtxThreadWaitingEventFlags, timeout)) {
  348. osRtxThreadListPut(osRtxObject(ef), running_thread);
  349. } else {
  350. EvrRtxEventFlagsWaitTimeout(ef);
  351. }
  352. event_flags = (uint32_t)osErrorTimeout;
  353. } else {
  354. EvrRtxEventFlagsWaitNotCompleted(ef, flags, options);
  355. event_flags = (uint32_t)osErrorResource;
  356. }
  357. }
  358. return event_flags;
  359. }
  360. /// Delete an Event Flags object.
  361. /// \note API identical to osEventFlagsDelete
  362. static osStatus_t svcRtxEventFlagsDelete (osEventFlagsId_t ef_id) {
  363. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  364. os_thread_t *thread;
  365. // Check parameters
  366. if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) {
  367. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  368. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  369. return osErrorParameter;
  370. }
  371. // Check object state
  372. if (ef->state == osRtxObjectInactive) {
  373. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  374. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  375. return osErrorResource;
  376. }
  377. // Unblock waiting threads
  378. if (ef->thread_list != NULL) {
  379. do {
  380. thread = osRtxThreadListGet(osRtxObject(ef));
  381. osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, FALSE);
  382. } while (ef->thread_list != NULL);
  383. osRtxThreadDispatch(NULL);
  384. }
  385. // Mark object as inactive and invalid
  386. ef->state = osRtxObjectInactive;
  387. ef->id = osRtxIdInvalid;
  388. // Free object memory
  389. if ((ef->flags & osRtxFlagSystemObject) != 0U) {
  390. if (osRtxInfo.mpi.event_flags != NULL) {
  391. (void)osRtxMemoryPoolFree(osRtxInfo.mpi.event_flags, ef);
  392. } else {
  393. (void)osRtxMemoryFree(osRtxInfo.mem.common, ef);
  394. }
  395. #if (defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0))
  396. osRtxEventFlagsMemUsage.cnt_free++;
  397. #endif
  398. }
  399. EvrRtxEventFlagsDestroyed(ef);
  400. return osOK;
  401. }
  402. // Service Calls definitions
  403. //lint ++flb "Library Begin" [MISRA Note 11]
  404. SVC0_1(EventFlagsNew, osEventFlagsId_t, const osEventFlagsAttr_t *)
  405. SVC0_1(EventFlagsGetName, const char *, osEventFlagsId_t)
  406. SVC0_2(EventFlagsSet, uint32_t, osEventFlagsId_t, uint32_t)
  407. SVC0_2(EventFlagsClear, uint32_t, osEventFlagsId_t, uint32_t)
  408. SVC0_1(EventFlagsGet, uint32_t, osEventFlagsId_t)
  409. SVC0_4(EventFlagsWait, uint32_t, osEventFlagsId_t, uint32_t, uint32_t, uint32_t)
  410. SVC0_1(EventFlagsDelete, osStatus_t, osEventFlagsId_t)
  411. //lint --flb "Library End"
  412. // ==== ISR Calls ====
  413. /// Set the specified Event Flags.
  414. /// \note API identical to osEventFlagsSet
  415. __STATIC_INLINE
  416. uint32_t isrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
  417. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  418. uint32_t event_flags;
  419. // Check parameters
  420. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) ||
  421. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  422. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  423. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  424. return ((uint32_t)osErrorParameter);
  425. }
  426. // Check object state
  427. if (ef->state == osRtxObjectInactive) {
  428. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  429. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  430. return ((uint32_t)osErrorResource);
  431. }
  432. // Set Event Flags
  433. event_flags = EventFlagsSet(ef, flags);
  434. // Register post ISR processing
  435. osRtxPostProcess(osRtxObject(ef));
  436. EvrRtxEventFlagsSetDone(ef, event_flags);
  437. return event_flags;
  438. }
  439. /// Wait for one or more Event Flags to become signaled.
  440. /// \note API identical to osEventFlagsWait
  441. __STATIC_INLINE
  442. uint32_t isrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
  443. os_event_flags_t *ef = osRtxEventFlagsId(ef_id);
  444. uint32_t event_flags;
  445. // Check parameters
  446. if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || (timeout != 0U) ||
  447. ((flags & ~(((uint32_t)1U << osRtxEventFlagsLimit) - 1U)) != 0U)) {
  448. EvrRtxEventFlagsError(ef, (int32_t)osErrorParameter);
  449. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  450. return ((uint32_t)osErrorParameter);
  451. }
  452. // Check object state
  453. if (ef->state == osRtxObjectInactive) {
  454. EvrRtxEventFlagsError(ef, (int32_t)osErrorResource);
  455. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  456. return ((uint32_t)osErrorResource);
  457. }
  458. // Check Event Flags
  459. event_flags = EventFlagsCheck(ef, flags, options);
  460. if (event_flags != 0U) {
  461. EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags);
  462. } else {
  463. EvrRtxEventFlagsWaitNotCompleted(ef, flags, options);
  464. event_flags = (uint32_t)osErrorResource;
  465. }
  466. return event_flags;
  467. }
  468. // ==== Public API ====
  469. /// Create and Initialize an Event Flags object.
  470. osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr) {
  471. osEventFlagsId_t ef_id;
  472. EvrRtxEventFlagsNew(attr);
  473. if (IsIrqMode() || IsIrqMasked()) {
  474. EvrRtxEventFlagsError(NULL, (int32_t)osErrorISR);
  475. ef_id = NULL;
  476. } else {
  477. ef_id = __svcEventFlagsNew(attr);
  478. }
  479. return ef_id;
  480. }
  481. /// Get name of an Event Flags object.
  482. const char *osEventFlagsGetName (osEventFlagsId_t ef_id) {
  483. const char *name;
  484. if (IsIrqMode() || IsIrqMasked()) {
  485. EvrRtxEventFlagsGetName(ef_id, NULL);
  486. name = NULL;
  487. } else {
  488. name = __svcEventFlagsGetName(ef_id);
  489. }
  490. return name;
  491. }
  492. /// Set the specified Event Flags.
  493. uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
  494. uint32_t event_flags;
  495. EvrRtxEventFlagsSet(ef_id, flags);
  496. if (IsIrqMode() || IsIrqMasked()) {
  497. event_flags = isrRtxEventFlagsSet(ef_id, flags);
  498. } else {
  499. event_flags = __svcEventFlagsSet(ef_id, flags);
  500. }
  501. return event_flags;
  502. }
  503. /// Clear the specified Event Flags.
  504. uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) {
  505. uint32_t event_flags;
  506. EvrRtxEventFlagsClear(ef_id, flags);
  507. if (IsIrqMode() || IsIrqMasked()) {
  508. event_flags = svcRtxEventFlagsClear(ef_id, flags);
  509. } else {
  510. event_flags = __svcEventFlagsClear(ef_id, flags);
  511. }
  512. return event_flags;
  513. }
  514. /// Get the current Event Flags.
  515. uint32_t osEventFlagsGet (osEventFlagsId_t ef_id) {
  516. uint32_t event_flags;
  517. if (IsIrqMode() || IsIrqMasked()) {
  518. event_flags = svcRtxEventFlagsGet(ef_id);
  519. } else {
  520. event_flags = __svcEventFlagsGet(ef_id);
  521. }
  522. return event_flags;
  523. }
  524. /// Wait for one or more Event Flags to become signaled.
  525. uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
  526. uint32_t event_flags;
  527. EvrRtxEventFlagsWait(ef_id, flags, options, timeout);
  528. if (IsIrqMode() || IsIrqMasked()) {
  529. event_flags = isrRtxEventFlagsWait(ef_id, flags, options, timeout);
  530. } else {
  531. event_flags = __svcEventFlagsWait(ef_id, flags, options, timeout);
  532. }
  533. return event_flags;
  534. }
  535. /// Delete an Event Flags object.
  536. osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id) {
  537. osStatus_t status;
  538. EvrRtxEventFlagsDelete(ef_id);
  539. if (IsIrqMode() || IsIrqMasked()) {
  540. EvrRtxEventFlagsError(ef_id, (int32_t)osErrorISR);
  541. status = osErrorISR;
  542. } else {
  543. status = __svcEventFlagsDelete(ef_id);
  544. }
  545. return status;
  546. }