forked from Polarisru/updiprog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devices.c
313 lines (300 loc) · 6.25 KB
/
devices.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include <string.h>
#include "devices.h"
tDevice DEVICES_List[] =
{
{
"mega480x",
0x4000,
48 * 1024,
128,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
11
},
{
"mega320x",
0x4000,
32 * 1024,
128,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
11
},
{
"mega160x",
0x4000,
16 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
11
},
{
"mega80x",
0x4000,
8 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
11
},
{
"tiny321x",
0x8000,
32 * 1024,
128,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny160x",
0x8000,
16 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny161x",
0x8000,
16 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny80x",
0x8000,
8 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny81x",
0x8000,
8 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
/*Parameter : Value : Different from attiny81x? : Source datasheet chapter*/
"tiny82x", /*Name : tiny82x : Yes : N.A. */
0x8000, /*Flash_start : 0x8000 : No : 7.3 */
8 * 1024, /*Flash_size : 8KB : No : 7.3 */
64, /*Flash_page_size : 64B : No : 7.3 */
0x0F00, /*Syscfg_address : 0xF000 : No : 8.1 */
0x1000, /*Nvmctrl_address : 0x1000 : No : 8.1 */
0x1100, /*Sigrow_address : 0x1100 : No : 8.1 */
0x1280, /*Fuses_address : 0x1280 : No : 8.1 */
0x1300, /*Userrow_address : 0x1300 : No : 8.1 */
8 /*number of fuses : 0x08 : Yes : 7.8.1 */
},
{
/*Parameter : Value : Different from attiny81x? : Source datasheet chapter*/
"tiny162x", /*Name : tiny82x : Yes : N.A. */
0x8000, /*Flash_start : 0x8000 : No : 7.3 */
16 * 1024, /*Flash_size : 16KB : Yes : 7.3 */
64, /*Flash_page_size : 64B : No : 7.3 */
0x0F00, /*Syscfg_address : 0xF000 : No : 8.1 */
0x1000, /*Nvmctrl_address : 0x1000 : No : 8.1 */
0x1100, /*Sigrow_address : 0x1100 : No : 8.1 */
0x1280, /*Fuses_address : 0x1280 : No : 8.1 */
0x1300, /*Userrow_address : 0x1300 : No : 8.1 */
8 /*number of fuses : 0x08 : Yes : 7.8.1 */
},
{
"tiny40x",
0x8000,
4 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny41x",
0x8000,
4 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
11
},
{
"tiny20x",
0x8000,
2 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny21x",
0x8000,
2 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
}
};
static int8_t DEVICE_Id = DEVICE_UNKNOWN_ID;
/** \brief Get device ID from name string
*
* \param [in] name Name to find as string
* \return index of the found device or -1 as error
*
*/
int8_t DEVICES_GetId(char *name)
{
uint8_t i;
for (i = 0; i < sizeof(DEVICES_List) / sizeof(tDevice); i++)
{
if (strcmp(name, DEVICES_List[i].name) == 0)
{
DEVICE_Id = i;
return i;
}
}
DEVICE_Id = DEVICE_UNKNOWN_ID;
return -1;
}
/** \brief Get flash memory length for selected device
*
* \return Size of the flash memory as uint16_t
*
*/
uint16_t DEVICES_GetFlashLength(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].flash_size;
}
/** \brief Get flash start address for selected device
*
* \return Address of the flash area as uint16_t
*
*/
uint16_t DEVICES_GetFlashStart(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].flash_start;
}
/** \brief Get flash page size for selected device
*
* \return Flash page size as uint16_t
*
*/
uint16_t DEVICES_GetPageSize(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].flash_pagesize;
}
/** \brief Get NVM control registers address for selected device
*
* \return NVM registers adress as uint16_t
*
*/
uint16_t DEVICES_GetNvmctrlAddress(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].nvmctrl_address;
}
/** \brief Get fuses address for selected device
*
* \return Fuses address as uint16_t
*
*/
uint16_t DEVICES_GetFusesAddress(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].fuses_address;
}
/** \brief Get number of the fuses for selected device
*
* \return Number of the fuses as uint8_t
*
*/
uint8_t DEVICES_GetFusesNumber(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].number_of_fuses;
}
/** \brief Get number of devices in the list
*
* \return Number of the devices as uint8_t
*
*/
uint8_t DEVICES_GetNumber(void)
{
return (uint8_t)(sizeof(DEVICES_List) / sizeof(tDevice));
}
/** \brief Get string name of the device by ID
*
* \return Device name as string
*
*/
char *DEVICES_GetNameByNumber(uint8_t number)
{
if (number >= sizeof(DEVICES_List) / sizeof(tDevice))
number = 0;
return DEVICES_List[number].name;
}