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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 173 sybreon
/* $Id: memtest.hh,v 1.1 2008-06-20 17:51:23 sybreon Exp $
2
**
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
 
53
  // prefill memory
54
  for (int i=1; (i & (len-1))!=0 ; i<<=1)
55
    {
56
      ram[i] = p;
57
    }
58
 
59
  // check 1 - stuck high
60
  ram[0] = q;
61
  for (int i=1; (i & (len-1))!=0 ; i<<=1)
62
    {
63
      if (ram[i] != p)
64
        return ram[i];
65
    }
66
  ram[0] = p;
67
 
68
  // check 2 - stuck low
69
  for (int j=1; (j & (len-1))!=0 ; j<<=1)
70
    {
71
      ram[j] = q;
72
      for (int i=1; (i & (len-1))!=0 ; i<<=1)
73
        {
74
          if ((ram[i] != p) && (i != j))
75
            return ram[i];
76
        }
77
      ram[j] = p;
78
    }
79
 
80
  return 0;
81
}
82
 
83
/**
84
   INCREMENT TEST
85
   Checks the entire memory device
86
   http://www.embedded.com/2000/0007/0007feat1list1.htm
87
 */
88
inline int memtestDeviceMem(volatile int *ram, int len)
89
{
90
  // prefill the memory
91
  for (int p=1, i=0; i
92
    {
93
      ram[i] = p;
94
    }
95
 
96
  // pass 1 - check and invert
97
  for (int p=1, i=0; i
98
    {
99
      if (ram[i] != p)
100
        return ram[i];
101
      ram[i] = ~p;
102
    }
103
 
104
  // pass 2 - check and zero
105
  for (int p=1, i=0; i
106
    {
107
      if (ram[i] != ~p)
108
        return ram[i];
109
      ram[i] = 0;
110
    }
111
 
112
  return 0;
113
}
114
 
115
#endif
116
 
117
/*
118
  $Log: not supported by cvs2svn $
119
 */

powered by: WebSVN 2.1.0

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