OpenCores
URL https://opencores.org/ocsvn/mb-jpeg/mb-jpeg/trunk

Subversion Repositories mb-jpeg

[/] [mb-jpeg/] [tags/] [STEP1_1/] [microblaze_0/] [libsrc/] [common_v1_00_a/] [src/] [xutil_memtest.c] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 quickwayne
/* $Id: xutil_memtest.c,v 1.1 2006-06-23 19:00:01 quickwayne Exp $ */
2
/******************************************************************************
3
*
4
*       XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
5
*       AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
6
*       SOLUTIONS FOR XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE,
7
*       OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
8
*       APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
9
*       THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
10
*       AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
11
*       FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
12
*       WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
13
*       IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
14
*       REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
15
*       INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16
*       FOR A PARTICULAR PURPOSE.
17
*
18
*       (c) Copyright 2002 Xilinx Inc.
19
*       All rights reserved.
20
*
21
******************************************************************************/
22
/*****************************************************************************/
23
/**
24
*
25
* @file xutil_memtest.c
26
*
27
* Contains the memory test utility functions.
28
*
29
* <pre>
30
* MODIFICATION HISTORY:
31
*
32
* Ver    Who    Date    Changes
33
* ----- ---- -------- -----------------------------------------------
34
* 1.00a ecm  11/01/01 First release
35
* 1.00a xd   11/03/04 Improved support for doxygen.
36
* </pre>
37
*
38
*****************************************************************************/
39
 
40
/***************************** Include Files ********************************/
41
#include "xbasic_types.h"
42
#include "xstatus.h"
43
#include "xutil.h"
44
 
45
/************************** Constant Definitions ****************************/
46
/************************** Function Prototypes *****************************/
47
 
48
static Xuint32 RotateLeft(Xuint32 Input, Xuint8 Width);
49
 
50
/* define ROTATE_RIGHT to give access to this functionality */
51
/* #define ROTATE_RIGHT */
52
#ifdef ROTATE_RIGHT
53
static Xuint32 RotateRight(Xuint32 Input, Xuint8 Width);
54
#endif /* ROTATE_RIGHT*/
55
 
56
 
57
/*****************************************************************************/
58
/**
59
*
60
* Performs a destructive 32-bit wide memory test.
61
*
62
* @param    Addr is a pointer to the region of memory to be tested.
63
* @param    Words is the length of the block.
64
* @param    Pattern is the constant used for the constant pattern test, if 0,
65
*           0xDEADBEEF is used.
66
* @param    Subtest is the test selected. See xutil.h for possible values.
67
*
68
* @return
69
*
70
* - XST_MEMTEST_FAILED is returned for a failure
71
* - XST_SUCCESS is returned for a pass
72
*
73
* @note
74
*
75
* Used for spaces where the address range of the region is smaller than
76
* the data width. If the memory range is greater than 2 ** width,
77
* the patterns used in XUT_WALKONES and XUT_WALKZEROS will repeat on a
78
* boundry of a power of two making it more difficult to detect addressing
79
* errors. The XUT_INCREMENT and XUT_INVERSEADDR tests suffer the same
80
* problem. Ideally, if large blocks of memory are to be tested, break
81
* them up into smaller regions of memory to allow the test patterns used
82
* not to repeat over the region tested.
83
*
84
*****************************************************************************/
85
XStatus XUtil_MemoryTest32(Xuint32 *Addr,Xuint32 Words,Xuint32 Pattern,
86
                           Xuint8 Subtest)
87
{
88
    Xuint32 i;
89
    Xuint32 j;
90
    Xuint32 Val = XUT_MEMTEST_INIT_VALUE;
91
    Xuint32 FirstVal = XUT_MEMTEST_INIT_VALUE;
92
    Xuint32 Word;
93
 
94
    XASSERT_NONVOID(Words != 0);
95
    XASSERT_NONVOID(Subtest <= XUT_MAXTEST);
96
 
97
    /*
98
     * Select the proper Subtest
99
     */
100
 
101
 
102
    switch (Subtest)
103
    {
104
 
105
        case XUT_ALLMEMTESTS:
106
 
107
        /* this case executes all of the Subtests */
108
 
109
        /* fall through case statement */
110
 
111
        case XUT_INCREMENT:
112
        {
113
 
114
            /*
115
             * Fill the memory with incrementing
116
             * values starting from 'FirstVal'
117
             */
118
            for (i = 0L; i < Words; i++)
119
            {
120
                Addr[i] = Val;
121
 
122
                /* write memory location */
123
 
124
                Val++;
125
            }
126
 
127
            /*
128
             * Restore the reference 'Val' to the
129
             * initial value
130
             */
131
 
132
            Val = FirstVal;
133
 
134
            /*
135
             * Check every word within the Words
136
             * of tested memory and compare it
137
             * with the incrementing reference
138
             * Val
139
             */
140
 
141
            for (i = 0L; i < Words; i++)
142
            {
143
                Word = Addr[i];
144
 
145
                if (Word != Val)
146
                {
147
                    return XST_MEMTEST_FAILED;
148
                }
149
 
150
                Val++;
151
            }
152
 
153
 
154
            if (Subtest != XUT_ALLMEMTESTS)
155
            {
156
                return XST_SUCCESS;
157
            }
158
 
159
 
160
        } /* end of case 1 */
161
 
162
        /* fall through case statement */
163
 
164
        case XUT_WALKONES:
165
        {
166
            /*
167
             * set up to cycle through all possible initial
168
             * test Patterns for walking ones test
169
             */
170
 
171
            for (j = 0L; j < 32; j++)
172
            {
173
                /*
174
                 * Generate an initial value for walking ones test to test for bad
175
                 * data bits
176
                 */
177
 
178
                Val = 1 << j;
179
 
180
                /*
181
                 * START walking ones test
182
                 * Write a one to each data bit indifferent locations
183
                 */
184
 
185
                for (i = 0L; i < 32; i++)
186
                {
187
 
188
                    /* write memory location */
189
 
190
                    Addr[i] = Val;
191
                    Val = (Xuint32) RotateLeft(Val, 32);
192
 
193
                }
194
 
195
                /*
196
                 * Restore the reference 'Val' to the
197
                 * initial value
198
                 */
199
                Val = 1 << j;
200
 
201
                /* Read the values from each location that was written */
202
 
203
                for (i = 0L; i < 32; i++)
204
                {
205
                    /* read memory location */
206
 
207
                    Word = Addr[i];
208
 
209
                    if (Word != Val)
210
                    {
211
                        return XST_MEMTEST_FAILED;
212
                    }
213
 
214
                    Val = (Xuint32) RotateLeft(Val, 32);
215
 
216
                }
217
 
218
            }
219
 
220
            if (Subtest != XUT_ALLMEMTESTS)
221
            {
222
                return XST_SUCCESS;
223
            }
224
 
225
 
226
        } /* end of case 2 */
227
 
228
        /* fall through case statement */
229
 
230
        case XUT_WALKZEROS:
231
        {
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
                /*
241
                 * Generate an initial value for walking ones test to test for
242
                 * bad data bits
243
                 */
244
 
245
                Val = ~(1 << j);
246
 
247
                /*
248
                 * START walking zeros test
249
                 * Write a one to each data bit indifferent locations
250
                 */
251
 
252
                for (i = 0L; i < 32; i++)
253
                {
254
 
255
                    /* write memory location */
256
 
257
                    Addr[i] = Val;
258
                    Val = ~((Xuint32) RotateLeft(~Val, 32));
259
 
260
                }
261
 
262
                /*
263
                 * Restore the reference 'Val' to the
264
                 * initial value
265
                 */
266
 
267
                Val = ~(1 << j);
268
 
269
                /* Read the values from each location that was written */
270
 
271
                for (i = 0L; i < 32; i++)
272
                {
273
 
274
                    /* read memory location */
275
 
276
                    Word = Addr[i];
277
 
278
                    if (Word != Val)
279
                    {
280
                        return XST_MEMTEST_FAILED;
281
                    }
282
 
283
                    Val = ~((Xuint32) RotateLeft(~Val, 32));
284
 
285
                }
286
 
287
            }
288
 
289
            if (Subtest != XUT_ALLMEMTESTS)
290
            {
291
                return XST_SUCCESS;
292
            }
293
 
294
        } /* end of case 3 */
295
 
296
        /* fall through case statement */
297
 
298
        case XUT_INVERSEADDR:
299
        {
300
 
301
            /* Fill the memory with inverse of address */
302
 
303
            for (i = 0L; i < Words; i++)
304
            {
305
 
306
                /* write memory location */
307
 
308
                Val = (Xuint32) (~((Xuint32)(&Addr[i])));
309
 
310
                Addr[i] = Val;
311
 
312
            }
313
 
314
            /*
315
             * Check every word within the Words
316
             * of tested memory
317
             */
318
 
319
            for (i = 0L; i < Words; i++)
320
            {
321
 
322
                /* Read the location */
323
 
324
                Word = Addr[i];
325
 
326
                Val = (Xuint32) (~((Xuint32)(&Addr[i])));
327
 
328
                if ((Word ^ Val) != 0x00000000)
329
                {
330
                    return XST_MEMTEST_FAILED;
331
                }
332
            }
333
 
334
            if (Subtest != XUT_ALLMEMTESTS)
335
            {
336
                return XST_SUCCESS;
337
            }
338
 
339
 
340
        } /* end of case 4 */
341
 
342
 
343
        /* fall through case statement */
344
 
345
        case XUT_FIXEDPATTERN:
346
        {
347
 
348
            /*
349
             * Generate an initial value for
350
             * memory testing
351
             */
352
 
353
            if (Pattern == 0)
354
            {
355
                Val = 0xDEADBEEF;
356
 
357
            }
358
            else
359
            {
360
                Val = Pattern;
361
 
362
            }
363
 
364
            /*
365
             * Fill the memory with fixed pattern
366
             */
367
 
368
            for (i = 0L; i < Words; i++)
369
            {
370
                /* write memory location */
371
 
372
                Addr[i] = Val;
373
 
374
            }
375
 
376
            /*
377
             * Check every word within the Words
378
             * of tested memory and compare it
379
             * with the fixed pattern
380
             */
381
 
382
            for (i = 0L; i < Words; i++)
383
            {
384
 
385
                /* read memory location */
386
 
387
                Word = Addr[i];
388
 
389
                if (Word != Val)
390
                {
391
                    return XST_MEMTEST_FAILED;
392
                }
393
            }
394
 
395
            if (Subtest != XUT_ALLMEMTESTS)
396
            {
397
                return XST_SUCCESS;
398
            }
399
 
400
        } /* end of case 5 */
401
 
402
        /* this break is for the prior fall through case statements */
403
 
404
        break ;
405
 
406
        default:
407
        {
408
            return XST_MEMTEST_FAILED;
409
        }
410
 
411
    }  /* end of switch */
