📄 avrdude-usb.patch
字号:
diff -urN orig/avrdude-4.0.0/Makefile.am avrdude-4.0.0/Makefile.am--- orig/avrdude-4.0.0/Makefile.am 2003-03-11 20:09:57.000000000 -0600+++ avrdude-4.0.0/Makefile.am 2003-11-24 21:44:21.000000000 -0600@@ -71,7 +71,11 @@ stk500.h \ stk500_private.h \ term.c \- term.h+ term.h \+ usb.c \+ avr_usb.h \+ hostlib.c \+ hostlib.h man_MANS = avrdude.1 diff -urN orig/avrdude-4.0.0/avr.c avrdude-4.0.0/avr.c--- orig/avrdude-4.0.0/avr.c 2003-03-04 22:30:20.000000000 -0600+++ avrdude-4.0.0/avr.c 2003-11-26 16:24:59.000000000 -0600@@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: avr.c,v 1.52 2003/03/05 04:30:20 bdean Exp $ */+/* $Id: avr.c,v 1.1 2003/11/26 22:24:50 jepler Exp jepler $ */ #include "ac_cfg.h" @@ -477,7 +477,7 @@ int rc; int readok=0; - if (!mem->paged) {+ if (!mem->paged && strcmp(pgm->type, "USB")) { /* * check to see if the write is necessary by reading the existing * value and only write if we are changing the value; we can't@@ -557,7 +557,8 @@ * read operation not supported for this memory type, just wait * the max programming time and then return */- usleep(mem->max_write_delay); /* maximum write delay */+ if(mem->max_write_delay > 0) + usleep(mem->max_write_delay); /* maximum write delay */ pgm->pgm_led(pgm, OFF); return 0; }diff -urN orig/avrdude-4.0.0/avr_usb.h avrdude-4.0.0/avr_usb.h--- orig/avrdude-4.0.0/avr_usb.h 1969-12-31 18:00:00.000000000 -0600+++ avrdude-4.0.0/avr_usb.h 2003-11-24 21:53:56.000000000 -0600@@ -0,0 +1,30 @@+/*+ * avrdude - A Downloader/Uploader for AVR device programmers+ * Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean <bsd@bsdhome.com>+ *+ * 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; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ */++/* $Id: par.h,v 1.1 2003/02/13 19:27:50 bdean Exp $ */++#ifndef __avr_usb_h__+#define __avr_usb_h__++#include "config.h"++void ausb_initpgm (PROGRAMMER * pgm);+#endif++diff -urN orig/avrdude-4.0.0/config_gram.y avrdude-4.0.0/config_gram.y--- orig/avrdude-4.0.0/config_gram.y 2003-03-04 19:19:17.000000000 -0600+++ avrdude-4.0.0/config_gram.y 2003-11-24 21:53:47.000000000 -0600@@ -29,6 +29,7 @@ #include "config.h" #include "lists.h" #include "par.h"+#include "avr_usb.h" #include "pindefs.h" #include "ppi.h" #include "pgm.h"@@ -102,6 +103,7 @@ %token K_SIZE %token K_STK500 %token K_TYPE+%token K_USB %token K_VCC %token K_VFYLED %token K_WRITEPAGE@@ -284,6 +286,12 @@ } } | + K_TYPE TKN_EQUAL K_USB {+ {+ ausb_initpgm(current_prog);+ }+ } |+ K_DESC TKN_EQUAL TKN_STRING { strncpy(current_prog->desc, $3->value.string, PGM_DESCLEN); current_prog->desc[PGM_DESCLEN-1] = 0;diff -urN orig/avrdude-4.0.0/hostlib.c avrdude-4.0.0/hostlib.c--- orig/avrdude-4.0.0/hostlib.c 1969-12-31 18:00:00.000000000 -0600+++ avrdude-4.0.0/hostlib.c 2003-11-28 09:45:41.000000000 -0600@@ -0,0 +1,101 @@+#include "hostlib.h"++#include <usb.h>+#include <stdio.h>+#include <time.h>++#define DO_DEBUG 0 +++#if DO_DEBUG+static struct timeval t0, t1; +#define DEBUG(x) (printf x)+#define TB() gettimeofday(&t0)+#define TE(s) gettimeofday(&t1); DEBUG(( s ": %f\n", t1.tv_sec - t0.tv_sec + (t1.tv_usec - t0.tv_usec) * 1e-6 ))+#else+#define TB() (void)0+#define TE(s) (void)0+#define DEBUG(x) (void)0+#endif+struct usb_device *find_on_bus(struct usb_bus *bus, u_int16_t v, u_int16_t p) {+ struct usb_device *dev = bus->devices;++ for(; dev; dev = dev->next) {+ if(dev->descriptor.idVendor == v && dev->descriptor.idProduct == p) {+ return dev;+ }+ }+ return NULL;+}++struct usb_device *find_dev(u_int16_t v, u_int16_t p) {+ struct usb_bus *bus = usb_get_busses();+ struct usb_device *dev = NULL;++ for(; bus; bus = bus->next) {+ dev = find_on_bus(bus, v, p);+ if(dev) return dev;+ }+ return NULL;+}++void send_command(avr_device *dev, int cmd, int val) {+ DEBUG(("send_command %d %02x\n", cmd, val));+ TB();+ usb_control_msg((usb_dev_handle *)dev, USB_TYPE_VENDOR, cmd, val,+ 0, NULL, 0, 1000);+ TE("send_command");+}++void send_command_idx(avr_device *dev, int cmd, int val, int idx) {+ DEBUG(("send_command %d %02x\n", cmd, val));+ TB();+ usb_control_msg((usb_dev_handle *)dev, USB_TYPE_VENDOR, cmd, val,+ idx, NULL, 0, 1000);+ TE("send_command");+}+++int get_response(avr_device *dev, int cmd, int val, char *buf, int len) {+ DEBUG(("get_response %d %02x", cmd, val));+ TB();+ int ret = usb_control_msg((usb_dev_handle *)dev,+ USB_TYPE_VENDOR | USB_ENDPOINT_IN, cmd, val,+ 0, buf, len, 1000);+ TE("get_response");+ DEBUG((" -> %d (buf[0] = %02x)\n", ret, (unsigned char)buf[0]));+ return ret;+}+++int get_response_idx(avr_device *dev, int cmd, int val, int idx,+ char *buf, int len) {+ DEBUG(("get_response %d %02x", cmd, val));+ TB();+ int ret = usb_control_msg((usb_dev_handle *)dev,+ USB_TYPE_VENDOR | USB_ENDPOINT_IN, cmd, val,+ idx, buf, len, 1000);+ TE("get_response");+ DEBUG((" -> %d (buf[0] = %02x)\n", ret, (unsigned char)buf[0]));+ return ret;+}++avr_device get_avr(void) {+ struct usb_device *dev;+ usb_dev_handle *devh;++ usb_init();+ usb_set_debug(0xff);+ usb_find_busses();+ usb_find_devices();++ dev = find_dev(0x3eb, 0x2);+ if(!dev) return NULL;++ devh = usb_open(dev);++ usb_claim_interface(devh, 0);+ return (avr_device)devh;+}++// vim:sts=4:sw=4:etdiff -urN orig/avrdude-4.0.0/hostlib.h avrdude-4.0.0/hostlib.h--- orig/avrdude-4.0.0/hostlib.h 1969-12-31 18:00:00.000000000 -0600+++ avrdude-4.0.0/hostlib.h 2003-11-28 09:45:54.000000000 -0600@@ -0,0 +1,27 @@+#ifndef AVR_HOSTLIB_H+#define AVR_HOSTLIB_H++#define AVR_INFRA_BUFFER_EMPTY 1+#define AVR_INFRA_GET_CODE 2+#define AVR_DDR_SET 3+#define AVR_DDR_GET 4+#define AVR_PORT_SET 5+#define AVR_PORT_GET 6+#define AVR_PIN_GET 7+#define AVR_EEPROM_READ 8+#define AVR_EEPROM_WRITE 9+#define AVR_RS232_WRITE 10+#define AVR_RS232_READ 11+#define AVR_RS232_BAUD_SET 12+#define AVR_RS232_BAUD_GET 13+#define AVR_SPI4 15++typedef void* avr_device;++avr_device get_avr();+void send_command(avr_device *dev, int cmd, int val);+void send_command_idx(avr_device *dev, int cmd, int val, int idx);+int get_response(avr_device *dev, int cmd, int val, char *buf, int len);+int get_response_idx(avr_device *dev, int cmd, int idx, int val,+ char *buf, int len);+#endifdiff -urN orig/avrdude-4.0.0/lexer.l avrdude-4.0.0/lexer.l--- orig/avrdude-4.0.0/lexer.l 2003-02-27 10:42:56.000000000 -0600+++ avrdude-4.0.0/lexer.l 2003-11-24 21:43:14.000000000 -0600@@ -153,6 +153,7 @@ size { yylval=NULL; return K_SIZE; } stk500 { yylval=NULL; return K_STK500; } type { yylval=NULL; return K_TYPE; }+usb { yylval=NULL; return K_USB; } vcc { yylval=NULL; return K_VCC; } vfyled { yylval=NULL; return K_VFYLED; } diff -urN orig/avrdude-4.0.0/pgm.h avrdude-4.0.0/pgm.h--- orig/avrdude-4.0.0/pgm.h 2003-02-22 10:45:13.000000000 -0600+++ avrdude-4.0.0/pgm.h 2003-11-24 21:48:36.000000000 -0600@@ -27,7 +27,7 @@ #include "avrpart.h" #include "lists.h" #include "pindefs.h"-+#include "hostlib.h" #define ON 1 #define OFF 0@@ -43,6 +43,7 @@ unsigned int pinno[N_PINS]; int ppidata; int fd;+ avr_device dev; int page_size; /* page size if the programmer supports paged write/load */ int (*rdy_led) (struct programmer_t * pgm, int value); int (*err_led) (struct programmer_t * pgm, int value);diff -urN orig/avrdude-4.0.0/usb.c avrdude-4.0.0/usb.c--- orig/avrdude-4.0.0/usb.c 1969-12-31 18:00:00.000000000 -0600+++ avrdude-4.0.0/usb.c 2003-11-28 09:46:47.000000000 -0600@@ -0,0 +1,431 @@+/*+ * avrdude - A Downloader/Uploader for AVR device programmers+ * Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean <bsd@bsdhome.com>+ *+ * 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; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ */++/* $Id: usb.c,v 1.2 2003/11/26 22:24:50 jepler Exp jepler $ */++#include "ac_cfg.h"++#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <fcntl.h>+#include <unistd.h>+#include <errno.h>++#include <usb.h>++#include "avr.h"+#include "pindefs.h"+#include "pgm.h"+#include "avr_usb.h"+#include "hostlib.h"++#define SLOW_TOGGLE 0++extern char * progname;+extern int do_cycles;+extern int verbose;+++static int ausb_setpin (PROGRAMMER *pgm, int pin, int value);++static int ausb_getpin (PROGRAMMER *pgm, int pin);++static int ausb_pulsepin (PROGRAMMER *pgm, int pin);+++static int ausb_rdy_led (PROGRAMMER * pgm, int value);++static int ausb_err_led (PROGRAMMER * pgm, int value);++static int ausb_pgm_led (PROGRAMMER * pgm, int value);++static int ausb_vfy_led (PROGRAMMER * pgm, int value);++static int ausb_cmd (PROGRAMMER * pgm, unsigned char cmd[4], + unsigned char res[4]);++static int ausb_chip_erase (PROGRAMMER * pgm, AVRPART * p);++static int ausb_program_enable (PROGRAMMER * pgm, AVRPART * p);++static void ausb_powerup (PROGRAMMER * pgm);++static void ausb_powerdown (PROGRAMMER * pgm);++static int ausb_initialize (PROGRAMMER * pgm, AVRPART * p);++static int ausb_save (PROGRAMMER * pgm);+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -