source: avrstuff/EPRoxygen/main.cpp@ 34c57e8

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

More work.

  • Power on/off sequence OK
  • Code to read chip ID written, but not working yet...

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

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