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