2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
31 * This file contains fairly comprehensive checks on the behaviour of event
\r
32 * groups. It is not intended to be a user friendly demonstration of the
\r
35 * NOTE: The tests implemented in this file are informal 'sanity' tests
\r
36 * only and are not part of the module tests that make use of the
\r
37 * mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
\r
41 /* Scheduler include files. */
\r
42 #include "FreeRTOS.h"
\r
44 #include "event_groups.h"
\r
46 /* Demo app includes. */
\r
47 #include "EventGroupsDemo.h"
\r
49 #if( INCLUDE_eTaskGetState != 1 )
\r
50 #error INCLUDE_eTaskGetState must be set to 1 in FreeRTOSConfig.h to use this demo file.
\r
53 /* Priorities used by the tasks. */
\r
54 #define ebSET_BIT_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
55 #define ebWAIT_BIT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
57 /* Generic bit definitions. */
\r
58 #define ebBIT_0 ( 0x01 )
\r
59 #define ebBIT_1 ( 0x02 )
\r
60 #define ebBIT_2 ( 0x04 )
\r
61 #define ebBIT_3 ( 0x08 )
\r
62 #define ebBIT_4 ( 0x10 )
\r
63 #define ebBIT_5 ( 0x20 )
\r
64 #define ebBIT_6 ( 0x40 )
\r
65 #define ebBIT_7 ( 0x80 )
\r
67 /* Combinations of bits used in the demo. */
\r
68 #define ebCOMBINED_BITS ( ebBIT_1 | ebBIT_5 | ebBIT_7 )
\r
69 #define ebALL_BITS ( ebBIT_0 | ebBIT_1 | ebBIT_2 | ebBIT_3 | ebBIT_4 | ebBIT_5 | ebBIT_6 | ebBIT_7 )
\r
71 /* Associate a bit to each task. These bits are used to identify all the tasks
\r
72 that synchronise with the xEventGroupSync() function. */
\r
73 #define ebSET_BIT_TASK_SYNC_BIT ebBIT_0
\r
74 #define ebWAIT_BIT_TASK_SYNC_BIT ebBIT_1
\r
75 #define ebRENDESVOUS_TASK_1_SYNC_BIT ebBIT_2
\r
76 #define ebRENDESVOUS_TASK_2_SYNC_BIT ebBIT_3
\r
77 #define ebALL_SYNC_BITS ( ebSET_BIT_TASK_SYNC_BIT | ebWAIT_BIT_TASK_SYNC_BIT | ebRENDESVOUS_TASK_1_SYNC_BIT | ebRENDESVOUS_TASK_2_SYNC_BIT )
\r
79 /* A block time of zero simply means "don't block". */
\r
80 #define ebDONT_BLOCK ( 0 )
\r
81 #define ebONE_TICK ( ( TickType_t ) 1 )
\r
84 #define ebSHORT_DELAY pdMS_TO_TICKS( ( TickType_t ) 5 )
\r
86 /* Used in the selective bits test which checks no, one or both tasks blocked on
\r
87 event bits in a group are unblocked as appropriate as different bits get set. */
\r
88 #define ebSELECTIVE_BITS_1 0x03
\r
89 #define ebSELECTIVE_BITS_2 0x05
\r
91 /*-----------------------------------------------------------*/
\r
94 * NOTE: The tests implemented in this function are informal 'sanity' tests
\r
95 * only and are not part of the module tests that make use of the
\r
96 * mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
\r
98 * The master test task. This task:
\r
100 * 1) Calls prvSelectiveBitsTestMasterFunction() to test the behaviour when two
\r
101 * tasks are blocked on different bits in an event group. The counterpart of
\r
102 * this test is implemented by the prvSelectiveBitsTestSlaveFunction()
\r
103 * function (which is called by the two tasks that block on the event group).
\r
105 * 2) Calls prvBitCombinationTestMasterFunction() to test the behaviour when
\r
106 * just one task is blocked on various combinations of bits within an event
\r
107 * group. The counterpart of this test is implemented within the 'test
\r
110 * 3) Calls prvPerformTaskSyncTests() to test task synchronisation behaviour.
\r
112 static void prvTestMasterTask( void *pvParameters );
\r
115 * A helper task that enables the 'test master' task to perform several
\r
116 * behavioural tests. See the comments above the prvTestMasterTask() prototype
\r
119 static void prvTestSlaveTask( void *pvParameters );
\r
122 * The part of the test that is performed between the 'test master' task and the
\r
123 * 'test slave' task to test the behaviour when the slave blocks on various
\r
124 * event bit combinations.
\r
126 static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle );
\r
129 * The part of the test that uses all the tasks to test the task synchronisation
\r
132 static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle );
\r
135 * Two instances of prvSyncTask() are created. They start by calling
\r
136 * prvSelectiveBitsTestSlaveFunction() to act as slaves when the test master is
\r
137 * executing the prvSelectiveBitsTestMasterFunction() function. They then loop
\r
138 * to test the task synchronisation (rendezvous) behaviour.
\r
140 static void prvSyncTask( void *pvParameters );
\r
143 * Functions used in a test that blocks two tasks on various different bits
\r
144 * within an event group - then sets each bit in turn and checks that the
\r
145 * correct tasks unblock at the correct times.
\r
147 static BaseType_t prvSelectiveBitsTestMasterFunction( void );
\r
148 static void prvSelectiveBitsTestSlaveFunction( void );
\r
150 /*-----------------------------------------------------------*/
\r
152 /* Variables that are incremented by the tasks on each cycle provided no errors
\r
153 have been found. Used to detect an error or stall in the test cycling. */
\r
154 static volatile uint32_t ulTestMasterCycles = 0, ulTestSlaveCycles = 0, ulISRCycles = 0;
\r
156 /* The event group used by all the task based tests. */
\r
157 static EventGroupHandle_t xEventGroup = NULL;
\r
159 /* The event group used by the interrupt based tests. */
\r
160 static EventGroupHandle_t xISREventGroup = NULL;
\r
162 /* Handles to the tasks that only take part in the synchronisation calls. */
\r
163 static TaskHandle_t xSyncTask1 = NULL, xSyncTask2 = NULL;
\r
165 /*-----------------------------------------------------------*/
\r
167 void vStartEventGroupTasks( void )
\r
169 TaskHandle_t xTestSlaveTaskHandle;
\r
172 * This file contains fairly comprehensive checks on the behaviour of event
\r
173 * groups. It is not intended to be a user friendly demonstration of the
\r
174 * event groups API.
\r
176 * NOTE: The tests implemented in this file are informal 'sanity' tests
\r
177 * only and are not part of the module tests that make use of the
\r
178 * mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
\r
180 * Create the test tasks as described at the top of this file.
\r
182 xTaskCreate( prvTestSlaveTask, "WaitO", configMINIMAL_STACK_SIZE, NULL, ebWAIT_BIT_TASK_PRIORITY, &xTestSlaveTaskHandle );
\r
183 xTaskCreate( prvTestMasterTask, "SetB", configMINIMAL_STACK_SIZE, ( void * ) xTestSlaveTaskHandle, ebSET_BIT_TASK_PRIORITY, NULL );
\r
184 xTaskCreate( prvSyncTask, "Rndv", configMINIMAL_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_1_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask1 );
\r
185 xTaskCreate( prvSyncTask, "Rndv", configMINIMAL_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_2_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask2 );
\r
187 /* If the last task was created then the others will have been too. */
\r
188 configASSERT( xSyncTask2 );
\r
190 /* Create the event group used by the ISR tests. The event group used by
\r
191 the tasks is created by the tasks themselves. */
\r
192 xISREventGroup = xEventGroupCreate();
\r
193 configASSERT( xISREventGroup );
\r
195 /*-----------------------------------------------------------*/
\r
197 static void prvTestMasterTask( void *pvParameters )
\r
201 /* The handle to the slave task is passed in as the task parameter. */
\r
202 TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
\r
204 /* Avoid compiler warnings. */
\r
205 ( void ) pvParameters;
\r
207 /* Create the event group used by the tasks ready for the initial tests. */
\r
208 xEventGroup = xEventGroupCreate();
\r
209 configASSERT( xEventGroup );
\r
211 /* Perform the tests that block two tasks on different combinations of bits,
\r
212 then set each bit in turn and check the correct tasks unblock at the correct
\r
214 xError = prvSelectiveBitsTestMasterFunction();
\r
218 /* Recreate the event group ready for the next cycle. */
\r
219 xEventGroup = xEventGroupCreate();
\r
220 configASSERT( xEventGroup );
\r
222 /* Perform the tests that check the behaviour when a single task is
\r
223 blocked on various combinations of event bits. */
\r
224 xError = prvBitCombinationTestMasterFunction( xError, xTestSlaveTaskHandle );
\r
226 /* Perform the task synchronisation tests. */
\r
227 xError = prvPerformTaskSyncTests( xError, xTestSlaveTaskHandle );
\r
229 /* Delete the event group. */
\r
230 vEventGroupDelete( xEventGroup );
\r
232 /* Now all the other tasks should have completed and suspended
\r
233 themselves ready for the next go around the loop. */
\r
234 if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
\r
239 if( eTaskGetState( xSyncTask1 ) != eSuspended )
\r
244 if( eTaskGetState( xSyncTask2 ) != eSuspended )
\r
249 /* Only increment the cycle variable if no errors have been detected. */
\r
250 if( xError == pdFALSE )
\r
252 ulTestMasterCycles++;
\r
255 configASSERT( xError == pdFALSE );
\r
258 /*-----------------------------------------------------------*/
\r
260 static void prvSyncTask( void *pvParameters )
\r
262 EventBits_t uxSynchronisationBit, uxReturned;
\r
264 /* A few tests that check the behaviour when two tasks are blocked on
\r
265 various different bits within an event group are performed before this task
\r
266 enters its infinite loop to carry out its main demo function. */
\r
267 prvSelectiveBitsTestSlaveFunction();
\r
269 /* The bit to use to indicate this task is at the synchronisation point is
\r
270 passed in as the task parameter. */
\r
271 uxSynchronisationBit = ( EventBits_t ) pvParameters;
\r
275 /* Now this task takes part in a task synchronisation - sometimes known
\r
276 as a 'rendezvous'. Its execution pattern is controlled by the 'test
\r
277 master' task, which is responsible for taking this task out of the
\r
278 Suspended state when it is time to test the synchronisation behaviour.
\r
279 See: http://www.freertos.org/xEventGroupSync.html. */
\r
280 vTaskSuspend( NULL );
\r
282 /* Set the bit that indicates this task is at the synchronisation
\r
283 point. The first time this is done the 'test master' task has a lower
\r
284 priority than this task so this task will get to the sync point before
\r
285 the set bits task - test this by first calling xEventGroupSync() with
\r
286 a zero block time, and a block time that is too short for the other
\r
287 task, before calling again with a max delay - the first two calls should
\r
288 return before the rendezvous completes, the third only after the
\r
289 rendezvous is complete. */
\r
290 uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
\r
291 uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
\r
292 ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
\r
293 ebDONT_BLOCK ); /* The maximum time to wait for the sync condition to be met before giving up. */
\r
295 /* No block time was specified, so as per the comments above, the
\r
296 rendezvous is not expected to have completed yet. */
\r
297 configASSERT( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS );
\r
299 uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
\r
300 uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
\r
301 ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
\r
302 ebONE_TICK ); /* The maximum time to wait for the sync condition to be met before giving up. */
\r
304 /* A short block time was specified, so as per the comments above, the
\r
305 rendezvous is not expected to have completed yet. */
\r
306 configASSERT( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS );
\r
308 uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
\r
309 uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
\r
310 ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
\r
311 portMAX_DELAY );/* The maximum time to wait for the sync condition to be met before giving up. */
\r
313 /* A max delay was used, so this task should only exit the above
\r
314 function call when the sync condition is met. Check this is the
\r
316 configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
\r
318 /* Remove compiler warning if configASSERT() is not defined. */
\r
319 ( void ) uxReturned;
\r
321 /* Wait until the 'test master' task unsuspends this task again. */
\r
322 vTaskSuspend( NULL );
\r
324 /* Set the bit that indicates this task is at the synchronisation
\r
325 point again. This time the 'test master' task has a higher priority
\r
326 than this task so will get to the sync point before this task. */
\r
327 uxReturned = xEventGroupSync( xEventGroup, uxSynchronisationBit, ebALL_SYNC_BITS, portMAX_DELAY );
\r
329 /* Again a max delay was used, so this task should only exit the above
\r
330 function call when the sync condition is met. Check this is the
\r
332 configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
\r
334 /* Block on the event group again. This time the event group is going
\r
335 to be deleted while this task is blocked on it so it is expected that 0
\r
337 uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
\r
338 configASSERT( uxReturned == 0 );
\r
341 /*-----------------------------------------------------------*/
\r
343 static void prvTestSlaveTask( void *pvParameters )
\r
345 EventBits_t uxReturned;
\r
346 BaseType_t xError = pdFALSE;
\r
348 /* Avoid compiler warnings. */
\r
349 ( void ) pvParameters;
\r
353 /**********************************************************************
\r
354 * Part 1: This section is the counterpart to the
\r
355 * prvBitCombinationTestMasterFunction() function which is called by the
\r
356 * test master task.
\r
357 ***********************************************************************
\r
359 This task is controller by the 'test master' task (which is
\r
360 implemented by prvTestMasterTask()). Suspend until resumed by the
\r
361 'test master' task. */
\r
362 vTaskSuspend( NULL );
\r
364 /* Wait indefinitely for one of the bits in ebCOMBINED_BITS to get
\r
365 set. Clear the bit on exit. */
\r
366 uxReturned = xEventGroupWaitBits( xEventGroup, /* The event group that contains the event bits being queried. */
\r
367 ebBIT_1, /* The bit to wait for. */
\r
368 pdTRUE, /* Clear the bit on exit. */
\r
369 pdTRUE, /* Wait for all the bits (only one in this case anyway). */
\r
370 portMAX_DELAY ); /* Block indefinitely to wait for the condition to be met. */
\r
372 /* The 'test master' task set all the bits defined by ebCOMBINED_BITS,
\r
373 only one of which was being waited for by this task. The return value
\r
374 shows the state of the event bits when the task was unblocked, however
\r
375 because the task was waiting for ebBIT_1 and 'clear on exit' was set to
\r
376 the current state of the event bits will have ebBIT_1 clear. */
\r
377 if( uxReturned != ebCOMBINED_BITS )
\r
382 /* Now call xEventGroupWaitBits() again, this time waiting for all the
\r
383 bits in ebCOMBINED_BITS to be set. This call should block until the
\r
384 'test master' task sets ebBIT_1 - which was the bit cleared in the call
\r
385 to xEventGroupWaitBits() above. */
\r
386 uxReturned = xEventGroupWaitBits( xEventGroup,
\r
387 ebCOMBINED_BITS, /* The bits being waited on. */
\r
388 pdFALSE, /* Don't clear the bits on exit. */
\r
389 pdTRUE, /* All the bits must be set to unblock. */
\r
392 /* Were all the bits set? */
\r
393 if( ( uxReturned & ebCOMBINED_BITS ) != ebCOMBINED_BITS )
\r
398 /* Suspend again to wait for the 'test master' task. */
\r
399 vTaskSuspend( NULL );
\r
401 /* Now call xEventGroupWaitBits() again, again waiting for all the bits
\r
402 in ebCOMBINED_BITS to be set, but this time clearing the bits when the
\r
403 task is unblocked. */
\r
404 uxReturned = xEventGroupWaitBits( xEventGroup,
\r
405 ebCOMBINED_BITS, /* The bits being waited on. */
\r
406 pdTRUE, /* Clear the bits on exit. */
\r
407 pdTRUE, /* All the bits must be set to unblock. */
\r
410 /* The 'test master' task set all the bits in the event group, so that
\r
411 is the value that should have been returned. The bits defined by
\r
412 ebCOMBINED_BITS will have been clear again in the current value though
\r
413 as 'clear on exit' was set to pdTRUE. */
\r
414 if( uxReturned != ebALL_BITS )
\r
423 /**********************************************************************
\r
424 * Part 2: This section is the counterpart to the
\r
425 * prvPerformTaskSyncTests() function which is called by the
\r
426 * test master task.
\r
427 ***********************************************************************
\r
430 Once again wait for the 'test master' task to unsuspend this task
\r
431 when it is time for the next test. */
\r
432 vTaskSuspend( NULL );
\r
434 /* Now peform a synchronisation with all the other tasks. At this point
\r
435 the 'test master' task has the lowest priority so will get to the sync
\r
436 point after all the other synchronising tasks. */
\r
437 uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the sync. */
\r
438 ebWAIT_BIT_TASK_SYNC_BIT, /* The bit in the event group used to indicate this task is at the sync point. */
\r
439 ebALL_SYNC_BITS, /* The bits to wait for. These bits are set by the other tasks taking part in the sync. */
\r
440 portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met before giving up. */
\r
442 /* A sync with a max delay should only exit when all the synchronisation
\r
444 if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
\r
449 /* ...but now the synchronisation bits should be clear again. Read back
\r
450 the current value of the bits within the event group to check that is
\r
451 the case. Setting the bits to zero will return the bits previous value
\r
452 then leave all the bits clear. */
\r
453 if( xEventGroupSetBits( xEventGroup, 0x00 ) != 0 )
\r
458 /* Check the bits are indeed 0 now by simply reading then. */
\r
459 if( xEventGroupGetBits( xEventGroup ) != 0 )
\r
464 if( xError == pdFALSE )
\r
466 /* This task is still cycling without finding an error. */
\r
467 ulTestSlaveCycles++;
\r
470 vTaskSuspend( NULL );
\r
472 /* This time sync when the 'test master' task has the highest priority
\r
473 at the point where it sets its sync bit - so this time the 'test master'
\r
474 task will get to the sync point before this task. */
\r
475 uxReturned = xEventGroupSync( xEventGroup, ebWAIT_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
\r
477 /* A sync with a max delay should only exit when all the synchronisation
\r
479 if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
\r
484 /* ...but now the sync bits should be clear again. */
\r
485 if( xEventGroupSetBits( xEventGroup, 0x00 ) != 0 )
\r
490 /* Block on the event group again. This time the event group is going
\r
491 to be deleted while this task is blocked on it, so it is expected that 0
\r
492 will be returned. */
\r
493 uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
\r
495 if( uxReturned != 0 )
\r
500 if( xError == pdFALSE )
\r
502 /* This task is still cycling without finding an error. */
\r
503 ulTestSlaveCycles++;
\r
506 configASSERT( xError == pdFALSE );
\r
509 /*-----------------------------------------------------------*/
\r
511 static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle )
\r
513 EventBits_t uxBits;
\r
515 /* The three tasks that take part in the synchronisation (rendezvous) are
\r
516 expected to be in the suspended state at the start of the test. */
\r
517 if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
\r
522 if( eTaskGetState( xSyncTask1 ) != eSuspended )
\r
527 if( eTaskGetState( xSyncTask2 ) != eSuspended )
\r
532 /* Try a synch with no other tasks involved. First set all the bits other
\r
533 than this task's bit. */
\r
534 xEventGroupSetBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
\r
536 /* Then wait on just one bit - the bit that is being set. */
\r
537 uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
\r
538 ebSET_BIT_TASK_SYNC_BIT,/* The bit set by this task when it reaches the sync point. */
\r
539 ebSET_BIT_TASK_SYNC_BIT,/* The bits to wait for - in this case it is just waiting for itself. */
\r
540 portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
\r
542 /* A sync with a max delay should only exit when all the synchronise
\r
543 bits are set...check that is the case. In this case there is only one
\r
544 sync bit anyway. */
\r
545 if( ( uxBits & ebSET_BIT_TASK_SYNC_BIT ) != ebSET_BIT_TASK_SYNC_BIT )
\r
550 /* ...but now the sync bits should be clear again, leaving all the other
\r
551 bits set (as only one bit was being waited for). */
\r
552 if( xEventGroupGetBits( xEventGroup ) != ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) )
\r
557 /* Clear all the bits to zero again. */
\r
558 xEventGroupClearBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
\r
559 if( xEventGroupGetBits( xEventGroup ) != 0 )
\r
564 /* Unsuspend the other tasks then check they have executed up to the
\r
565 synchronisation point. */
\r
566 vTaskResume( xTestSlaveTaskHandle );
\r
567 vTaskResume( xSyncTask1 );
\r
568 vTaskResume( xSyncTask2 );
\r
570 if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
\r
575 if( eTaskGetState( xSyncTask1 ) != eBlocked )
\r
580 if( eTaskGetState( xSyncTask2 ) != eBlocked )
\r
585 /* Set this task's sync bit. */
\r
586 uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
\r
587 ebSET_BIT_TASK_SYNC_BIT,/* The bit set by this task when it reaches the sync point. */
\r
588 ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks that take part in the sync. */
\r
589 portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
\r
591 /* A sync with a max delay should only exit when all the synchronise
\r
592 bits are set...check that is the case. */
\r
593 if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
\r
598 /* ...but now the sync bits should be clear again. */
\r
599 if( xEventGroupGetBits( xEventGroup ) != 0 )
\r
605 /* The other tasks should now all be suspended again, ready for the next
\r
606 synchronisation. */
\r
607 if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
\r
612 if( eTaskGetState( xSyncTask1 ) != eSuspended )
\r
617 if( eTaskGetState( xSyncTask2 ) != eSuspended )
\r
623 /* Sync again - but this time set the last necessary bit as the
\r
624 highest priority task, rather than the lowest priority task. Unsuspend
\r
625 the other tasks then check they have executed up to the synchronisation
\r
627 vTaskResume( xTestSlaveTaskHandle );
\r
628 vTaskResume( xSyncTask1 );
\r
629 vTaskResume( xSyncTask2 );
\r
631 if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
\r
636 if( eTaskGetState( xSyncTask1 ) != eBlocked )
\r
641 if( eTaskGetState( xSyncTask2 ) != eBlocked )
\r
646 /* Raise the priority of this task above that of the other tasks. */
\r
647 vTaskPrioritySet( NULL, ebWAIT_BIT_TASK_PRIORITY + 1 );
\r
649 /* Set this task's sync bit. */
\r
650 uxBits = xEventGroupSync( xEventGroup, ebSET_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
\r
652 /* A sync with a max delay should only exit when all the synchronisation
\r
654 if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
\r
659 /* ...but now the sync bits should be clear again. */
\r
660 if( xEventGroupGetBits( xEventGroup ) != 0 )
\r
666 /* The other tasks should now all be in the ready state again, but not
\r
667 executed yet as this task still has a higher relative priority. */
\r
668 if( eTaskGetState( xTestSlaveTaskHandle ) != eReady )
\r
673 if( eTaskGetState( xSyncTask1 ) != eReady )
\r
678 if( eTaskGetState( xSyncTask2 ) != eReady )
\r
684 /* Reset the priority of this task back to its original value. */
\r
685 vTaskPrioritySet( NULL, ebSET_BIT_TASK_PRIORITY );
\r
687 /* Now all the other tasks should have reblocked on the event bits
\r
688 to test the behaviour when the event bits are deleted. */
\r
689 if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
\r
694 if( eTaskGetState( xSyncTask1 ) != eBlocked )
\r
699 if( eTaskGetState( xSyncTask2 ) != eBlocked )
\r
706 /*-----------------------------------------------------------*/
\r
708 static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle )
\r
710 EventBits_t uxBits;
\r
712 /* Resume the other task. It will block, pending a single bit from
\r
713 within ebCOMBINED_BITS. */
\r
714 vTaskResume( xTestSlaveTaskHandle );
\r
716 /* Ensure the other task is blocked on the task. */
\r
717 if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
\r
722 /* Set all the bits in ebCOMBINED_BITS - the 'test slave' task is only
\r
723 blocked waiting for one of them. */
\r
724 xEventGroupSetBits( xEventGroup, ebCOMBINED_BITS );
\r
726 /* The 'test slave' task should now have executed, clearing ebBIT_1 (the
\r
727 bit it was blocked on), then re-entered the Blocked state to wait for
\r
728 all the other bits in ebCOMBINED_BITS to be set again. First check
\r
729 ebBIT_1 is clear. */
\r
730 uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
\r
732 if( uxBits != ( ebCOMBINED_BITS & ~ebBIT_1 ) )
\r
737 /* Ensure the other task is still in the blocked state. */
\r
738 if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
\r
743 /* Set all the bits other than ebBIT_1 - which is the bit that must be
\r
744 set before the other task unblocks. */
\r
745 xEventGroupSetBits( xEventGroup, ebALL_BITS & ~ebBIT_1 );
\r
747 /* Ensure all the expected bits are still set. */
\r
748 uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
\r
750 if( uxBits != ( ebALL_BITS & ~ebBIT_1 ) )
\r
755 /* Ensure the other task is still in the blocked state. */
\r
756 if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
\r
761 /* Now also set ebBIT_1, which should unblock the other task, which will
\r
762 then suspend itself. */
\r
763 xEventGroupSetBits( xEventGroup, ebBIT_1 );
\r
765 /* Ensure the other task is suspended. */
\r
766 if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
\r
771 /* The other task should not have cleared the bits - so all the bits
\r
772 should still be set. */
\r
773 if( xEventGroupSetBits( xEventGroup, 0x00 ) != ebALL_BITS )
\r
778 /* Clear ebBIT_1 again. */
\r
779 if( xEventGroupClearBits( xEventGroup, ebBIT_1 ) != ebALL_BITS )
\r
784 /* Resume the other task - which will wait on all the ebCOMBINED_BITS
\r
785 again - this time clearing the bits when it is unblocked. */
\r
786 vTaskResume( xTestSlaveTaskHandle );
\r
788 /* Ensure the other task is blocked once again. */
\r
789 if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
\r
794 /* Set the bit the other task is waiting for. */
\r
795 xEventGroupSetBits( xEventGroup, ebBIT_1 );
\r
797 /* Ensure the other task is suspended once again. */
\r
798 if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
\r
803 /* The other task should have cleared the bits in ebCOMBINED_BITS.
\r
804 Clear the remaining bits. */
\r
805 uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
\r
807 if( uxBits != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
\r
812 /* Clear all bits ready for the sync with the other three tasks. The
\r
813 value returned is the value prior to the bits being cleared. */
\r
814 if( xEventGroupClearBits( xEventGroup, ebALL_BITS ) != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
\r
819 /* The bits should be clear now. */
\r
820 if( xEventGroupGetBits( xEventGroup ) != 0x00 )
\r
827 /*-----------------------------------------------------------*/
\r
829 static void prvSelectiveBitsTestSlaveFunction( void )
\r
831 EventBits_t uxPendBits, uxReturned;
\r
833 /* Used in a test that blocks two tasks on various different bits within an
\r
834 event group - then sets each bit in turn and checks that the correct tasks
\r
835 unblock at the correct times.
\r
837 This function is called by two different tasks - each of which will use a
\r
838 different bit. Check the task handle to see which task the function was
\r
840 if( xTaskGetCurrentTaskHandle() == xSyncTask1 )
\r
842 uxPendBits = ebSELECTIVE_BITS_1;
\r
846 uxPendBits = ebSELECTIVE_BITS_2;
\r
851 /* Wait until it is time to perform the next cycle of the test. The
\r
852 task is unsuspended by the tests implemented in the
\r
853 prvSelectiveBitsTestMasterFunction() function. */
\r
854 vTaskSuspend( NULL );
\r
855 uxReturned = xEventGroupWaitBits( xEventGroup, uxPendBits, pdTRUE, pdFALSE, portMAX_DELAY );
\r
857 if( uxReturned == ( EventBits_t ) 0 )
\r
863 /*-----------------------------------------------------------*/
\r
865 static BaseType_t prvSelectiveBitsTestMasterFunction( void )
\r
867 BaseType_t xError = pdFALSE;
\r
870 /* Used in a test that blocks two tasks on various different bits within an
\r
871 event group - then sets each bit in turn and checks that the correct tasks
\r
872 unblock at the correct times. The two other tasks (xSyncTask1 and
\r
873 xSyncTask2) call prvSelectiveBitsTestSlaveFunction() to perform their parts in
\r
876 Both other tasks should start in the suspended state. */
\r
877 if( eTaskGetState( xSyncTask1 ) != eSuspended )
\r
882 if( eTaskGetState( xSyncTask2 ) != eSuspended )
\r
887 /* Test each bit in the byte individually. */
\r
888 for( uxBit = 0x01; uxBit < 0x100; uxBit <<= 1 )
\r
890 /* Resume both tasks. */
\r
891 vTaskResume( xSyncTask1 );
\r
892 vTaskResume( xSyncTask2 );
\r
894 /* Now both tasks should be blocked on the event group. */
\r
895 if( eTaskGetState( xSyncTask1 ) != eBlocked )
\r
900 if( eTaskGetState( xSyncTask2 ) != eBlocked )
\r
906 xEventGroupSetBits( xEventGroup, uxBit );
\r
908 /* Is the bit set in the first set of selective bits? If so the first
\r
909 sync task should have unblocked and returned to the suspended state. */
\r
910 if( ( uxBit & ebSELECTIVE_BITS_1 ) == 0 )
\r
912 /* Task should not have unblocked. */
\r
913 if( eTaskGetState( xSyncTask1 ) != eBlocked )
\r
920 /* Task should have unblocked and returned to the suspended state. */
\r
921 if( eTaskGetState( xSyncTask1 ) != eSuspended )
\r
927 /* Same checks for the second sync task. */
\r
928 if( ( uxBit & ebSELECTIVE_BITS_2 ) == 0 )
\r
930 /* Task should not have unblocked. */
\r
931 if( eTaskGetState( xSyncTask2 ) != eBlocked )
\r
938 /* Task should have unblocked and returned to the suspended state. */
\r
939 if( eTaskGetState( xSyncTask2 ) != eSuspended )
\r
946 /* Ensure both tasks are blocked on the event group again, then delete the
\r
947 event group so the other tasks leave this portion of the test. */
\r
948 vTaskResume( xSyncTask1 );
\r
949 vTaskResume( xSyncTask2 );
\r
951 /* Deleting the event group is the signal that the two other tasks should
\r
952 leave the prvSelectiveBitsTestSlaveFunction() function and continue to the main
\r
953 part of their functionality. */
\r
954 vEventGroupDelete( xEventGroup );
\r
958 /*-----------------------------------------------------------*/
\r
960 void vPeriodicEventGroupsProcessing( void )
\r
962 static BaseType_t xCallCount = 0, xISRTestError = pdFALSE;
\r
963 const BaseType_t xSetBitCount = 100, xGetBitsCount = 200, xClearBitsCount = 300;
\r
964 const EventBits_t uxBitsToSet = 0x12U;
\r
965 EventBits_t uxReturned;
\r
966 BaseType_t xMessagePosted;
\r
968 /* Called periodically from the tick hook to exercise the "FromISR"
\r
973 if( xCallCount == xSetBitCount )
\r
975 /* All the event bits should start clear. */
\r
976 uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
\r
977 if( uxReturned != 0x00 )
\r
979 xISRTestError = pdTRUE;
\r
983 /* Set the bits. This is called from the tick hook so it is not
\r
984 necessary to use the last parameter to ensure a context switch
\r
985 occurs immediately. */
\r
986 xMessagePosted = xEventGroupSetBitsFromISR( xISREventGroup, uxBitsToSet, NULL );
\r
987 if( xMessagePosted != pdPASS )
\r
989 xISRTestError = pdTRUE;
\r
993 else if( xCallCount == xGetBitsCount )
\r
995 /* Check the bits were set as expected. */
\r
996 uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
\r
997 if( uxReturned != uxBitsToSet )
\r
999 xISRTestError = pdTRUE;
\r
1002 else if( xCallCount == xClearBitsCount )
\r
1004 /* Clear the bits again. */
\r
1005 uxReturned = ( EventBits_t ) xEventGroupClearBitsFromISR( xISREventGroup, uxBitsToSet );
\r
1007 /* Check the message was posted. */
\r
1008 if( uxReturned != pdPASS )
\r
1010 xISRTestError = pdTRUE;
\r
1013 /* Go back to the start. */
\r
1016 /* If no errors have been detected then increment the count of test
\r
1018 if( xISRTestError == pdFALSE )
\r
1025 /* Nothing else to do. */
\r
1029 /*-----------------------------------------------------------*/
\r
1030 /* This is called to check that all the created tasks are still running. */
\r
1031 BaseType_t xAreEventGroupTasksStillRunning( void )
\r
1033 static uint32_t ulPreviousWaitBitCycles = 0, ulPreviousSetBitCycles = 0, ulPreviousISRCycles = 0;
\r
1034 BaseType_t xStatus = pdPASS;
\r
1036 /* Check the tasks are still cycling without finding any errors. */
\r
1037 if( ulPreviousSetBitCycles == ulTestMasterCycles )
\r
1041 ulPreviousSetBitCycles = ulTestMasterCycles;
\r
1043 if( ulPreviousWaitBitCycles == ulTestSlaveCycles )
\r
1047 ulPreviousWaitBitCycles = ulTestSlaveCycles;
\r
1049 if( ulPreviousISRCycles == ulISRCycles )
\r
1053 ulPreviousISRCycles = ulISRCycles;
\r