/* * kolter1.c * * This program reads the kolter PROTO-3 pci card at the base address * and writes these short int continuously into the 1457152 byte big file * /usr/local/ftp/pub/kolter1.out. * * If the program is started without any parameter and if /usr/local/ftp/pub/ * does not existt, the progam terminates with signal 11. * * The number of the last cyxle is written into /usr/local/ftp/pub/kolter1.log * as a unsigned long long int. * * This Program won't work on the sparc, where there's no concept of I/O space. * Tested with 2.0 and 2.2 and with 0, 1 and 2 PRPTO-3 on the x86 * * Important: this program won't work without the compiler-option -O or -02 ... * and this program can only be run by a superuser (or another user after * "chown root.root kolter1; chmod 4755 kolter1"). * * This user space program and the module (kolter2) can be used at the same time, * but one value from the card can be read from only one program. 2000 Rolf Freitag, rolf.freiag at email.de This Program is free software; you can redistribute it and/od modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at yout option) any later version. This Program is distributed in the hope that it will be useful, but WITHOUT ANY WARRENTY; without even the implied warrenty of MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this Program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef __sparc__ # error "This Program can't run on the Sparc platform" #endif #include "kolter.h" // for kolter pci card base #include /* error codes */ #include /* ioperm ... */ #include /* file characteristics */ #include /* iostream/stdio */ #include /* Signals */ #include #include #include // geteuid #include // simple version number #define SOFTWARE_VERSION_NUMBER 1.0 #define DEV_ID 0x0017 // Device ID: PRPTO-3 static FILE *ofp1 = NULL; /* first output file pointer */ static FILE *ofp2 = NULL; /* log file number of &ofp1 */ static long long int i = 0; static unsigned long long int wordanz = 728576; /* 5 1/4 " disc size : 1457152 Byte */ static unsigned long long int ll = 0; /* actual number of ofp2 */ static int ssm = 0; /* single-shot or continuous mode */ static unsigned short us = 0x0; /* for storing the words (16 bit) */ static unsigned int kolter_card_base = 0xffffffff;// base of the kolter card void sig_handler () __attribute__ ((noreturn)); int main () __attribute__ ((noreturn)); void sig_handler (int sig) /* signal handler */ { printf ("\aSignal %d - program exiting... \r\n", sig); if (ofp1 != NULL) fclose (ofp1); if (ofp2 != NULL) fclose (ofp2); iopl (0); /* no I/O permission */ exit (0); } /* sig_handler */ void direct () /* direct reading from the card and direct writing to the ofp1 */ { for (;;) { rewind (ofp2); fprintf (ofp2, "%llu \n", ll); fflush (ofp2); rewind (ofp1); for (i = 1; i <= wordanz; i++) { us ^= inw (kolter_card_base); /* direct reading and error tolerant storing */ /* direct writing */ fwrite (&us, sizeof (unsigned short), 1, ofp1); } fflush (ofp1); /* emty buffer */ ll++; if (ssm) break; } } /* direct */ int main (const int argc, const char * const argv[]) { int chm = 1; /* f. chmod */ char line[0xffff] = { '\0' }; long long int lli = -1; // for SuSE example FTP environment char outname1[0x7fff] = "/usr/local/ftp/pub/kolter1.out"; // for SuSE example FTP environment char outname2[0x7fff] = "/usr/local/ftp/pub/kolter1.log"; signal (SIGHUP, sig_handler); signal (SIGINT, sig_handler); signal (SIGQUIT, sig_handler); signal (SIGILL, sig_handler); signal (SIGTRAP, sig_handler); signal (SIGIOT, sig_handler); /* signal(SIGEMT, sig_handler); */ signal (SIGFPE, sig_handler); signal (SIGKILL, sig_handler); signal (SIGBUS, sig_handler); signal (SIGSEGV, sig_handler); /* signal(SIGSYS, sig_handler); */ signal (SIGPIPE, sig_handler); signal (SIGALRM, sig_handler); signal (SIGTERM, sig_handler); signal (SIGABRT, sig_handler); if ( (argc>1) and not strncmp (argv[1], "-V", 123) ) { fprintf (stdout, "%s version %.1f\n", argv[0], SOFTWARE_VERSION_NUMBER); exit ( (2 == argc) ? 0 : -1); } if ((argc > 3) or (argc < 2)) { fprintf (stderr, "\aUsage: %s [output file size in 2*(n/2) Byte] [output file name]\n", argv[0]); fprintf (stderr, "or: %s -V\n", argv[0]); fprintf (stderr, "[] = Optional <> = Parameter Requirement. 1..2 parameters required.\n"); exit (-1); } if (geteuid () != 0) { printf ("\a\nError: $EUID==%d isn't zero (no unlimited I/O permission, your apparently id is not the root id).\n\n", getuid ()); exit (-EPERM); } if (argc >= 2) { sscanf (argv[1], "%s", line); if (sscanf (line, "%lld", &i) == 0) // if argv[1] is no number if (sscanf (line, "%s", outname1)) chm = 0; } if (i) wordanz = i / 2; if (argc == 3) { sscanf (argv[2], "%s", line); if (sscanf (line, "%s", outname1)) chm = 0; } // get base port lli = get_first_kolter_pci_device_baseaddress (DEV_ID); if (lli < 0) //error { fprintf (stderr, "\a\r\nError: no kolter pci card found. I'm aborting now.\r\n\r\n"); exit (-ENODEV); } else kolter_card_base = (unsigned int) lli; iopl (3); // unlimited I/O access permission, nessesary above the 0x3ff limit e. g. at 0x9800 if (!(chm)) strcpy (outname2, "/dev/null"); if (chm == 0) ssm = 1; // single shot mode ofp1 = fopen (outname1, "w"); if (ferror (ofp1)) { perror ("\a output-file-error "); if (ofp1 != NULL) fclose (ofp1); exit (errno); } if (chm) { sprintf (line, "chmod 01644 %s", outname1); system (line); /* read for all, write only for root */ } ofp2 = fopen (outname2, "w"); if (ferror (ofp2)) { perror ("\a output-log-file-error "); if (ofp1 != NULL) fclose (ofp1); if (ofp2 != NULL) fclose (ofp2); exit (errno); } if (chm) { sprintf (line, "chmod 01644 %s", outname2); system (line); /* read for all, write only for root */ } direct (); if (ofp1 != NULL) fclose (ofp1); if (ofp2 != NULL) fclose (ofp2); iopl (0); /* no I/O permission */ exit (0); } /* main */