]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/TaskNotify.c
Update TaskNotify.c to test the condition where a direct to task notification is...
[freertos] / FreeRTOS / Demo / Common / Minimal / TaskNotify.c
index c06d9822b1cb8f62a2776411b60f0a8935364310..a1d1f35dcbe996f8097ddd614523a52fe9855d92 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\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
@@ -8,7 +8,7 @@
 \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
+    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
@@ -84,6 +84,8 @@
 #include "TaskNotify.h"\r
 \r
 #define notifyTASK_PRIORITY            ( tskIDLE_PRIORITY )\r
+#define notifyUINT32_MAX       ( ( uint32_t ) 0xffffffff )\r
+#define notifySUSPENDED_TEST_TIMER_PERIOD pdMS_TO_TICKS( 50 )\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -108,6 +110,14 @@ static void prvNotifyingTimer( TimerHandle_t xTimer );
  */\r
 static UBaseType_t prvRand( void );\r
 \r
+/*\r
+ * Callback for a timer that is used during preliminary testing.  The timer\r
+ * tests the behaviour when 1: a task waiting for a notification is suspended\r
+ * and then resumed without ever receiving a notification, and 2: when a task\r
+ * waiting for a notification receives a notification while it is suspended.\r
+ */\r
+static void prvSuspendedTaskTimerTestCallback( TimerHandle_t xExpiredTimer );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /* Used to latch errors during the test's execution. */\r
@@ -128,7 +138,7 @@ static uint32_t ulTimerNotificationsReceived = 0UL, ulTimerNotificationsSent = 0
 static TimerHandle_t xTimer = NULL;\r
 \r
 /* Used by the pseudo random number generating function. */\r
-static uint32_t ulNextRand = 0;\r
+static size_t uxNextRand = 0;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -139,7 +149,7 @@ void vStartTaskNotifyTask( void  )
        xTaskCreate( prvNotifiedTask, "Notified", configMINIMAL_STACK_SIZE, NULL, notifyTASK_PRIORITY, &xTaskToNotify );\r
 \r
        /* Pseudo seed the random number generator. */\r
-       ulNextRand = ( uint32_t ) prvRand;\r
+       uxNextRand = ( size_t ) prvRand;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -151,11 +161,13 @@ uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedV
 TickType_t xTimeOnEntering;\r
 const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;\r
 const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;\r
+TimerHandle_t xSingleTaskTimer;\r
+\r
 \r
-       /* -------------------------------------------------------------------------\r
+       /* ------------------------------------------------------------------------\r
        Check blocking when there are no notifications. */\r
        xTimeOnEntering = xTaskGetTickCount();\r
-       xReturned = xTaskNotifyWait( ULONG_MAX, 0, &ulNotifiedValue, xTicksToWait );\r
+       xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );\r
 \r
        /* Should have blocked for the entire block time. */\r
        if( ( xTaskGetTickCount() - xTimeOnEntering ) < xTicksToWait )\r
@@ -168,7 +180,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /* -------------------------------------------------------------------------\r
+       /* ------------------------------------------------------------------------\r
        Check no blocking when notifications are pending.  First notify itself -\r
        this would not be a normal thing to do and is done here for test purposes\r
        only. */\r
@@ -183,7 +195,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
        /* The task should now have a notification pending, and so not time out. */\r
        xTimeOnEntering = xTaskGetTickCount();\r
-       xReturned = xTaskNotifyWait( ULONG_MAX, 0, &ulNotifiedValue, xTicksToWait );\r
+       xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );\r
 \r
        if( ( xTaskGetTickCount() - xTimeOnEntering ) >= xTicksToWait )\r
        {\r
@@ -202,7 +214,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check the non-overwriting functionality.  The notification is done twice\r
        using two different notification values.  The action says don't overwrite so\r
        only the first notification should pass and the value read back should also\r
@@ -215,7 +227,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
        /* Waiting for the notification should now return immediately so a block\r
        time of zero is used. */\r
-       xReturned = xTaskNotifyWait( ULONG_MAX, 0, &ulNotifiedValue, 0 );\r
+       xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
 \r
        configASSERT( xReturned == pdPASS );\r
        configASSERT( ulNotifiedValue == ulFirstNotifiedConst );\r
@@ -224,7 +236,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Do the same again, only this time use the overwriting version.  This time\r
        both notifications should pass, and the value written the second time should\r
        overwrite the value written the first time, and so be the value that is read\r
@@ -233,26 +245,26 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
        configASSERT( xReturned == pdPASS );\r
        xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithOverwrite );\r
        configASSERT( xReturned == pdPASS );\r
-       xReturned = xTaskNotifyWait( ULONG_MAX, 0, &ulNotifiedValue, 0 );\r
+       xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdPASS );\r
        configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );\r
 \r
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check notifications with no action pass without updating the value.  Even\r
        though ulFirstNotifiedConst is used as the value the value read back should\r
        remain at ulSecondNotifiedConst. */\r
        xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eNoAction );\r
        configASSERT( xReturned == pdPASS );\r
