]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/TaskNotify.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / Common / Minimal / TaskNotify.c
index a1d1f35dcbe996f8097ddd614523a52fe9855d92..1afdde76083640c07c173f486fc6a36792a8fbbf 100644 (file)
@@ -1,71 +1,29 @@
 /*\r
-    FreeRTOS V9.0.0 - Copyright (C) 2016 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
-    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
-    ***************************************************************************\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
-\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 on the following\r
-    link: http://www.freertos.org/a00114.html\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that is more than just the market leader, it     *\r
-     *    is the industry's de facto standard.                               *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly while simultaneously helping     *\r
-     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
-     *    tutorial book, reference manual, or both:                          *\r
-     *    http://www.FreeRTOS.org/Documentation                              *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
-    the FAQ page "My application does not run, what could be wrong?".  Have you\r
-    defined configASSERT()?\r
-\r
-    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
-    embedded software for free we request you assist our global community by\r
-    participating in the support forum.\r
-\r
-    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
-    be as productive as possible as early as possible.  Now you can receive\r
-    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
-    Ltd, and the world's leading authority on the world's leading RTOS.\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.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
-    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
-\r
-    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
-    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and commercial 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.3.0\r
+ * Copyright (C) 2020 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
 /* Demo program include files. */\r
 #include "TaskNotify.h"\r
 \r
+/* Allow parameters to be overridden on a demo by demo basis. */\r
+#ifndef notifyNOTIFIED_TASK_STACK_SIZE\r
+       #define notifyNOTIFIED_TASK_STACK_SIZE configMINIMAL_STACK_SIZE\r
+#endif\r
+\r
 #define notifyTASK_PRIORITY            ( tskIDLE_PRIORITY )\r
-#define notifyUINT32_MAX       ( ( uint32_t ) 0xffffffff )\r
+\r
+/* Constants used in tests when setting/clearing bits. */\r
+#define notifyUINT32_MAX               ( ( uint32_t ) 0xffffffff )\r
+#define notifyUINT32_HIGH_BYTE ( ( uint32_t ) 0xff000000 )\r
+#define notifyUINT32_LOW_BYTE  ( ( uint32_t ) 0x000000ff )\r
+\r
 #define notifySUSPENDED_TEST_TIMER_PERIOD pdMS_TO_TICKS( 50 )\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -146,7 +114,12 @@ void vStartTaskNotifyTask( void  )
 {\r
        /* Create the task that performs some tests by itself, then loops around\r
        being notified by both a software timer and an interrupt. */\r
-       xTaskCreate( prvNotifiedTask, "Notified", configMINIMAL_STACK_SIZE, NULL, notifyTASK_PRIORITY, &xTaskToNotify );\r
+       xTaskCreate( prvNotifiedTask, /* Function that implements the task. */\r
+                                "Notified", /* Text name for the task - for debugging only - not used by the kernel. */\r
+                                notifyNOTIFIED_TASK_STACK_SIZE, /* Task's stack size in words, not bytes!. */\r
+                                NULL, /* Task parameter, not used in this case. */\r
+                                notifyTASK_PRIORITY, /* Task priority, 0 is the lowest. */\r
+                                &xTaskToNotify ); /* Used to pass a handle to the task out is needed, otherwise set to NULL. */\r
 \r
        /* Pseudo seed the random number generator. */\r
        uxNextRand = ( size_t ) prvRand;\r
@@ -168,6 +141,7 @@ TimerHandle_t xSingleTaskTimer;
        Check blocking when there are no notifications. */\r
        xTimeOnEntering = xTaskGetTickCount();\r
        xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
        /* Should have blocked for the entire block time. */\r
        if( ( xTaskGetTickCount() - xTimeOnEntering ) < xTicksToWait )\r
@@ -176,6 +150,8 @@ TimerHandle_t xSingleTaskTimer;
        }\r
        configASSERT( xReturned == pdFAIL );\r
        configASSERT( ulNotifiedValue == 0UL );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+       ( void ) ulNotifiedValue;\r
 \r
 \r
 \r
@@ -189,9 +165,11 @@ TimerHandle_t xSingleTaskTimer;
        /* Even through the 'without overwrite' action was used the update should\r
        have been successful. */\r
        configASSERT( xReturned == pdPASS );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
        /* No bits should have been pending previously. */\r
        configASSERT( ulPreviousValue == 0 );\r
+       ( void ) ulPreviousValue;\r
 \r
        /* The task should now have a notification pending, and so not time out. */\r
        xTimeOnEntering = xTaskGetTickCount();\r
@@ -206,6 +184,8 @@ TimerHandle_t xSingleTaskTimer;
        be equal to ulFirstNotifiedConst. */\r
        configASSERT( xReturned == pdPASS );\r
        configASSERT( ulNotifiedValue == ulFirstNotifiedConst );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+       ( void ) ulNotifiedValue;\r
 \r
        /* Incremented to show the task is still running. */\r
        ulNotifyCycleCount++;\r
@@ -221,9 +201,11 @@ TimerHandle_t xSingleTaskTimer;
        be that used with the first notification. */\r
        xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite );\r
        configASSERT( xReturned == pdPASS );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
        xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithoutOverwrite );\r
        configASSERT( xReturned == pdFAIL );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
        /* Waiting for the notification should now return immediately so a block\r
        time of zero is used. */\r
