File: avrp.h

package info (click to toggle)
avrp 1.0beta3-6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 204 kB
  • ctags: 194
  • sloc: ansic: 2,463; makefile: 40; perl: 6; sh: 5
file content (232 lines) | stat: -rw-r--r-- 5,784 bytes parent folder | download | duplicates (2)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/***********************************************************************
 *  avrp - Atmel AVR programming software to use with Atmel's
 *         serial-port programmers.
 *  Copyright (C) 1997-1998 Jon Anders Haugum
 *
 *  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 program 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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.  If not, write to
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *
 *
 *  Author of avrp can be reached at:
 *     email: jonah@colargol.tihlde.hist.no
 *     www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html
 *     Postal address: Jon Anders Haugum
 *                     �vre M�llenbergsgt 52
 *                     7014 Trondheim
 */

#include "args.h"
#include "misc.h"

/* Handle SAS/C and older gcc on the Amiga */
#ifndef __amigaos__
#if defined(_AMIGA) || defined(__amiga__)
#define __amigaos__
#endif
#endif

#ifdef __amigaos__
#define DEFFILENAME "env:avrp.def"
#endif

#if defined(__linux__) || defined(__FreeBSD__) || defined (__GNU__) || defined(__GLIBC__)
#if defined(DEBIAN)
#define DEFFILENAME "/etc/avrp.def"
#else
#define DEFFILENAME "/usr/local/etc/avrp.def"
#endif
#endif

#ifdef _WIN32
#define DEFFILENAME "C:\\bin\\avrp.def"
#endif

#ifndef DEFFILENAME
#error "Your system is not supported!"
#endif

#define DEFFILEVERSION  2
#define DEFFILEREVISION 0

/* Option enumeration */
enum
	{
	ARG_SERIALPORT =  0,  /* -s <serial port>        */
	ARG_AVRTYPE,          /* -a <AVR type>           */
	ARG_PROG,             /* -p                      */
	ARG_READ,             /* -r                      */
	ARG_VERIFY,           /* -v                      */
	ARG_FLASH,            /* -f <file to read/write> */
	ARG_EEPROM,           /* -e <file to read/write> */
	ARG_QUICK,            /* -q                      */
	ARG_DEFFILE,          /* -d                      */
	ARG_IGNORESIG,        /* -I                      */
	ARG_LOCKMODE,         /* -l                      */
	ARG_ENABLE,           /* --enable                */
	ARG_DISABLE,          /* --disable               */
	ARG_AUTOINC,          /* --autoinc               */
	ARG_VER,              /* --version               */
	ARG_HELP,             /* -h --help               */
	ARG_COUNT
	};


enum
	{
	FILETYPE_UNKNOWN = 0,
	FILETYPE_INTEL_HEX8M,
	FILETYPE_ATMEL_GENERIC
	};


/* Structures */
struct ProgramInfo
	{
	void *Ser;
	struct args *args;
	int ProgType;
	struct ChipNode *SelectedChipNode;
	/* List starts */
	struct ChipNode *FirstChipNode;
	struct VendorNode *FirstVendorNode;
	struct FamilyNode *FirstFamilyNode;
	struct ArchNode *FirstArchNode;
	struct FuseNode *FirstFuseNode;
	struct LockNode *FirstLockNode;
	};

struct ChipNode
	{
	struct ChipNode *Next;
	char *Name;
	int Code;
	int EepromSize;
	int Sig;
	int Supported;
	struct VendorNode *VendorNode;
	struct FamilyNode *FamilyNode;
	int FuseType;
	struct FuseNode *FuseNode;
	int LockType;
	struct LockNode *LockNode;
	};

struct VendorNode
	{
	struct VendorNode *Next;
	int Code;
	char *Name;
	};

struct FamilyNode
	{
	struct FamilyNode *Next;
	int Code;
	char *Name;
	int FlashSize;
	struct ArchNode *ArchNode;
	};

struct ArchNode
	{
	struct ArchNode *Next;
	char *Name;
	int WordSize;
	int NeedFlashErase;
	};

struct FuseNode
	{
	struct FuseNode *Next;
	int Num;
	struct FuseBitNode *FirstFuseBitNode;
	};

struct FuseBitNode
	{
	struct FuseBitNode *Next;
	char *ShortName;
	int BitNum;
	char *LongName;
	};

struct LockNode
	{
	struct LockNode *Next;
	int Num;
	int NumberOfBits;
	int WriteBits;
	int ReadBits;
	struct LockBitNode *FirstLockBitNode;
	};

struct LockBitNode
	{
	struct LockBitNode *Next;
	int Mode;
	int Mask;
	char *LongName;
	};

struct DataFile
	{
	FILE *FP;
	int FileType;
	};


/* Prototypes */
/* avrp.c */
struct ProgramInfo *GetPI(struct args *args);
int DetectAVRType(struct ProgramInfo *PI);
void FreePI(struct ProgramInfo *PI);

/* talking.c */
int InquireHW(struct ProgramInfo *PI);
int InquireID(struct ProgramInfo *PI);
int DoTheTalk(struct ProgramInfo *PI);
int CheckLockAndErase(struct ProgramInfo *PI, unsigned char *Sig);
int CheckSig(struct ProgramInfo *PI, unsigned char *Sig);
int DoMoreTalk(struct ProgramInfo *PI);
int Erase(struct ProgramInfo *PI);
int DoFuses(struct ProgramInfo *PI);
void print_comm_err(char comm);

/* memtalk.c */
int Program(struct ProgramInfo *PI, int ProgWhat, int DoWhat);
int prog_adr(struct ProgramInfo *PI, int adr, int data, int What, int *StatAdr);
int verify_adr(struct ProgramInfo *PI, int adr, int data, int What, int *StatAdr);
int Read(struct ProgramInfo *PI, int What);
void Progress(int *StatAdr, int Adr, char DidWhat);

/* file.c */
struct DataFile *OpenDataFile(char *FileName);
void CloseDataFile(struct DataFile *DataFile);
int ReadDefFile(struct ProgramInfo *PI);
char *GetNextString(char *Buff, int *index);

/* io_[linux|amiga|win32].c */
void *OpenSer(char *SerPort);
void CloseSer(void *Ser);
void SerWriteByte(void *Ser, unsigned char Byte);
int SerReadData(void *Ser, unsigned char *Buff, int Count);

/* stdextra.c */
char *nocase_strcmp(char *s, char *t);
char *nocase_strncmp(char *s, char *t, int n);
char *nocase_strstr(char *s, char *t);
int atox(char *s);
int atoi_n(char *s, int n);
int atox_n(char *s, int n);