-       xReturned = xTaskNotifyWait( ULONG_MAX, 0, &ulNotifiedValue, 0 );\r
+       xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
        configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );\r
 \r
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check incrementing values.  Send ulMaxLoop increment notifications, then\r
        ensure the received value is as expected - which should be\r
        ulSecondNotificationValueConst plus how ever many times to loop iterated. */\r
@@ -262,7 +274,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
                configASSERT( xReturned == pdPASS );\r
        }\r
 \r
-       xReturned = xTaskNotifyWait( ULONG_MAX, 0, &ulNotifiedValue, 0 );\r
+       xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdPASS );\r
        configASSERT( ulNotifiedValue == ( ulSecondNotifiedValueConst + ulMaxLoops ) );\r
 \r
@@ -273,7 +285,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check all bits can be set by notifying the task with one additional bit set\r
        on each notification, and exiting the loop when all the bits are found to be\r
        set.  As there are 32-bits the loop should execute 32 times before all the\r
@@ -282,7 +294,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
        ulLoop = 0;\r
 \r
        /* Start with all bits clear. */\r
-       xTaskNotifyWait( ULONG_MAX, 0, &ulNotifiedValue, 0 );\r
+       xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
 \r
        do\r
        {\r
@@ -300,7 +312,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
                /* Use the next bit on the next iteration around this loop. */\r
                ulNotifyingValue <<= 1UL;\r
 \r
-       } while ( ulNotifiedValue != ULONG_MAX );\r
+       } while ( ulNotifiedValue != notifyUINT32_MAX );\r
 \r
        /* As a 32-bit value was used the loop should have executed 32 times before\r
        all the bits were set. */\r
@@ -309,7 +321,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check bits are cleared on entry but not on exit when a notification fails\r
        to arrive before timing out - both with and without a timeout value.  Wait\r
        for the notification again - but this time it is not given by anything and\r
@@ -320,21 +332,21 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
        configASSERT( xReturned == pdFAIL );\r
 \r
        /* Notify the task with no action so as not to update the bits even though\r
-       ULONG_MAX is used as the notification value. */\r
-       xTaskNotify( xTaskToNotify, ULONG_MAX, eNoAction );\r
+       notifyUINT32_MAX is used as the notification value. */\r
+       xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eNoAction );\r
 \r
        /* Reading back the value should should find bit 0 is clear, as this was\r
        cleared on entry, but bit 1 is not clear as it will not have been cleared on\r
        exit as no notification was received. */\r
        xReturned = xTaskNotifyWait( 0x00UL, 0x00UL, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdPASS );\r
-       configASSERT( ulNotifiedValue == ( ULONG_MAX & ~ulBit0 ) );\r
+       configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );\r
 \r
 \r
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Now try clearing the bit on exit.  For that to happen a notification must be\r
        received, so the task is notified first. */\r
        xTaskNotify( xTaskToNotify, 0, eNoAction );\r
@@ -343,25 +355,25 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
        /* However as the bit is cleared on exit, after the returned notification\r
        value is set, the returned notification value should not have the bit\r
        cleared... */\r
-       configASSERT( ulNotifiedValue == ( ULONG_MAX & ~ulBit0 ) );\r
+       configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );\r
 \r
        /* ...but reading the value back again should find that the bit was indeed\r
        cleared internally.  The returned value should be pdFAIL however as nothing\r
        has notified the task in the mean time. */\r
        xReturned = xTaskNotifyWait( 0x00, 0x00, &ulNotifiedValue, 0 );\r
        configASSERT( xReturned == pdFAIL );\r
-       configASSERT( ulNotifiedValue == ( ULONG_MAX & ~( ulBit0 | ulBit1 ) ) );\r
+       configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );\r
 \r
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
-       Now try querying the previus value while notifying a task. */\r
+       /*-------------------------------------------------------------------------\r
+       Now try querying the previous value while notifying a task. */\r
        xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );\r
-       configASSERT( ulNotifiedValue == ( ULONG_MAX & ~( ulBit0 | ulBit1 ) ) );\r
+       configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );\r
 \r
        /* Clear all bits. */\r
-       xTaskNotifyWait( 0x00, ULONG_MAX, &ulNotifiedValue, 0 );\r
+       xTaskNotifyWait( 0x00, notifyUINT32_MAX, &ulNotifiedValue, 0 );\r
        xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );\r
        configASSERT( ulPreviousValue == 0 );\r
 \r
@@ -376,11 +388,115 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
                ulExpectedValue |= ulLoop;\r
        }\r
 \r
