source: drsdaq/VME/struck/sis1100/V2.02/eeprom_tools/read_eeprom.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 1.8 KB
Line 
1/*
2 * $ZEL: read_eeprom.c,v 1.1 2003/08/21 17:30:35 wuestner Exp $
3 */
4
5#define _GNU_SOURCE
6
7#include <stdio.h>
8#include <errno.h>
9#include <string.h>
10#include <sys/types.h>
11#include <time.h>
12#include <unistd.h>
13#include <stdlib.h>
14#include <fcntl.h>
15#include <sys/mman.h>
16#include <sys/ioctl.h>
17
18#include "plx_eeprom.h"
19
20int verbose, start, len;
21const char* pathname;
22
23static void
24printhelp(const char* progname)
25{
26 fprintf(stderr, "usage: %s [-h] [-v] [-a start] [-l len] path_to_device\n", progname);
27}
28
29static int
30getoptions(int argc, char* argv[])
31{
32 extern char *optarg;
33 extern int optind;
34 int errflag, c;
35 const char* args="a:l:hv";
36
37 optarg=0; errflag=0;
38 verbose=0;
39 start=0;
40 len=EEPROM_LEN;
41
42 while (!errflag && ((c=getopt(argc, argv, args))!=-1)) {
43 switch (c) {
44 case 'h': errflag++; break;
45 case 'v': verbose++; break;
46 case 'a': start=strtol(optarg, 0, 0); break;
47 case 'l': len=strtol(optarg, 0, 0); break;
48 default: errflag++;
49 }
50 }
51
52 if (errflag || (argc-optind)!=1) {
53 printhelp(argv[0]);
54 return -1;
55 }
56
57 pathname=argv[optind];
58
59 return 0;
60}
61
62int main(int argc, char* argv[])
63{
64 u_int16_t data[EEPROM_LEN];
65 int p;
66
67 fprintf(stderr, "\n==== SIS1100 EEPROM Reader; V1.0 ====\n\n");
68
69 if (getoptions(argc, argv)) return 1;
70
71 start>>=1;
72 if (start>=EEPROM_LEN) {
73 fprintf(stderr, "start must be less than %d\n", EEPROM_LEN<<1);
74 return 1;
75 }
76
77 if (start+len>EEPROM_LEN) {
78 len=EEPROM_LEN-start;
79 }
80
81 p=open(pathname, O_RDWR, 0);
82 if (p<0) {
83 fprintf(stderr, "open \"%s\": %s\n", pathname, strerror(errno));
84 return 2;
85 }
86
87 if (eeprom_read(p, data, start, len)<0) return 3;
88 close(p);
89 eeprom_dump(data, start, len, verbose);
90
91 return 0;
92}
Note: See TracBrowser for help on using the repository browser.