]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v4_1/src/xil_testmem.c
Add back Zynq demo - this time using SDK V14.2.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v4_1 / src / xil_testmem.c
1 /******************************************************************************
2 *
3 * (c) Copyright 2009 Xilinx, Inc. All rights reserved.
4 *
5 * This file contains confidential and proprietary information of Xilinx, Inc.
6 * and is protected under U.S. and international copyright and other
7 * intellectual property laws.
8 *
9 * DISCLAIMER
10 * This disclaimer is not a license and does not grant any rights to the
11 * materials distributed herewith. Except as otherwise provided in a valid
12 * license issued to you by Xilinx, and to the maximum extent permitted by
13 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
14 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
15 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
16 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
17 * and (2) Xilinx shall not be liable (whether in contract or tort, including
18 * negligence, or under any other theory of liability) for any loss or damage
19 * of any kind or nature related to, arising under or in connection with these
20 * materials, including for any direct, or any indirect, special, incidental,
21 * or consequential loss or damage (including loss of data, profits, goodwill,
22 * or any type of loss or damage suffered as a result of any action brought by
23 * a third party) even if such damage or loss was reasonably foreseeable or
24 * Xilinx had been advised of the possibility of the same.
25 *
26 * CRITICAL APPLICATIONS
27 * Xilinx products are not designed or intended to be fail-safe, or for use in
28 * any application requiring fail-safe performance, such as life-support or
29 * safety devices or systems, Class III medical devices, nuclear facilities,
30 * applications related to the deployment of airbags, or any other applications
31 * that could lead to death, personal injury, or severe property or
32 * environmental damage (individually and collectively, "Critical
33 * Applications"). Customer assumes the sole risk and liability of any use of
34 * Xilinx products in Critical Applications, subject only to applicable laws
35 * and regulations governing limitations on product liability.
36 *
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
38 * AT ALL TIMES.
39 *
40 *
41 ******************************************************************************/
42 /*****************************************************************************/
43 /**
44 *
45 * @file xil_testmem.c
46 *
47 * Contains the memory test utility functions.
48 *
49 * <pre>
50 * MODIFICATION HISTORY:
51 *
52 * Ver    Who    Date    Changes
53 * ----- ---- -------- -----------------------------------------------
54 * 1.00a hbm  08/25/09 First release
55 * </pre>
56 *
57 *****************************************************************************/
58
59 /***************************** Include Files ********************************/
60 #include "xil_testmem.h"
61 #include "xil_io.h"
62 #include "xil_assert.h"
63
64 /************************** Constant Definitions ****************************/
65 /************************** Function Prototypes *****************************/
66
67 static u32 RotateLeft(u32 Input, u8 Width);
68
69 /* define ROTATE_RIGHT to give access to this functionality */
70 /* #define ROTATE_RIGHT */
71 #ifdef ROTATE_RIGHT
72 static u32 RotateRight(u32 Input, u8 Width);
73 #endif /* ROTATE_RIGHT */
74
75
76 /*****************************************************************************/
77 /**
78 *
79 * Perform a destructive 32-bit wide memory test.
80 *
81 * @param    Addr is a pointer to the region of memory to be tested.
82 * @param    Words is the length of the block.
83 * @param    Pattern is the constant used for the constant pattern test, if 0,
84 *           0xDEADBEEF is used.
85 * @param    Subtest is the test selected. See xil_testmem.h for possible
86 *           values.
87 *
88 * @return
89 *
90 * - 0 is returned for a pass
91 * - -1 is returned for a failure
92 *
93 * @note
94 *
95 * Used for spaces where the address range of the region is smaller than
96 * the data width. If the memory range is greater than 2 ** Width,
97 * the patterns used in XIL_TESTMEM_WALKONES and XIL_TESTMEM_WALKZEROS will
98 * repeat on a boundry of a power of two making it more difficult to detect
99 * addressing errors. The XIL_TESTMEM_INCREMENT and XIL_TESTMEM_INVERSEADDR
100 * tests suffer the same problem. Ideally, if large blocks of memory are to be
101 * tested, break them up into smaller regions of memory to allow the test
102 * patterns used not to repeat over the region tested.
103 *
104 *****************************************************************************/
105 int Xil_TestMem32(u32 *Addr, u32 Words, u32 Pattern, u8 Subtest)
106 {
107         u32 I;
108         u32 J;
109         u32 Val;
110         u32 FirtVal;
111         u32 Word;
112
113         Xil_AssertNonvoid(Words != 0);
114         Xil_AssertNonvoid(Subtest <= XIL_TESTMEM_MAXTEST);
115
116         /*
117          * variable initialization
118          */
119         Val = XIL_TESTMEM_INIT_VALUE;
120         FirtVal = XIL_TESTMEM_INIT_VALUE;
121
122         /*
123          * Select the proper Subtest
124          */
125         switch (Subtest) {
126
127         case XIL_TESTMEM_ALLMEMTESTS:
128
129                 /* this case executes all of the Subtests */
130
131                 /* fall through case statement */
132
133         case XIL_TESTMEM_INCREMENT:
134                 
135                 /*
136                  * Fill the memory with incrementing
137                  * values starting from 'FirtVal'
138                  */
139                 for (I = 0L; I < Words; I++) {
140                         Addr[I] = Val;
141                         Val++;
142                 }
143
144                 /*
145                  * Restore the reference 'Val' to the
146                  * initial value
147                  */
148                 Val = FirtVal;
149
150                 /*
151                  * Check every word within the words
152                  * of tested memory and compare it
153                  * with the incrementing reference
154                  * Val
155                  */
156
157                 for (I = 0L; I < Words; I++) {
158                         Word = Addr[I];
159
160                         if (Word != Val) {
161                                 return -1;
162                         }
163
164                         Val++;
165                 }
166
167
168                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
169                         return 0;
170                 }
171
172
173                 /* end of case 1 */
174
175                 /* fall through case statement */
176
177         case XIL_TESTMEM_WALKONES:
178                 /*
179                  * set up to cycle through all possible initial
180                  * test Patterns for walking ones test
181                  */
182                 
183                 for (J = 0L; J < 32; J++) {
184                         /*
185                          * Generate an initial value for walking ones test
186                          * to test for bad data bits
187                          */
188                         
189                         Val = 1 << J;
190
191                         /*
192                          * START walking ones test
193                          * Write a one to each data bit indifferent locations
194                          */
195
196                         for (I = 0L; I < 32; I++) {
197                                 /* write memory location */
198                                 Addr[I] = Val;
199                                 Val = (u32) RotateLeft(Val, 32);
200                         }
201
202                         /*
203                          * Restore the reference 'val' to the
204                          * initial value
205                          */
206                         Val = 1 << J;
207
208                         /* Read the values from each location that was
209                          * written */
210                         for (I = 0L; I < 32; I++) {
211                                 /* read memory location */
212                                 
213                                 Word = Addr[I];
214
215                                 if (Word != Val) {
216                                         return -1;
217                                 }
218
219                                 Val = (u32)RotateLeft(Val, 32);
220                         }
221
222                 }
223
224                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
225                         return 0;
226                 }
227
228                 /* end of case 2 */
229                 /* fall through case statement */
230
231         case XIL_TESTMEM_WALKZEROS:
232                 /*
233                  * set up to cycle through all possible
234                  * initial test Patterns for walking zeros test
235                  */
236
237                 for (J = 0L; J < 32; J++) {
238
239                         /*
240                          * Generate an initial value for walking ones test
241                          * to test for bad data bits
242                          */
243
244                         Val = ~(1 << J);
245
246                         /*
247                          * START walking zeros test
248                          * Write a one to each data bit indifferent locations
249                          */
250                         
251                         for (I = 0L; I < 32; I++) {
252                                 /* write memory location */
253                                 Addr[I] = Val;
254                                 Val = ~((u32)RotateLeft(~Val, 32));
255                         }
256
257                         /*
258                          * Restore the reference 'Val' to the
259                          * initial value
260                          */
261
262                         Val = ~(1 << J);
263
264                         /* Read the values from each location that was
265                          * written */
266                         for (I = 0L; I < 32; I++) {
267                                 /* read memory location */
268                                 Word = Addr[I];
269                                 if (Word != Val) {
270                                         return -1;
271                                 }
272                                 Val = ~((u32)RotateLeft(~Val, 32));
273                         }
274
275                 }
276
277                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
278                         return 0;
279                 }
280
281                 /* end of case 3 */
282
283                 /* fall through case statement */
284
285         case XIL_TESTMEM_INVERSEADDR:
286                 /* Fill the memory with inverse of address */
287                 for (I = 0L; I < Words; I++) {
288                         /* write memory location */
289                         Val = (u32) (~((u32) (&Addr[I])));
290                         Addr[I] = Val;
291                 }
292
293                 /*
294                  * Check every word within the words
295                  * of tested memory
296                  */
297                 
298                 for (I = 0L; I < Words; I++) {
299                         /* Read the location */
300                         Word = Addr[I];
301                         Val = (u32) (~((u32) (&Addr[I])));
302                         
303                         if ((Word ^ Val) != 0x00000000) {
304                                 return -1;
305                         }
306                 }
307
308                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
309                         return 0;
310                 }
311                 /* end of case 4 */
312
313                 /* fall through case statement */
314
315         case XIL_TESTMEM_FIXEDPATTERN:
316                 /*
317                  * Generate an initial value for
318                  * memory testing
319                  */
320
321                 if (Pattern == 0) {
322                         Val = 0xDEADBEEF;
323                 }
324                 else {
325                         Val = Pattern;
326                 }
327
328                 /*
329                  * Fill the memory with fixed Pattern
330                  */
331
332                 for (I = 0L; I < Words; I++) {
333                         /* write memory location */
334                         Addr[I] = Val;
335                 }
336
337                 /*
338                  * Check every word within the words
339                  * of tested memory and compare it
340                  * with the fixed Pattern
341                  */
342                 
343                 for (I = 0L; I < Words; I++) {
344                         
345                         /* read memory location */
346                         
347                         Word = Addr[I];
348                         if (Word != Val) {
349                                 return -1;
350                         }
351                 }
352
353                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
354                         return 0;
355                 }
356                 /* end of case 5 */
357
358                 /* this break is for the prior fall through case statements */
359
360                 break;
361
362         default:
363                 return -1;
364
365         }                       /* end of switch */
366
367         /* Successfully passed memory test ! */
368
369         return 0;
370 }
371
372 /*****************************************************************************/
373 /**
374 *
375 * Perform a destructive 16-bit wide memory test.
376 *
377 * @param    Addr is a pointer to the region of memory to be tested.
378 * @param    Words is the length of the block.
379 * @param    Pattern is the constant used for the constant Pattern test, if 0,
380 *           0xDEADBEEF is used.
381 * @param    Subtest is the test selected. See xil_testmem.h for possible
382 *           values.
383 *
384 * @return
385 *
386 * - -1 is returned for a failure
387 * - 0 is returned for a pass
388 *
389 * @note
390 *
391 * Used for spaces where the address range of the region is smaller than
392 * the data width. If the memory range is greater than 2 ** Width,
393 * the patterns used in XIL_TESTMEM_WALKONES and XIL_TESTMEM_WALKZEROS will
394 * repeat on a boundry of a power of two making it more difficult to detect
395 * addressing errors. The XIL_TESTMEM_INCREMENT and XIL_TESTMEM_INVERSEADDR
396 * tests suffer the same problem. Ideally, if large blocks of memory are to be
397 * tested, break them up into smaller regions of memory to allow the test
398 * patterns used not to repeat over the region tested.
399 *
400 *****************************************************************************/
401 int Xil_TestMem16(u16 *Addr, u32 Words, u16 Pattern, u8 Subtest)
402 {
403         u32 I;
404         u32 J;
405         u16 Val;
406         u16 FirtVal;
407         u16 Word;
408
409         Xil_AssertNonvoid(Words != 0);
410         Xil_AssertNonvoid(Subtest <= XIL_TESTMEM_MAXTEST);
411
412         /*
413          * variable initialization
414          */
415         Val = XIL_TESTMEM_INIT_VALUE;
416         FirtVal = XIL_TESTMEM_INIT_VALUE;
417
418         /*
419          * selectthe proper Subtest(s)
420          */
421
422         switch (Subtest) {
423
424         case XIL_TESTMEM_ALLMEMTESTS:
425
426                 /* this case executes all of the Subtests */
427
428                 /* fall through case statement */
429
430         case XIL_TESTMEM_INCREMENT:
431                 /*
432                  * Fill the memory with incrementing
433                  * values starting from 'FirtVal'
434                  */
435                 for (I = 0L; I < Words; I++) {
436                         /* write memory location */
437                         Addr[I] = Val;
438                         Val++;
439                 }
440                 /*
441                  * Restore the reference 'Val' to the
442                  * initial value
443                  */
444                 Val = FirtVal;
445
446                 /*
447                  * Check every word within the words
448                  * of tested memory and compare it
449                  * with the incrementing reference val
450                  */
451                 
452                 for (I = 0L; I < Words; I++) {
453                         /* read memory location */
454                         Word = Addr[I];
455                         if (Word != Val) {
456                                 return -1;
457                         }
458                         Val++;
459                 }
460                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
461                         return 0;
462                 }
463
464                 /* end of case 1 */
465                 /* fall through case statement */
466
467         case XIL_TESTMEM_WALKONES:
468                 /*
469                  * set up to cycle through all possible initial test
470                  * Patterns for walking ones test
471                  */
472                 
473                 for (J = 0L; J < 16; J++) {
474                         /*
475                          * Generate an initial value for walking ones test
476                          * to test for bad data bits
477                          */
478                         
479                         Val = 1 << J;
480                         /*
481                          * START walking ones test
482                          * Write a one to each data bit indifferent locations
483                          */
484
485                         for (I = 0L; I < 16; I++) {
486                                 /* write memory location */
487                                 Addr[I] = Val;
488                                 Val = (u16)RotateLeft(Val, 16);
489                         }
490                         /*
491                          * Restore the reference 'Val' to the
492                          * initial value
493                          */
494                         Val = 1 << J;
495                         /* Read the values from each location that was written */
496                         for (I = 0L; I < 16; I++) {
497                                 /* read memory location */
498                                 Word = Addr[I];
499                                 if (Word != Val) {
500                                         return -1;
501                                 }
502                                 Val = (u16)RotateLeft(Val, 16);
503                         }
504
505                 }
506                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
507                         return 0;
508                 }
509                 /* end of case 2 */
510                 /* fall through case statement */
511
512         case XIL_TESTMEM_WALKZEROS:
513                 /*
514                  * set up to cycle through all possible initial
515                  * test Patterns for walking zeros test
516                  */
517
518                 for (J = 0L; J < 16; J++) {
519                         /*
520                          * Generate an initial value for walking ones
521                          * test to test for bad
522                          * data bits
523                          */
524
525                         Val = ~(1 << J);
526                         /*
527                          * START walking zeros test
528                          * Write a one to each data bit indifferent locations
529                          */
530                         
531                         for (I = 0L; I < 16; I++) {
532                                 /* write memory location */
533                                 Addr[I] = Val;
534                                 Val = ~((u16)RotateLeft(~Val, 16));
535                         }
536                         /*
537                          * Restore the reference 'Val' to the
538                          * initial value
539                          */
540                         Val = ~(1 << J);
541                         /* Read the values from each location that was written */
542                         for (I = 0L; I < 16; I++) {
543                                 /* read memory location */
544                                 Word = Addr[I];
545                                 if (Word != Val) {
546                                         return -1;
547                                 }
548                                 Val = ~((u16)RotateLeft(~Val, 16));
549                         }
550
551                 }
552                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
553                         return 0;
554                 }
555                 /* end of case 3 */
556                 /* fall through case statement */
557
558         case XIL_TESTMEM_INVERSEADDR:
559                 /* Fill the memory with inverse of address */
560                 for (I = 0L; I < Words; I++) {
561                         /* write memory location */
562                         Val = (u16) (~((u32) (&Addr[I])));
563                         Addr[I] = Val;
564                 }
565                 /*
566                  * Check every word within the words
567                  * of tested memory
568                  */
569
570                 for (I = 0L; I < Words; I++) {
571                         /* read memory location */
572                         Word = Addr[I];
573                         Val = (u16) (~((u32) (&Addr[I])));
574                         if ((Word ^ Val) != 0x0000) {
575                                 return -1;
576                         }
577                 }
578                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
579                         return 0;
580                 }
581                 /* end of case 4 */
582                 /* fall through case statement */
583
584         case XIL_TESTMEM_FIXEDPATTERN:
585                 /*
586                  * Generate an initial value for
587                  * memory testing
588                  */
589                 if (Pattern == 0) {
590                         Val = 0xDEAD;
591                 }
592                 else {
593                         Val = Pattern;
594                 }
595
596                 /*
597                  * Fill the memory with fixed pattern
598                  */
599
600                 for (I = 0L; I < Words; I++) {
601                         /* write memory location */
602                         Addr[I] = Val;
603                 }
604
605                 /*
606                  * Check every word within the words
607                  * of tested memory and compare it
608                  * with the fixed pattern
609                  */
610                 
611                 for (I = 0L; I < Words; I++) {
612                         /* read memory location */
613                         Word = Addr[I];
614                         if (Word != Val) {
615                                 return -1;
616                         }
617                 }
618                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
619                         return 0;
620                 }
621                 /* end of case 5 */
622                 /* this break is for the prior fall through case statements */
623
624                 break;
625
626         default:
627                 return -1;
628
629         }                       /* end of switch */
630
631         /* Successfully passed memory test ! */
632
633         return 0;
634 }
635
636
637 /*****************************************************************************/
638 /**
639 *
640 * Perform a destructive 8-bit wide memory test.
641 *
642 * @param    Addr is a pointer to the region of memory to be tested.
643 * @param    Words is the length of the block.
644 * @param    Pattern is the constant used for the constant pattern test, if 0,
645 *           0xDEADBEEF is used.
646 * @param    Subtest is the test selected. See xil_testmem.h for possible
647 *           values.
648 *
649 * @return
650 *
651 * - -1 is returned for a failure
652 * - 0 is returned for a pass
653 *
654 * @note
655 *
656 * Used for spaces where the address range of the region is smaller than
657 * the data width. If the memory range is greater than 2 ** Width,
658 * the patterns used in XIL_TESTMEM_WALKONES and XIL_TESTMEM_WALKZEROS will
659 * repeat on a boundry of a power of two making it more difficult to detect
660 * addressing errors. The XIL_TESTMEM_INCREMENT and XIL_TESTMEM_INVERSEADDR
661 * tests suffer the same problem. Ideally, if large blocks of memory are to be
662 * tested, break them up into smaller regions of memory to allow the test
663 * patterns used not to repeat over the region tested.
664 *
665 *****************************************************************************/
666 int Xil_TestMem8(u8 *Addr, u32 Words, u8 Pattern, u8 Subtest)
667 {
668         u32 I;
669         u32 J;
670         u8 Val;
671         u8 FirtVal;
672         u8 Word;
673
674         Xil_AssertNonvoid(Words != 0);
675         Xil_AssertNonvoid(Subtest <= XIL_TESTMEM_MAXTEST);
676
677         /*
678          * variable initialization
679          */
680         Val = XIL_TESTMEM_INIT_VALUE;
681         FirtVal = XIL_TESTMEM_INIT_VALUE;
682
683         /*
684          * select the proper Subtest(s)
685          */
686
687         switch (Subtest) {
688
689         case XIL_TESTMEM_ALLMEMTESTS:
690                 /* this case executes all of the Subtests */
691                 /* fall through case statement */
692
693         case XIL_TESTMEM_INCREMENT:
694                 /*
695                  * Fill the memory with incrementing
696                  * values starting from 'FirtVal'
697                  */
698                 for (I = 0L; I < Words; I++) {
699                         /* write memory location */
700                         Addr[I] = Val;
701                         Val++;
702                 }
703                 /*
704                  * Restore the reference 'Val' to the
705                  * initial value
706                  */
707                 Val = FirtVal;
708                 /*
709                  * Check every word within the words
710                  * of tested memory and compare it
711                  * with the incrementing reference
712                  * Val
713                  */
714
715                 for (I = 0L; I < Words; I++) {
716                         /* read memory location */
717                         Word = Addr[I];
718                         if (Word != Val) {
719                                 return -1;
720                         }
721                         Val++;
722                 }
723
724                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
725                         return 0;
726                 }
727                 /* end of case 1 */
728
729                 /* fall through case statement */
730
731         case XIL_TESTMEM_WALKONES:
732                 /*
733                  * set up to cycle through all possible initial
734                  * test Patterns for walking ones test
735                  */
736
737                 for (J = 0L; J < 8; J++) {
738                         /*
739                          * Generate an initial value for walking ones test
740                          * to test for bad data bits
741                          */
742                         Val = 1 << J;
743                         /*
744                          * START walking ones test
745                          * Write a one to each data bit indifferent locations
746                          */
747                         for (I = 0L; I < 8; I++) {
748                                 /* write memory location */
749                                 Addr[I] = Val;
750                                 Val = (u8)RotateLeft(Val, 8);
751                         }
752                         /*
753                          * Restore the reference 'Val' to the
754                          * initial value
755                          */
756                         Val = 1 << J;
757                         /* Read the values from each location that was written */
758                         for (I = 0L; I < 8; I++) {
759                                 /* read memory location */
760                                 Word = Addr[I];
761                                 if (Word != Val) {
762                                         return -1;
763                                 }
764                                 Val = (u8)RotateLeft(Val, 8);
765                         }
766                 }
767
768                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
769                         return 0;
770                 }
771                 /* end of case 2 */
772                 /* fall through case statement */
773
774         case XIL_TESTMEM_WALKZEROS:
775                 /*
776                  * set up to cycle through all possible initial test
777                  * Patterns for walking zeros test
778                  */
779
780                 for (J = 0L; J < 8; J++) {
781                         /*
782                          * Generate an initial value for walking ones test to test
783                          * for bad data bits
784                          */
785                         Val = ~(1 << J);
786                         /*
787                          * START walking zeros test
788                          * Write a one to each data bit indifferent locations
789                          */
790                         for (I = 0L; I < 8; I++) {
791                                 /* write memory location */
792                                 Addr[I] = Val;
793                                 Val = ~((u8)RotateLeft(~Val, 8));
794                         }
795                         /*
796                          * Restore the reference 'Val' to the
797                          * initial value
798                          */
799                         Val = ~(1 << J);
800                         /* Read the values from each location that was written */
801                         for (I = 0L; I < 8; I++) {
802                                 /* read memory location */
803                                 Word = Addr[I];
804                                 if (Word != Val) {
805                                         return -1;
806                                 }
807
808                                 Val = ~((u8)RotateLeft(~Val, 8));
809                         }
810                 }
811
812                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
813                         return 0;
814                 }
815                 /* end of case 3 */
816                 /* fall through case statement */
817
818         case XIL_TESTMEM_INVERSEADDR:
819                 /* Fill the memory with inverse of address */
820                 for (I = 0L; I < Words; I++) {
821                         /* write memory location */
822                         Val = (u8) (~((u32) (&Addr[I])));
823                         Addr[I] = Val;
824                 }
825                 
826                 /*
827                  * Check every word within the words
828                  * of tested memory
829                  */
830                 
831                 for (I = 0L; I < Words; I++) {
832                         /* read memory location */
833                         Word = Addr[I];
834                         Val = (u8) (~((u32) (&Addr[I])));
835                         if ((Word ^ Val) != 0x00) {
836                                 return -1;
837                         }
838                 }
839                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
840                         return 0;
841                 }
842                 /* end of case 4 */
843                 /* fall through case statement */
844
845         case XIL_TESTMEM_FIXEDPATTERN:
846                 /*
847                  * Generate an initial value for
848                  * memory testing
849                  */
850
851                 if (Pattern == 0) {
852                         Val = 0xA5;
853                 }
854                 else {
855                         Val = Pattern;
856                 }
857                 /*
858                  * Fill the memory with fixed Pattern
859                  */
860                 for (I = 0L; I < Words; I++) {
861                         /* write memory location */
862                         Addr[I] = Val;
863                 }
864                 /*
865                  * Check every word within the words
866                  * of tested memory and compare it
867                  * with the fixed Pattern
868                  */
869                 
870                 for (I = 0L; I < Words; I++) {
871                         /* read memory location */
872                         Word = Addr[I];
873                         if (Word != Val) {
874                                 return -1;
875                         }
876                 }
877
878                 if (Subtest != XIL_TESTMEM_ALLMEMTESTS) {
879                         return 0;
880                 }
881
882                 /* end of case 5 */
883
884                 /* this break is for the prior fall through case statements */
885
886                 break;
887
888         default:
889                 return -1;
890
891         }       /* end of switch */
892
893         /* Successfully passed memory test ! */
894
895         return 0;
896 }
897
898
899 /*****************************************************************************/
900 /**
901 *
902 * Rotates the provided value to the left one bit position
903 *
904 * @param    Input is value to be rotated to the left
905 * @param    Width is the number of bits in the input data
906 *
907 * @return
908 *
909 * The resulting unsigned long value of the rotate left
910 *
911 * @note
912 *
913 * None.
914 *
915 *****************************************************************************/
916 static u32 RotateLeft(u32 Input, u8 Width)
917 {
918         u32 Msb;
919         u32 ReturnVal;
920         u32 WidthMask;
921         u32 MsbMask;
922
923         /*
924          * set up the WidthMask and the MsbMask
925          */
926
927         MsbMask = 1 << (Width - 1);
928
929         WidthMask = (MsbMask << 1) - 1;
930
931         /*
932          * set the Width of the Input to the correct width
933          */
934
935         Input = Input & WidthMask;
936
937         Msb = Input & MsbMask;
938
939         ReturnVal = Input << 1;
940
941         if (Msb != 0x00000000) {
942                 ReturnVal = ReturnVal | 0x00000001;
943         }
944
945         ReturnVal = ReturnVal & WidthMask;
946
947         return ReturnVal;
948
949 }
950
951 #ifdef ROTATE_RIGHT
952 /*****************************************************************************/
953 /**
954 *
955 * Rotates the provided value to the right one bit position
956 *
957 * @param    Input is value to be rotated to the right
958 * @param    Width is the number of bits in the input data
959 *
960 * @return
961 *
962 * The resulting u32 value of the rotate right
963 *
964 * @note
965 *
966 * None.
967 *
968 *****************************************************************************/
969 static u32 RotateRight(u32 Input, u8 Width)
970 {
971         u32 Lsb;
972         u32 ReturnVal;
973         u32 WidthMask;
974         u32 MsbMask;
975
976         /*
977          * set up the WidthMask and the MsbMask
978          */
979
980         MsbMask = 1 << (Width - 1);
981
982         WidthMask = (MsbMask << 1) - 1;
983
984         /*
985          * set the width of the input to the correct width
986          */
987
988         Input = Input & WidthMask;
989
990         ReturnVal = Input >> 1;
991
992         Lsb = Input & 0x00000001;
993
994         if (Lsb != 0x00000000) {
995                 ReturnVal = ReturnVal | MsbMask;
996         }
997
998         ReturnVal = ReturnVal & WidthMask;
999
1000         return ReturnVal;
1001
1002 }
1003 #endif /* ROTATE_RIGHT */
1004