+\r
+\r
+       /* ------------------------------------------------------------------------\r
+       Clear the previous notifications. */\r
+       xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
+\r
+       /* The task should not have any notifications pending, so an attempt to clear\r
+       the notification state should fail. */\r
+       configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );\r
+\r
+       /* Get the task to notify itself.  This is not a normal thing to do, and is\r
+       only done here for test purposes. */\r
+       xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );\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
+       configASSERT( xSingleTaskTimer );\r
+\r
+       /* Incremented to show the task is still running. */\r
+       ulNotifyCycleCount++;\r
+\r
+       /* Ensure no notifications are pending. */\r
+       xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );\r
+\r
+       /* Raise the task's priority so it can suspend itself before the timer\r
+       expires. */\r
+       vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );\r
+\r
+       /* Start the timer that will try notifying this task while it is\r
+       suspended, then wait for a notification.  The first time the callback\r
+       executes the timer will suspend the task, then resume the task, without\r
+       ever sending a notification to the task. */\r
+       ulNotifiedValue = 0;\r
+       xTimerStart( xSingleTaskTimer, portMAX_DELAY );\r
+\r
+       /* Check a notification is not received. */\r
+       xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );\r
+       configASSERT( xReturned == pdFALSE );\r
+       configASSERT( ulNotifiedValue == 0 );\r
+\r
+       /* Incremented to show the task is still running. */\r
+       ulNotifyCycleCount++;\r
+\r
+       /* Start the timer that will try notifying this task while it is\r
+       suspended, then wait for a notification.  The second time the callback\r
+       executes the timer will suspend the task, notify the task, then resume the\r
+       task (previously it was suspended and resumed without being notified). */\r
+       xTimerStart( xSingleTaskTimer, portMAX_DELAY );\r
+\r
+       /* Check a notification is received. */\r
+       xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );\r
+       configASSERT( xReturned == pdPASS );\r
+       configASSERT( ulNotifiedValue != 0 );\r
+\r
+       /* Return the task to its proper priority and delete the timer as it is\r
+       not used again. */\r
+       vTaskPrioritySet( NULL, notifyTASK_PRIORITY );\r
+       xTimerDelete( xSingleTaskTimer, portMAX_DELAY );\r
+\r
        /* Incremented to show the task is still running. */\r
        ulNotifyCycleCount++;\r
 \r
        /* Leave all bits cleared. */\r