@@ -231,6 +213,8 @@ TimerHandle_t xSingleTaskTimer;
 \r
        configASSERT( xReturned == pdPASS );\r
        configASSERT( ulNotifiedValue == ulFirstNotifiedConst );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+       ( void ) ulNotifiedValue;\r
 \r
 \r
 \r
@@ -243,11 +227,15 @@ TimerHandle_t xSingleTaskTimer;
        back. */\r
        xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithOverwrite );\r
        configASSERT( xReturned == pdPASS );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
        xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithOverwrite );\r
        configASSERT( xReturned == pdPASS );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
        xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdPASS );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
        configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );\r
+       ( void ) ulNotifiedValue;\r
 \r
 \r
 \r
@@ -258,8 +246,10 @@ TimerHandle_t xSingleTaskTimer;
        remain at ulSecondNotifiedConst. */\r
        xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eNoAction );\r
        configASSERT( xReturned == pdPASS );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
        xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
        configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );\r
+       ( void ) ulNotifiedValue; /* In case configASSERT() is not defined. */\r
 \r
 \r
 \r
@@ -272,15 +262,20 @@ TimerHandle_t xSingleTaskTimer;
        {\r
                xReturned = xTaskNotify( xTaskToNotify, 0, eIncrement );\r
                configASSERT( xReturned == pdPASS );\r
+               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
        }\r
 \r
        xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdPASS );\r
        configASSERT( ulNotifiedValue == ( ulSecondNotifiedValueConst + ulMaxLoops ) );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+       ( void ) ulNotifiedValue;\r
 \r
        /* Should not be any notifications pending now. */\r
        xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdFAIL );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+       ( void ) ulNotifiedValue;\r
 \r
 \r
 \r
@@ -306,6 +301,7 @@ TimerHandle_t xSingleTaskTimer;
                when all the bits are set. */\r
                xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );\r
                configASSERT( xReturned == pdPASS );\r
+               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
                ulLoop++;\r
 \r
@@ -330,6 +326,7 @@ TimerHandle_t xSingleTaskTimer;
        entry should actually get cleared. */\r
        xReturned = xTaskNotifyWait( ulBit0, ulBit1, &ulNotifiedValue, xTicksToWait );\r
        configASSERT( xReturned == pdFAIL );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
        /* Notify the task with no action so as not to update the bits even though\r
        notifyUINT32_MAX is used as the notification value. */\r
@@ -341,6 +338,7 @@ TimerHandle_t xSingleTaskTimer;
        xReturned = xTaskNotifyWait( 0x00UL, 0x00UL, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdPASS );\r
        configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
 \r
 \r
@@ -363,6 +361,7 @@ TimerHandle_t xSingleTaskTimer;
        xReturned = xTaskNotifyWait( 0x00, 0x00, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdFAIL );\r
        configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
 \r
 \r
@@ -409,6 +408,37 @@ TimerHandle_t xSingleTaskTimer;
 \r
 \r
 \r
+       /* ------------------------------------------------------------------------\r
+       Clear bits in the notification value. */\r
+\r
+       /* Get the task to set all bits its own notification value.  This is not a\r
+       normal thing to do, and is only done here for test purposes. */\r
+       xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eSetBits );\r
+\r
+       /* Now clear the top bytes - the returned value from the first call should\r
+       indicate that previously all bits were set. */\r
+       configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_HIGH_BYTE ) == notifyUINT32_MAX );\r
+\r
+       /* Next clear the bottom bytes - the returned value this time should indicate\r
+       that the top byte was clear (before the bottom byte was cleared. */\r
+       configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_LOW_BYTE ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE ) );\r
+\r
+       /* Next clear all bytes - the returned value should indicate that previously the\r
+       high and low bytes were clear. */\r
+       configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE & ~notifyUINT32_LOW_BYTE ) );\r
+\r
+       /* Now all bits should be clear. */\r
+       configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );\r
+       configASSERT( ulTaskNotifyValueClear( xTaskToNotify, 0UL ) == 0 );\r
+       configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );\r
+\r
+       /* Now the notification state should be eNotified, so it should now be\r
+       possible to clear the notification state. */\r
+       configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );\r
+       configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );\r
+\r
+\r
+\r
        /* ------------------------------------------------------------------------\r
        Create a timer that will try notifying this task while it is suspended. */\r
        xSingleTaskTimer = xTimerCreate( "SingleNotify", notifySUSPENDED_TEST_TIMER_PERIOD, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );\r
@@ -435,6 +465,7 @@ TimerHandle_t xSingleTaskTimer;
        xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );\r
        configASSERT( xReturned == pdFALSE );\r
        configASSERT( ulNotifiedValue == 0 );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
 \r
        /* Incremented to show the task is still running. */\r
        ulNotifyCycleCount++;\r
@@ -448,6 +479,7 @@ TimerHandle_t xSingleTaskTimer;
        /* Check a notification is received. */\r
        xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );\r
        configASSERT( xReturned == pdPASS );\r
+       ( void ) xReturned; /* In case configASSERT() is not defined. */\r
        configASSERT( ulNotifiedValue != 0 );\r
 \r
        /* Return the task to its proper priority and delete the timer as it is\r
@@ -613,6 +645,9 @@ const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );
 uint32_t ulPreviousValue;\r
 const uint32_t ulUnexpectedValue = 0xff;\r
 \r
+       /* Check the task notification demo tasks were actually created. */\r
+       configASSERT( xTaskToNotify );\r
+\r
        /* The task performs some tests before starting the timer that gives the\r
        notification from this interrupt.  If the timer has not been created yet\r
        then the initial tests have not yet completed and the notification should\r