source: avrstuff/EPRoxygen/main.cpp@ 16cf6ff

main
Last change on this file since 16cf6ff was 16cf6ff, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Add some suport for reading 27c020 chips.

Should be usable with most other ROMs as well.

git-svn-id: svn://pulkomandy.tk/avrstuff@61 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#define _XOPEN_SOURCE 700
2
3// C99
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8// POSIX/XSI
9#include <getopt.h>
10
11#include "device.h"
12#include "27c020.h"
13#include "at29c040.h"
14
15
16int main(int argc, char* argv[])
17{
18 char c;
19 const char* file = NULL;
20 char opcode = 0;
21 int port_base = 0x378;
22 Device* device = NULL;
23 int error = 0;
24
25 fprintf(stderr, "EPRoxygen - UNIX driver for SEEIT EPR-02 ROM programmer\n"
26 "Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.tk>\n"
27 "Distributed under the terms of the MIT licence\n"
28 );
29
30 while((c = getopt(argc, argv, "p:d:r:w:e")) >= 0)
31 {
32 switch(c)
33 {
34 case '?':
35 case ':':
36 fprintf(stderr, "Unrecognized option -%c\n", optopt);
37 // TODO print help
38 error = -1;
39 goto abort;
40 case 'p':
41 // Set port
42 if(sscanf(optarg, "%d", &port_base) != 1)
43 {
44 fprintf(stderr, "Invalid I/O port address\n");
45 error = -4;
46 goto abort;
47 }
48 break;
49 case 'd':
50 // TODO Set device
51 if (strcmp(optarg, "AT29C040") == 0)
52 {
53 device = new AT29C040();
54 } else if(strcmp(optarg, "27C020") == 0)
55 {
56 device = new x27C020();
57 } else {
58 fprintf(stderr,"Unknown device (only AT29C040 is supported)\n");
59 error = -3;
60 goto abort;
61 }
62 break;
63 case 'r':
64 case 'w':
65 // Set file
66 file = optarg;
67 // Fallthrough
68 case 'e':
69 // Set operation
70 if (opcode != 0)
71 {
72 fprintf(stderr, "Multiple operations requested (only one of r,w,e is allowed)\n");
73 error = -2;
74 goto abort;
75 }
76 opcode = c;
77 }
78 }
79
80 if (optind < argc)
81 {
82 fprintf(stderr, "Error parsing the command line before \"%s\"\n", argv[optind]);
83 error = -7;
84 goto abort;
85 }
86
87 if (opcode == 0)
88 {
89 fprintf(stderr, "No operation specified (one of r,w,e). Aborting.\n");
90 error = -5;
91 goto abort;
92 }
93
94 if (device == NULL)
95 {
96 fprintf(stderr, "No device specified.\n");
97 error = -6;
98 goto abort;
99 }
100
101 // Configure voltage and powerpins according to device
102 if(device->setup(port_base) != 0)
103 {
104 error = -7;
105 goto abort;
106 }
107
108 fprintf(stderr,"Now insert chip into socket, then press any key...\n");
109 getchar();
110
111 device->power();
112
113 // Do action (program/erase/write)
114 switch(opcode)
115 {
116 case 'r':
117 device->read(file);
118 break;
119 case 'w':
120 device->write(file);
121 break;
122 case 'e':
123 device->erase();
124 break;
125 default:
126 fprintf(stderr, "!!? invalid operation ?!\n");
127 }
128
129abort:
130 // TODO in case ioperm failed, delete will try to shutdown() and give a bus error...
131 delete device;
132
133 exit(error);
134}
135
136int Device::port;
137
Note: See TracBrowser for help on using the repository browser.