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