Debian Codegraph @

xpp/oct612x/octdeviceapi/oct6100api/oct6100_api/oct6100_miscellaneous.c

raw
1 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2
3 File: oct6100_miscellaneous.c
4
5 Copyright (c) 2001-2007 Octasic Inc.
6
7 Description:
8
9 This file contains miscellaneous functions used in various files.
10
11 This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API is
12 free software; you can redistribute it and/or modify it under the terms of
13 the GNU General Public License as published by the Free Software Foundation;
14 either version 2 of the License, or (at your option) any later version.
15
16 The OCT6100 GPL API is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with the OCT6100 GPL API; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 $Octasic_Release: OCT612xAPI-01.00-PR49 $
26
27 $Octasic_Revision: 35 $
28
29 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
30
31
32 /***************************** INCLUDE FILES *******************************/
33
34 #include "octdef.h"
35
36 #include "oct6100api/oct6100_defines.h"
37 #include "oct6100api/oct6100_errors.h"
38
39 #include "apilib/octapi_largmath.h"
40
41 #include "oct6100api/oct6100_apiud.h"
42 #include "oct6100api/oct6100_tlv_inst.h"
43 #include "oct6100api/oct6100_chip_open_inst.h"
44 #include "oct6100api/oct6100_chip_stats_inst.h"
45 #include "oct6100api/oct6100_interrupts_inst.h"
46 #include "oct6100api/oct6100_remote_debug_inst.h"
47 #include "oct6100api/oct6100_debug_inst.h"
48 #include "oct6100api/oct6100_api_inst.h"
49 #include "oct6100api/oct6100_channel_inst.h"
50
51 #include "oct6100api/oct6100_interrupts_pub.h"
52 #include "oct6100api/oct6100_chip_open_pub.h"
53 #include "oct6100api/oct6100_channel_pub.h"
54
55 #include "oct6100_chip_open_priv.h"
56 #include "oct6100_channel_priv.h"
57 #include "oct6100_miscellaneous_priv.h"
58
59
60 /**************************** PRIVATE FUNCTIONS ****************************/
61
62
63 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
64
65 Function: Oct6100ApiWaitForTime
66
67 Description: Waits for the specified amount of time.
68
69 -------------------------------------------------------------------------------
70 | Argument | Description
71 -------------------------------------------------------------------------------
72 f_aulWaitTime[ 2 ] The amout of time to be waited.
73
74 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
75 #if !SKIP_Oct6100ApiWaitForTime
76 UINT32 Oct6100ApiWaitForTime(
77 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
78 IN UINT32 f_aulWaitTime[ 2 ] )
79 {
80 tOCT6100_GET_TIME StartTime;
81 tOCT6100_GET_TIME CurrentTime;
82 UINT32 aulTimeDelta[ 2 ];
83 UINT32 ulResult;
84 UINT16 usTempVar;
85 BOOL fConditionFlag = TRUE;
86
87 /* Copy the process context. */
88 StartTime.pProcessContext = f_pApiInstance->pProcessContext;
89 CurrentTime.pProcessContext = f_pApiInstance->pProcessContext;
90
91 ulResult = Oct6100UserGetTime( &StartTime );
92 if ( ulResult != cOCT6100_ERR_OK )
93 return ulResult;
94
95 while ( fConditionFlag )
96 {
97 ulResult = Oct6100UserGetTime( &CurrentTime );
98 if ( ulResult != cOCT6100_ERR_OK )
99 return ulResult;
100
101 ulResult = octapi_lm_subtract(
102 CurrentTime.aulWallTimeUs, 1,
103 StartTime.aulWallTimeUs, 1,
104 aulTimeDelta, 1,
105 &usTempVar );
106 if ( ulResult != cOCT6100_ERR_OK )
107 return cOCT6100_ERR_FATAL_37;
108
109 if ( aulTimeDelta[ 1 ] >= f_aulWaitTime[ 1 ] &&
110 aulTimeDelta[ 0 ] >= f_aulWaitTime[ 0 ] )
111 fConditionFlag = FALSE;
112 }
113
114 return cOCT6100_ERR_OK;
115 }
116 #endif
117
118
119 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
120
121 Function: Oct6100ApiWaitForPcRegisterBit
122
123 Description: Polls the specified PC register bit. The function exits once
124 the bit is cleared by hardware, or when the specified timeout
125 period has been expired.
126
127 -------------------------------------------------------------------------------
128 | Argument | Description
129 -------------------------------------------------------------------------------
130 f_pApiInstance Pointer to API instance. This memory is used to keep the
131 present state of the chip and all its resources.
132
133 f_ulPcRegAdd Address of the register containing the PC bit.
134 f_ulPcBitNum Number of the PC bit within the register.
135 f_ulValue Expected value of the bit.
136 f_ulTimeoutUs The timeout period, in usec.
137 f_pfBitEqual Pointer to the result of the bit comparison.
138
139 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
140 #if !SKIP_Oct6100ApiWaitForPcRegisterBit
141 UINT32 Oct6100ApiWaitForPcRegisterBit(
142 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
143 IN UINT32 f_ulPcRegAdd,
144 IN UINT32 f_ulPcBitNum,
145 IN UINT32 f_ulValue,
146 IN UINT32 f_ulTimeoutUs,
147 OUT PBOOL f_pfBitEqual )
148 {
149 tOCT6100_READ_PARAMS ReadParams;
150 tOCT6100_GET_TIME StartTime;
151 tOCT6100_GET_TIME TimeoutTime;
152 tOCT6100_GET_TIME CurrentTime;
153 UINT32 ulResult;
154 UINT16 usReadData;
155 BOOL fConditionFlag = TRUE;
156
157 /* Copy the process context. */
158 StartTime.pProcessContext = f_pApiInstance->pProcessContext;
159 CurrentTime.pProcessContext = f_pApiInstance->pProcessContext;
160
161 /* Get the current system time. */
162 ulResult = Oct6100UserGetTime( &StartTime );
163 if ( ulResult != cOCT6100_ERR_OK )
164 return ulResult;
165
166 /* Mark the bit as not being equal, for now. */
167 *f_pfBitEqual = FALSE;
168
169 /* Determine the time at which the timeout has expired. */
170 ulResult = octapi_lm_add(
171 StartTime.aulWallTimeUs, 1,
172 &f_ulTimeoutUs, 0,
173 TimeoutTime.aulWallTimeUs, 1 );
174 if ( ulResult != cOCT6100_ERR_OK )
175 return ulResult;
176
177 /* Prepare read structure. */
178 ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
179
180 ReadParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
181 ReadParams.ulReadAddress = f_ulPcRegAdd;
182 ReadParams.pusReadData = &usReadData;
183
184 /* Read the PC bit while the timeout period hasn't expired. */
185 while ( fConditionFlag )
186 {
187 /* Read the current time again to check for timeout. */
188 ulResult = Oct6100UserGetTime( &CurrentTime );
189 if ( ulResult != cOCT6100_ERR_OK )
190 return ulResult;
191
192 ulResult = Oct6100UserDriverReadApi( &ReadParams );
193 if ( ulResult != cOCT6100_ERR_OK )
194 return ulResult;
195
196 if ( ( UINT16 )((usReadData >> f_ulPcBitNum) & 0x1) == ( UINT16 )f_ulValue )
197 {
198 /* Mark the bit as being equal. */
199 *f_pfBitEqual = TRUE;
200 fConditionFlag = FALSE;
201 }
202
203 if ( CurrentTime.aulWallTimeUs[ 1 ] > TimeoutTime.aulWallTimeUs[ 1 ] ||
204 (CurrentTime.aulWallTimeUs[ 1 ] == TimeoutTime.aulWallTimeUs[ 1 ] &&
205 CurrentTime.aulWallTimeUs[ 0 ] >= TimeoutTime.aulWallTimeUs[ 0 ]) )
206 fConditionFlag = FALSE;
207 }
208
209 return cOCT6100_ERR_OK;
210 }
211 #endif
212
213
214 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
215
216 Function: Oct6100ApiReadDword
217
218 Description: Read a DWORD at specified address in external memory.
219
220 -------------------------------------------------------------------------------
221 | Argument | Description
222 -------------------------------------------------------------------------------
223 f_pApiInstance Pointer to API instance. This memory is used to keep the
224 present state of the chip and all its resources.
225
226 f_ulAddress DWORD address where to read.
227 f_pulReadData Resulting data.
228
229 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
230 #if !SKIP_Oct6100ApiReadDword
231 UINT32 Oct6100ApiReadDword(
232 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
233 IN UINT32 f_ulAddress,
234 OUT PUINT32 f_pulReadData )
235 {
236 tOCT6100_READ_PARAMS ReadParams;
237 UINT16 usReadData;
238
239 UINT32 ulResult;
240 UINT32 ulTempData;
241
242 ReadParams.pProcessContext = f_pApiInstance->pProcessContext;
243
244 ReadParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
245 ReadParams.pusReadData = &usReadData;
246
247 /*==================================================================================*/
248 /* Read the first 16 bits. */
249 ReadParams.ulReadAddress = f_ulAddress;
250 mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
251 if ( ulResult != cOCT6100_ERR_OK )
252 return ulResult;
253
254 /* Save data. */
255 ulTempData = usReadData << 16;
256
257 /* Read the last 16 bits. */
258 ReadParams.ulReadAddress += 2;
259 mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
260 if ( ulResult != cOCT6100_ERR_OK )
261 return ulResult;
262
263 /* Save data. */
264 ulTempData |= usReadData;
265
266 /*==================================================================================*/
267
268 /* Return the read value.*/
269 *f_pulReadData = ulTempData;
270
271 return cOCT6100_ERR_OK;
272 }
273 #endif
274
275
276 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
277
278 Function: Oct6100ApiWriteDword
279
280 Description: Write a DWORD at specified address in external memory.
281
282 -------------------------------------------------------------------------------
283 | Argument | Description
284 -------------------------------------------------------------------------------
285 f_pApiInstance Pointer to API instance. This memory is used to keep the
286 present state of the chip and all its resources.
287
288 f_ulAddress DWORD address where to write.
289 f_ulWriteData DWORD data to write.
290
291 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
292 #if !SKIP_Oct6100ApiWriteDword
293 UINT32 Oct6100ApiWriteDword(
294 IN OUT tPOCT6100_INSTANCE_API f_pApiInstance,
295 IN UINT32 f_ulAddress,
296 IN UINT32 f_ulWriteData )
297 {
298 tOCT6100_WRITE_PARAMS WriteParams;
299 UINT32 ulResult;
300
301 WriteParams.pProcessContext = f_pApiInstance->pProcessContext;
302
303 WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;
304
305 /* Write the first 16 bits. */
306 WriteParams.ulWriteAddress = f_ulAddress;
307 WriteParams.usWriteData = (UINT16)((f_ulWriteData >> 16) & 0xFFFF);
308 mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
309 if ( ulResult != cOCT6100_ERR_OK )
310 return ulResult;
311
312 /* Write the last word. */
313 WriteParams.ulWriteAddress += 2;
314 WriteParams.usWriteData = (UINT16)(f_ulWriteData & 0xFFFF);
315 mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
316 if ( ulResult != cOCT6100_ERR_OK )
317 return ulResult;
318
319 return cOCT6100_ERR_OK;
320 }
321 #endif
322
323
324 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
325
326 Function: Oct6100ApiCreateFeatureMask
327
328 Description:
329
330 -------------------------------------------------------------------------------
331 | Argument | Description
332 -------------------------------------------------------------------------------
333
334 f_ulFieldSize Size of the field, in bits.
335 f_ulFieldBitOffset Bit offset, from the least significant bit.
336 f_pulFieldMask Resulting mask.
337
338 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
339 #if !SKIP_Oct6100ApiCreateFeatureMask
340 VOID Oct6100ApiCreateFeatureMask(
341 IN UINT32 f_ulFieldSize,
342 IN UINT32 f_ulFieldBitOffset,
343 OUT PUINT32 f_pulFieldMask )
344 {
345 UINT32 ulMask;
346 UINT32 i;
347
348 ulMask = 0;
349
350 /* Create the mask based on the field size. */
351 for ( i = 0; i < f_ulFieldSize; i++ )
352 {
353 ulMask <<= 1;
354 ulMask |= 1;
355 }
356
357 /* Once the mask is of the desired size, offset it to fit the field */
358 /* within the DWORD read. */
359 ulMask <<= f_ulFieldBitOffset;
360
361 /* Return the mask. */
362 *f_pulFieldMask = ulMask;
363 }
364 #endif
365
366
367 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
368
369 Function: Oct6100ApiStrStr
370
371 Description: OCT6100 API version of strstr()
372
373 -------------------------------------------------------------------------------
374 | Argument | Description
375 -------------------------------------------------------------------------------
376
377 f_pszSource Source string to analyze.
378 f_pszString String to look for.
379 f_pszLastCharPtr Last character in the source string.
380
381 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
382 #if !SKIP_Oct6100ApiStrStr
383 unsigned char const *Oct6100ApiStrStr(
384 IN unsigned char const *f_pszSource,
385 IN unsigned char const *f_pszString,
386 IN unsigned char const *f_pszLastCharPtr )
387 {
388 UINT32 ulCurrentPos;
389 UINT32 ulStringLength;
390 UINT32 ulNumMatchingCharFound = 0;
391 unsigned char const *pchFirstChar = NULL;
392 UINT32 ulSourceLength;
393
394 if ( f_pszLastCharPtr < f_pszSource )
395 return NULL;
396
397 ulSourceLength = (UINT32)( f_pszLastCharPtr - f_pszSource );
398 ulStringLength = Oct6100ApiStrLen( f_pszString );
399
400 for ( ulCurrentPos = 0; ulCurrentPos < ulSourceLength; ulCurrentPos++ )
401 {
402 /* Check if the character matches. */
403 if ( f_pszSource[ ulCurrentPos ] == f_pszString[ ulNumMatchingCharFound ] )
404 {
405 if ( ulNumMatchingCharFound == 0 )
406 pchFirstChar = ( f_pszSource + ulCurrentPos );
407
408 ulNumMatchingCharFound++;
409
410 /* Check if the whole string matched. */
411 if ( ulNumMatchingCharFound == ulStringLength )
412 break;
413 }
414 else if ( ulNumMatchingCharFound != 0 )
415 {
416 ulNumMatchingCharFound = 0;
417
418 /* Reset the search, but take a look at the current character. It might */
419 /* be the beginning of the string we are looking for. */
420 if ( f_pszSource[ ulCurrentPos ] == f_pszString[ ulNumMatchingCharFound ] )
421 {
422 pchFirstChar = ( f_pszSource + ulCurrentPos );
423 ulNumMatchingCharFound++;
424
425 /* Check if the whole string matched. */
426 /* This check must be done in case we have the 1 character strstr */
427 if ( ulNumMatchingCharFound == ulStringLength )
428 break;
429 }
430 }
431 }
432
433 if ( ulCurrentPos == ulSourceLength )
434 return NULL;
435 else
436 return pchFirstChar;
437 }
438 #endif
439
440
441 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
442
443 Function: Oct6100ApiStrLen
444
445 Description: OCT6100 API version of strlen()
446
447 -------------------------------------------------------------------------------
448 | Argument | Description
449 -------------------------------------------------------------------------------
450
451 f_pszString Source string to count length of.
452
453 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
454 #if !SKIP_Oct6100ApiStrLen
455 UINT32 Oct6100ApiStrLen(
456 IN unsigned char const *f_pszString )
457 {
458 UINT32 ulCount = 0;
459
460 while( f_pszString[ ulCount ] != '\0' )
461 ulCount++;
462
463 return ulCount;
464 }
465 #endif
466
467
468 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
469
470 Function: Oct6100ApiAsciiToHex
471
472 Description: Convert an ASCII character to an hexadecimal value.
473
474 -------------------------------------------------------------------------------
475 | Argument | Description
476 -------------------------------------------------------------------------------
477
478 f_chCharacter ASCII character to convert.
479 f_pulValue Resulting hexadecimal value.
480
481 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
482 #if !SKIP_Oct6100ApiAsciiToHex
483 UINT32 Oct6100ApiAsciiToHex(
484 IN UINT8 f_chCharacter,
485 OUT PUINT32 f_pulValue )
486 {
487 switch ( f_chCharacter )
488 {
489 case '0':
490 (*f_pulValue) = 0x0;
491 break;
492 case '1':
493 (*f_pulValue) = 0x1;
494 break;
495 case '2':
496 (*f_pulValue) = 0x2;
497 break;
498 case '3':
499 (*f_pulValue) = 0x3;
500 break;
501 case '4':
502 (*f_pulValue) = 0x4;
503 break;
504 case '5':
505 (*f_pulValue) = 0x5;
506 break;
507 case '6':
508 (*f_pulValue) = 0x6;
509 break;
510 case '7':
511 (*f_pulValue) = 0x7;
512 break;
513 case '8':
514 (*f_pulValue) = 0x8;
515 break;
516 case '9':
517 (*f_pulValue) = 0x9;
518 break;
519 case 'A':
520 case 'a':
521 (*f_pulValue) = 0xA;
522 break;
523 case 'B':
524 case 'b':
525 (*f_pulValue) = 0xB;
526 break;
527 case 'C':
528 case 'c':
529 (*f_pulValue) = 0xC;
530 break;
531 case 'D':
532 case 'd':
533 (*f_pulValue) = 0xD;
534 break;
535 case 'E':
536 case 'e':
537 (*f_pulValue) = 0xE;
538 break;
539 case 'F':
540 case 'f':
541 (*f_pulValue) = 0xF;
542 break;
543 default:
544 (*f_pulValue) = 0x0;
545 return cOCT6100_ERR_MISC_ASCII_CONVERSION_FAILED;
546 }
547
548 return cOCT6100_ERR_OK;
549 }
550 #endif
551
552
553 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
554
555 Function: Oct6100ApiHexToAscii
556
557 Description: Convert an hexadecimal value to an ASCII character.
558
559 -------------------------------------------------------------------------------
560 | Argument | Description
561 -------------------------------------------------------------------------------
562
563 f_ulNumber Hexadecimal value to convert.
564
565 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
566 #if !SKIP_Oct6100ApiHexToAscii
567 UINT8 Oct6100ApiHexToAscii(
568 IN UINT32 f_ulNumber )
569 {
570 if ( f_ulNumber >= 0xA )
571 return (UINT8)( 55 + f_ulNumber ); /* Hex values from 0xA to 0xF */
572 else
573 return (UINT8)( 48 + f_ulNumber ); /* Hex values from 0x0 to 0x9 */
574 }
575 #endif
576
577
578 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
579
580 Function: Oct6100ApiRand
581
582 Description: Random number generator.
583
584 -------------------------------------------------------------------------------
585 | Argument | Description
586 -------------------------------------------------------------------------------
587
588 f_ulRange Range of the random number to be generated.
589
590 \*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
591 #if !SKIP_Oct6100ApiRand
592 UINT32 Oct6100ApiRand(
593 IN UINT32 f_ulRange )
594 {
595 static UINT32 ulRandomSeed = 0x12345678;
596 UINT32 ulBit0;
597
598 UINT32 i, j;
599 UINT16 ulWithinRange = FALSE;
600
601 UINT32 ulResult = cOCT6100_ERR_OK;
602 UINT16 ulLoop;
603
604 UINT32 ulRangeMask;
605 UINT32 ulAddedValue;
606
607
608 ulRangeMask = 1;
609 ulLoop = TRUE;
610 i = 1;
611
612 while ( ulLoop )
613 {
614
615 ulAddedValue = 2;
616 for ( j = 1; j < i; j++ )
617 ulAddedValue *= 2;
618
619 ulRangeMask = ulRangeMask + ulAddedValue;
620
621 if ( ulRangeMask >= f_ulRange )
622 ulLoop = FALSE;
623
624 i++;
625 }
626
627 while ( !ulWithinRange )
628 {
629 ulBit0 = ((ulRandomSeed >> 19) & 0x1) ^ ((ulRandomSeed >> 16) & 0x1);
630 ulRandomSeed = ((ulRandomSeed << 1) & 0xFFFFF) | ulBit0;
631
632 ulResult = ulRandomSeed & ulRangeMask;
633
634 if ( ulResult <= f_ulRange )
635 ulWithinRange = TRUE;
636 }
637
638 return ulResult;
639 }
640 #endif