412
 
413
    /* Successfully passed memory test ! */
414
 
415
    return XST_SUCCESS;
416
}
417
 
418
/*****************************************************************************/
419
/**
420
*
421
* Performs a destructive 16-bit wide memory test.
422
*
423
* @param    Addr is a pointer to the region of memory to be tested.
424
* @param    Words is the length of the block.
425
* @param    Pattern is the constant used for the constant pattern test, if 0,
426
*           0xDEADBEEF is used.
427
* @param    Subtest is the test selected. See xutil.h for possible values.
428
*
429
* @return
430
*
431
* - XST_MEMTEST_FAILED is returned for a failure
432
* - XST_SUCCESS is returned for a pass
433
*
434
* @note
435
*
436
* Used for spaces where the address range of the region is smaller than
437
* the data width. If the memory range is greater than 2 ** width,
438
* the patterns used in XUT_WALKONES and XUT_WALKZEROS will repeat on a
439
* boundry of a power of two making it more difficult to detect addressing
440
* errors. The XUT_INCREMENT and XUT_INVERSEADDR tests suffer the same
441
* problem. Ideally, if large blocks of memory are to be tested, break
442
* them up into smaller regions of memory to allow the test patterns used
443
* not to repeat over the region tested.
444
*
445
*****************************************************************************/
446
XStatus XUtil_MemoryTest16(Xuint16 *Addr,Xuint32 Words, Xuint16 Pattern,
447
                           Xuint8 Subtest)
