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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 179 sybreon
/* $Id: memtest.hh,v 1.6 2008-06-23 23:40:28 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 176 sybreon
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
 
29 173 sybreon
/**
30
   WALKING ONES TEST
31
   Checks individual bit lines in O(1)
32
   http://www.embedded.com/2000/0007/0007feat1list1.htm
33
*/
34
 
35 179 sybreon
static inline int memTestDataBus(volatile int *ram)
36 173 sybreon
{
37
  for (int i=1; i!=0; i<<=1)
38
    {
39
      *ram = i; // write test value
40
      if (*ram != i) // read back test
41
        return i;
42
    }
43
  return 0; // 0 if success
44
}
45
 
46
/**
47
   POWERS OF TWO TEST
48
   Checks the address lines
49
   http://www.embedded.com/2000/0007/0007feat1list2.htm
50
 */
51
 
52 179 sybreon
static inline int memTestAddrBus(volatile int *ram, int len)
53 173 sybreon
{
54
  const int p = 0xAAAAAAAA;
55
  const int q = 0x55555555;
56 179 sybreon
  int nlen = (len / sizeof(int)) - 1;
57 175 sybreon
 
58 173 sybreon
  // prefill memory
59 175 sybreon
  for (int i=1; (i & nlen)!=0 ; i<<=1)
60 173 sybreon
    {
61
      ram[i] = p;
62
    }
63
 
64
  // check 1 - stuck high
65
  ram[0] = q;
66 175 sybreon
  for (int i=1; (i & nlen)!=0 ; i<<=1)
67 173 sybreon
    {
68
      if (ram[i] != p)
69 179 sybreon
        return i;
70 173 sybreon
    }
71
 
72
  // check 2 - stuck low
73 179 sybreon
  ram[0] = p;
74 175 sybreon
  for (int j=1; (j & nlen)!=0 ; j<<=1)
75 173 sybreon
    {
76
      ram[j] = q;
77 175 sybreon
      for (int i=1; (i & nlen)!=0 ; i<<=1)
78 173 sybreon
        {
79
          if ((ram[i] != p) && (i != j))
80 179 sybreon
            return i;
81 173 sybreon
        }
82
      ram[j] = p;
83
    }
84
 
85
  return 0;
86
}
87
 
88
/**
89
   INCREMENT TEST
90
   Checks the entire memory device
91
   http://www.embedded.com/2000/0007/0007feat1list1.htm
92
 */
93 174 sybreon
 
94 179 sybreon
static inline int memTestFullDev(volatile int *ram, int len)
95 173 sybreon
{
96 179 sybreon
  int nlen = len / sizeof(int);
97 178 sybreon
 
98 173 sybreon
  // prefill the memory
99 178 sybreon
  for (int p=1, i=0; i
100 173 sybreon
    {
101
      ram[i] = p;
102
    }
103
 
104
  // pass 1 - check and invert
105 178 sybreon
  for (int p=1, i=0; i
106 173 sybreon
    {
107
      if (ram[i] != p)
108 179 sybreon
        return p;
109 173 sybreon
      ram[i] = ~p;
110
    }
111
 
112
  // pass 2 - check and zero
113 178 sybreon
  for (int p=1, i=0; i
114 173 sybreon
    {
115
      if (ram[i] != ~p)
116 179 sybreon
        return p;
117 173 sybreon
      ram[i] = 0;
118
    }
119
 
120
  return 0;
121
}
122
 
123 176 sybreon
#ifdef __cplusplus
124
}
125 173 sybreon
#endif
126
 
127 176 sybreon
#endif
128
 
129 173 sybreon
/*
130
  $Log: not supported by cvs2svn $
131 179 sybreon
  Revision 1.5  2008/06/23 22:28:00  sybreon
132
  resized fulldev test
133
 
134 178 sybreon
  Revision 1.4  2008/06/23 22:08:39  sybreon
135
  Renamed functions
136
 
137 176 sybreon
  Revision 1.3  2008/06/23 22:05:14  sybreon
138
  *** empty log message ***
139
 
140 175 sybreon
  Revision 1.2  2008/06/21 10:01:35  sybreon
141
  *** empty log message ***
142
 
143 174 sybreon
  Revision 1.1  2008/06/20 17:51:23  sybreon
144
  initial import
145
 
146 173 sybreon
 */

powered by: WebSVN 2.1.0

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