Rev 9 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9 | Rev 11 | ||
---|---|---|---|
1 | //**************************************************************************** |
1 | //**************************************************************************** |
2 | // Copyright (C) 2000-2004 ARW Elektronik Germany |
2 | // Copyright (C) 2000-2004 ARW Elektronik Germany |
3 | // |
3 | // |
4 | // This program is free software; you can redistribute it and/or modify |
4 | // This program is free software; you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation; either version 2 of the License, or |
6 | // the Free Software Foundation; either version 2 of the License, or |
7 | // (at your option) any later version. |
7 | // (at your option) any later version. |
8 | // |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
12 | // GNU General Public License for more details. |
13 | // |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program; if not, write to the Free Software |
15 | // along with this program; if not, write to the Free Software |
16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | // |
17 | // |
18 | // This product is not authorized for use as critical component in |
18 | // This product is not authorized for use as critical component in |
19 | // life support systems without the express written approval of |
19 | // life support systems without the express written approval of |
20 | // ARW Elektronik Germany. |
20 | // ARW Elektronik Germany. |
21 | // |
21 | // |
22 | // Please announce changes and hints to ARW Elektronik |
22 | // Please announce changes and hints to ARW Elektronik |
23 | // |
23 | // |
24 | // Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de) |
24 | // Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de) |
25 | // |
25 | // |
26 | //**************************************************************************** |
26 | //**************************************************************************** |
27 | 27 | ||
28 | //**************************************************************************** |
28 | //**************************************************************************** |
29 | // |
29 | // |
30 | // simpleTest.c -- a simple test program for the PCIVME PCI to VME Interface |
30 | // simpleTest.c -- a simple test program for the PCIVME PCI to VME Interface |
31 | // |
31 | // |
32 | // $Log: simpleTest.c,v $ |
32 | // $Log: simpleTest.c,v $ |
33 | // Revision 1.4 2004/08/13 19:23:55 klaus |
33 | // Revision 1.4 2004/08/13 19:23:55 klaus |
34 | // conversion to kernel-version 2.6, released version 3.0 |
34 | // conversion to kernel-version 2.6, released version 3.0 |
35 | // |
35 | // |
36 | // Revision 1.3 2002/10/17 19:05:03 klaus |
36 | // Revision 1.3 2002/10/17 19:05:03 klaus |
37 | // VME access is working through test to lib to driver |
37 | // VME access is working through test to lib to driver |
38 | // |
38 | // |
39 | // Revision 1.2 2002/10/12 22:12:19 klaus |
39 | // Revision 1.2 2002/10/12 22:12:19 klaus |
40 | // simple change |
40 | // simple change |
41 | // |
41 | // |
42 | // Revision 1.1.1.1 2002/10/09 19:36:29 klaus |
42 | // Revision 1.1.1.1 2002/10/09 19:36:29 klaus |
43 | // initial import |
43 | // initial import |
44 | // |
44 | // |
45 | // |
45 | // |
46 | //**************************************************************************** |
46 | //**************************************************************************** |
47 | 47 | ||
48 | /*--- INCLUDES -----------------------------------------------------------------------------------*/ |
48 | /*--- INCLUDES -----------------------------------------------------------------------------------*/ |
49 | #include <stdio.h> |
49 | #include <stdio.h> |
50 | #include <stdlib.h> |
50 | #include <stdlib.h> |
51 | #include <limits.h> // rand() |
51 | #include <limits.h> // rand() |
52 | #include <string.h> |
52 | #include <string.h> |
53 | #include <unistd.h> |
53 | #include <unistd.h> |
54 | #include <sys/mman.h> |
54 | #include <sys/mman.h> |
55 | #include <linux/types.h> |
55 | #include <linux/types.h> |
56 | #include <errno.h> |
56 | #include <errno.h> |
57 | #include <ctype.h> |
57 | #include <ctype.h> |
58 | 58 | ||
59 | #include <../driver/pcivme.h> |
59 | #include <../driver/pcivme.h> |
60 | #include <../lib/pcivme_ni.h> |
60 | #include <../lib/pcivme_ni.h> |
61 | 61 | ||
62 | /*--- DEFINES ------------------------------------------------------------------------------------*/ |
62 | /*--- DEFINES ------------------------------------------------------------------------------------*/ |
63 | #define DEVICE_NAME "/dev/vmemm_1" |
63 | #define DEVICE_NAME "/dev/vmemm_1" |
64 | #define DEFAULT_WIDTH BYTE_ACCESS |
64 | #define DEFAULT_WIDTH BYTE_ACCESS |
65 | #define DEFAULT_MODIFIER 0x39 |
65 | #define DEFAULT_MODIFIER 0x39 |
66 | #define BUFFER_SIZE 0x10000 // local buffer for temporary use |
66 | #define BUFFER_SIZE 0x10000 // local buffer for temporary use |
67 | 67 | ||
68 | /*--- TYPEDEFS -----------------------------------------------------------------------------------*/ |
68 | /*--- TYPEDEFS -----------------------------------------------------------------------------------*/ |
69 | 69 | ||
70 | /*--- GLOBALS ------------------------------------------------------------------------------------*/ |
70 | /*--- GLOBALS ------------------------------------------------------------------------------------*/ |
71 | char *cszPrgName; |
71 | char *cszPrgName; |
72 | 72 | ||
73 | /*--- FUNCTIONS ----------------------------------------------------------------------------------*/ |
73 | /*--- FUNCTIONS ----------------------------------------------------------------------------------*/ |
74 | void hlpMsg(void) |
74 | void hlpMsg(void) |
75 | { |
75 | { |
76 | printf("simpleTest - a program to do a RAM test with help of the PCIVME interface of ARW Elektronik Germany.\n"); |
76 | printf("simpleTest - a program to do a RAM test with help of the PCIVME interface of ARW Elektronik Germany.\n"); |
77 | printf("Copyright: see the GPL of the free software foundation. K.Hitschler, %s.\n", __DATE__); |
77 | printf("Copyright: see the GPL of the free software foundation. K.Hitschler, %s.\n", __DATE__); |
78 | printf("usage: simpleTest [-d=DeviceName] -s=StartAddress [-l=Length] [-m=AddressModifier] [-w=AccessWidth] [-?]\n"); |
78 | printf("usage: simpleTest [-d=DeviceName] -s=StartAddress [-l=Length] [-m=AddressModifier] [-w=AccessWidth] [-?]\n"); |
79 | printf(" -d - choose a device to use. (Default: %s)\n", DEVICE_NAME); |
79 | printf(" -d - choose a device to use. (Default: %s)\n", DEVICE_NAME); |
80 | printf(" -s=StartAddress - address to start the test, mandatory.\n"); |
80 | printf(" -s=StartAddress - address to start the test, mandatory.\n"); |
81 | printf(" -w=AccessWidth - data element width, 1,2 or 4. (Default: %d)\n", DEFAULT_WIDTH); |
81 | printf(" -w=AccessWidth - data element width, 1,2 or 4. (Default: %d)\n", DEFAULT_WIDTH); |
82 | printf(" -l=Length - area length to test in bytes. (Default: equal AccessWidth)\n"); |
82 | printf(" -l=Length - area length to test in bytes. (Default: equal AccessWidth)\n"); |
83 | printf(" -m=AddressModifier - VME address modifier for accesses. (Default: 0x%02x)\n", DEFAULT_MODIFIER); |
83 | printf(" -m=AddressModifier - VME address modifier for accesses. (Default: 0x%02x)\n", DEFAULT_MODIFIER); |
84 | printf(" -? - this help.\n"); |
84 | printf(" -? - this help.\n"); |
85 | } |
85 | } |
86 | 86 | ||
87 | /*--- TEST RAM LOOP ------------------------------------------------------------------------------*/ |
87 | /*--- TEST RAM LOOP ------------------------------------------------------------------------------*/ |
88 | __u32 SimpleRamTest(int handle, __u32 start, __u32 length, __u8 accessWidth) |
88 | __u32 SimpleRamTest(int handle, __u32 start, __u32 length, __u8 accessWidth) |
89 | { |
89 | { |
90 | int error = 0; |
90 | int error = 0; |
91 | __u32 r, w; |
91 | __u32 r, w; |
92 | __u32 dwErrorCount = 0; |
92 | __u32 dwErrorCount = 0; |
93 | 93 | ||
94 | while (length >= accessWidth) |
94 | while (length >= accessWidth) |
95 | { |
95 | { |
96 | w = rand(); |
96 | w = rand(); |
97 | 97 | ||
98 | error = VMEwrite(handle, start, accessWidth, 1, &w); |
98 | error = VMEwrite(handle, start, accessWidth, 1, &w); |
99 | if (error) |
99 | if (error) |
100 | { |
100 | { |
101 | dwErrorCount++; |
101 | dwErrorCount++; |
102 | printf("%s : Can't write @ adr: 0x%08x (%s)\n" |
102 | printf("%s : Can't write @ adr: 0x%08x AM 0x%0x %d(%s)\n", cszPrgName, start, accessWidth,error, strerror(error)); |
103 | } |
103 | } |
104 | else |
104 | else |
105 | { |
105 | { |
106 | error = VMEread(handle, start, accessWidth, 1, &r); |
106 | error = VMEread(handle, start, accessWidth, 1, &r); |
107 | if (error) |
107 | if (error) |
108 | { |
108 | { |
109 | dwErrorCount++; |
109 | dwErrorCount++; |
110 | printf("%s : Can't read @ adr: 0x%08x (%s)\n", cszPrgName, start, strerror(error)); |
110 | printf("%s : Can't read @ adr: 0x%08x (%s)\n", cszPrgName, start, strerror(error)); |
111 | } |
111 | } |
112 | else |
112 | else |
113 | { |
113 | { |
114 | error = ENOANO; |
114 | error = ENOANO; |
115 | 115 | ||
116 | switch (accessWidth) |
116 | switch (accessWidth) |
117 | { |
117 | { |
118 | case BYTE_ACCESS: |
118 | case BYTE_ACCESS: |
119 | if ((w & 0xff) != (r & 0xff)) |
119 | if ((w & 0xff) != (r & 0xff)) |
120 | { |
120 | { |
121 | dwErrorCount++; |
121 | dwErrorCount++; |
122 | printf("%s : Compare failed @ adr:0x%08x w:0x%02x r:0x%02x\n",cszPrgName, start, w & 0xff, r & 0xff); |
122 | printf("%s : Compare failed @ adr:0x%08x w:0x%02x r:0x%02x\n",cszPrgName, start, w & 0xff, r & 0xff); |
123 | } |
123 | } |
124 | break; |
124 | break; |
125 | case WORD_ACCESS: |
125 | case WORD_ACCESS: |
126 | if ((w & 0xffff) != (r & 0xffff)) |
126 | if ((w & 0xffff) != (r & 0xffff)) |
127 | { |
127 | { |
128 | dwErrorCount++; |
128 | dwErrorCount++; |
129 | printf("%s : Compare failed @ adr:0x%08x w:0x%04x r:0x%04x\n",cszPrgName, start, w & 0xffff, r & 0xffff); |
129 | printf("%s : Compare failed @ adr:0x%08x w:0x%04x r:0x%04x\n",cszPrgName, start, w & 0xffff, r & 0xffff); |
130 | } |
130 | } |
131 | break; |
131 | break; |
132 | case LONG_ACCESS: |
132 | case LONG_ACCESS: |
133 | if (w != r) |
133 | if (w != r) |
134 | { |
134 | { |
135 | dwErrorCount++; |
135 | dwErrorCount++; |
136 | printf("%s : Compare failed @ adr:0x%08x w:0x%08x r:0x%08x\n",cszPrgName, start, w, r); |
136 | printf("%s : Compare failed @ adr:0x%08x w:0x%08x r:0x%08x\n",cszPrgName, start, w, r); |
137 | } |
137 | } |
138 | break; |
138 | break; |
139 | } |
139 | } |
140 | } |
140 | } |
141 | } |
141 | } |
142 | length -= accessWidth; |
142 | length -= accessWidth; |
143 | start += accessWidth; |
143 | start += accessWidth; |
144 | } |
144 | } |
145 | 145 | ||
146 | return dwErrorCount; |
146 | return dwErrorCount; |
147 | } |
147 | } |
148 | 148 | ||
149 | int main(int argc, char **argv) |
149 | int main(int argc, char **argv) |
150 | { |
150 | { |
151 | char *fname = DEVICE_NAME; |
151 | char *fname = DEVICE_NAME; |
152 | char *ptr; |
152 | char *ptr; |
153 | char ch; |
153 | char ch; |
154 | int i; |
154 | int i; |
155 | int error = 0; |
155 | int error = 0; |
156 | int handle; |
156 | int handle; |
157 | __u8 bAddressModifier = DEFAULT_MODIFIER; |
157 | __u8 bAddressModifier = DEFAULT_MODIFIER; |
158 | __u8 bAccessWidth = DEFAULT_WIDTH; |
158 | __u8 bAccessWidth = DEFAULT_WIDTH; |
159 | __u32 dwStartAddress = -1; |
159 | __u32 dwStartAddress = -1; |
160 | __u32 dwLength = -1; |
160 | __u32 dwLength = -1; |
161 | 161 | ||
162 | //----------------------------------------------------------------------------------- |
162 | //----------------------------------------------------------------------------------- |
163 | // scan command line |
163 | // scan command line |
164 | cszPrgName = argv[0]; |
164 | cszPrgName = argv[0]; |
165 | for (i = 1; i < argc; i++) |
165 | for (i = 1; i < argc; i++) |
166 | { |
166 | { |
167 | ptr = argv[i]; |
167 | ptr = argv[i]; |
168 | 168 | ||
169 | if (*ptr == '-') |
169 | if (*ptr == '-') |
170 | ptr++; |
170 | ptr++; |
171 | ch = *ptr; |
171 | ch = *ptr; |
172 | 172 | ||
173 | ptr++; |
173 | ptr++; |
174 | if (*ptr == '=') |
174 | if (*ptr == '=') |
175 | ptr++; |
175 | ptr++; |
176 | 176 | ||
177 | switch (tolower(ch)) |
177 | switch (tolower(ch)) |
178 | { |
178 | { |
179 | case 'h': |
179 | case 'h': |
180 | case '?': hlpMsg(); exit(0); |
180 | case '?': hlpMsg(); exit(0); |
181 | case 'd': fname = ptr; break; |
181 | case 'd': fname = ptr; break; |
182 | case 's': dwStartAddress = strtoul(ptr, NULL, 16); break; |
182 | case 's': dwStartAddress = strtoul(ptr, NULL, 16); break; |
183 | case 'w': bAccessWidth = (__u8)atoi(ptr); break; |
183 | case 'w': bAccessWidth = (__u8)atoi(ptr); break; |
184 | case 'l': dwLength = strtoul(ptr, NULL, 16); break; |
184 | case 'l': dwLength = strtoul(ptr, NULL, 16); break; |
185 | case 'm': bAddressModifier = (__u8)strtoul(ptr, NULL, 16); break; |
185 | case 'm': bAddressModifier = (__u8)strtoul(ptr, NULL, 16); break; |
186 | default: printf("%s : Unknown command \"%c\"!\n", cszPrgName, ch); exit(0); |
186 | default: printf("%s : Unknown command \"%c\"!\n", cszPrgName, ch); exit(0); |
187 | } |
187 | } |
188 | } |
188 | } |
189 | 189 | ||
190 | //----------------------------------------------------------------------------------- |
190 | //----------------------------------------------------------------------------------- |
191 | // test for correct parameters |
191 | // test for correct parameters |
192 | if (!fname) |
192 | if (!fname) |
193 | { |
193 | { |
194 | printf("%s : Must have devicename!\n", cszPrgName); |
194 | printf("%s : Must have devicename!\n", cszPrgName); |
195 | exit(EINVAL); |
195 | exit(EINVAL); |
196 | } |
196 | } |
197 | 197 | ||
198 | if (dwStartAddress == -1) |
198 | if (dwStartAddress == -1) |
199 | { |
199 | { |
200 | printf("%s : Must have a start address!\n", cszPrgName); |
200 | printf("%s : Must have a start address!\n", cszPrgName); |
201 | exit(EINVAL); |
201 | exit(EINVAL); |
202 | } |
202 | } |
203 | 203 | ||
204 | if ((bAccessWidth > 4) || (bAccessWidth == 3)) |
204 | if ((bAccessWidth > 4) || (bAccessWidth == 3)) |
205 | { |
205 | { |
206 | printf("%s : Illegal AccessWidth (%d)!\n", cszPrgName, bAccessWidth); |
206 | printf("%s : Illegal AccessWidth (%d)!\n", cszPrgName, bAccessWidth); |
207 | exit(EINVAL); |
207 | exit(EINVAL); |
208 | } |
208 | } |
209 | 209 | ||
210 | if (bAddressModifier > 0x3F) |
210 | if (bAddressModifier > 0x3F) |
211 | { |
211 | { |
212 | printf("%s : Illegal VME AddressModifer (0x%02x)!\n", cszPrgName, bAddressModifier); |
212 | printf("%s : Illegal VME AddressModifer (0x%02x)!\n", cszPrgName, bAddressModifier); |
213 | exit(EINVAL); |
213 | exit(EINVAL); |
214 | } |
214 | } |
215 | 215 | ||
216 | if (dwLength == -1) |
216 | if (dwLength == -1) |
217 | dwLength = bAccessWidth; |
217 | dwLength = bAccessWidth; |
218 | 218 | ||
219 | printf("%s: Testing %s from 0x%08x to 0x%08x with Modifier 0x%02x.\n", |
219 | printf("%s: Testing %s from 0x%08x to 0x%08x with Modifier 0x%02x.\n", |
220 | cszPrgName, |
220 | cszPrgName, |
221 | (bAccessWidth == BYTE_ACCESS) ? "bytes" : ((bAccessWidth == WORD_ACCESS) ? "words" : "longs"), |
221 | (bAccessWidth == BYTE_ACCESS) ? "bytes" : ((bAccessWidth == WORD_ACCESS) ? "words" : "longs"), |
222 | dwStartAddress, dwStartAddress + dwLength, bAddressModifier); |
222 | dwStartAddress, dwStartAddress + dwLength, bAddressModifier); |
223 | 223 | ||
224 | //----------------------------------------------------------------------------------- |
224 | //----------------------------------------------------------------------------------- |
225 | // open the path to device |
225 | // open the path to device |
226 | error = VMEopen(fname, bAddressModifier, &handle); |
226 | error = VMEopen(fname, bAddressModifier, &handle); |
227 | if (error) |
227 | if (error) |
228 | { |
228 | { |
229 | printf("%s : Can't open path to %s! (%s)\n", cszPrgName, fname, strerror(error)); |
229 | printf("%s : Can't open path to %s! (%s)\n", cszPrgName, fname, strerror(error)); |
230 | exit(error); |
230 | exit(error); |
231 | } |
231 | } |
232 | 232 | ||
233 | //----------------------------------------------------------------------------------- |
233 | //----------------------------------------------------------------------------------- |
234 | // loop until error |
234 | // loop until error |
235 | error = SimpleRamTest(handle, dwStartAddress, dwLength, bAccessWidth); |
235 | error = SimpleRamTest(handle, dwStartAddress, dwLength, bAccessWidth); |
236 | if (error) |
236 | if (error) |
237 | printf("%s: %d test errors!\n", cszPrgName, error); |
237 | printf("%s: %d test errors!\n", cszPrgName, error); |
238 | else |
238 | else |
239 | printf("%s: No test errors.\n", cszPrgName); |
239 | printf("%s: No test errors.\n", cszPrgName); |
240 | 240 | ||
241 | //----------------------------------------------------------------------------------- |
241 | //----------------------------------------------------------------------------------- |
242 | // close the path to device |
242 | // close the path to device |
243 | error = VMEclose(handle); |
243 | error = VMEclose(handle); |
244 | if (!error) |
244 | if (!error) |
245 | printf("%s: Close OK.\n", cszPrgName); |
245 | printf("%s: Close OK.\n", cszPrgName); |
246 | else |
246 | else |
247 | printf("%s: Close with error, %s!\n", cszPrgName, strerror(error)); |
247 | printf("%s: Close with error, %s!\n", cszPrgName, strerror(error)); |
248 | 248 | ||
249 | return error; |
249 | return error; |
250 | } |
250 | } |
251 | 251 | ||
252 | 252 |