-
Notifications
You must be signed in to change notification settings - Fork 1
/
usbasp.c.diff
498 lines (481 loc) · 15.2 KB
/
usbasp.c.diff
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
--- avrdude-6.3/usbasp.c 2014-11-20 23:49:14.000000000 +0100
+++ usbasp.c 2016-05-29 17:02:36.000000000 +0200
@@ -40,6 +40,8 @@
#include "usbasp.h"
#include "usbdevs.h"
+#include "xmega_pdi.h"
+
#if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)
#ifdef HAVE_LIBUSB_1_0
@@ -106,10 +108,11 @@
#endif
-
/*
* Private data for this programmer.
*/
+enum UsbAspMode { ISP, TPI, PDI };
+
struct pdata
{
#ifdef USE_LIBUSB_1_0
@@ -119,7 +122,8 @@
#endif
int sckfreq_hz;
unsigned int capabilities;
- int use_tpi;
+
+ enum UsbAspMode mode;
};
#define PDATA(pgm) ((struct pdata *)(pgm->cookie))
@@ -174,6 +178,21 @@
static int usbasp_tpi_set_sck_period(PROGRAMMER *pgm, double sckperiod);
static int usbasp_tpi_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char * value);
static int usbasp_tpi_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char data);
+////// PDI
+//static int usbasp_pdi_program_enable(PROGRAMMER * pgm, AVRPART * p);
+static int usbasp_pdi_chip_erase(PROGRAMMER * pgm, AVRPART * p);
+static int usbasp_pdi_page_erase(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned int baseaddr);
+static int usbasp_pdi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
+ unsigned int page_size,
+ unsigned int address, unsigned int n_bytes);
+static int usbasp_pdi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
+ unsigned int page_size,
+ unsigned int address, unsigned int n_bytes);
+static int usbasp_pdi_set_sck_period(PROGRAMMER *pgm, double sckperiod);
+static int usbasp_pdi_cmd(PROGRAMMER * pgm, const unsigned char *cmd, unsigned char *res);
+static int usbasp_pdi_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char * value);
+static int usbasp_pdi_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char data);
+
/* Interface - management */
@@ -214,6 +233,10 @@
case USBASP_FUNC_TPI_READBLOCK: return "USBASP_FUNC_TPI_READBLOCK"; break;
case USBASP_FUNC_TPI_WRITEBLOCK: return "USBASP_FUNC_TPI_WRITEBLOCK"; break;
case USBASP_FUNC_GETCAPABILITIES: return "USBASP_FUNC_GETCAPABILITIES"; break;
+ case USBASP_FUNC_PDI_CONNECT: return "USBASP_FUNC_PDI_CONNECT"; break;
+ case USBASP_FUNC_PDI_DISCONNECT: return "USBASP_FUNC_PDI_DISCONNECT"; break;
+ case USBASP_FUNC_PDI_READ: return "USBASP_FUNC_PDI_READ"; break;
+ case USBASP_FUNC_PDI_SEND: return "USBASP_FUNC_PDI_SEND"; break;
default: return "Unknown USBASP function"; break;
}
}
@@ -511,12 +534,20 @@
if (PDATA(pgm)->usbhandle!=NULL) {
unsigned char temp[4];
memset(temp, 0, sizeof(temp));
+ temp[0] = pgm->exit_reset;
- if (PDATA(pgm)->use_tpi) {
- usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_DISCONNECT, temp, temp, sizeof(temp));
- } else {
- usbasp_transmit(pgm, 1, USBASP_FUNC_DISCONNECT, temp, temp, sizeof(temp));
- }
+ switch (PDATA(pgm)->mode)
+ {
+ case TPI:
+ usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_DISCONNECT, temp, temp, sizeof(temp));
+ break;
+ case ISP:
+ usbasp_transmit(pgm, 1, USBASP_FUNC_DISCONNECT, temp, temp, sizeof(temp));
+ break;
+ case PDI:
+ usbasp_transmit(pgm, 1, USBASP_FUNC_PDI_DISCONNECT, temp, temp, sizeof(temp));
+ break;
+ }
#ifdef USE_LIBUSB_1_0
libusb_close(PDATA(pgm)->usbhandle);
@@ -569,50 +600,78 @@
else
pdata->capabilities = 0;
- pdata->use_tpi = ((pdata->capabilities & USBASP_CAP_TPI) != 0 && (p->flags & AVRPART_HAS_TPI) != 0) ? 1 : 0;
+ pdata->mode = ISP;
+ if ((pdata->capabilities & USBASP_CAP_TPI) != 0 && (p->flags & AVRPART_HAS_TPI) != 0)
+ pdata->mode = TPI;
+ if ((pdata->capabilities & USBASP_CAP_PDI) != 0 && (p->flags & AVRPART_HAS_PDI) != 0)
+ pdata->mode = PDI;
- if(pdata->use_tpi)
- {
- /* calc tpiclk delay */
- int dly = 1500000.0 * pgm->bitclock;
- if(dly < 1)
- dly = 1;
- else if(dly > 2047)
- dly = 2047;
- temp[0] = dly;
- temp[1] = dly >> 8;
+ int dly = 0;
- /* connect */
- usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_CONNECT, temp, res, sizeof(res));
-
- /* change interface */
- pgm->program_enable = usbasp_tpi_program_enable;
- pgm->chip_erase = usbasp_tpi_chip_erase;
- pgm->cmd = usbasp_tpi_cmd;
- pgm->read_byte = usbasp_tpi_read_byte;
- pgm->write_byte = usbasp_tpi_write_byte;
- pgm->paged_write = usbasp_tpi_paged_write;
- pgm->paged_load = usbasp_tpi_paged_load;
- pgm->set_sck_period = usbasp_tpi_set_sck_period;
- }
- else
+ switch (pdata->mode)
{
- /* set sck period */
- pgm->set_sck_period(pgm, pgm->bitclock);
-
- /* connect to target device */
- usbasp_transmit(pgm, 1, USBASP_FUNC_CONNECT, temp, res, sizeof(res));
-
- /* change interface */
- pgm->program_enable = usbasp_spi_program_enable;
- pgm->chip_erase = usbasp_spi_chip_erase;
- pgm->cmd = usbasp_spi_cmd;
- pgm->read_byte = avr_read_byte_default;
- pgm->write_byte = avr_write_byte_default;
- pgm->paged_write = usbasp_spi_paged_write;
- pgm->paged_load = usbasp_spi_paged_load;
- pgm->set_sck_period = usbasp_spi_set_sck_period;
+ case TPI:
+ /* calc tpiclk delay */
+ dly = 1500000.0 * pgm->bitclock;
+ if (dly < 1)
+ dly = 1;
+ else if (dly > 2047)
+ dly = 2047;
+ temp[0] = dly;
+ temp[1] = dly >> 8;
+
+ /* connect */
+ usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_CONNECT, temp, res, sizeof(res));
+
+ /* change interface */
+ pgm->program_enable = usbasp_tpi_program_enable;
+ pgm->chip_erase = usbasp_tpi_chip_erase;
+ pgm->cmd = usbasp_tpi_cmd;
+ pgm->read_byte = usbasp_tpi_read_byte;
+ pgm->write_byte = usbasp_tpi_write_byte;
+ pgm->paged_write = usbasp_tpi_paged_write;
+ pgm->paged_load = usbasp_tpi_paged_load;
+ pgm->set_sck_period = usbasp_tpi_set_sck_period;
+ break;
+
+ case ISP:
+ /* set sck period */
+ pgm->set_sck_period(pgm, pgm->bitclock);
+
+ /* connect to target device */
+ usbasp_transmit(pgm, 1, USBASP_FUNC_CONNECT, temp, res, sizeof(res));
+
+ /* change interface */
+ pgm->program_enable = usbasp_spi_program_enable;
+ pgm->chip_erase = usbasp_spi_chip_erase;
+ pgm->cmd = usbasp_spi_cmd;
+ pgm->read_byte = avr_read_byte_default;
+ pgm->write_byte = avr_write_byte_default;
+ pgm->paged_write = usbasp_spi_paged_write;
+ pgm->paged_load = usbasp_spi_paged_load;
+ pgm->set_sck_period = usbasp_spi_set_sck_period;
+ break;
+
+ case PDI:
+ /* change interface */
+ pgm->program_enable = NULL;
+ pgm->chip_erase = usbasp_pdi_chip_erase;
+ pgm->cmd = usbasp_pdi_cmd;
+ pgm->read_byte = usbasp_pdi_read_byte;
+ pgm->write_byte = usbasp_pdi_write_byte;
+ pgm->paged_write = usbasp_pdi_paged_write;
+ pgm->paged_load = usbasp_pdi_paged_load;
+ pgm->set_sck_period = usbasp_pdi_set_sck_period;
+ pgm->page_erase = usbasp_pdi_page_erase;
+
+ /* connect to target device */
+ int nbytes = usbasp_transmit(pgm, 1, USBASP_FUNC_PDI_CONNECT, temp, res, 1);
+ if ((nbytes == 1) && (res[0] == 0))
+ return 0;
+ return -1;
+ break;
}
+
/* wait, so device is ready to receive commands */
usleep(100000);
@@ -1164,6 +1223,277 @@
return -1;
}
+//////////////////////////////////////////////
+
+static int usbasp_pdi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
+ unsigned int page_size,
+ unsigned int address, unsigned int n_bytes)
+{
+ //printf("pdi paged load addr=0x%x offset=0x%x page_size=0x%x bytes=0x%x\n",address,m->offset,page_size,n_bytes);
+
+ uint8_t buf[256];
+ int done = 0;
+ uint8_t *dptr = m->buf + address;
+ uint32_t addr = m->offset + address;
+
+ while (done < n_bytes)
+ {
+ int need = n_bytes - done;
+ if (need>128) need = 128;
+ int have = usbasp_transmit(pgm, 1, USBASP_FUNC_PDI_READ, (unsigned char*)&addr, buf, need);
+ if (have <= 0)
+ {
+ fprintf(stderr, "%s: paged_load failed\n", progname);
+ return -3;
+ }
+ if (have>need) have = need;
+ memmove(dptr, buf, have);
+ done += have;
+ addr += have;
+ dptr += have;
+ }
+
+ return n_bytes;
+}
+
+static void pdi_nvm_set_reg(uint8_t** cmd, uint32_t addr, uint8_t value)
+{
+ uint8_t *c = *cmd;
+ c[0] = XNVM_PDI_STS_INSTR | XNVM_PDI_LONG_ADDRESS_MASK | XNVM_PDI_BYTE_DATA_MASK;
+ memmove(c + 1, &addr, 4);
+ c[5] = value;
+ *cmd = c + 6;
+}
+
+static void pdi_set_addr(uint8_t** cmd, uint32_t addr)
+{
+ uint8_t *c = *cmd;
+ c[0] = XNVM_PDI_ST_INSTR | XNVM_PDI_LD_PTR_ADDRESS_MASK | XNVM_PDI_LONG_DATA_MASK;
+ memmove(c + 1, &addr, 4);
+ *cmd = c + 5;
+}
+
+static int usbasp_pdi_page_erase(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned int baseaddr)
+{
+ //printf("pdi page erase 0x%lx\n",baseaddr);
+
+ int eeprom = !strcmp(m->desc, "eeprom");
+
+ uint8_t args[4] = { USBASP_PDI_WAIT_BUSY + USBASP_PDI_MARK_BUSY };
+ uint8_t cmd[20];
+ uint8_t *c = cmd;
+
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CMD_REG_OFFSET,
+ eeprom ? XNVM_CMD_ERASE_EEPROM_PAGE : XNVM_CMD_ERASE_FLASH_PAGE);
+ pdi_set_addr(&c, baseaddr + m->offset);
+ *(c++) = XNVM_PDI_ST_INSTR | XNVM_PDI_LD_PTR_STAR_INC_MASK | XNVM_PDI_BYTE_DATA_MASK;
+ *(c++) = 0;
+
+ int n = c - cmd;
+ if (usbasp_transmit(pgm, 0, USBASP_FUNC_PDI_SEND, args, cmd, n) != n)
+ {
+ fprintf(stderr, "%s: page_erase failed\n", progname);
+ return -1;
+ }
+ else
+ usleep(p->chip_erase_delay);
+
+ return 0;
+
+ /*
+ uint8_t pdi[20]={USBASP_PDI_WAIT_BUSY+USBASP_PDI_HINT_BUSY,
+ XNVM_PDI_STS_INSTR | XNVM_PDI_LONG_ADDRESS_MASK | XNVM_PDI_BYTE_DATA_MASK,
+ 0,0,0,0, //2 - cmd reg addr
+ eeprom ? XNVM_CMD_ERASE_EEPROM_PAGE : XNVM_CMD_ERASE_FLASH_PAGE,//6
+
+ XNVM_PDI_ST_INSTR | XNVM_PDI_LD_PTR_ADDRESS_MASK | XNVM_PDI_LONG_DATA_MASK,
+ 0,0,0,0, //8 - base_addr
+ XNVM_PDI_ST_INSTR | XNVM_PDI_LD_PTR_STAR_INC_MASK | XNVM_PDI_BYTE_DATA_MASK,
+ 0}; //13
+
+ uint32_t cmd_reg_addr=XNVM_DATA_BASE+XNVM_CONTROLLER_BASE+XNVM_CONTROLLER_CMD_REG_OFFSET;
+ memmove(pdi+2,&cmd_reg_addr,4);
+ uint32_t base_addr=baseaddr+m->offset;
+ memmove(pdi+8,&base_addr,4);
+
+ if (usbasp_transmit(pgm, 0, USBASP_FUNC_PDI_SEND, cmd, pdi, 14)==14)
+ {
+ usleep(p->chip_erase_delay);
+ return 0;
+ }
+
+ return -1;
+ */
+
+}
+
+static int usbasp_pdi_chip_erase(PROGRAMMER * pgm, AVRPART * p)
+{
+ //printf("pdi chip erase\n");
+ uint8_t args[4] = { USBASP_PDI_WAIT_BUSY + USBASP_PDI_MARK_BUSY };
+ uint8_t cmd[20];
+ uint8_t *c = cmd;
+
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CMD_REG_OFFSET, XNVM_CMD_CHIP_ERASE);
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CTRLA_REG_OFFSET, XNVM_CTRLA_CMDEX);
+
+ int n = c - cmd;
+ if (usbasp_transmit(pgm, 0, USBASP_FUNC_PDI_SEND, args, cmd, n) != n)
+ {
+ fprintf(stderr, "%s: chip_erase failed\n", progname);
+ return -1;
+ }
+ else
+ usleep(p->chip_erase_delay);
+
+ return 0;
+}
+
+
+static int usbasp_pdi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
+ unsigned int page_size,
+ unsigned int address, unsigned int n_bytes)
+{
+ //printf("pdi paged write addr=0x%x offset=0x%x page_size=0x%x bytes=0x%x\n",address,m->offset,page_size,n_bytes);
+
+ unsigned char* sptr;
+ int remaining = n_bytes;
+
+ uint32_t a = m->offset + address;
+ sptr = m->buf + address;
+ int eeprom = !strcmp(m->desc, "eeprom");
+
+#define MAXBLOCK 64
+ uint8_t args[4] = { 0 };
+ uint8_t cmd[100];
+ uint8_t* c;
+ int n;
+
+ c = cmd;
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CMD_REG_OFFSET, eeprom ? XNVM_CMD_ERASE_EEPROM_PAGE_BUFFER : XNVM_CMD_ERASE_FLASH_PAGE_BUFFER);
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CTRLA_REG_OFFSET, XNVM_CTRLA_CMDEX);
+ n = c - cmd;
+ //printf("pdi send erase buf\n");
+ args[0] = USBASP_PDI_WAIT_BUSY + USBASP_PDI_MARK_BUSY;
+ if (usbasp_transmit(pgm, 0, USBASP_FUNC_PDI_SEND, args, cmd, n) != n)
+ goto fail;
+
+ while (remaining > 0)
+ {
+ int bsize = remaining;
+ if (bsize > MAXBLOCK)
+ bsize = MAXBLOCK;
+ remaining -= MAXBLOCK;
+
+ c = cmd;
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CMD_REG_OFFSET, eeprom ? XNVM_CMD_LOAD_EEPROM_PAGE_BUFFER : XNVM_CMD_LOAD_FLASH_PAGE_BUFFER);
+ pdi_set_addr(&c, a);
+ *(c++) = XNVM_PDI_REPEAT_INSTR | XNVM_PDI_BYTE_DATA_MASK;
+ *(c++) = bsize - 1;
+ *(c++) = XNVM_PDI_ST_INSTR | XNVM_PDI_LD_PTR_STAR_INC_MASK | XNVM_PDI_BYTE_DATA_MASK;
+ memmove(c, sptr, bsize); c += bsize;
+
+ args[0] = USBASP_PDI_WAIT_BUSY;
+ n = c - cmd;
+ // printf("pdi send load buf 0x%lx\n",a);
+ if (usbasp_transmit(pgm, 0, USBASP_FUNC_PDI_SEND, args, cmd, n) != n)
+ goto fail;
+
+ a += bsize;
+ sptr += bsize;
+ }
+
+ c = cmd;
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CMD_REG_OFFSET, eeprom ? XNVM_CMD_WRITE_EEPROM_PAGE : XNVM_CMD_WRITE_FLASH_PAGE);
+ a = m->offset + address;
+ pdi_set_addr(&c, a);
+ *(c++) = XNVM_PDI_ST_INSTR | XNVM_PDI_LD_PTR_STAR_INC_MASK | XNVM_PDI_BYTE_DATA_MASK;
+ *(c++) = 0;
+
+ args[0] = USBASP_PDI_WAIT_BUSY + USBASP_PDI_MARK_BUSY;
+ n = c - cmd;
+ //printf("pdi send write page 0x%lx\n",a);
+ if (usbasp_transmit(pgm, 0, USBASP_FUNC_PDI_SEND, args, cmd, n) != n)
+ goto fail;
+
+ return n_bytes;
+
+fail:
+ fprintf(stderr, "%s: paged_write failed\n", progname);
+ return -3;
+
+}
+
+static int usbasp_pdi_set_sck_period(PROGRAMMER *pgm, double sckperiod)
+{
+ //printf("pdi set sck period (NOP)\n");
+ return 0;
+}
+
+static int usbasp_pdi_cmd(PROGRAMMER * pgm, const unsigned char *cmd, unsigned char *res)
+{
+ fprintf(stderr, "pdi cmd not implemented\n");
+ return -1;
+}
+
+static int usbasp_pdi_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char * value)
+{
+ //printf("pdi read byte: addr=0x%lx offset=0x%x\n",addr,m->offset);
+
+ uint32_t a = m->offset + addr;
+ if (usbasp_transmit(pgm, 1, USBASP_FUNC_PDI_READ, (unsigned char*)&a, value, 1) == 1)
+ return 0;
+ return -1;
+}
+
+static int usbasp_pdi_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char data)
+{
+ //printf("pdi write byte 0x%lx 0x%x\n",addr+m->offset,data);
+
+ uint8_t args[4] = { USBASP_PDI_WAIT_BUSY + USBASP_PDI_MARK_BUSY };
+ uint8_t cmd[20];
+ uint8_t *c = cmd;
+ uint32_t a = addr + m->offset;
+
+ pdi_nvm_set_reg(&c, XNVM_DATA_BASE + XNVM_CONTROLLER_BASE + XNVM_CONTROLLER_CMD_REG_OFFSET, XNVM_CMD_WRITE_FUSE);
+ *(c++) = XNVM_PDI_STS_INSTR | XNVM_PDI_LONG_ADDRESS_MASK | XNVM_PDI_BYTE_DATA_MASK;
+ memmove(c, &a, 4); c += 4;
+ *(c++) = data;
+
+ int n = c - cmd;
+ if (usbasp_transmit(pgm, 0, USBASP_FUNC_PDI_SEND, args, cmd, n) != n)
+ {
+ fprintf(stderr, "%s: write_byte failed\n", progname);
+ return -1;
+ }
+ return 0;
+}
+
+/////////////////////////////////////////////
+
+/*
+* parse the -E string (subset of par.c/par_parseexitspecs)
+*/
+static int usbasp_parseexitspecs(PROGRAMMER * pgm, char *s)
+{
+ char *cp;
+
+ while ((cp = strtok(s, ","))) {
+ if (strcmp(cp, "reset") == 0) {
+ pgm->exit_reset = EXIT_RESET_ENABLED;
+ }
+ else if (strcmp(cp, "noreset") == 0) {
+ pgm->exit_reset = EXIT_RESET_DISABLED;
+ }
+ else {
+ return -1;
+ }
+ s = 0; /* strtok() should be called with the actual string only once */
+ }
+
+ return 0;
+}
+
void usbasp_initpgm(PROGRAMMER * pgm)
{
@@ -1194,6 +1524,7 @@
pgm->setup = usbasp_setup;
pgm->teardown = usbasp_teardown;
pgm->set_sck_period = usbasp_spi_set_sck_period;
+ pgm->parseexitspecs = usbasp_parseexitspecs;
}