source: drsdaq/VME/struck/sis1100/V2.02/eeprom_tools/write_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: 2.4 KB
Line 
1/*
2 * $ZEL: write_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;
21const char* pathname;
22
23static void
24printhelp(const char* progname)
25{
26 fprintf(stderr, "usage: %s [-h] [-v] 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="hv";
36
37 optarg=0; errflag=0;
38 verbose=0;
39
40 while (!errflag && ((c=getopt(argc, argv, args))!=-1)) {
41 switch (c) {
42 case 'h': errflag++; break;
43 case 'v': verbose++; break;
44 default: errflag++;
45 }
46 }
47
48 if (errflag || (argc-optind)!=1) {
49 printhelp(argv[0]);
50 return -1;
51 }
52
53 pathname=argv[optind];
54
55 return 0;
56}
57
58int main(int argc, char* argv[])
59{
60 u_int16_t data_prom[EEPROM_LEN];
61 u_int16_t data_file[EEPROM_LEN];
62 u_int16_t addr[EEPROM_LEN];
63 int p, num, i, n;
64
65 fprintf(stderr, "\n==== SIS1100 EEPROM Writer; V1.0 ====\n\n");
66
67 if (getoptions(argc, argv)) return 1;
68
69 num=EEPROM_LEN;
70 if (read_eepom_data_from_file(stdin, data_file, addr, &num)<0) return 1;
71
72 p=open(pathname, O_RDWR, 0);
73 if (p<0) {
74 fprintf(stderr, "open \"%s\": %s\n", pathname, strerror(errno));
75 return 2;
76 }
77
78 if (eeprom_read(p, data_prom, 0, EEPROM_LEN)<0) return 3;
79
80 for (i=0; i<num; i++) {
81 u_int16_t a=addr[i]>>1;
82 if (a>=EEPROM_LEN) {
83 fprintf(stderr, "invalid address 0x%04x.\n", addr[i]);
84 return 1;
85 }
86 data_prom[a]=data_file[i];
87 }
88
89 if (eeprom_write(p, data_prom, 0, EEPROM_LEN)<0) return 3;
90
91 if (eeprom_read(p, data_prom, 0, EEPROM_LEN)<0) return 3;
92
93 close(p);
94
95 for (i=0, n=0; i<num; i++) {
96 u_int16_t a=addr[i]>>1;
97 if (data_prom[a]!=data_file[i]) {
98 if (!n) {
99 printf("Differences after write:\n");
100 printf("addr eprom file\n");
101 }
102 printf("0x%02x: %04x %04x", a*2, data_prom[a], data_file[i]);
103 if (verbose) printf(" # %s", eeprom_names[a]);
104 printf("\n");
105 n++;
106 }
107 }
108 printf("eeprom %ssuccessfully written.\n", n?"NOT ":"");
109 return n?10:0;
110}
Note: See TracBrowser for help on using the repository browser.