]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c
Add some asserts into the common demo tasks to catch scenarios where the tasks are...
[freertos] / FreeRTOS / Demo / Common / Minimal / EventGroupsDemo.c
index 1db774ac4b13ece47bb03c766d953765b601ceae..21b2d7769da04b53297b599e5e105c6593da26ab 100644 (file)
@@ -1,67 +1,29 @@
 /*\r
-    FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
-    All rights reserved\r
-\r
-    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that has become a de facto standard.             *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly and support the FreeRTOS         *\r
-     *    project by purchasing a FreeRTOS tutorial book, reference          *\r
-     *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
-     *                                                                       *\r
-     *    Thank you!                                                         *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    This file is part of the FreeRTOS distribution.\r
-\r
-    FreeRTOS is free software; you can redistribute it and/or modify it under\r
-    the terms of the GNU General Public License (version 2) as published by the\r
-    Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
-\r
-    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
-    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
-    >>!   obliged to provide the source code for proprietary components     !<<\r
-    >>!   outside of the FreeRTOS kernel.                                   !<<\r
-\r
-    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
-    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
-    FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
-    link: http://www.freertos.org/a00114.html\r
-\r
-    1 tab == 4 spaces!\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    Having a problem?  Start by reading the FAQ "My application does   *\r
-     *    not run, what could be wrong?"                                     *\r
-     *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
-\r
-    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
-    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
-    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
-\r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
-    Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and middleware.\r
-\r
-    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
-    engineered and independently SIL3 certified version for use in safety and\r
-    mission critical applications that require provable dependability.\r
-\r
-    1 tab == 4 spaces!\r
-*/\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
 \r
 \r
 \r
 #define ebWAIT_BIT_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
 \r
 /* Generic bit definitions. */\r
-#define ebBIT_0                ( 0x01UL )\r
-#define ebBIT_1                ( 0x02UL )\r
-#define ebBIT_2                ( 0x04UL )\r
-#define ebBIT_3                ( 0x08UL )\r
-#define ebBIT_4                ( 0x10UL )\r
-#define ebBIT_5                ( 0x20UL )\r
-#define ebBIT_6                ( 0x40UL )\r
-#define ebBIT_7                ( 0x80UL )\r
+#define ebBIT_0                ( 0x01 )\r
+#define ebBIT_1                ( 0x02 )\r
+#define ebBIT_2                ( 0x04 )\r
+#define ebBIT_3                ( 0x08 )\r
+#define ebBIT_4                ( 0x10 )\r
+#define ebBIT_5                ( 0x20 )\r
+#define ebBIT_6                ( 0x40 )\r
+#define ebBIT_7                ( 0x80 )\r
 \r
 /* Combinations of bits used in the demo. */\r
 #define ebCOMBINED_BITS ( ebBIT_1 | ebBIT_5 | ebBIT_7 )\r
@@ -116,15 +78,24 @@ that synchronise with the xEventGroupSync() function. */
 \r
 /* A block time of zero simply means "don't block". */\r
 #define ebDONT_BLOCK   ( 0 )\r
+#define ebONE_TICK             ( ( TickType_t ) 1 )\r
 \r
 /* A 5ms delay. */\r
-#define ebSHORT_DELAY  ( 5 / portTICK_PERIOD_MS )\r
+#define ebSHORT_DELAY  pdMS_TO_TICKS( ( TickType_t ) 5 )\r
 \r
 /* Used in the selective bits test which checks no, one or both tasks blocked on\r
 event bits in a group are unblocked as appropriate as different bits get set. */\r
 #define ebSELECTIVE_BITS_1             0x03\r
 #define ebSELECTIVE_BITS_2             0x05\r
 \r
+#ifndef ebRENDESVOUS_TEST_TASK_STACK_SIZE\r
+       #define ebRENDESVOUS_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE\r
+#endif\r
+\r
+#ifndef ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE\r
+       #define ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE     configMINIMAL_STACK_SIZE\r
+#endif\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -216,10 +187,10 @@ TaskHandle_t xTestSlaveTaskHandle;
         *\r
         * Create the test tasks as described at the top of this file.\r
         */\r
-       xTaskCreate( prvTestSlaveTask, "WaitO", configMINIMAL_STACK_SIZE, NULL, ebWAIT_BIT_TASK_PRIORITY, &xTestSlaveTaskHandle );\r
-       xTaskCreate( prvTestMasterTask, "SetB", configMINIMAL_STACK_SIZE, ( void * ) xTestSlaveTaskHandle, ebSET_BIT_TASK_PRIORITY, NULL );\r
-       xTaskCreate( prvSyncTask, "Rndv", configMINIMAL_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_1_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask1 );\r
-       xTaskCreate( prvSyncTask, "Rndv", configMINIMAL_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_2_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask2 );\r
+       xTaskCreate( prvTestSlaveTask, "WaitO", ebRENDESVOUS_TEST_TASK_STACK_SIZE, NULL, ebWAIT_BIT_TASK_PRIORITY, &xTestSlaveTaskHandle );\r
+       xTaskCreate( prvTestMasterTask, "SetB", ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE, ( void * ) xTestSlaveTaskHandle, ebSET_BIT_TASK_PRIORITY, NULL );\r
+       xTaskCreate( prvSyncTask, "Rndv", ebRENDESVOUS_TEST_TASK_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_1_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask1 );\r
+       xTaskCreate( prvSyncTask, "Rndv", ebRENDESVOUS_TEST_TASK_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_2_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask2 );\r
 \r
        /* If the last task was created then the others will have been too. */\r
        configASSERT( xSyncTask2 );\r
@@ -319,7 +290,29 @@ EventBits_t uxSynchronisationBit, uxReturned;
                /* Set the bit that indicates this task is at the synchronisation\r
                point.  The first time this is done the 'test master' task has a lower\r
                priority than this task so this task will get to the sync point before\r
-               the set bits task. */\r
+               the set bits task - test this by first calling xEventGroupSync() with\r
+               a zero block time, and a block time that is too short for the other\r
+               task, before calling again with a max delay - the first two calls should\r
+               return before the rendezvous completes, the third only after the\r
+               rendezvous is complete. */\r
+               uxReturned = xEventGroupSync( xEventGroup,      /* The event group used for the synchronisation. */\r
+                                                                         uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */\r
+                                                                         ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */\r
+                                                                         ebDONT_BLOCK ); /* The maximum time to wait for the sync condition to be met before giving up. */\r
+\r
+               /* No block time was specified, so as per the comments above, the\r
+               rendezvous is not expected to have completed yet. */\r
+               configASSERT( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS );\r
+\r
+               uxReturned = xEventGroupSync( xEventGroup,      /* The event group used for the synchronisation. */\r
+                                                                         uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */\r
+                                                                         ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks taking part in the sync. */\r
+                                                                         ebONE_TICK ); /* The maximum time to wait for the sync condition to be met before giving up. */\r
+\r
+               /* A short block time was specified, so as per the comments above, the\r
+               rendezvous is not expected to have completed yet. */\r
+               configASSERT( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS );\r
+\r
                uxReturned = xEventGroupSync( xEventGroup,      /* The event group used for the synchronisation. */\r
                                                                        uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */\r
                                                                        ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */\r
@@ -983,6 +976,9 @@ BaseType_t xMessagePosted;
        /* Called periodically from the tick hook to exercise the "FromISR"\r
        functions. */\r
 \r
+       /* Check the even group tasks were actually created. */\r
+       configASSERT( xISREventGroup );\r
+\r
        xCallCount++;\r
 \r
        if( xCallCount == xSetBitCount )\r
@@ -1017,7 +1013,7 @@ BaseType_t xMessagePosted;
        else if( xCallCount == xClearBitsCount )\r
        {\r
                /* Clear the bits again. */\r
-               uxReturned = xEventGroupClearBitsFromISR( xISREventGroup, uxBitsToSet );\r
+               uxReturned = ( EventBits_t ) xEventGroupClearBitsFromISR( xISREventGroup, uxBitsToSet );\r
 \r
                /* Check the message was posted. */\r
                if( uxReturned != pdPASS )\r