3
This is Picprog, Microchip PIC programmer software for the serial port device.
4
Copyright © 1997,2002,2003,2004,2006 Jaakko Hyvätti
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License version 2 as
8
published by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software Foundation,
17
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
The author may be contacted at:
21
Email: Jaakko.Hyvatti@iki.fi
22
URL: http://www.iki.fi/hyvatti/
23
Phone: +358 40 5011222
25
Please send any suggestions, bug reports, success stories etc. to the
44
char short_opts [] = "d:p:i:o:c:qh?";
47
main (int argc, char **argv)
54
int opt_format = hexfile::unknown;
55
char *opt_port = (char *)"/dev/ttyS0";
56
char *opt_input = NULL;
57
char *opt_output = NULL;
62
int opt_calibration = 0;
66
// Auto ident (-1) is the default, or if that fails, first device (0)
69
struct option long_opts[] = {
70
{"quiet", no_argument, NULL, 'q'},
71
{"warranty", no_argument, &opt_warranty, 1},
72
{"copying", no_argument, &opt_copying, 1},
73
{"help", no_argument, NULL, 'h'},
74
{"device", required_argument, NULL, 'd'},
75
{"pic-serial-port", required_argument, NULL, 'p'},
76
{"input-hexfile", required_argument, NULL, 'i'},
77
{"output-hexfile", required_argument, NULL, 'o'},
78
{"ihx32", no_argument, &opt_format, hexfile::ihx32},
79
{"ihx16", no_argument, &opt_format, hexfile::ihx16},
80
{"ihx8m", no_argument, &opt_format, hexfile::ihx8m},
81
{"cc-hexfile", required_argument, NULL, 'c'},
82
{"skip-ones", no_argument, &opt_skip, 1},
83
{"erase", no_argument, &opt_erase, 1},
84
{"burn", no_argument, &opt_burn, 1},
85
{"force-calibration", no_argument, &opt_calibration, 1},
86
{"nordtsc", no_argument, &opt_nordtsc, 1},
87
{"rdtsc", no_argument, &opt_nordtsc, 0},
88
{"slow", no_argument, &opt_slow, 1},
96
while (0 <= (optc = getopt_long (argc, argv, short_opts, long_opts, NULL)))
101
if (!strcmp (optarg, "auto"))
103
else if (-1 == (opt_device = hexfile::find_device (optarg)))
121
default: // -? -h --help unknown flag
125
if (!opt_quiet || opt_warranty || opt_copying || opt_usage)
126
// Locale charset should be respected here.
127
cerr << "Picprog version 1.8.3, Copyright © 2006 Jaakko Hyvätti <Jaakko.Hyvatti@iki.fi>\n"
128
"Picprog comes with ABSOLUTELY NO WARRANTY; for details\n"
129
"type `" << prog.name << " --warranty'. This is free software,\n"
130
"and you are welcome to redistribute it under certain conditions;\n"
131
"type `" << prog.name << " --copying' for details.\n\n";
140
cerr << "Full documentation is at "
141
"<URL:http://www.iki.fi/hyvatti/pic/picprog.html>" << endl
142
<< "The author may be contacted at:" << endl << endl
144
<< "Email: Jaakko.Hyvatti@iki.fi" << endl
145
<< "URL: http://www.iki.fi/hyvatti/" << endl << endl
147
<< "Supported devices:" << endl;
148
hexfile::print_devices ();
151
prog.usage (long_opts, short_opts);
154
if (opt_warranty || opt_copying || opt_usage)
157
if (!opt_input && !opt_output && !opt_erase) {
158
cerr << "Please specify either input or output hexfile or --erase option."
160
prog.usage (long_opts, short_opts);
163
if (opt_cc && !opt_input) {
164
cerr << "Carbon copy does not make sense without input file." << endl;
165
prog.usage (long_opts, short_opts);
168
// if both input and output files are specified, first program the device
171
if (opt_input || opt_erase) {
175
if (EX_OK != (retval = mem.setdevice (opt_port, opt_device, opt_nordtsc, opt_slow)))
177
if (opt_input && EX_OK != (retval = mem.load (opt_input)))
180
if (EX_OK != (retval = mem.program (opt_port, opt_erase, opt_calibration, opt_nordtsc, opt_slow)))
183
cout << "No --burn option specified, device not programmed.\n";
185
if (opt_input && opt_cc)
186
if (EX_OK != (retval = mem.save (opt_cc,
187
hexfile::formats (opt_format),
196
if (EX_OK != (retval = mem.setdevice (opt_port, opt_device, opt_nordtsc, opt_slow)))
198
if (EX_OK != (retval = mem.read (opt_port, opt_nordtsc, opt_slow)))
200
if (EX_OK != (retval = mem.save (opt_output,
201
hexfile::formats (opt_format),