event_groups.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. /*
  2. * FreeRTOS Kernel V10.4.3
  3. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * https://www.FreeRTOS.org
  23. * https://github.com/FreeRTOS
  24. *
  25. */
  26. #ifndef EVENT_GROUPS_H
  27. #define EVENT_GROUPS_H
  28. #ifndef INC_FREERTOS_H
  29. #error "include FreeRTOS.h" must appear in source files before "include event_groups.h"
  30. #endif
  31. /* FreeRTOS includes. */
  32. #include "timers.h"
  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. * <pre>
  88. * EventGroupHandle_t xEventGroupCreate( void );
  89. * </pre>
  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 xEventGropuCreate() 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 xEventGropuCreateStatic() 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. * <pre>
  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. * </pre>
  134. * \defgroup xEventGroupCreate xEventGroupCreate
  135. * \ingroup EventGroup
  136. */
  137. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  138. EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
  139. #endif
  140. /**
  141. * event_groups.h
  142. * <pre>
  143. * EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
  144. * </pre>
  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 xEventGropuCreate() 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 xEventGropuCreateStatic() 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. * <pre>
  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. * </pre>
  188. */
  189. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  190. EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) PRIVILEGED_FUNCTION;
  191. #endif
  192. /**
  193. * event_groups.h
  194. * <pre>
  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. * </pre>
  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. * <pre>
  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. * </pre>
  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 ) PRIVILEGED_FUNCTION;
  289. /**
  290. * event_groups.h
  291. * <pre>
  292. * EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
  293. * </pre>
  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. * <pre>
  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. * </pre>
  341. * \defgroup xEventGroupClearBits xEventGroupClearBits
  342. * \ingroup EventGroup
  343. */
  344. EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
  345. const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
  346. /**
  347. * event_groups.h
  348. * <pre>
  349. * BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
  350. * </pre>
  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. * <pre>
  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. * </pre>
  396. * \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR
  397. * \ingroup EventGroup
  398. */
  399. #if ( configUSE_TRACE_FACILITY == 1 )
  400. BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
  401. const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
  402. #else
  403. #define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) \
  404. xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL )
  405. #endif
  406. /**
  407. * event_groups.h
  408. * <pre>
  409. * EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
  410. * </pre>
  411. *
  412. * Set bits within an event group.
  413. * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR()
  414. * is a version that can be called from an interrupt.
  415. *
  416. * Setting bits in an event group will automatically unblock tasks that are
  417. * blocked waiting for the bits.
  418. *
  419. * @param xEventGroup The event group in which the bits are to be set.
  420. *
  421. * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
  422. * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
  423. * and bit 0 set uxBitsToSet to 0x09.
  424. *
  425. * @return The value of the event group at the time the call to
  426. * xEventGroupSetBits() returns. There are two reasons why the returned value
  427. * might have the bits specified by the uxBitsToSet parameter cleared. First,
  428. * if setting a bit results in a task that was waiting for the bit leaving the
  429. * blocked state then it is possible the bit will be cleared automatically
  430. * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
  431. * unblocked (or otherwise Ready state) task that has a priority above that of
  432. * the task that called xEventGroupSetBits() will execute and may change the
  433. * event group value before the call to xEventGroupSetBits() returns.
  434. *
  435. * Example usage:
  436. * <pre>
  437. #define BIT_0 ( 1 << 0 )
  438. #define BIT_4 ( 1 << 4 )
  439. *
  440. * void aFunction( EventGroupHandle_t xEventGroup )
  441. * {
  442. * EventBits_t uxBits;
  443. *
  444. * // Set bit 0 and bit 4 in xEventGroup.
  445. * uxBits = xEventGroupSetBits(
  446. * xEventGroup, // The event group being updated.
  447. * BIT_0 | BIT_4 );// The bits being set.
  448. *
  449. * if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  450. * {
  451. * // Both bit 0 and bit 4 remained set when the function returned.
  452. * }
  453. * else if( ( uxBits & BIT_0 ) != 0 )
  454. * {
  455. * // Bit 0 remained set when the function returned, but bit 4 was
  456. * // cleared. It might be that bit 4 was cleared automatically as a
  457. * // task that was waiting for bit 4 was removed from the Blocked
  458. * // state.
  459. * }
  460. * else if( ( uxBits & BIT_4 ) != 0 )
  461. * {
  462. * // Bit 4 remained set when the function returned, but bit 0 was
  463. * // cleared. It might be that bit 0 was cleared automatically as a
  464. * // task that was waiting for bit 0 was removed from the Blocked
  465. * // state.
  466. * }
  467. * else
  468. * {
  469. * // Neither bit 0 nor bit 4 remained set. It might be that a task
  470. * // was waiting for both of the bits to be set, and the bits were
  471. * // cleared as the task left the Blocked state.
  472. * }
  473. * }
  474. * </pre>
  475. * \defgroup xEventGroupSetBits xEventGroupSetBits
  476. * \ingroup EventGroup
  477. */
  478. EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
  479. const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
  480. /**
  481. * event_groups.h
  482. * <pre>
  483. * BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
  484. * </pre>
  485. *
  486. * A version of xEventGroupSetBits() that can be called from an interrupt.
  487. *
  488. * Setting bits in an event group is not a deterministic operation because there
  489. * are an unknown number of tasks that may be waiting for the bit or bits being
  490. * set. FreeRTOS does not allow nondeterministic operations to be performed in
  491. * interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR()
  492. * sends a message to the timer task to have the set operation performed in the
  493. * context of the timer task - where a scheduler lock is used in place of a
  494. * critical section.
  495. *
  496. * @param xEventGroup The event group in which the bits are to be set.
  497. *
  498. * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
  499. * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
  500. * and bit 0 set uxBitsToSet to 0x09.
  501. *
  502. * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
  503. * will result in a message being sent to the timer daemon task. If the
  504. * priority of the timer daemon task is higher than the priority of the
  505. * currently running task (the task the interrupt interrupted) then
  506. * *pxHigherPriorityTaskWoken will be set to pdTRUE by
  507. * xEventGroupSetBitsFromISR(), indicating that a context switch should be
  508. * requested before the interrupt exits. For that reason
  509. * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
  510. * example code below.
  511. *
  512. * @return If the request to execute the function was posted successfully then
  513. * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
  514. * if the timer service queue was full.
  515. *
  516. * Example usage:
  517. * <pre>
  518. #define BIT_0 ( 1 << 0 )
  519. #define BIT_4 ( 1 << 4 )
  520. *
  521. * // An event group which it is assumed has already been created by a call to
  522. * // xEventGroupCreate().
  523. * EventGroupHandle_t xEventGroup;
  524. *
  525. * void anInterruptHandler( void )
  526. * {
  527. * BaseType_t xHigherPriorityTaskWoken, xResult;
  528. *
  529. * // xHigherPriorityTaskWoken must be initialised to pdFALSE.
  530. * xHigherPriorityTaskWoken = pdFALSE;
  531. *
  532. * // Set bit 0 and bit 4 in xEventGroup.
  533. * xResult = xEventGroupSetBitsFromISR(
  534. * xEventGroup, // The event group being updated.
  535. * BIT_0 | BIT_4 // The bits being set.
  536. * &xHigherPriorityTaskWoken );
  537. *
  538. * // Was the message posted successfully?
  539. * if( xResult == pdPASS )
  540. * {
  541. * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
  542. * // switch should be requested. The macro used is port specific and
  543. * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  544. * // refer to the documentation page for the port being used.
  545. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  546. * }
  547. * }
  548. * </pre>
  549. * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
  550. * \ingroup EventGroup
  551. */
  552. #if ( configUSE_TRACE_FACILITY == 1 )
  553. BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
  554. const EventBits_t uxBitsToSet,
  555. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  556. #else
  557. #define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) \
  558. xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken )
  559. #endif
  560. /**
  561. * event_groups.h
  562. * <pre>
  563. * EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
  564. * const EventBits_t uxBitsToSet,
  565. * const EventBits_t uxBitsToWaitFor,
  566. * TickType_t xTicksToWait );
  567. * </pre>
  568. *
  569. * Atomically set bits within an event group, then wait for a combination of
  570. * bits to be set within the same event group. This functionality is typically
  571. * used to synchronise multiple tasks, where each task has to wait for the other
  572. * tasks to reach a synchronisation point before proceeding.
  573. *
  574. * This function cannot be used from an interrupt.
  575. *
  576. * The function will return before its block time expires if the bits specified
  577. * by the uxBitsToWait parameter are set, or become set within that time. In
  578. * this case all the bits specified by uxBitsToWait will be automatically
  579. * cleared before the function returns.
  580. *
  581. * @param xEventGroup The event group in which the bits are being tested. The
  582. * event group must have previously been created using a call to
  583. * xEventGroupCreate().
  584. *
  585. * @param uxBitsToSet The bits to set in the event group before determining
  586. * if, and possibly waiting for, all the bits specified by the uxBitsToWait
  587. * parameter are set.
  588. *
  589. * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
  590. * inside the event group. For example, to wait for bit 0 and bit 2 set
  591. * uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set
  592. * uxBitsToWaitFor to 0x07. Etc.
  593. *
  594. * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
  595. * for all of the bits specified by uxBitsToWaitFor to become set.
  596. *
  597. * @return The value of the event group at the time either the bits being waited
  598. * for became set, or the block time expired. Test the return value to know
  599. * which bits were set. If xEventGroupSync() returned because its timeout
  600. * expired then not all the bits being waited for will be set. If
  601. * xEventGroupSync() returned because all the bits it was waiting for were
  602. * set then the returned value is the event group value before any bits were
  603. * automatically cleared.
  604. *
  605. * Example usage:
  606. * <pre>
  607. * // Bits used by the three tasks.
  608. #define TASK_0_BIT ( 1 << 0 )
  609. #define TASK_1_BIT ( 1 << 1 )
  610. #define TASK_2_BIT ( 1 << 2 )
  611. *
  612. #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT )
  613. *
  614. * // Use an event group to synchronise three tasks. It is assumed this event
  615. * // group has already been created elsewhere.
  616. * EventGroupHandle_t xEventBits;
  617. *
  618. * void vTask0( void *pvParameters )
  619. * {
  620. * EventBits_t uxReturn;
  621. * TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
  622. *
  623. * for( ;; )
  624. * {
  625. * // Perform task functionality here.
  626. *
  627. * // Set bit 0 in the event flag to note this task has reached the
  628. * // sync point. The other two tasks will set the other two bits defined
  629. * // by ALL_SYNC_BITS. All three tasks have reached the synchronisation
  630. * // point when all the ALL_SYNC_BITS are set. Wait a maximum of 100ms
  631. * // for this to happen.
  632. * uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait );
  633. *
  634. * if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS )
  635. * {
  636. * // All three tasks reached the synchronisation point before the call
  637. * // to xEventGroupSync() timed out.
  638. * }
  639. * }
  640. * }
  641. *
  642. * void vTask1( void *pvParameters )
  643. * {
  644. * for( ;; )
  645. * {
  646. * // Perform task functionality here.
  647. *
  648. * // Set bit 1 in the event flag to note this task has reached the
  649. * // synchronisation point. The other two tasks will set the other two
  650. * // bits defined by ALL_SYNC_BITS. All three tasks have reached the
  651. * // synchronisation point when all the ALL_SYNC_BITS are set. Wait
  652. * // indefinitely for this to happen.
  653. * xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY );
  654. *
  655. * // xEventGroupSync() was called with an indefinite block time, so
  656. * // this task will only reach here if the synchronisation was made by all
  657. * // three tasks, so there is no need to test the return value.
  658. * }
  659. * }
  660. *
  661. * void vTask2( void *pvParameters )
  662. * {
  663. * for( ;; )
  664. * {
  665. * // Perform task functionality here.
  666. *
  667. * // Set bit 2 in the event flag to note this task has reached the
  668. * // synchronisation point. The other two tasks will set the other two
  669. * // bits defined by ALL_SYNC_BITS. All three tasks have reached the
  670. * // synchronisation point when all the ALL_SYNC_BITS are set. Wait
  671. * // indefinitely for this to happen.
  672. * xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY );
  673. *
  674. * // xEventGroupSync() was called with an indefinite block time, so
  675. * // this task will only reach here if the synchronisation was made by all
  676. * // three tasks, so there is no need to test the return value.
  677. * }
  678. * }
  679. *
  680. * </pre>
  681. * \defgroup xEventGroupSync xEventGroupSync
  682. * \ingroup EventGroup
  683. */
  684. EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
  685. const EventBits_t uxBitsToSet,
  686. const EventBits_t uxBitsToWaitFor,
  687. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  688. /**
  689. * event_groups.h
  690. * <pre>
  691. * EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
  692. * </pre>
  693. *
  694. * Returns the current value of the bits in an event group. This function
  695. * cannot be used from an interrupt.
  696. *
  697. * @param xEventGroup The event group being queried.
  698. *
  699. * @return The event group bits at the time xEventGroupGetBits() was called.
  700. *
  701. * \defgroup xEventGroupGetBits xEventGroupGetBits
  702. * \ingroup EventGroup
  703. */
  704. #define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 )
  705. /**
  706. * event_groups.h
  707. * <pre>
  708. * EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
  709. * </pre>
  710. *
  711. * A version of xEventGroupGetBits() that can be called from an ISR.
  712. *
  713. * @param xEventGroup The event group being queried.
  714. *
  715. * @return The event group bits at the time xEventGroupGetBitsFromISR() was called.
  716. *
  717. * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR
  718. * \ingroup EventGroup
  719. */
  720. EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
  721. /**
  722. * event_groups.h
  723. * <pre>
  724. * void xEventGroupDelete( EventGroupHandle_t xEventGroup );
  725. * </pre>
  726. *
  727. * Delete an event group that was previously created by a call to
  728. * xEventGroupCreate(). Tasks that are blocked on the event group will be
  729. * unblocked and obtain 0 as the event group's value.
  730. *
  731. * @param xEventGroup The event group being deleted.
  732. */
  733. void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
  734. /* For internal use only. */
  735. void vEventGroupSetBitsCallback( void * pvEventGroup,
  736. const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION;
  737. void vEventGroupClearBitsCallback( void * pvEventGroup,
  738. const uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
  739. #if ( configUSE_TRACE_FACILITY == 1 )
  740. UBaseType_t uxEventGroupGetNumber( void * xEventGroup ) PRIVILEGED_FUNCTION;
  741. void vEventGroupSetNumber( void * xEventGroup,
  742. UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION;
  743. #endif
  744. /* *INDENT-OFF* */
  745. #ifdef __cplusplus
  746. }
  747. #endif
  748. /* *INDENT-ON* */
  749. #endif /* EVENT_GROUPS_H */