-       xTaskNotifyWait( ULONG_MAX, 0, NULL, 0 );\r
+       xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvSuspendedTaskTimerTestCallback( TimerHandle_t xExpiredTimer )\r
+{\r
+static uint32_t ulCallCount = 0;\r
+\r
+       /* Remove compiler warnings about unused parameters. */\r
+       ( void ) xExpiredTimer;\r
+\r
+       /* Callback for a timer that is used during preliminary testing.  The timer\r
+       tests the behaviour when 1: a task waiting for a notification is suspended\r
+       and then resumed without ever receiving a notification, and 2: when a task\r
+       waiting for a notification receives a notification while it is suspended. */\r
+\r
+       if( ulCallCount == 0 )\r
+       {\r
+               vTaskSuspend( xTaskToNotify );\r
+               configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );\r
+               vTaskResume( xTaskToNotify );\r
+       }\r
+       else\r
+       {\r
+               vTaskSuspend( xTaskToNotify );\r
+\r
+               /* Sending a notification while the task is suspended should pass, but\r
+               not cause the task to resume.  ulCallCount is just used as a convenient\r
+               non-zero value. */\r
+               xTaskNotify( xTaskToNotify, ulCallCount, eSetValueWithOverwrite );\r
+\r
+               /* Make sure giving the notification didn't resume the task. */\r
+               configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );\r
+\r
+               vTaskResume( xTaskToNotify );\r
+       }\r
+\r
+       ulCallCount++;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -403,6 +519,7 @@ static void prvNotifiedTask( void *pvParameters )
 {\r
 const TickType_t xMaxPeriod = pdMS_TO_TICKS( 90 ), xMinPeriod = pdMS_TO_TICKS( 10 ), xDontBlock = 0;\r
 TickType_t xPeriod;\r
+const uint32_t ulCyclesToRaisePriority = 50UL;\r
 \r
        /* Remove compiler warnings about unused parameters. */\r
        ( void ) pvParameters;\r
@@ -418,20 +535,20 @@ TickType_t xPeriod;
        for( ;; )\r
        {\r
                /* Start the timer again with a different period.  Sometimes the period\r
-               will be higher than the tasks block time, sometimes it will be lower\r
-               than the tasks block time. */\r
+               will be higher than the task's block time, sometimes it will be lower\r
+               than the task's block time. */\r
                xPeriod = prvRand() % xMaxPeriod;\r
                if( xPeriod < xMinPeriod )\r
                {\r
                        xPeriod = xMinPeriod;\r
                }\r
 \r
+               /* Change the timer period and start the timer. */\r
                xTimerChangePeriod( xTimer, xPeriod, portMAX_DELAY );\r
-               xTimerStart( xTimer, portMAX_DELAY );\r
 \r
                /* Block waiting for the notification again with a different period.\r
-               Sometimes the period will be higher than the tasks block time, sometimes\r
-               it will be lower than the tasks block time. */\r
+               Sometimes the period will be higher than the task's block time,\r
+               sometimes it will be lower than the task's block time. */\r
                xPeriod = prvRand() % xMaxPeriod;\r
                if( xPeriod < xMinPeriod )\r
                {\r
@@ -460,9 +577,28 @@ TickType_t xPeriod;
                the function call. */\r
                ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, xPeriod );\r
 \r
-               /* Wait for the next notification again, clearing all notifications if\r
-               one is received, but this time blocking indefinitely. */\r
-               ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
+               /* Occasionally raise the priority of the task being notified to test\r
+               the path where the task is notified from an ISR and becomes the highest\r
+               priority ready state task, but the pxHigherPriorityTaskWoken parameter\r
+               is NULL (which it is in the tick hook that sends notifications to this\r
+               task). */\r
+               if( ( ulNotifyCycleCount % ulCyclesToRaisePriority ) == 0 )\r
+               {\r
+                       vTaskPrioritySet( xTaskToNotify, configMAX_PRIORITIES - 1 );\r
+\r
+                       /* Wait for the next notification again, clearing all notifications\r
+                       if one is received, but this time blocking indefinitely. */\r
+                       ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
+\r
+                       /* Reset the priority. */\r
+                       vTaskPrioritySet( xTaskToNotify, notifyTASK_PRIORITY );\r
+               }\r
+               else\r
+               {\r
+                       /* Wait for the next notification again, clearing all notifications\r
+                       if one is received, but this time blocking indefinitely. */\r
+                       ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
+               }\r
 \r
                /* Incremented to show the task is still running. */\r
                ulNotifyCycleCount++;\r
@@ -472,8 +608,10 @@ TickType_t xPeriod;
 \r
 void xNotifyTaskFromISR( void )\r
 {\r
-static BaseType_t xCallCount = 0;\r
+static BaseType_t xCallCount = 0, xAPIToUse = 0;\r
 const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );\r
+uint32_t ulPreviousValue;\r
+const uint32_t ulUnexpectedValue = 0xff;\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
@@ -488,7 +626,28 @@ const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );
                        /* It is time to 'give' the notification again. */\r
                        xCallCount = 0;\r
 \r
-                       vTaskNotifyGiveFromISR( xTaskToNotify, NULL );\r
+                       /* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR()\r
+                       and xTaskNotifyAndQueryFromISR(). */\r
+                       switch( xAPIToUse )\r
+                       {\r
+                               case 0: vTaskNotifyGiveFromISR( xTaskToNotify, NULL );\r
+                                               xAPIToUse++;\r
+                                               break;\r
+\r
+                               case 1: xTaskNotifyFromISR( xTaskToNotify, 0, eIncrement, NULL );\r
+                                               xAPIToUse++;\r
+                                               break;\r
+\r
+                               case 2: ulPreviousValue = ulUnexpectedValue;\r
+                                               xTaskNotifyAndQueryFromISR( xTaskToNotify, 0, eIncrement, &ulPreviousValue, NULL );\r
+                                               configASSERT( ulPreviousValue != ulUnexpectedValue );\r
+                                               xAPIToUse = 0;\r
+                                               break;\r
+\r
+                               default:/* Should never get here!. */\r
+                                               break;\r
+                       }\r
+\r
                        ulTimerNotificationsSent++;\r
                }\r
        }\r
@@ -515,7 +674,7 @@ const uint32_t ulMaxSendReceiveDeviation = 5UL;
 \r
        /* Check the count of 'takes' from the software timer is keeping track with\r
        the amount of 'gives'. */\r
-       if( ulTimerNotificationsSent > ulTimerNotificationsSent )\r
+       if( ulTimerNotificationsSent > ulTimerNotificationsReceived )\r
        {\r
                if( ( ulTimerNotificationsSent - ulTimerNotificationsReceived ) > ulMaxSendReceiveDeviation )\r
                {\r
@@ -529,10 +688,10 @@ const uint32_t ulMaxSendReceiveDeviation = 5UL;
 \r
 static UBaseType_t prvRand( void )\r
 {\r
-const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;\r
+const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;\r
 \r
        /* Utility function to generate a pseudo random number. */\r
-       ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;\r
-       return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );\r
+       uxNextRand = ( uxMultiplier * uxNextRand ) + uxIncrement;\r
+       return( ( uxNextRand >> 16 ) & ( ( size_t ) 0x7fff ) );\r
 }\r
 /*-----------------------------------------------------------*/\r