448
{
449
    Xuint32 i;
450
    Xuint32 j;
451
    Xuint16 Val= XUT_MEMTEST_INIT_VALUE;
452
    Xuint16 FirstVal= XUT_MEMTEST_INIT_VALUE;
453
    Xuint16 Word;
454
 
455
    XASSERT_NONVOID(Words != 0);
456
    XASSERT_NONVOID(Subtest <= XUT_MAXTEST);
457
 
458
    /*
459
     * selectthe proper Subtest(s)
460
     */
461
 
462
    switch (Subtest)
463
    {
464
 
465
        case XUT_ALLMEMTESTS:
466
 
467
        /* this case executes all of the Subtests */
468
 
469
        /* fall through case statement */
470
 
471
        case XUT_INCREMENT:
472
        {
473
 
474
            /*
475
             * Fill the memory with incrementing
476
             * values starting from 'FirstVal'
477
             */
478
            for (i = 0L; i < Words; i++)
479
            {
480
                /* write memory location */
481
 
482
                Addr[i] = Val;
483
 
484
                Val++;
485
            }
486
 
487
            /*
488
             * Restore the reference 'Val' to the
489
             * initial value
490
             */
491
 
492
            Val = FirstVal;
493
 
494
            /*
495
             * Check every word within the Words
496
             * of tested memory and compare it
497
             * with the incrementing reference
498
             * Val
499
             */
500
 
501
            for (i = 0L; i < Words; i++)
502
            {
503
 
504
                /* read memory location */
505
 
506
                Word = Addr[i];
507
 
508
                if (Word != Val)
509
                {
510
                    return XST_MEMTEST_FAILED;
511
                }
512
                Val++;
513
            }
514
 
515
            if (Subtest != XUT_ALLMEMTESTS)
516
            {
517
                return XST_SUCCESS;
518
            }
519
 
520
        } /* end of case 1 */
521
 
522
        /* fall through case statement */
523
 
524
        case XUT_WALKONES:
525
        {
526
            /*
527
             * set up to cycle through all possible initial test
528
             * Patterns for walking ones test
529
             */
530
 
531
            for (j = 0L; j < 16; j++)
532
            {
533
                /*
534
                 * Generate an initial value for walking ones test to test for bad
535
                 * data bits
536
                 */
537
 
538
                Val = 1 << j;
539
 
540
                /*
541
                 * START walking ones test
542
                 * Write a one to each data bit indifferent locations
543
                 */
544
 
545
                for (i = 0L; i < 16; i++)
546
                {
547
 
548
                    /* write memory location */
549
 
550
                    Addr[i] = Val;
551
 
552
                    Val = (Xuint16) RotateLeft(Val, 16);
553
 
554
                }
555
 
556
                /*
557
                 * Restore the reference 'Val' to the
558
                 * initial value
559
                 */
560
 
561
                Val = 1 << j;
562
 
563
                /* Read the values from each location that was written */
564
 
565
                for (i = 0L; i < 16; i++)
566
                {
567
 
568
                    /* read memory location */
569
 
570
                    Word = Addr[i];
571
 
572
                    if (Word != Val)
573
                    {
574
                        return XST_MEMTEST_FAILED;
575
                    }
576
 
577
                    Val = (Xuint16) RotateLeft(Val, 16);
578
 
579
                }
580
 
581
            }
582
 
583
            if (Subtest != XUT_ALLMEMTESTS)
584
            {
585
                return XST_SUCCESS;
586
            }
587
 
588
 
589
        } /* end of case 2 */
590
 
591
        /* fall through case statement */
592
 
593
        case XUT_WALKZEROS:
594
        {
595
            /*
596
             * set up to cycle through all possible initial
597
             * test Patterns for walking zeros test
598
             */
599
 
600
            for (j = 0L; j < 16; j++)
601
            {
602
 
603
                /*
604
                 * Generate an initial value for walking ones
605
                 * test to test for bad
606
                 * data bits
607
                 */
608
 
609
                Val = ~(1 << j);
610
 
611
                /*
612
                 * START walking zeros test
613
                 * Write a one to each data bit indifferent locations
614
                 */
615
 
616
                for (i = 0L; i < 16; i++)
617
                {
618
 
619
 
620
                    /* write memory location */
621
 
622
                    Addr[i] = Val;
623
                    Val = ~((Xuint16) RotateLeft(~Val, 16));
624
 
625
                }
626
 
627
                /*
628
                 * Restore the reference 'Val' to the
629
                 * initial value
630
                 */
631
 
632
                Val = ~(1 << j);
633
 
634
                /* Read the values from each location that was written */
635
 
636
                for (i = 0L; i < 16; i++)
637
                {
638
 
639
                    /* read memory location */
640
 
641
                    Word = Addr[i];
642
 
643
                    if (Word != Val)
644
                    {
645
                        return XST_MEMTEST_FAILED;
646
                    }
647
 
648
                    Val = ~((Xuint16) RotateLeft(~Val, 16));
649
 
650
                }
651
 
652
            }
653
 
654
            if (Subtest != XUT_ALLMEMTESTS)
655
            {
656
                return XST_SUCCESS;
657
            }
658
 
659
        } /* end of case 3 */
660
 
661
        /* fall through case statement */
662
 
663
        case XUT_INVERSEADDR:
664
        {
665
 
666
            /* Fill the memory with inverse of address */
667
 
668
            for (i = 0L; i < Words; i++)
669
            {
670
                /* write memory location */
671
 
672
                Val = (Xuint16) (~((Xuint32)(&Addr[i])));
673
                Addr[i] = Val;
674
 
675
            }
676
 
677
            /*
678
             * Check every word within the Words
679
             * of tested memory
680
             */
681
 
682
            for (i = 0L; i < Words; i++)
683
            {
684
 
685
                 /* read memory location */
686
 
687
                Word = Addr[i];
688
 
689
                Val = (Xuint16) (~((Xuint32)(&Addr[i])));
690
 
691
                if ((Word ^ Val) != 0x0000)
692
                {
693
                    return XST_MEMTEST_FAILED;
694
                }
695
            }
696
 
697
            if (Subtest != XUT_ALLMEMTESTS)
698
            {
699
                return XST_SUCCESS;
700
            }
701
 
702
 
703
        } /* end of case 4 */
704
 
705
 
706
        /* fall through case statement */
707
 
708
        case XUT_FIXEDPATTERN:
709
        {
710
 
711
            /*
712
             * Generate an initial value for
713
             * memory testing
714
             */
715
 
716
            if (Pattern == 0)
717
            {
718
                Val = 0xDEAD;
719
 
720
            }
721
            else
722
            {
723
                Val = Pattern;
724
 
725
            }
726
 
727
            /*
728
             * Fill the memory with fixed pattern
729
             */
730
 
731
            for (i = 0L; i < Words; i++)
732
            {
733
 
734
                /* write memory location */
735
 
736
                Addr[i] = Val;
737
 
738
            }
739
 
740
            /*
741
             * Check every word within the Words
742
             * of tested memory and compare it
743
             * with the fixed pattern
744
             */
745
 
746
            for (i = 0L; i < Words; i++)
747
            {
748
 
749
                /* read memory location */
750
 
751
                Word = Addr[i];
752
 
753
                if (Word != Val)
754
                {
755
                    return XST_MEMTEST_FAILED;
756
                }
757
            }
758
 
759
            if (Subtest != XUT_ALLMEMTESTS)
760
            {
761
                return XST_SUCCESS;
762
            }
763
 
764
        } /* end of case 5 */
765
 
766
        /* this break is for the prior fall through case statements */
767
 
768
        break ;
769
 
770
        default:
771
        {
772
            return XST_MEMTEST_FAILED;
773
        }
774
 
775
    }  /* end of switch */
776
 
777
    /* Successfully passed memory test ! */
778
 
779
    return XST_SUCCESS;
780
}
781
 
