event_groups.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef EVENT_GROUPS_H
  29. #define EVENT_GROUPS_H
  30. #ifndef INC_FREERTOS_H
  31. #error "include FreeRTOS.h" must appear in source files before "include event_groups.h"
  32. #endif
  33. /* *INDENT-OFF* */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* *INDENT-ON* */
  38. /**
  39. * An event group is a collection of bits to which an application can assign a
  40. * meaning. For example, an application may create an event group to convey
  41. * the status of various CAN bus related events in which bit 0 might mean "A CAN
  42. * message has been received and is ready for processing", bit 1 might mean "The
  43. * application has queued a message that is ready for sending onto the CAN
  44. * network", and bit 2 might mean "It is time to send a SYNC message onto the
  45. * CAN network" etc. A task can then test the bit values to see which events
  46. * are active, and optionally enter the Blocked state to wait for a specified
  47. * bit or a group of specified bits to be active. To continue the CAN bus
  48. * example, a CAN controlling task can enter the Blocked state (and therefore
  49. * not consume any processing time) until either bit 0, bit 1 or bit 2 are
  50. * active, at which time the bit that was actually active would inform the task
  51. * which action it had to take (process a received message, send a message, or
  52. * send a SYNC).
  53. *
  54. * The event groups implementation contains intelligence to avoid race
  55. * conditions that would otherwise occur were an application to use a simple
  56. * variable for the same purpose. This is particularly important with respect
  57. * to when a bit within an event group is to be cleared, and when bits have to
  58. * be set and then tested atomically - as is the case where event groups are
  59. * used to create a synchronisation point between multiple tasks (a
  60. * 'rendezvous').
  61. *
  62. * \defgroup EventGroup
  63. */
  64. /**
  65. * event_groups.h
  66. *
  67. * Type by which event groups are referenced. For example, a call to
  68. * xEventGroupCreate() returns an EventGroupHandle_t variable that can then
  69. * be used as a parameter to other event group functions.
  70. *
  71. * \defgroup EventGroupHandle_t EventGroupHandle_t
  72. * \ingroup EventGroup
  73. */
  74. struct EventGroupDef_t;
  75. typedef struct EventGroupDef_t * EventGroupHandle_t;
  76. /*
  77. * The type that holds event bits always matches TickType_t - therefore the
  78. * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1,
  79. * 32 bits if set to 0.
  80. *
  81. * \defgroup EventBits_t EventBits_t
  82. * \ingroup EventGroup
  83. */
  84. typedef TickType_t EventBits_t;
  85. /**
  86. * event_groups.h
  87. * @code{c}
  88. * EventGroupHandle_t xEventGroupCreate( void );
  89. * @endcode
  90. *
  91. * Create a new event group.
  92. *
  93. * Internally, within the FreeRTOS implementation, event groups use a [small]
  94. * block of memory, in which the event group's structure is stored. If an event
  95. * groups is created using xEventGroupCreate() then the required memory is
  96. * automatically dynamically allocated inside the xEventGroupCreate() function.
  97. * (see https://www.FreeRTOS.org/a00111.html). If an event group is created
  98. * using xEventGroupCreateStatic() then the application writer must instead
  99. * provide the memory that will get used by the event group.
  100. * xEventGroupCreateStatic() therefore allows an event group to be created
  101. * without using any dynamic memory allocation.
  102. *
  103. * Although event groups are not related to ticks, for internal implementation
  104. * reasons the number of bits available for use in an event group is dependent
  105. * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If
  106. * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
  107. * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has
  108. * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store
  109. * event bits within an event group.
  110. *
  111. * @return If the event group was created then a handle to the event group is
  112. * returned. If there was insufficient FreeRTOS heap available to create the
  113. * event group then NULL is returned. See https://www.FreeRTOS.org/a00111.html
  114. *
  115. * Example usage:
  116. * @code{c}
  117. * // Declare a variable to hold the created event group.
  118. * EventGroupHandle_t xCreatedEventGroup;
  119. *
  120. * // Attempt to create the event group.
  121. * xCreatedEventGroup = xEventGroupCreate();
  122. *
  123. * // Was the event group created successfully?
  124. * if( xCreatedEventGroup == NULL )
  125. * {
  126. * // The event group was not created because there was insufficient
  127. * // FreeRTOS heap available.
  128. * }
  129. * else
  130. * {
  131. * // The event group was created.
  132. * }
  133. * @endcode
  134. * \defgroup xEventGroupCreate xEventGroupCreate
  135. * \ingroup EventGroup
  136. */
  137. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  138. EventGroupHandle_t xEventGroupCreate( void );
  139. #endif
  140. /**
  141. * event_groups.h
  142. * @code{c}
  143. * EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
  144. * @endcode
  145. *
  146. * Create a new event group.
  147. *
  148. * Internally, within the FreeRTOS implementation, event groups use a [small]
  149. * block of memory, in which the event group's structure is stored. If an event
  150. * groups is created using xEventGroupCreate() then the required memory is
  151. * automatically dynamically allocated inside the xEventGroupCreate() function.
  152. * (see https://www.FreeRTOS.org/a00111.html). If an event group is created
  153. * using xEventGroupCreateStatic() then the application writer must instead
  154. * provide the memory that will get used by the event group.
  155. * xEventGroupCreateStatic() therefore allows an event group to be created
  156. * without using any dynamic memory allocation.
  157. *
  158. * Although event groups are not related to ticks, for internal implementation
  159. * reasons the number of bits available for use in an event group is dependent
  160. * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If
  161. * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
  162. * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has
  163. * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store
  164. * event bits within an event group.
  165. *
  166. * @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type
  167. * StaticEventGroup_t, which will be then be used to hold the event group's data
  168. * structures, removing the need for the memory to be allocated dynamically.
  169. *
  170. * @return If the event group was created then a handle to the event group is
  171. * returned. If pxEventGroupBuffer was NULL then NULL is returned.
  172. *
  173. * Example usage:
  174. * @code{c}
  175. * // StaticEventGroup_t is a publicly accessible structure that has the same
  176. * // size and alignment requirements as the real event group structure. It is
  177. * // provided as a mechanism for applications to know the size of the event
  178. * // group (which is dependent on the architecture and configuration file
  179. * // settings) without breaking the strict data hiding policy by exposing the
  180. * // real event group internals. This StaticEventGroup_t variable is passed
  181. * // into the xSemaphoreCreateEventGroupStatic() function and is used to store
  182. * // the event group's data structures
  183. * StaticEventGroup_t xEventGroupBuffer;
  184. *
  185. * // Create the event group without dynamically allocating any memory.
  186. * xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
  187. * @endcode
  188. */
  189. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  190. EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer );
  191. #endif
  192. /**
  193. * event_groups.h
  194. * @code{c}
  195. * EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
  196. * const EventBits_t uxBitsToWaitFor,
  197. * const BaseType_t xClearOnExit,
  198. * const BaseType_t xWaitForAllBits,
  199. * const TickType_t xTicksToWait );
  200. * @endcode
  201. *
  202. * [Potentially] block to wait for one or more bits to be set within a
  203. * previously created event group.
  204. *
  205. * This function cannot be called from an interrupt.
  206. *
  207. * @param xEventGroup The event group in which the bits are being tested. The
  208. * event group must have previously been created using a call to
  209. * xEventGroupCreate().
  210. *
  211. * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
  212. * inside the event group. For example, to wait for bit 0 and/or bit 2 set
  213. * uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set
  214. * uxBitsToWaitFor to 0x07. Etc.
  215. *
  216. * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within
  217. * uxBitsToWaitFor that are set within the event group will be cleared before
  218. * xEventGroupWaitBits() returns if the wait condition was met (if the function
  219. * returns for a reason other than a timeout). If xClearOnExit is set to
  220. * pdFALSE then the bits set in the event group are not altered when the call to
  221. * xEventGroupWaitBits() returns.
  222. *
  223. * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then
  224. * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor
  225. * are set or the specified block time expires. If xWaitForAllBits is set to
  226. * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set
  227. * in uxBitsToWaitFor is set or the specified block time expires. The block
  228. * time is specified by the xTicksToWait parameter.
  229. *
  230. * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
  231. * for one/all (depending on the xWaitForAllBits value) of the bits specified by
  232. * uxBitsToWaitFor to become set.
  233. *
  234. * @return The value of the event group at the time either the bits being waited
  235. * for became set, or the block time expired. Test the return value to know
  236. * which bits were set. If xEventGroupWaitBits() returned because its timeout
  237. * expired then not all the bits being waited for will be set. If
  238. * xEventGroupWaitBits() returned because the bits it was waiting for were set
  239. * then the returned value is the event group value before any bits were
  240. * automatically cleared in the case that xClearOnExit parameter was set to
  241. * pdTRUE.
  242. *
  243. * Example usage:
  244. * @code{c}
  245. * #define BIT_0 ( 1 << 0 )
  246. * #define BIT_4 ( 1 << 4 )
  247. *
  248. * void aFunction( EventGroupHandle_t xEventGroup )
  249. * {
  250. * EventBits_t uxBits;
  251. * const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
  252. *
  253. * // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
  254. * // the event group. Clear the bits before exiting.
  255. * uxBits = xEventGroupWaitBits(
  256. * xEventGroup, // The event group being tested.
  257. * BIT_0 | BIT_4, // The bits within the event group to wait for.
  258. * pdTRUE, // BIT_0 and BIT_4 should be cleared before returning.
  259. * pdFALSE, // Don't wait for both bits, either bit will do.
  260. * xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
  261. *
  262. * if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  263. * {
  264. * // xEventGroupWaitBits() returned because both bits were set.
  265. * }
  266. * else if( ( uxBits & BIT_0 ) != 0 )
  267. * {
  268. * // xEventGroupWaitBits() returned because just BIT_0 was set.
  269. * }
  270. * else if( ( uxBits & BIT_4 ) != 0 )
  271. * {
  272. * // xEventGroupWaitBits() returned because just BIT_4 was set.
  273. * }
  274. * else
  275. * {
  276. * // xEventGroupWaitBits() returned because xTicksToWait ticks passed
  277. * // without either BIT_0 or BIT_4 becoming set.
  278. * }
  279. * }
  280. * @endcode
  281. * \defgroup xEventGroupWaitBits xEventGroupWaitBits
  282. * \ingroup EventGroup
  283. */
  284. EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
  285. const EventBits_t uxBitsToWaitFor,
  286. const BaseType_t xClearOnExit,
  287. const BaseType_t xWaitForAllBits,
  288. TickType_t xTicksToWait );
  289. /**
  290. * event_groups.h
  291. * @code{c}
  292. * EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
  293. * @endcode
  294. *
  295. * Clear bits within an event group. This function cannot be called from an
  296. * interrupt.
  297. *
  298. * @param xEventGroup The event group in which the bits are to be cleared.
  299. *
  300. * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear
  301. * in the event group. For example, to clear bit 3 only, set uxBitsToClear to
  302. * 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09.
  303. *
  304. * @return The value of the event group before the specified bits were cleared.
  305. *
  306. * Example usage:
  307. * @code{c}
  308. * #define BIT_0 ( 1 << 0 )
  309. * #define BIT_4 ( 1 << 4 )
  310. *
  311. * void aFunction( EventGroupHandle_t xEventGroup )
  312. * {
  313. * EventBits_t uxBits;
  314. *
  315. * // Clear bit 0 and bit 4 in xEventGroup.
  316. * uxBits = xEventGroupClearBits(
  317. * xEventGroup, // The event group being updated.
  318. * BIT_0 | BIT_4 );// The bits being cleared.
  319. *
  320. * if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  321. * {
  322. * // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
  323. * // called. Both will now be clear (not set).
  324. * }
  325. * else if( ( uxBits & BIT_0 ) != 0 )
  326. * {
  327. * // Bit 0 was set before xEventGroupClearBits() was called. It will
  328. * // now be clear.
  329. * }
  330. * else if( ( uxBits & BIT_4 ) != 0 )
  331. * {
  332. * // Bit 4 was set before xEventGroupClearBits() was called. It will
  333. * // now be clear.
  334. * }
  335. * else
  336. * {
  337. * // Neither bit 0 nor bit 4 were set in the first place.
  338. * }
  339. * }
  340. * @endcode
  341. * \defgroup xEventGroupClearBits xEventGroupClearBits
  342. * \ingroup EventGroup
  343. */
  344. EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
  345. const EventBits_t uxBitsToClear );
  346. /**
  347. * event_groups.h
  348. * @code{c}
  349. * BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
  350. * @endcode
  351. *
  352. * A version of xEventGroupClearBits() that can be called from an interrupt.
  353. *
  354. * Setting bits in an event group is not a deterministic operation because there
  355. * are an unknown number of tasks that may be waiting for the bit or bits being
  356. * set. FreeRTOS does not allow nondeterministic operations to be performed
  357. * while interrupts are disabled, so protects event groups that are accessed
  358. * from tasks by suspending the scheduler rather than disabling interrupts. As
  359. * a result event groups cannot be accessed directly from an interrupt service
  360. * routine. Therefore xEventGroupClearBitsFromISR() sends a message to the
  361. * timer task to have the clear operation performed in the context of the timer
  362. * task.
  363. *
  364. * @param xEventGroup The event group in which the bits are to be cleared.
  365. *
  366. * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear.
  367. * For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3
  368. * and bit 0 set uxBitsToClear to 0x09.
  369. *
  370. * @return If the request to execute the function was posted successfully then
  371. * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
  372. * if the timer service queue was full.
  373. *
  374. * Example usage:
  375. * @code{c}
  376. * #define BIT_0 ( 1 << 0 )
  377. * #define BIT_4 ( 1 << 4 )
  378. *
  379. * // An event group which it is assumed has already been created by a call to
  380. * // xEventGroupCreate().
  381. * EventGroupHandle_t xEventGroup;
  382. *
  383. * void anInterruptHandler( void )
  384. * {
  385. * // Clear bit 0 and bit 4 in xEventGroup.
  386. * xResult = xEventGroupClearBitsFromISR(
  387. * xEventGroup, // The event group being updated.
  388. * BIT_0 | BIT_4 ); // The bits being set.
  389. *
  390. * if( xResult == pdPASS )
  391. * {
  392. * // The message was posted successfully.
  393. * }
  394. * }
  395. * @endcode
  396. * \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR
  397. * \ingroup EventGroup
  398. */
  399. BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
  400. const EventBits_t uxBitsToClear );
  401. /**
  402. * event_groups.h
  403. * @code{c}
  404. * EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
  405. * @endcode
  406. *
  407. * Set bits within an event group.
  408. * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR()
  409. * is a version that can be called from an interrupt.
  410. *
  411. * Setting bits in an event group will automatically unblock tasks that are
  412. * blocked waiting for the bits.
  413. *
  414. * @param xEventGroup The event group in which the bits are to be set.
  415. *
  416. * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
  417. * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
  418. * and bit 0 set uxBitsToSet to 0x09.
  419. *
  420. * @return The value of the event group at the time the call to
  421. * xEventGroupSetBits() returns. There are two reasons why the returned value
  422. * might have the bits specified by the uxBitsToSet parameter cleared. First,
  423. * if setting a bit results in a task that was waiting for the bit leaving the
  424. * blocked state then it is possible the bit will be cleared automatically
  425. * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
  426. * unblocked (or otherwise Ready state) task that has a priority above that of
  427. * the task that called xEventGroupSetBits() will execute and may change the
  428. * event group value before the call to xEventGroupSetBits() returns.
  429. *
  430. * Example usage:
  431. * @code{c}
  432. * #define BIT_0 ( 1 << 0 )
  433. * #define BIT_4 ( 1 << 4 )
  434. *
  435. * void aFunction( EventGroupHandle_t xEventGroup )
  436. * {
  437. * EventBits_t uxBits;
  438. *
  439. * // Set bit 0 and bit 4 in xEventGroup.
  440. * uxBits = xEventGroupSetBits(
  441. * xEventGroup, // The event group being updated.
  442. * BIT_0 | BIT_4 );// The bits being set.
  443. *
  444. * if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  445. * {
  446. * // Both bit 0 and bit 4 remained set when the function returned.
  447. * }
  448. * else if( ( uxBits & BIT_0 ) != 0 )
  449. * {
  450. * // Bit 0 remained set when the function returned, but bit 4 was
  451. * // cleared. It might be that bit 4 was cleared automatically as a
  452. * // task that was waiting for bit 4 was removed from the Blocked
  453. * // state.
  454. * }
  455. * else if( ( uxBits & BIT_4 ) != 0 )
  456. * {
  457. * // Bit 4 remained set when the function returned, but bit 0 was
  458. * // cleared. It might be that bit 0 was cleared automatically as a
  459. * // task that was waiting for bit 0 was removed from the Blocked
  460. * // state.
  461. * }
  462. * else
  463. * {
  464. * // Neither bit 0 nor bit 4 remained set. It might be that a task
  465. * // was waiting for both of the bits to be set, and the bits were
  466. * // cleared as the task left the Blocked state.
  467. * }
  468. * }
  469. * @endcode
  470. * \defgroup xEventGroupSetBits xEventGroupSetBits
  471. * \ingroup EventGroup
  472. */
  473. EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
  474. const EventBits_t uxBitsToSet );
  475. /**
  476. * event_groups.h
  477. * @code{c}
  478. * BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
  479. * @endcode
  480. *
  481. * A version of xEventGroupSetBits() that can be called from an interrupt.
  482. *
  483. * Setting bits in an event group is not a deterministic operation because there
  484. * are an unknown number of tasks that may be waiting for the bit or bits being
  485. * set. FreeRTOS does not allow nondeterministic operations to be performed in
  486. * interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR()
  487. * sends a message to the timer task to have the set operation performed in the
  488. * context of the timer task - where a scheduler lock is used in place of a
  489. * critical section.
  490. *
  491. * @param xEventGroup The event group in which the bits are to be set.
  492. *
  493. * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
  494. * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
  495. * and bit 0 set uxBitsToSet to 0x09.
  496. *
  497. * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
  498. * will result in a message being sent to the timer daemon task. If the
  499. * priority of the timer daemon task is higher than the priority of the
  500. * currently running task (the task the interrupt interrupted) then
  501. * *pxHigherPriorityTaskWoken will be set to pdTRUE by
  502. * xEventGroupSetBitsFromISR(), indicating that a context switch should be
  503. * requested before the interrupt exits. For that reason
  504. * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
  505. * example code below.
  506. *
  507. * @return If the request to execute the function was posted successfully then
  508. * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
  509. * if the timer service queue was full.
  510. *
  511. * Example usage:
  512. * @code{c}
  513. * #define BIT_0 ( 1 << 0 )
  514. * #define BIT_4 ( 1 << 4 )
  515. *
  516. * // An event group which it is assumed has already been created by a call to
  517. * // xEventGroupCreate().
  518. * EventGroupHandle_t xEventGroup;
  519. *
  520. * void anInterruptHandler( void )
  521. * {
  522. * BaseType_t xHigherPriorityTaskWoken, xResult;
  523. *
  524. * // xHigherPriorityTaskWoken must be initialised to pdFALSE.
  525. * xHigherPriorityTaskWoken = pdFALSE;
  526. *
  527. * // Set bit 0 and bit 4 in xEventGroup.
  528. * xResult = xEventGroupSetBitsFromISR(
  529. * xEventGroup, // The event group being updated.
  530. * BIT_0 | BIT_4 // The bits being set.
  531. * &xHigherPriorityTaskWoken );
  532. *
  533. * // Was the message posted successfully?
  534. * if( xResult == pdPASS )
  535. * {
  536. * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
  537. * // switch should be requested. The macro used is port specific and
  538. * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  539. * // refer to the documentation page for the port being used.
  540. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  541. * }
  542. * }
  543. * @endcode
  544. * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
  545. * \ingroup EventGroup
  546. */
  547. BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
  548. const EventBits_t uxBitsToSet,
  549. BaseType_t * pxHigherPriorityTaskWoken );
  550. /**
  551. * event_groups.h
  552. * @code{c}
  553. * EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
  554. * @endcode
  555. *
  556. * Returns the current value of the bits in an event group. This function
  557. * cannot be used from an interrupt.
  558. *
  559. * @param xEventGroup The event group being queried.
  560. *
  561. * @return The event group bits at the time xEventGroupGetBits() was called.
  562. *
  563. * \defgroup xEventGroupGetBits xEventGroupGetBits
  564. * \ingroup EventGroup
  565. */
  566. #define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 )
  567. /**
  568. * event_groups.h
  569. * @code{c}
  570. * EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
  571. * @endcode
  572. *
  573. * A version of xEventGroupGetBits() that can be called from an ISR.
  574. *
  575. * @param xEventGroup The event group being queried.
  576. *
  577. * @return The event group bits at the time xEventGroupGetBitsFromISR() was called.
  578. *
  579. * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR
  580. * \ingroup EventGroup
  581. */
  582. EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
  583. /**
  584. * event_groups.h
  585. * @code{c}
  586. * void xEventGroupDelete( EventGroupHandle_t xEventGroup );
  587. * @endcode
  588. *
  589. * Delete an event group that was previously created by a call to
  590. * xEventGroupCreate(). Tasks that are blocked on the event group will be
  591. * unblocked and obtain 0 as the event group's value.
  592. *
  593. * @param xEventGroup The event group being deleted.
  594. */
  595. void vEventGroupDelete( EventGroupHandle_t xEventGroup );
  596. /* *INDENT-OFF* */
  597. #ifdef __cplusplus
  598. }
  599. #endif
  600. /* *INDENT-ON* */
  601. #endif /* EVENT_GROUPS_H */