-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep0.c
123 lines (112 loc) · 3.04 KB
/
step0.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* @file step0.c
* @brief
* @details
* @version
* @date Thu 20 Dec 2018 11:12:22 PM EST
* @author
* @copyright The GNU General Public License
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* --- include files --- */
#include "intelhex.h"
#include <stdio.h>
# ifndef S_SPLINT_S
#include <unistd.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <argp.h>
/* --- defines and constants --- */
#define HEXFILESIZEMAX 0x8000
/* --- global variables --- */
/* --- function prototypes --- */
/* --- main --- */
char *devicename;
char *infile;
char *outfile;
static int
parse_opt (int key, char *arg,
struct argp_state *state)
{
switch (key)
{
case 'd':
{
devicename=arg;
printf ("Target device is %s \n", devicename);
break;
}
case 'e':
{
printf ("Erase Device Flash \n");
break;
}
case 'i':
{
infile=arg;
printf ("Input File is %s \n", infile);
break;
}
case 'o':
{
outfile=arg;
printf ("Out File is %s \n", outfile);
break;
}
case 'p':
{
infile=arg;
printf ("Program Device Flash using %s \n", infile);
//will parse file into an array
uint8_t hexarray[HEXFILESIZEMAX];
//bytes read into the array
int hexarraysize;
//file to be loaded
FILE *hexfile;
hexfile=openfile(infile,"rb");
printf("file opened \n");
fclose(hexfile);
break;
}
case 'r':
{
printf ("Read Device Flash to stdout or <outfile>\n");
break;
}
case 'v':
{
printf ("Verify device Flash against <infile>\n");
break;
}
}
return 0;
}
int
main (int argc, char **argv)
{
struct argp_option options[] =
{
{ 0, 'd', "<attiny4|attiny5|attiny9|attiny10>", 0, "Device name. Must be applied when programming the device."},
{ 0, 'e', 0, 0, "Erase device. The device will be erased before any other programming takes place."},
{ 0, 'i', "<inputfile>", 0, "Name of Flash input file. Required for programming or verification of the Flash memory. The file format is Intel Extended HEX."},
{ 0, 'o', "<outputfile>", 0, "Name of Flash output file. Required for readout of the Flash memoryi to a file. The file format is Intel Extended HEX."},
{ 0, 'p', "<inputfile>", 0, "Program device Flash. Corresponding input files are required."},
{ 0, 'r', 0, 0, "Read out device Flash. Will output to stdout if output file is not specified."},
{ 0, 'v', 0, 0, "Verify device Flash. Can be used with –p or alone. Corresponding input files are required."},
{ 0 }
};
struct argp argp = { options, parse_opt, 0,0 };
return argp_parse (&argp, argc, argv, 0, 0, 0);
}
/* --- functions --- */