782
 
783
/*****************************************************************************/
784
/**
785
*
786
* Performs a destructive 8-bit wide memory test.
787
*
788
* @param    Addr is a pointer to the region of memory to be tested.
789
* @param    Words is the length of the block.
790
* @param    Pattern is the constant used for the constant pattern test, if 0,
791
*           0xDEADBEEF is used.
792
* @param    Subtest is the test selected. See xutil.h for possible values.
793
*
794
* @return
795
*
796
* - XST_MEMTEST_FAILED is returned for a failure
797
* - XST_SUCCESS is returned for a pass
798
*
799
* @note
800
*
801
* Used for spaces where the address range of the region is smaller than
802
* the data width. If the memory range is greater than 2 ** width,
803
* the patterns used in XUT_WALKONES and XUT_WALKZEROS will repeat on a
804
* boundry of a power of two making it more difficult to detect addressing
805
* errors. The XUT_INCREMENT and XUT_INVERSEADDR tests suffer the same
806
* problem. Ideally, if large blocks of memory are to be tested, break
807
* them up into smaller regions of memory to allow the test patterns used
808
* not to repeat over the region tested.
809
*
810
*****************************************************************************/
811
XStatus XUtil_MemoryTest8(Xuint8 *Addr,Xuint32 Words, Xuint8 Pattern,
812
                          Xuint8 Subtest)
813
{
814
    Xuint32 i;
815
    Xuint32 j;
816
    Xuint8 Val= XUT_MEMTEST_INIT_VALUE;
817
    Xuint8 FirstVal= XUT_MEMTEST_INIT_VALUE;
818
    Xuint8 Word;
819
 
820
    XASSERT_NONVOID(Words != 0);
821
    XASSERT_NONVOID(Subtest <= XUT_MAXTEST);
822
 
823
    /*
824
     * select the proper Subtest(s)
825
     */
826
 
827
    switch (Subtest)
828
    {
829
 
830
        case XUT_ALLMEMTESTS:
831
 
832
        /* this case executes all of the Subtests */
833
 
834
        /* fall through case statement */
835
 
836
        case XUT_INCREMENT:
837
        {
838
 
839
            /*
840
             * Fill the memory with incrementing
841
             * values starting from 'FirstVal'
842
             */
843
            for (i = 0L; i < Words; i++)
844
            {
845
 
846
                /* write memory location */
847
 
848
                Addr[i] = Val;
849
                Val++;
850
            }
851
 
852
            /*
853
             * Restore the reference 'Val' to the
854
             * initial value
855
             */
856
 
857
            Val = FirstVal;
858
 
859
            /*
860
             * Check every word within the Words
861
             * of tested memory and compare it
862
             * with the incrementing reference
863
             * Val
864
             */
865
 
866
            for (i = 0L; i < Words; i++)
867
            {
868
 
869
                /* read memory location */
870
 
871
                Word = Addr[i];
872
 
873
                if (Word != Val)
874
                {
875
                    return XST_MEMTEST_FAILED;
876
                }
877
                Val++;
878
            }
879
 
880
 
881
            if (Subtest != XUT_ALLMEMTESTS)
882
            {
883
                return XST_SUCCESS;
884
            }
885
 
886
 
887
        } /* end of case 1 */
888
 
889
        /* fall through case statement */
890
 
891
        case XUT_WALKONES:
892
        {
893
            /*
894
             * set up to cycle through all possible initial
895
             * test Patterns for walking ones test
896
             */
897
 
898
            for (j = 0L; j < 8; j++)
899
            {
900
                /*
901
                 * Generate an initial value for walking ones test to test
902
                 * for bad data bits
903
                 */
904
 
905
                Val = 1 << j;
906
 
907
                /*
908
                 * START walking ones test
909
                 * Write a one to each data bit indifferent locations
910
                 */
911
 
912
                for (i = 0L; i < 8; i++)
913
                {
914
 
915
                    /* write memory location */
916
 
917
                    Addr[i] = Val;
918
                    Val = (Xuint8) RotateLeft(Val, 8);
919
                }
920
 
921
                /*
922
                 * Restore the reference 'Val' to the
923
                 * initial value
924
                 */
925
                Val = 1 << j;
926
 
927
                /* Read the values from each location that was written */
928
 
929
                for (i = 0L; i < 8; i++)
930
                {
931
 
932
                    /* read memory location */
933
 
934
                    Word = Addr[i];
935
 
936
                    if (Word != Val)
937
                    {
938
                        return XST_MEMTEST_FAILED;
939
                    }
940
 
941
                    Val = (Xuint8) RotateLeft(Val, 8);
942
 
943
                }
944
 
945
            }
946
 
947
            if (Subtest != XUT_ALLMEMTESTS)
948
            {
949
                return XST_SUCCESS;
950
            }
951
 
952
 
953
        } /* end of case 2 */
954
 
955
        /* fall through case statement */
956
 
957
        case XUT_WALKZEROS:
958
        {
959
            /*
960
             * set up to cycle through all possible initial test
961
             * Patterns for walking zeros test
962
             */
963
 
964
            for (j = 0L; j < 8; j++)
965
            {
966
 
967
                /*
968
                 * Generate an initial value for walking ones test to test
969
                 * for bad data bits
970
                 */
971
 
972
                Val = ~(1 << j);
973
 
974
                /*
975
                 * START walking zeros test
976
                 * Write a one to each data bit indifferent locations
977
                 */
978
 
979
                for (i = 0L; i < 8; i++)
980
                {
981
 
982
 
983
                    /* write memory location */
984
 
985
                    Addr[i] = Val;
986
                    Val = ~((Xuint8) RotateLeft(~Val, 8));
987
 
988
                }
989
 
990
                /*
991
                 * Restore the reference 'Val' to the
992
                 * initial value
993
                 */
994
 
995
                Val = ~(1 << j);
996
 
997
                /* Read the values from each location that was written */
998
 
999
                for (i = 0L; i < 8; i++)
1000
                {
1001
 
1002
                    /* read memory location */
1003
 
1004
                    Word = Addr[i];
1005
 
1006
                    if (Word != Val)
1007
                    {
1008
                        return XST_MEMTEST_FAILED;
1009
                    }
1010
 
1011
                    Val = ~((Xuint8) RotateLeft(~Val, 8));
1012
 
1013
                }
1014
 
1015
            }
1016
 
1017
            if (Subtest != XUT_ALLMEMTESTS)
1018
            {
1019
                return XST_SUCCESS;
1020
            }
1021
 
1022
        } /* end of case 3 */
1023
 
1024
        /* fall through case statement */
1025
 
1026
        case XUT_INVERSEADDR:
1027
        {
1028
 
1029
            /* Fill the memory with inverse of address */
1030
 
1031
            for (i = 0L; i < Words; i++)
1032
            {
1033
 
1034
                /* write memory location */
1035
 
1036
                Val = (Xuint8) (~((Xuint32)(&Addr[i])));
1037
                Addr[i] = Val;
1038
 
1039
            }
1040
 
1041
            /*
1042
             * Check every word within the Words
1043
             * of tested memory
1044
             */
1045
 
1046
            for (i = 0L; i < Words; i++)
1047
            {
1048
 
1049
                /* read memory location */
1050
 
1051
                Word = Addr[i];
1052
 
1053
                Val = (Xuint8) (~((Xuint32)(&Addr[i])));
1054
 
1055
                if ((Word ^ Val) != 0x00)
1056
                {
1057
                    return XST_MEMTEST_FAILED;
1058
                }
1059
            }
1060
 
1061
            if (Subtest != XUT_ALLMEMTESTS)
1062
            {
1063
                return XST_SUCCESS;
1064
            }
1065
 
1066
 
1067
        } /* end of case 4 */
1068
 
1069
 
1070
        /* fall through case statement */
1071
 
1072
        case XUT_FIXEDPATTERN:
1073
        {
1074
 
1075
            /*
1076
             * Generate an initial value for
1077
             * memory testing
1078
             */
1079
 
1080
            if (Pattern == 0)
1081
            {
1082
                Val = 0xA5;
1083
 
1084
            }
1085
            else
1086
            {
1087
                Val = Pattern;
1088
 
1089
            }
1090
 
1091
            /*
1092
             * Fill the memory with fixed pattern
1093
             */
1094
 
1095
            for (i = 0L; i < Words; i++)
1096
            {
1097
 
1098
                /* write memory location */
1099
 
1100
                Addr[i] = Val;
1101
 
1102
            }
1103
 
1104
            /*
1105
             * Check every word within the Words
1106
             * of tested memory and compare it
1107
             * with the fixed pattern
1108
             */
1109
 
1110
            for (i = 0L; i < Words; i++)
1111
            {
1112
 
1113
                /* read memory location */
1114
 
1115
                Word = Addr[i];
1116
 
1117
                if (Word != Val)
1118
                {
1119
                    return XST_MEMTEST_FAILED;
1120
                }
1121
            }
1122
 
1123
            if (Subtest != XUT_ALLMEMTESTS)
1124
            {
1125
                return XST_SUCCESS;
1126
            }
1127
 
1128
        } /* end of case 5 */
1129
 
1130
        /* this break is for the prior fall through case statements */
1131
 
1132
        break ;
1133
 
1134
        default:
1135
        {
1136
            return XST_MEMTEST_FAILED;
1137
        }
1138
 
1139
    }  /* end of switch */
1140
 
1141
    /* Successfully passed memory test ! */
1142
 
1143
    return XST_SUCCESS;
1144
}
1145
 
1146
 
1147
/*****************************************************************************/
1148
/**
1149
*
1150
* Rotates the provided value to the left one bit position
1151
*
1152
* @param    Input is value to be rotated to the left
1153
* @param    Width is the number of bits in the input data
1154
*
1155
* @return
1156
*
1157
* The resulting unsigned long value of the rotate left
1158
*
1159
* @note
1160
*
1161
* None.
1162
*
1163
*****************************************************************************/
1164
static Xuint32 RotateLeft(Xuint32 Input, Xuint8 Width)
1165
{
1166
    Xuint32 Msb;
1167
    Xuint32 ReturnVal;
1168
    Xuint32 WidthMask;
1169
    Xuint32 MsbMask;
1170
 
1171
    /*
1172
     * set up the WidthMask and the MsbMask
1173
     */
1174
 
1175
    MsbMask = 1 << (Width-1);
1176
 
1177
    WidthMask = (MsbMask << 1) - 1;
1178
 
1179
    /*
1180
     * set the width of the Input to the correct width
1181
     */
1182
 
1183
    Input = Input & WidthMask;
1184
 
1185
    Msb = Input & MsbMask;
1186
 
1187
    ReturnVal = Input << 1;
1188
 
1189
    if (Msb != 0x00000000)
1190
    {
1191
        ReturnVal = ReturnVal | 0x00000001;
1192
    }
1193
 
1194
    ReturnVal = ReturnVal & WidthMask;
1195
 
1196
    return (ReturnVal);
1197
 
1198
}
1199
 
1200
#ifdef ROTATE_RIGHT
1201
/*****************************************************************************/
1202
/**
1203
*
1204
* Rotates the provided value to the right one bit position
1205
*
1206
* @param    Input is value to be rotated to the right
1207
* @param    Width is the number of bits in the input data
1208
*
1209
* @return
1210
*
1211
* The resulting Xuint32 value of the rotate right
1212
*
1213
* @note
1214
*
1215
* None.
1216
*
1217
*****************************************************************************/
1218
static Xuint32 RotateRight(Xuint32 Input, Xuint8 Width)
1219
{
1220
    Xuint32 Lsb;
1221
    Xuint32 ReturnVal;
1222
    Xuint32 WidthMask;
1223
    Xuint32 MsbMask;
1224
 
1225
    /*
1226
     * set up the WidthMask and the MsbMask
1227
     */
1228
 
1229
    MsbMask = 1 << (Width-1);
1230
 
1231
    WidthMask = (MsbMask << 1) - 1;
1232
 
1233
    /*
1234
     * set the width of the Input to the correct width
1235
     */
1236
 
1237
    Input = Input & WidthMask;
1238
 
1239
    ReturnVal = Input >> 1;
1240
 
1241
    Lsb = Input & 0x00000001;
1242
 
1243
    if (Lsb != 0x00000000)
1244
    {
1245
        ReturnVal = ReturnVal | MsbMask;
1246
    }
1247
 
1248
    ReturnVal = ReturnVal & WidthMask;
1249
 
1250
    return (ReturnVal);
1251
 
1252
}
1253
#endif /* ROTATE_RIGHT */
1254
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.