⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avrdude-usb.patch

📁 单片机的USB ISP软件包,不可多得
💻 PATCH
📖 第 1 页 / 共 2 页
字号:
+static void ausb_restore        (PROGRAMMER * pgm);++static void ausb_disable        (PROGRAMMER * pgm);++static void ausb_enable         (PROGRAMMER * pgm);++static void ausb_open           (PROGRAMMER * pgm, char * port);++static void ausb_close          (PROGRAMMER * pgm);+++#define USB_RESET 4+#define USB_MOSI 5+#define USB_MISO 6+#define USB_SCK 7++static unsigned pins = 0;++static int ausb_setpin(PROGRAMMER *pgm, int pin, int value)+{+  unsigned char c = pins;++  if (pin < 0 || pin > 7)+    return -1;++  if(value)+	c |= (1<<pin);+  else+	c &= ~(1<<pin);++  if(c == pins) return;++  send_command(pgm->dev, AVR_PORT_SET, c);+  pins = c;++  return 0;+}+++static int ausb_getpin(PROGRAMMER *pgm, int pin)+{+  int value;+  unsigned char c;++  if (pin < 0 || pin > 7)+    return -1;++  if (pin == USB_MISO)+    get_response(pgm->dev, AVR_PIN_GET, 0, &c, 1);+  else+    c = pins;++  value = !!(c & (1<<pin));++  return value;+}+++static int ausb_pulsepin(PROGRAMMER *pgm, int pin)+{+  int value;++  if (pin < 0 || pin > 7)+    return -1;++  value = ausb_getpin(pgm->dev, pin);++  ausb_setpin(pgm, pin, !value);+  ausb_setpin(pgm, pin, value);++  return 0;+}++static int ausb_rdy_led(PROGRAMMER * pgm, int value)+{+  //ausb_setpin(pgm, USB_RDY, value);+}++static int ausb_err_led(PROGRAMMER * pgm, int value)+{+  //ausb_setpin(pgm, USB_ERR, value);+}++static int ausb_pgm_led(PROGRAMMER * pgm, int value)+{+  //ausb_setpin(pgm, USB_PGM, value);+}++static int ausb_vfy_led(PROGRAMMER * pgm, int value)+{+  //ausb_setpin(pgm, USB_VFY, value);+}+++/*+ * transmit an AVR device command and return the results; 'cmd' and+ * 'res' must point to at least a 4 byte data buffer+ */+static int ausb_cmd(PROGRAMMER * pgm, unsigned char cmd[4], +                   unsigned char res[4])+{+  int i;++  get_response_idx(pgm->dev, AVR_SPI4, cmd[0] + 256*cmd[1],+		   cmd[2] + 256*cmd[3], res, 4);++    if(verbose >= 2)+	{+        fprintf(stderr, "ausb_cmd(): [ ");+        for(i = 0; i < 4; i++)+            fprintf(stderr, "%02X ", cmd[i]);+        fprintf(stderr, "] [ ");+        for(i = 0; i < 4; i++)+		{+            fprintf(stderr, "%02X ", res[i]);+		}+        fprintf(stderr, "]\n");+	}++  return 0;+}+++/*+ * issue the 'chip erase' command to the AVR device+ */+static int ausb_chip_erase(PROGRAMMER * pgm, AVRPART * p)+{+  unsigned char cmd[4];+  unsigned char res[4];+  int cycles;+  int rc;++  if (p->op[AVR_OP_CHIP_ERASE] == NULL) {+    fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n",+            p->desc);+    return -1;+  }++  rc = avr_get_cycle_count(pgm, p, &cycles);++  /*+   * only print out the current cycle count if we aren't going to+   * display it below +   */+  if (!do_cycles && ((rc >= 0) && (cycles != 0xffffffff))) {+    fprintf(stderr,+            "%s: current erase-rewrite cycle count is %d%s\n",+            progname, cycles, +            do_cycles ? "" : " (if being tracked)");+  }++  pgm->pgm_led(pgm, ON);++  memset(cmd, 0, sizeof(cmd));++  avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd);+  pgm->cmd(pgm, cmd, res);+  usleep(p->chip_erase_delay);+  pgm->initialize(pgm, p);++  pgm->pgm_led(pgm, OFF);++  if (do_cycles && (cycles != -1)) {+    if (cycles == 0x00ffff) {+      cycles = 0;+    }+    cycles++;+    fprintf(stderr, "%s: erase-rewrite cycle count is now %d\n", +            progname, cycles);+    avr_put_cycle_count(pgm, p, cycles);+  }++  return 0;+}++/*+ * issue the 'program enable' command to the AVR device+ */+static int ausb_program_enable(PROGRAMMER * pgm, AVRPART * p)+{+  unsigned char cmd[4];+  unsigned char res[4];++  if (p->op[AVR_OP_PGM_ENABLE] == NULL) {+    fprintf(stderr, "program enable instruction not defined for part \"%s\"\n",+            p->desc);+    return -1;+  }++  memset(cmd, 0, sizeof(cmd));+  avr_set_bits(p->op[AVR_OP_PGM_ENABLE], cmd);+  pgm->cmd(pgm, cmd, res);++  if (res[2] != cmd[1])+    return -2;++  return 0;+}+++/*+ * apply power to the AVR processor+ */+static void ausb_powerup(PROGRAMMER * pgm)+{+}+++/*+ * remove power from the AVR processor+ */+static void ausb_powerdown(PROGRAMMER * pgm)+{+}+++/*+ * initialize the AVR device and prepare it to accept commands+ */+static int ausb_initialize(PROGRAMMER * pgm, AVRPART * p)+{+  int rc;+  int tries;++  pgm->powerup(pgm);+  usleep(20000);++  ausb_setpin(pgm, USB_SCK, 0);+  ausb_setpin(pgm, USB_RESET, 0);+  usleep(20000);++  ausb_pulsepin(pgm, USB_RESET);++  usleep(20000); /* 20 ms XXX should be a per-chip parameter */++  /*+   * Enable programming mode.  If we are programming an AT90S1200, we+   * can only issue the command and hope it worked.  If we are using+   * one of the other chips, the chip will echo 0x53 when issuing the+   * third byte of the command.  In this case, try up to 32 times in+   * order to possibly get back into sync with the chip if we are out+   * of sync.+   */+  if (strcmp(p->desc, "AT90S1200")==0) {+    pgm->program_enable(pgm, p);+  }+  else {+    tries = 0;+    do {+      rc = pgm->program_enable(pgm, p);+      if ((rc == 0)||(rc == -1))+        break;+      ausb_pulsepin(pgm, USB_SCK);+      tries++;+    } while (tries < 65);++    /*+     * can't sync with the device, maybe it's not attached?+     */+    if (rc) {+      fprintf(stderr, "%s: AVR device not responding\n", progname);+      return -1;+    }+  }++  return 0;+}+++static int ausb_save(PROGRAMMER * pgm)+{+  int rc;++  return 0;+}++static void ausb_restore(PROGRAMMER * pgm)+{+}++static void ausb_disable(PROGRAMMER * pgm)+{+}++static void ausb_enable(PROGRAMMER * pgm)+{+  /*+   * Prepare to start talking to the connected device - pull reset low+   * first, delay a few milliseconds, then enable the buffer.  This+   * sequence allows the AVR to be reset before the buffer is enabled+   * to avoid a short period of time where the AVR may be driving the+   * programming lines at the same time the programmer tries to.  Of+   * course, if a buffer is being used, then the /RESET line from the+   * programmer needs to be directly connected to the AVR /RESET line+   * and not via the buffer chip.+   */++  ausb_setpin(pgm, USB_RESET, 0);+  usleep(1);+}+++static void ausb_open(PROGRAMMER * pgm, char * port)+{+  pgm->dev = get_avr();+  if (pgm->dev == 0) {+    fprintf(stderr, "%s: failed to open usb port \"%s\"\n\n",+            progname, port);+    exit(1);+  }++  send_command(pgm->dev, AVR_DDR_SET, ~(1<<USB_MISO));+  send_command(pgm->dev, AVR_PORT_SET, 1<<USB_MISO);+}+++static void ausb_close(PROGRAMMER * pgm)+{+  send_command(pgm->dev, AVR_DDR_SET, 0x00);+  send_command(pgm->dev, AVR_PORT_SET, 0x00);++  pgm->dev = (avr_device)-1;+}+++static void ausb_display(PROGRAMMER * pgm, char * p)+{+  fprintf(stderr, "BUH?   FUH!\n");+}+++void ausb_initpgm(PROGRAMMER * pgm)+{+  strcpy(pgm->type, "USB");++  pgm->rdy_led        = ausb_rdy_led;+  pgm->err_led        = ausb_err_led;+  pgm->pgm_led        = ausb_pgm_led;+  pgm->vfy_led        = ausb_vfy_led;+  pgm->initialize     = ausb_initialize;+  pgm->display        = ausb_display;+  pgm->save           = ausb_save;+  pgm->restore        = ausb_restore;+  pgm->enable         = ausb_enable;+  pgm->disable        = ausb_disable;+  pgm->powerup        = ausb_powerup;+  pgm->powerdown      = ausb_powerdown;+  pgm->program_enable = ausb_program_enable;+  pgm->chip_erase     = ausb_chip_erase;+  pgm->cmd            = ausb_cmd;+  pgm->open           = ausb_open;+  pgm->close          = ausb_close;+}++

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -