OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [memtest.hh] - Blame information for rev 175

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 175 sybreon
/* $Id: memtest.hh,v 1.3 2008-06-23 22:05:14 sybreon Exp $
2 173 sybreon
**
3
** MEMORY TEST FUNCTIONS
4
** Copyright (C) 2008 Shawn Tan 
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9
** under the terms of the GNU General Public License as published by
10
** the Free Software Foundation, either version 3 of the License, or
11
** (at your option) any later version.
12
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
** License for more details.
17
**
18
** You should have received a copy of the GNU General Public License
19
** along with AEMB.  If not, see .
20
*/
21
 
22
#ifndef MEMTEST_HH
23
#define MEMTEST_HH
24
 
25
/**
26
   WALKING ONES TEST
27
   Checks individual bit lines in O(1)
28
   http://www.embedded.com/2000/0007/0007feat1list1.htm
29
*/
30
 
31
inline int memtestDataBus(volatile int *ram)
32
{
33
  for (int i=1; i!=0; i<<=1)
34
    {
35
      *ram = i; // write test value
36
      if (*ram != i) // read back test
37
        return i;
38
    }
39
  return 0; // 0 if success
40
}
41
 
42
/**
43
   POWERS OF TWO TEST
44
   Checks the address lines
45
   http://www.embedded.com/2000/0007/0007feat1list2.htm
46
 */
47
 
48
inline int memtestAddressBus(volatile int *ram, int len)
49
{
50
  const int p = 0xAAAAAAAA;
51
  const int q = 0x55555555;
52 175 sybreon
  int nlen = (len >> 2) - 1;
53
 
54 173 sybreon
  // prefill memory
55 175 sybreon
  for (int i=1; (i & nlen)!=0 ; i<<=1)
56 173 sybreon
    {
57
      ram[i] = p;
58
    }
59
 
60
  // check 1 - stuck high
61
  ram[0] = q;
62 175 sybreon
  for (int i=1; (i & nlen)!=0 ; i<<=1)
63 173 sybreon
    {
64
      if (ram[i] != p)
65
        return ram[i];
66
    }
67
  ram[0] = p;
68
 
69
  // check 2 - stuck low
70 175 sybreon
  for (int j=1; (j & nlen)!=0 ; j<<=1)
71 173 sybreon
    {
72
      ram[j] = q;
73 175 sybreon
      for (int i=1; (i & nlen)!=0 ; i<<=1)
74 173 sybreon
        {
75
          if ((ram[i] != p) && (i != j))
76
            return ram[i];
77
        }
78
      ram[j] = p;
79
    }
80
 
81
  return 0;
82
}
83
 
84
/**
85
   INCREMENT TEST
86
   Checks the entire memory device
87
   http://www.embedded.com/2000/0007/0007feat1list1.htm
88
 */
89 174 sybreon
 
90 173 sybreon
inline int memtestDeviceMem(volatile int *ram, int len)
91
{
92
  // prefill the memory
93
  for (int p=1, i=0; i
94
    {
95
      ram[i] = p;
96
    }
97
 
98
  // pass 1 - check and invert
99
  for (int p=1, i=0; i
100
    {
101
      if (ram[i] != p)
102
        return ram[i];
103
      ram[i] = ~p;
104
    }
105
 
106
  // pass 2 - check and zero
107
  for (int p=1, i=0; i
108
    {
109
      if (ram[i] != ~p)
110
        return ram[i];
111
      ram[i] = 0;
112
    }
113
 
114
  return 0;
115
}
116
 
117
#endif
118
 
119
/*
120
  $Log: not supported by cvs2svn $
121 175 sybreon
  Revision 1.2  2008/06/21 10:01:35  sybreon
122
  *** empty log message ***
123
 
124 174 sybreon
  Revision 1.1  2008/06/20 17:51:23  sybreon
125
  initial import
126
 
127 173 sybreon
 */

powered by: WebSVN 2.1.0

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