]> begriffs open source - cmsis-freertos/blob - Demo/Common/Minimal/TaskNotify.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / Common / Minimal / TaskNotify.c
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70
71 /*
72  * Tests the behaviour of direct task notifications.
73  */
74
75 /* Standard includes. */
76 #include <limits.h>
77
78 /* Scheduler include files. */
79 #include "FreeRTOS.h"
80 #include "task.h"
81 #include "timers.h"
82
83 /* Demo program include files. */
84 #include "TaskNotify.h"
85
86 #define notifyTASK_PRIORITY             ( tskIDLE_PRIORITY )
87 #define notifyUINT32_MAX        ( ( uint32_t ) 0xffffffff )
88 /*-----------------------------------------------------------*/
89
90 /*
91  * Implementation of the task that gets notified.
92  */
93 static void prvNotifiedTask( void *pvParameters );
94
95 /*
96  * Performs a few initial tests that can be done prior to creating the second
97  * task.
98  */
99 static void prvSingleTaskTests( void );
100
101 /*
102  * Software timer callback function from which xTaskNotify() is called.
103  */
104 static void prvNotifyingTimer( TimerHandle_t xTimer );
105
106 /*
107  * Utility function to create pseudo random numbers.
108  */
109 static UBaseType_t prvRand( void );
110
111 /*-----------------------------------------------------------*/
112
113 /* Used to latch errors during the test's execution. */
114 static BaseType_t xErrorStatus = pdPASS;
115
116 /* Used to ensure the task has not stalled. */
117 static volatile uint32_t ulNotifyCycleCount = 0;
118
119 /* The handle of the task that receives the notifications. */
120 static TaskHandle_t xTaskToNotify = NULL;
121
122 /* Used to count the notifications sent to the task from a software timer and
123 the number of notifications received by the task from the software timer.  The
124 two should stay synchronised. */
125 static uint32_t ulTimerNotificationsReceived = 0UL, ulTimerNotificationsSent = 0UL;
126
127 /* The timer used to notify the task. */
128 static TimerHandle_t xTimer = NULL;
129
130 /* Used by the pseudo random number generating function. */
131 static size_t uxNextRand = 0;
132
133 /*-----------------------------------------------------------*/
134
135 void vStartTaskNotifyTask( void  )
136 {
137         /* Create the task that performs some tests by itself, then loops around
138         being notified by both a software timer and an interrupt. */
139         xTaskCreate( prvNotifiedTask, "Notified", configMINIMAL_STACK_SIZE, NULL, notifyTASK_PRIORITY, &xTaskToNotify );
140
141         /* Pseudo seed the random number generator. */
142         uxNextRand = ( size_t ) prvRand;
143 }
144 /*-----------------------------------------------------------*/
145
146 static void prvSingleTaskTests( void )
147 {
148 const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
149 BaseType_t xReturned;
150 uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
151 TickType_t xTimeOnEntering;
152 const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
153 const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
154
155         /* -------------------------------------------------------------------------
156         Check blocking when there are no notifications. */
157         xTimeOnEntering = xTaskGetTickCount();
158         xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
159
160         /* Should have blocked for the entire block time. */
161         if( ( xTaskGetTickCount() - xTimeOnEntering ) < xTicksToWait )
162         {
163                 xErrorStatus = pdFAIL;
164         }
165         configASSERT( xReturned == pdFAIL );
166         configASSERT( ulNotifiedValue == 0UL );
167
168
169
170
171         /* -------------------------------------------------------------------------
172         Check no blocking when notifications are pending.  First notify itself -
173         this would not be a normal thing to do and is done here for test purposes
174         only. */
175         xReturned = xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
176
177         /* Even through the 'without overwrite' action was used the update should
178         have been successful. */
179         configASSERT( xReturned == pdPASS );
180
181         /* No bits should have been pending previously. */
182         configASSERT( ulPreviousValue == 0 );
183
184         /* The task should now have a notification pending, and so not time out. */
185         xTimeOnEntering = xTaskGetTickCount();
186         xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
187
188         if( ( xTaskGetTickCount() - xTimeOnEntering ) >= xTicksToWait )
189         {
190                 xErrorStatus = pdFAIL;
191         }
192
193         /* The task should have been notified, and the notified value should
194         be equal to ulFirstNotifiedConst. */
195         configASSERT( xReturned == pdPASS );
196         configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
197
198         /* Incremented to show the task is still running. */
199         ulNotifyCycleCount++;
200
201
202
203
204
205         /*--------------------------------------------------------------------------
206         Check the non-overwriting functionality.  The notification is done twice
207         using two different notification values.  The action says don't overwrite so
208         only the first notification should pass and the value read back should also
209         be that used with the first notification. */
210         xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite );
211         configASSERT( xReturned == pdPASS );
212
213         xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithoutOverwrite );
214         configASSERT( xReturned == pdFAIL );
215
216         /* Waiting for the notification should now return immediately so a block
217         time of zero is used. */
218         xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
219
220         configASSERT( xReturned == pdPASS );
221         configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
222
223
224
225
226
227         /*--------------------------------------------------------------------------
228         Do the same again, only this time use the overwriting version.  This time
229         both notifications should pass, and the value written the second time should
230         overwrite the value written the first time, and so be the value that is read
231         back. */
232         xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithOverwrite );
233         configASSERT( xReturned == pdPASS );
234         xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithOverwrite );
235         configASSERT( xReturned == pdPASS );
236         xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
237         configASSERT( xReturned == pdPASS );
238         configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
239
240
241
242
243         /*--------------------------------------------------------------------------
244         Check notifications with no action pass without updating the value.  Even
245         though ulFirstNotifiedConst is used as the value the value read back should
246         remain at ulSecondNotifiedConst. */
247         xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eNoAction );
248         configASSERT( xReturned == pdPASS );
249         xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
250         configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
251
252
253
254
255         /*--------------------------------------------------------------------------
256         Check incrementing values.  Send ulMaxLoop increment notifications, then
257         ensure the received value is as expected - which should be
258         ulSecondNotificationValueConst plus how ever many times to loop iterated. */
259         for( ulLoop = 0; ulLoop < ulMaxLoops; ulLoop++ )
260         {
261                 xReturned = xTaskNotify( xTaskToNotify, 0, eIncrement );
262                 configASSERT( xReturned == pdPASS );
263         }
264
265         xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
266         configASSERT( xReturned == pdPASS );
267         configASSERT( ulNotifiedValue == ( ulSecondNotifiedValueConst + ulMaxLoops ) );
268
269         /* Should not be any notifications pending now. */
270         xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );
271         configASSERT( xReturned == pdFAIL );
272
273
274
275
276         /*--------------------------------------------------------------------------
277         Check all bits can be set by notifying the task with one additional bit set
278         on each notification, and exiting the loop when all the bits are found to be
279         set.  As there are 32-bits the loop should execute 32 times before all the
280         bits are found to be set. */
281         ulNotifyingValue = 0x01;
282         ulLoop = 0;
283
284         /* Start with all bits clear. */
285         xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
286
287         do
288         {
289                 /* Set the next bit in the task's notified value. */
290                 xTaskNotify( xTaskToNotify, ulNotifyingValue, eSetBits );
291
292                 /* Wait for the notified value - which of course will already be
293                 available.  Don't clear the bits on entry or exit as this loop is exited
294                 when all the bits are set. */
295                 xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );
296                 configASSERT( xReturned == pdPASS );
297
298                 ulLoop++;
299
300                 /* Use the next bit on the next iteration around this loop. */
301                 ulNotifyingValue <<= 1UL;
302
303         } while ( ulNotifiedValue != notifyUINT32_MAX );
304
305         /* As a 32-bit value was used the loop should have executed 32 times before
306         all the bits were set. */
307         configASSERT( ulLoop == 32 );
308
309
310
311
312         /*--------------------------------------------------------------------------
313         Check bits are cleared on entry but not on exit when a notification fails
314         to arrive before timing out - both with and without a timeout value.  Wait
315         for the notification again - but this time it is not given by anything and
316         should return pdFAIL.  The parameters are set to clear bit zero on entry and
317         bit one on exit.  As no notification was received only the bit cleared on
318         entry should actually get cleared. */
319         xReturned = xTaskNotifyWait( ulBit0, ulBit1, &ulNotifiedValue, xTicksToWait );
320         configASSERT( xReturned == pdFAIL );
321
322         /* Notify the task with no action so as not to update the bits even though
323         notifyUINT32_MAX is used as the notification value. */
324         xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eNoAction );
325
326         /* Reading back the value should should find bit 0 is clear, as this was
327         cleared on entry, but bit 1 is not clear as it will not have been cleared on
328         exit as no notification was received. */
329         xReturned = xTaskNotifyWait( 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
330         configASSERT( xReturned == pdPASS );
331         configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
332
333
334
335
336
337         /*--------------------------------------------------------------------------
338         Now try clearing the bit on exit.  For that to happen a notification must be
339         received, so the task is notified first. */
340         xTaskNotify( xTaskToNotify, 0, eNoAction );
341         xTaskNotifyWait( 0x00, ulBit1, &ulNotifiedValue, 0 );
342
343         /* However as the bit is cleared on exit, after the returned notification
344         value is set, the returned notification value should not have the bit
345         cleared... */
346         configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
347
348         /* ...but reading the value back again should find that the bit was indeed
349         cleared internally.  The returned value should be pdFAIL however as nothing
350         has notified the task in the mean time. */
351         xReturned = xTaskNotifyWait( 0x00, 0x00, &ulNotifiedValue, 0 );
352         configASSERT( xReturned == pdFAIL );
353         configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
354
355
356
357
358         /*--------------------------------------------------------------------------
359         Now try querying the previus value while notifying a task. */
360         xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );
361         configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
362
363         /* Clear all bits. */
364         xTaskNotifyWait( 0x00, notifyUINT32_MAX, &ulNotifiedValue, 0 );
365         xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );
366         configASSERT( ulPreviousValue == 0 );
367
368         ulExpectedValue = 0;
369         for( ulLoop = 0x01; ulLoop < 0x80UL; ulLoop <<= 1UL )
370         {
371                 /* Set the next bit up, and expect to receive the last bits set (so
372                 the previous value will not yet have the bit being set this time
373                 around). */
374                 xTaskNotifyAndQuery( xTaskToNotify, ulLoop, eSetBits, &ulPreviousValue );
375                 configASSERT( ulExpectedValue == ulPreviousValue );
376                 ulExpectedValue |= ulLoop;
377         }
378
379
380
381         /* -------------------------------------------------------------------------
382         Clear the previous notifications. */
383         xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
384
385         /* The task should not have any notifications pending, so an attempt to clear
386         the notification state should fail. */
387         configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
388
389         /* Get the task to notify itself.  This is not a normal thing to do, and is
390         only done here for test purposes. */
391         xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
392
393         /* Now the notification state should be eNotified, so it should now be
394         possible to clear the notification state. */
395         configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
396         configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
397
398
399
400
401         /* Incremented to show the task is still running. */
402         ulNotifyCycleCount++;
403
404         /* Leave all bits cleared. */
405         xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );
406 }
407 /*-----------------------------------------------------------*/
408
409 static void prvNotifyingTimer( TimerHandle_t xNotUsed )
410 {
411         ( void ) xNotUsed;
412
413         xTaskNotifyGive( xTaskToNotify );
414
415         /* This value is also incremented from an interrupt. */
416         taskENTER_CRITICAL();
417         {
418                 ulTimerNotificationsSent++;
419         }
420         taskEXIT_CRITICAL();
421 }
422 /*-----------------------------------------------------------*/
423
424 static void prvNotifiedTask( void *pvParameters )
425 {
426 const TickType_t xMaxPeriod = pdMS_TO_TICKS( 90 ), xMinPeriod = pdMS_TO_TICKS( 10 ), xDontBlock = 0;
427 TickType_t xPeriod;
428 const uint32_t ulCyclesToRaisePriority = 50UL;
429
430         /* Remove compiler warnings about unused parameters. */
431         ( void ) pvParameters;
432
433         /* Run a few tests that can be done from a single task before entering the
434         main loop. */
435         prvSingleTaskTests();
436
437         /* Create the software timer that is used to send notifications to this
438         task.  Notifications are also received from an interrupt. */
439         xTimer = xTimerCreate( "Notifier", xMaxPeriod, pdFALSE, NULL, prvNotifyingTimer );
440
441         for( ;; )
442         {
443                 /* Start the timer again with a different period.  Sometimes the period
444                 will be higher than the tasks block time, sometimes it will be lower
445                 than the tasks block time. */
446                 xPeriod = prvRand() % xMaxPeriod;
447                 if( xPeriod < xMinPeriod )
448                 {
449                         xPeriod = xMinPeriod;
450                 }
451
452                 /* Change the timer period and start the timer. */
453                 xTimerChangePeriod( xTimer, xPeriod, portMAX_DELAY );
454
455                 /* Block waiting for the notification again with a different period.
456                 Sometimes the period will be higher than the tasks block time, sometimes
457                 it will be lower than the tasks block time. */
458                 xPeriod = prvRand() % xMaxPeriod;
459                 if( xPeriod < xMinPeriod )
460                 {
461                         xPeriod = xMinPeriod;
462                 }
463
464                 /* Block to wait for a notification but without clearing the
465                 notification count, so only add one to the count of received
466                 notifications as any other notifications will remain pending. */
467                 if( ulTaskNotifyTake( pdFALSE, xPeriod ) != 0 )
468                 {
469                         ulTimerNotificationsReceived++;
470                 }
471
472
473                 /* Take a notification without clearing again, but this time without a
474                 block time specified. */
475                 if( ulTaskNotifyTake( pdFALSE, xDontBlock ) != 0 )
476                 {
477                         ulTimerNotificationsReceived++;
478                 }
479
480                 /* Wait for the next notification from the timer, clearing all
481                 notifications if one is received, so this time adding the total number
482                 of notifications that were pending as none will be left pending after
483                 the function call. */
484                 ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, xPeriod );
485
486                 /* Occasionally raise the priority of the task being notified to test
487                 the path where the task is notified from an ISR and becomes the highest
488                 priority ready state task, but the pxHigherPriorityTaskWoken parameter
489                 is NULL (which it is in the tick hook that sends notifications to this
490                 task. */
491                 if( ( ulNotifyCycleCount % ulCyclesToRaisePriority ) == 0 )
492                 {
493                         vTaskPrioritySet( xTaskToNotify, configMAX_PRIORITIES - 1 );
494
495                         /* Wait for the next notification again, clearing all notifications if
496                         one is received, but this time blocking indefinitely. */
497                         ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
498
499                         /* Reset the priority. */
500                         vTaskPrioritySet( xTaskToNotify, notifyTASK_PRIORITY );
501                 }
502                 else
503                 {
504                         /* Wait for the next notification again, clearing all notifications if
505                         one is received, but this time blocking indefinitely. */
506                         ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
507                 }
508
509                 /* Incremented to show the task is still running. */
510                 ulNotifyCycleCount++;
511         }
512 }
513 /*-----------------------------------------------------------*/
514
515 void xNotifyTaskFromISR( void )
516 {
517 static BaseType_t xCallCount = 0, xAPIToUse = 0;
518 const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );
519 uint32_t ulPreviousValue;
520 const uint32_t ulUnexpectedValue = 0xff;
521
522         /* The task performs some tests before starting the timer that gives the
523         notification from this interrupt.  If the timer has not been created yet
524         then the initial tests have not yet completed and the notification should
525         not be sent. */
526         if( xTimer != NULL )
527         {
528                 xCallCount++;
529
530                 if( xCallCount >= xCallInterval )
531                 {
532                         /* It is time to 'give' the notification again. */
533                         xCallCount = 0;
534
535                         /* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR()
536                         and xTaskNotifyAndQueryFromISR(). */
537                         switch( xAPIToUse )
538                         {
539                                 case 0: vTaskNotifyGiveFromISR( xTaskToNotify, NULL );
540                                                 xAPIToUse++;
541                                                 break;
542
543                                 case 1: xTaskNotifyFromISR( xTaskToNotify, 0, eIncrement, NULL );
544                                                 xAPIToUse++;
545                                                 break;
546
547                                 case 2: ulPreviousValue = ulUnexpectedValue;
548                                                 xTaskNotifyAndQueryFromISR( xTaskToNotify, 0, eIncrement, &ulPreviousValue, NULL );
549                                                 configASSERT( ulPreviousValue != ulUnexpectedValue );
550                                                 xAPIToUse = 0;
551                                                 break;
552
553                                 default:/* Should never get here!. */
554                                                 break;
555                         }
556
557                         ulTimerNotificationsSent++;
558                 }
559         }
560 }
561 /*-----------------------------------------------------------*/
562
563 /* This is called to check the created tasks are still running and have not
564 detected any errors. */
565 BaseType_t xAreTaskNotificationTasksStillRunning( void )
566 {
567 static uint32_t ulLastNotifyCycleCount = 0;
568 const uint32_t ulMaxSendReceiveDeviation = 5UL;
569
570         /* Check the cycle count is still incrementing to ensure the task is still
571         actually running. */
572         if( ulLastNotifyCycleCount == ulNotifyCycleCount )
573         {
574                 xErrorStatus = pdFAIL;
575         }
576         else
577         {
578                 ulLastNotifyCycleCount = ulNotifyCycleCount;
579         }
580
581         /* Check the count of 'takes' from the software timer is keeping track with
582         the amount of 'gives'. */
583         if( ulTimerNotificationsSent > ulTimerNotificationsReceived )
584         {
585                 if( ( ulTimerNotificationsSent - ulTimerNotificationsReceived ) > ulMaxSendReceiveDeviation )
586                 {
587                         xErrorStatus = pdFAIL;
588                 }
589         }
590
591         return xErrorStatus;
592 }
593 /*-----------------------------------------------------------*/
594
595 static UBaseType_t prvRand( void )
596 {
597 const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;
598
599         /* Utility function to generate a pseudo random number. */
600         uxNextRand = ( uxMultiplier * uxNextRand ) + uxIncrement;
601         return( ( uxNextRand >> 16 ) & ( ( size_t ) 0x7fff ) );
602 }
603 /*-----------------------------------------------------------*/