usbpid from LNODEID -> std::vector
@@ -668,14 +668,19 @@ | ||
668 | 668 | else |
669 | 669 | vid = USB_VENDOR_FTDI; |
670 | 670 | |
671 | - LNODEID usbpid = lfirst(pgm->usbpid); | |
672 | - if (usbpid) { | |
673 | - pid = *(int *)(ldata(usbpid)); | |
674 | - if (lnext(usbpid)) | |
675 | - avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", | |
671 | + if(pgm->usbpid.size()) | |
672 | + { | |
673 | + pid = pgm->usbpid[0]; | |
674 | + if(pgm->usbpid.size() > 1) | |
675 | + { | |
676 | + avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", | |
676 | 677 | progname, pid); |
677 | - } else | |
678 | - pid = USB_DEVICE_FT2232; | |
678 | + } | |
679 | + } | |
680 | + else | |
681 | + { | |
682 | + pid = USB_DEVICE_FT2232; | |
683 | + } | |
679 | 684 | |
680 | 685 | if (0 == pgm->usbsn[0]) /* we don't care about SN. Use first avail. */ |
681 | 686 | serial = NULL; |
@@ -564,25 +564,18 @@ | ||
564 | 564 | TKN_NUMBER { |
565 | 565 | { |
566 | 566 | /* overwrite pids, so clear the existing entries */ |
567 | - ldestroy_cb(current_prog->usbpid, free); | |
568 | - current_prog->usbpid = lcreat(NULL, 0); | |
567 | + current_prog->usbpid.clear(); | |
569 | 568 | } |
570 | 569 | { |
571 | - int *ip = static_cast<int*>(malloc(sizeof(int))); | |
572 | - if (ip) { | |
573 | - *ip = $1->value.number; | |
574 | - ladd(current_prog->usbpid, ip); | |
575 | - } | |
570 | + int ip = $1->value.number; | |
571 | + current_prog->usbpid.push_back(ip); | |
576 | 572 | free_token($1); |
577 | 573 | } |
578 | 574 | } | |
579 | 575 | usb_pid_list TKN_COMMA TKN_NUMBER { |
580 | 576 | { |
581 | - int *ip = static_cast<int*>(malloc(sizeof(int))); | |
582 | - if (ip) { | |
583 | - *ip = $3->value.number; | |
584 | - ladd(current_prog->usbpid, ip); | |
585 | - } | |
577 | + int ip = $3->value.number; | |
578 | + current_prog->usbpid.push_back(ip); | |
586 | 579 | free_token($3); |
587 | 580 | } |
588 | 581 | } |
@@ -234,13 +234,17 @@ | ||
234 | 234 | */ |
235 | 235 | |
236 | 236 | vid = (pgm->usbvid != 0) ? pgm->usbvid : USB_VENDOR_ATMEL; |
237 | - LNODEID usbpid = lfirst(pgm->usbpid); | |
238 | - if (usbpid) { | |
239 | - pid = *(int *)(ldata(usbpid)); | |
240 | - if (lnext(usbpid)) | |
237 | + if(pgm->usbpid.size()) | |
238 | + { | |
239 | + pid = pgm->usbpid[0]; | |
240 | + if(pgm->usbpid.size() > 1) | |
241 | + { | |
241 | 242 | avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", |
242 | 243 | progname, pid); |
243 | - } else { | |
244 | + } | |
245 | + } | |
246 | + else | |
247 | + { | |
244 | 248 | pid = part->usbpid; |
245 | 249 | } |
246 | 250 | if (!ovsigck && (part->flags & AVRPART_HAS_PDI)) { |
@@ -227,13 +227,17 @@ | ||
227 | 227 | */ |
228 | 228 | |
229 | 229 | vid = (pgm->usbvid != 0) ? pgm->usbvid : USB_VENDOR_ATMEL; |
230 | - LNODEID usbpid = lfirst(pgm->usbpid); | |
231 | - if (usbpid) { | |
232 | - pid = *(int *)(ldata(usbpid)); | |
233 | - if (lnext(usbpid)) | |
230 | + if(pgm->usbpid.size()) | |
231 | + { | |
232 | + pid = pgm->usbpid[0]; | |
233 | + if(pgm->usbpid.size() > 1) | |
234 | + { | |
234 | 235 | avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", |
235 | 236 | progname, pid); |
236 | - } else { | |
237 | + } | |
238 | + } | |
239 | + else | |
240 | + { | |
237 | 241 | pid = part->usbpid; |
238 | 242 | } |
239 | 243 |
@@ -1416,7 +1416,6 @@ | ||
1416 | 1416 | int jtag3_open_common(PROGRAMMER * pgm, char * port) |
1417 | 1417 | { |
1418 | 1418 | union pinfo pinfo; |
1419 | - LNODEID usbpid; | |
1420 | 1419 | int rv = -1; |
1421 | 1420 | |
1422 | 1421 | #if !defined(HAVE_LIBUSB) && !defined(HAVE_LIBHIDAPI) |
@@ -1424,20 +1423,21 @@ | ||
1424 | 1423 | return -1; |
1425 | 1424 | #endif |
1426 | 1425 | |
1427 | - if (strncmp(port, "usb", 3) != 0) { | |
1426 | + if(strncmp(port, "usb", 3) != 0) | |
1427 | + { | |
1428 | 1428 | avrdude_message(MSG_INFO, "%s: jtag3_open_common(): JTAGICE3/EDBG port names must start with \"usb\"\n", |
1429 | 1429 | progname); |
1430 | 1430 | return -1; |
1431 | 1431 | } |
1432 | 1432 | |
1433 | - if (pgm->usbvid) | |
1433 | + if(pgm->usbvid) | |
1434 | 1434 | pinfo.usbinfo.vid = pgm->usbvid; |
1435 | 1435 | else |
1436 | 1436 | pinfo.usbinfo.vid = USB_VENDOR_ATMEL; |
1437 | 1437 | |
1438 | 1438 | /* If the config entry did not specify a USB PID, insert the default one. */ |
1439 | - if (lfirst(pgm->usbpid) == NULL) | |
1440 | - ladd(pgm->usbpid, (void *)USB_DEVICE_JTAGICE3); | |
1439 | + if(!pgm->usbpid.size()) | |
1440 | + pgm->usbpid.push_back(USB_DEVICE_JTAGICE3); | |
1441 | 1441 | |
1442 | 1442 | #if defined(HAVE_LIBHIDAPI) |
1443 | 1443 | /* |
@@ -1445,9 +1445,11 @@ | ||
1445 | 1445 | * troubles for HID-class devices in some OSes (like Windows). |
1446 | 1446 | */ |
1447 | 1447 | serdev = &usbhid_serdev; |
1448 | - for (usbpid = lfirst(pgm->usbpid); rv < 0 && usbpid != NULL; usbpid = lnext(usbpid)) { | |
1448 | + for(std::vector<int>::const_iterator it = pgm->usbpid.begin(); it != pgm->usbpid.end(); ++it) | |
1449 | + { | |
1450 | + int usbpid = *it; | |
1449 | 1451 | pinfo.usbinfo.flags = PINFO_FL_SILENT; |
1450 | - pinfo.usbinfo.pid = *(int *)(ldata(usbpid)); | |
1452 | + pinfo.usbinfo.pid = usbpid; | |
1451 | 1453 | pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_3; |
1452 | 1454 | pgm->fd.usb.rep = USBDEV_BULK_EP_READ_3; |
1453 | 1455 | pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_3; |
@@ -1455,14 +1457,19 @@ | ||
1455 | 1457 | |
1456 | 1458 | strcpy(pgm->port, port); |
1457 | 1459 | rv = serial_open(port, pinfo, &pgm->fd); |
1460 | + if(rv >= 0) | |
1461 | + break; | |
1458 | 1462 | } |
1459 | - if (rv < 0) { | |
1463 | + if(rv < 0) | |
1460 | 1464 | #endif /* HAVE_LIBHIDAPI */ |
1465 | + { | |
1461 | 1466 | #if defined(HAVE_LIBUSB) |
1462 | 1467 | serdev = &usb_serdev_frame; |
1463 | - for (usbpid = lfirst(pgm->usbpid); rv < 0 && usbpid != NULL; usbpid = lnext(usbpid)) { | |
1468 | + for(std::vector<int>::const_iterator it = pgm->usbpid.begin(); it != pgm->usbpid.end(); ++it) | |
1469 | + { | |
1470 | + int usbpid = *it; | |
1464 | 1471 | pinfo.usbinfo.flags = PINFO_FL_SILENT; |
1465 | - pinfo.usbinfo.pid = *(int *)(ldata(usbpid)); | |
1472 | + pinfo.usbinfo.pid = usbpid; | |
1466 | 1473 | pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_3; |
1467 | 1474 | pgm->fd.usb.rep = USBDEV_BULK_EP_READ_3; |
1468 | 1475 | pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_3; |
@@ -1472,17 +1479,18 @@ | ||
1472 | 1479 | rv = serial_open(port, pinfo, &pgm->fd); |
1473 | 1480 | } |
1474 | 1481 | #endif /* HAVE_LIBUSB */ |
1475 | -#if defined(HAVE_LIBHIDAPI) | |
1476 | 1482 | } |
1477 | -#endif | |
1478 | - if (rv < 0) { | |
1483 | + if(rv < 0) | |
1484 | + { | |
1479 | 1485 | avrdude_message(MSG_INFO, "%s: jtag3_open_common(): Did not find any device matching VID 0x%04x and PID list: ", |
1480 | 1486 | progname, (unsigned)pinfo.usbinfo.vid); |
1481 | 1487 | int notfirst = 0; |
1482 | - for (usbpid = lfirst(pgm->usbpid); usbpid != NULL; usbpid = lnext(usbpid)) { | |
1483 | - if (notfirst) | |
1488 | + for(std::vector<int>::const_iterator it = pgm->usbpid.begin(); it != pgm->usbpid.end(); ++it) | |
1489 | + { | |
1490 | + int usbpid = *it; | |
1491 | + if(notfirst) | |
1484 | 1492 | avrdude_message(MSG_INFO, ", "); |
1485 | - avrdude_message(MSG_INFO, "0x%04x", (unsigned int)(*(int *)(ldata(usbpid)))); | |
1493 | + avrdude_message(MSG_INFO, "0x%04x", usbpid); | |
1486 | 1494 | notfirst = 1; |
1487 | 1495 | } |
1488 | 1496 | fputc('\n', stderr); |
@@ -1490,7 +1498,7 @@ | ||
1490 | 1498 | return -1; |
1491 | 1499 | } |
1492 | 1500 | |
1493 | - if (pgm->fd.usb.eep == 0) | |
1501 | + if(pgm->fd.usb.eep == 0) | |
1494 | 1502 | { |
1495 | 1503 | /* The event EP has been deleted by usb_open(), so we are |
1496 | 1504 | running on a CMSIS-DAP device, using EDBG protocol */ |
@@ -629,7 +629,7 @@ | ||
629 | 629 | int ppictrl; |
630 | 630 | int baudrate; |
631 | 631 | int usbvid; |
632 | - LISTID usbpid; | |
632 | + std::vector<int> usbpid; | |
633 | 633 | char usbdev[PGM_USBSTRINGLEN], usbsn[PGM_USBSTRINGLEN]; |
634 | 634 | char usbvendor[PGM_USBSTRINGLEN], usbproduct[PGM_USBSTRINGLEN]; |
635 | 635 | double bitclock; /* JTAG ICE clock period in microseconds */ |
@@ -697,7 +697,6 @@ | ||
697 | 697 | |
698 | 698 | PROGRAMMER *pgm_new(); |
699 | 699 | PROGRAMMER *pgm_dup(const PROGRAMMER *src); |
700 | -void pgm_free(PROGRAMMER * const p); | |
701 | 700 | |
702 | 701 | void programmer_display(PROGRAMMER * pgm, const char * p); |
703 | 702 |
@@ -108,7 +108,6 @@ | ||
108 | 108 | pgm->cookie = 0; |
109 | 109 | pgm->flag = 0; |
110 | 110 | |
111 | - pgm->usbpid = lcreat(NULL, 0); | |
112 | 111 | pgm->desc[0] = 0; |
113 | 112 | pgm->type[0] = 0; |
114 | 113 | pgm->config_file[0] = 0; |
@@ -171,44 +170,18 @@ | ||
171 | 170 | return pgm; |
172 | 171 | } |
173 | 172 | |
174 | -void pgm_free(PROGRAMMER * const p) | |
175 | -{ | |
176 | - ldestroy_cb(p->usbpid, free); | |
177 | - p->usbpid = NULL; | |
178 | - /* this is done by pgm_teardown, but usually cookie is not set to NULL */ | |
179 | - /* if (p->cookie !=NULL) { | |
180 | - free(p->cookie); | |
181 | - p->cookie = NULL; | |
182 | - }*/ | |
183 | -} | |
184 | - | |
185 | 173 | PROGRAMMER *pgm_dup(const PROGRAMMER *src) |
186 | 174 | { |
187 | - LNODEID ln; | |
188 | - | |
189 | 175 | PROGRAMMER *pgm = new PROGRAMMER(*src); |
190 | - if (pgm == NULL) { | |
176 | + if(pgm == NULL) | |
177 | + { | |
191 | 178 | avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n", |
192 | 179 | progname); |
193 | 180 | return NULL; |
194 | 181 | } |
195 | 182 | |
196 | - //memcpy(pgm, src, sizeof(*pgm)); | |
197 | - | |
198 | 183 | pgm->id.clear(); |
199 | - pgm->usbpid = lcreat(NULL, 0); | |
200 | 184 | |
201 | - for (ln = lfirst(src->usbpid); ln; ln = lnext(ln)) { | |
202 | - int *ip = static_cast<int*>(malloc(sizeof(int))); | |
203 | - if (ip == NULL) { | |
204 | - avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n", | |
205 | - progname); | |
206 | - exit(1); | |
207 | - } | |
208 | - *ip = *(int *) ldata(ln); | |
209 | - ladd(pgm->usbpid, ip); | |
210 | - } | |
211 | - | |
212 | 185 | return pgm; |
213 | 186 | } |
214 | 187 |
@@ -152,7 +152,6 @@ | ||
152 | 152 | PROGRAMMER *p = &(*it); |
153 | 153 | if(p == data_ptr) |
154 | 154 | { |
155 | - pgm_free(p); | |
156 | 155 | programmers.erase(it); |
157 | 156 | return; |
158 | 157 | } |
@@ -468,14 +468,18 @@ | ||
468 | 468 | progname, port); |
469 | 469 | |
470 | 470 | /* usb_init will be done in usbOpenDevice */ |
471 | - LNODEID usbpid = lfirst(pgm->usbpid); | |
472 | 471 | int pid, vid; |
473 | - if (usbpid) { | |
474 | - pid = *(int *)(ldata(usbpid)); | |
475 | - if (lnext(usbpid)) | |
472 | + if(pgm->usbpid.size()) | |
473 | + { | |
474 | + pid = pgm->usbpid[0]; | |
475 | + if(pgm->usbpid.size() > 1) | |
476 | + { | |
476 | 477 | avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", |
477 | 478 | progname, pid); |
478 | - } else { | |
479 | + } | |
480 | + } | |
481 | + else | |
482 | + { | |
479 | 483 | pid = USBASP_SHARED_PID; |
480 | 484 | } |
481 | 485 | vid = pgm->usbvid? pgm->usbvid: USBASP_SHARED_VID; |
@@ -333,13 +333,17 @@ | ||
333 | 333 | else |
334 | 334 | vid = USBTINY_VENDOR_DEFAULT; |
335 | 335 | |
336 | - LNODEID usbpid = lfirst(pgm->usbpid); | |
337 | - if (usbpid) { | |
338 | - pid = *(int *)(ldata(usbpid)); | |
339 | - if (lnext(usbpid)) | |
336 | + if(pgm->usbpid.size()) | |
337 | + { | |
338 | + pid = pgm->usbpid[0]; | |
339 | + if(pgm->usbpid.size() > 1) | |
340 | + { | |
340 | 341 | avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", |
341 | 342 | progname, pid); |
342 | - } else { | |
343 | + } | |
344 | + } | |
345 | + else | |
346 | + { | |
343 | 347 | pid = USBTINY_PRODUCT_DEFAULT; |
344 | 348 | } |
345 | 349 |