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

Subversion Repositories aemb

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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