From d09bc2e1fb18600aa15bc8131a041a4de8d9f4b8 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Mon, 19 May 2014 10:01:59 +0000 Subject: [PATCH] Join the former "public" header files (avr.h avrpart.h pindefs.h serial.h fileio.h safemode.h update.h pgm_type.h config.h confwin.h lists.h) into a single header that can be included by anyone wanting to link against the library. Adapt everything to cope with this situation. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1311 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 88 ++++ Makefile.am | 16 +- arduino.c | 3 +- avr.c | 7 +- avr.h | 77 ---- avr910.c | 6 +- avr910.h | 2 - avrftdi.c | 6 +- avrftdi_tpi.c | 8 +- avrftdi_tpi.h | 3 - avrpart.c | 3 +- avrpart.h | 236 ----------- bitbang.c | 5 +- buspirate.c | 5 +- butterfly.c | 5 +- config.c | 4 +- config.h | 117 ------ config_gram.y | 7 +- configure.ac | 2 +- confwin.c | 1 + confwin.h | 39 -- dfu.c | 8 +- fileio.c | 3 +- fileio.h | 64 --- flip1.c | 7 +- flip1.h | 2 - flip2.c | 8 +- flip2.h | 2 - ft245r.c | 7 +- ft245r.h | 2 - jtag3.c | 5 +- jtagmkI.c | 5 +- jtagmkII.c | 5 +- lexer.l | 3 +- libavrdude.h | 1003 ++++++++++++++++++++++++++++++++++++++++++++ linuxgpio.c | 5 +- lists.c | 2 +- lists.h | 116 ----- main.c | 11 +- par.c | 5 +- pgm.c | 2 +- pgm_type.c | 3 +- pgm_type.h | 50 --- pickit2.c | 3 +- pickit2.h | 2 - pindefs.c | 4 +- pindefs.h | 202 --------- ppi.c | 5 +- ppiwin.c | 5 +- safemode.c | 5 +- safemode.h | 46 -- ser_avrdoper.c | 2 +- ser_posix.c | 2 +- ser_win32.c | 5 +- serbb_posix.c | 5 +- serbb_win32.c | 6 +- serial.h | 94 ----- stk500.c | 5 +- stk500generic.c | 3 +- stk500v2.c | 5 +- stk500v2_private.h | 2 - term.c | 7 +- term.h | 3 +- update.c | 6 +- update.h | 61 --- usb_libusb.c | 3 +- usbasp.c | 4 +- usbasp.h | 2 - usbtiny.c | 5 +- usbtiny.h | 3 - wiring.c | 4 +- 71 files changed, 1183 insertions(+), 1274 deletions(-) delete mode 100644 avr.h delete mode 100644 avrpart.h delete mode 100644 config.h delete mode 100644 confwin.h delete mode 100644 fileio.h create mode 100644 libavrdude.h delete mode 100644 lists.h delete mode 100644 pgm_type.h delete mode 100644 pindefs.h delete mode 100644 safemode.h delete mode 100644 serial.h delete mode 100644 update.h diff --git a/ChangeLog b/ChangeLog index 8fc6d2ee..6aa3c322 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,91 @@ +2014-05-19 Joerg Wunsch + + * libavrdude.h: Join the former "public" header files (avr.h avrpart.h pindefs.h + serial.h fileio.h safemode.h update.h pgm_type.h config.h confwin.h lists.h) into + a single header that can be included by anyone wanting to link against the + library + * avr.h: Remove file. + * avrpart.h: (Dito.) + * pindefs.h: (Dito.) + * serial.h: (Dito.) + * fileio.h: (Dito.) + * safemode.h: (Dito.) + * update.h: (Dito.) + * pgm_type.h: (Dito.) + * config.h: (Dito.) + * confwin.h: (Dito.) + * lists.h: (Dito.) + * Makefile.am: Adapt for new include file constellation; install shared lib + * configure.ac: Bump version date + * arduino.c: #include rather than a bunch of different headers + * avr910.c: (Dito.) + * avr910.h: (Dito.) + * avr.c: (Dito.) + * avrftdi.c: (Dito.) + * avrftdi_tpi.c: (Dito.) + * avrftdi_tpi.h: (Dito.) + * avr.h: (Dito.) + * avrpart.c: (Dito.) + * avrpart.h: (Dito.) + * bitbang.c: (Dito.) + * buspirate.c: (Dito.) + * butterfly.c: (Dito.) + * config.c: (Dito.) + * config_gram.y: (Dito.) + * config.h: (Dito.) + * confwin.c: (Dito.) + * confwin.h: (Dito.) + * dfu.c: (Dito.) + * fileio.c: (Dito.) + * fileio.h: (Dito.) + * flip1.c: (Dito.) + * flip1.h: (Dito.) + * flip2.c: (Dito.) + * flip2.h: (Dito.) + * ft245r.c: (Dito.) + * ft245r.h: (Dito.) + * jtag3.c: (Dito.) + * jtagmkI.c: (Dito.) + * jtagmkII.c: (Dito.) + * lexer.l: (Dito.) + * libavrdude.h: (Dito.) + * linuxgpio.c: (Dito.) + * lists.c: (Dito.) + * lists.h: (Dito.) + * main.c: (Dito.) + * par.c: (Dito.) + * pgm.c: (Dito.) + * pgm_type.c: (Dito.) + * pgm_type.h: (Dito.) + * pickit2.c: (Dito.) + * pickit2.h: (Dito.) + * pindefs.c: (Dito.) + * pindefs.h: (Dito.) + * ppi.c: (Dito.) + * ppiwin.c: (Dito.) + * safemode.c: (Dito.) + * safemode.h: (Dito.) + * ser_avrdoper.c: (Dito.) + * serbb_posix.c: (Dito.) + * serbb_win32.c: (Dito.) + * serial.h: (Dito.) + * ser_posix.c: (Dito.) + * ser_win32.c: (Dito.) + * stk500.c: (Dito.) + * stk500generic.c: (Dito.) + * stk500v2.c: (Dito.) + * stk500v2_private.h: (Dito.) + * term.c: (Dito.) + * term.h: (Dito.) + * update.c: (Dito.) + * update.h: (Dito.) + * usbasp.c: (Dito.) + * usbasp.h: (Dito.) + * usb_libusb.c: (Dito.) + * usbtiny.c: (Dito.) + * usbtiny.h: (Dito.) + * wiring.c: (Dito.) + 2014-05-19 Joerg Wunsch * main.c: Cleanup unused include files. diff --git a/Makefile.am b/Makefile.am index 3ae184f7..1d915b01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,7 +71,7 @@ avrdude_LDADD = $(top_builddir)/$(noinst_LIBRARIES) @LIBUSB_1_0@ @LIBUSB@ @LIBF bin_PROGRAMS = avrdude noinst_LIBRARIES = libavrdude.a -noinst_LTLIBRARIES = libavrdude.la +lib_LTLIBRARIES = libavrdude.la # automake thinks these generated files should be in the distribution, # but this might cause trouble for some users, so we rather don't want @@ -94,7 +94,6 @@ libavrdude_a_SOURCES = \ arduino.h \ arduino.c \ avr.c \ - avr.h \ avr910.c \ avr910.h \ avrdude.h \ @@ -104,7 +103,6 @@ libavrdude_a_SOURCES = \ avrftdi_tpi.c \ avrftdi_tpi.h \ avrpart.c \ - avrpart.h \ bitbang.c \ bitbang.h \ buspirate.c \ @@ -112,15 +110,12 @@ libavrdude_a_SOURCES = \ butterfly.c \ butterfly.h \ config.c \ - config.h \ confwin.c \ - confwin.h \ crc16.c \ crc16.h \ dfu.c \ dfu.h \ fileio.c \ - fileio.h \ flip1.c \ flip1.h \ flip2.c \ @@ -137,28 +132,24 @@ libavrdude_a_SOURCES = \ jtag3.c \ jtag3.h \ jtag3_private.h \ + libavrdude.h \ linuxgpio.c \ linuxgpio.h \ linux_ppdev.h \ lists.c \ - lists.h \ my_ddk_hidsdi.h \ par.c \ par.h \ pgm.c \ pgm.h \ pgm_type.c \ - pgm_type.h \ pickit2.c \ pickit2.h \ pindefs.c \ - pindefs.h \ ppi.c \ ppi.h \ ppiwin.c \ safemode.c \ - safemode.h \ - serial.h \ serbb.h \ serbb_posix.c \ serbb_win32.c \ @@ -181,13 +172,14 @@ libavrdude_a_SOURCES = \ usb_libusb.c \ usbtiny.h \ usbtiny.c \ - update.h \ update.c \ wiring.h \ wiring.c libavrdude_la_SOURCES = $(libavrdude_a_SOURCES) libavrdude_la_LDFLAGS = -version-info 1:0 +include_HEADERS = libavrdude.h + avrdude_SOURCES = \ main.c \ term.c \ diff --git a/arduino.c b/arduino.c index fa7e41e7..681a99b1 100644 --- a/arduino.c +++ b/arduino.c @@ -32,10 +32,9 @@ #include #include "avrdude.h" -#include "pgm.h" +#include "libavrdude.h" #include "stk500_private.h" #include "stk500.h" -#include "serial.h" #include "arduino.h" /* read signature bytes - arduino version */ diff --git a/avr.c b/avr.c index 13330196..c03c524d 100644 --- a/avr.c +++ b/avr.c @@ -29,13 +29,8 @@ #include #include "avrdude.h" +#include "libavrdude.h" -#include "avr.h" -#include "lists.h" -#include "pindefs.h" -#include "ppi.h" -#include "safemode.h" -#include "update.h" #include "tpi.h" FP_UpdateProgress update_progress; diff --git a/avr.h b/avr.h deleted file mode 100644 index cf9e690b..00000000 --- a/avr.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2000-2004 Brian S. Dean - * - * 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, see . - */ - -/* $Id$ */ - -#ifndef __avr_h__ -#define __avr_h__ - -#include - -#include "avrpart.h" -#include "pgm.h" - -typedef void (*FP_UpdateProgress)(int percent, double etime, char *hdr); - -extern struct avrpart parts[]; - -extern FP_UpdateProgress update_progress; - -#ifdef __cplusplus -extern "C" { -#endif - -int avr_tpi_poll_nvmbsy(PROGRAMMER *pgm); -int avr_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p); -int avr_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p, unsigned char guard_time); -int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, - unsigned long addr, unsigned char * value); - -int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, AVRPART * v); - -int avr_write_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, - unsigned long addr); - -int avr_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, - unsigned long addr, unsigned char data); - -int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, - unsigned long addr, unsigned char data); - -int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size, - int auto_erase); - -int avr_signature(PROGRAMMER * pgm, AVRPART * p); - -int avr_verify(AVRPART * p, AVRPART * v, char * memtype, int size); - -int avr_get_cycle_count(PROGRAMMER * pgm, AVRPART * p, int * cycles); - -int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles); - -int avr_mem_hiaddr(AVRMEM * mem); - -int avr_chip_erase(PROGRAMMER * pgm, AVRPART * p); - -void report_progress (int completed, int total, char *hdr); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/avr910.c b/avr910.c index 2f721274..3e2aa190 100644 --- a/avr910.c +++ b/avr910.c @@ -36,11 +36,9 @@ #include #include "avrdude.h" -#include "avr.h" -#include "config.h" -#include "pgm.h" +#include "libavrdude.h" + #include "avr910.h" -#include "serial.h" /* * Private data for this programmer. diff --git a/avr910.h b/avr910.h index ca918f50..808f7e68 100644 --- a/avr910.h +++ b/avr910.h @@ -21,8 +21,6 @@ #ifndef avr910_h #define avr910_h -#include "avrpart.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/avrftdi.c b/avrftdi.c index 7258fddc..c9b534bd 100644 --- a/avrftdi.c +++ b/avrftdi.c @@ -34,11 +34,9 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pgm.h" -#include "pindefs.h" +#include "libavrdude.h" + #include "avrftdi.h" -#include "avrpart.h" #include "avrftdi_tpi.h" #include "avrftdi_private.h" #include "usbdevs.h" diff --git a/avrftdi_tpi.c b/avrftdi_tpi.c index 5a0e6fe8..d82444e8 100644 --- a/avrftdi_tpi.c +++ b/avrftdi_tpi.c @@ -5,11 +5,9 @@ #include #include -#include "avr.h" -#include "pgm.h" -#include "avrpart.h" -#include "pindefs.h" -#include "tpi.h" +#include "avrdude.h" +#include "libavrdude.h" + #include "usbasp.h" #include "avrftdi_tpi.h" diff --git a/avrftdi_tpi.h b/avrftdi_tpi.h index ca17a8d5..6082a379 100644 --- a/avrftdi_tpi.h +++ b/avrftdi_tpi.h @@ -1,8 +1,5 @@ #pragma once -#include "pgm.h" -#include "avrpart.h" - //int avrftdi_tpi_write_byte(PROGRAMMER * pgm, unsigned char byte); //int avrftdi_tpi_read_byte(PROGRAMMER * pgm, unsigned char * byte); int avrftdi_cmd_tpi(PROGRAMMER * pgm, const unsigned char *cmd, int cmd_len, diff --git a/avrpart.c b/avrpart.c index 61463e90..f4332989 100644 --- a/avrpart.c +++ b/avrpart.c @@ -24,8 +24,7 @@ #include #include "avrdude.h" -#include "avrpart.h" -#include "pindefs.h" +#include "libavrdude.h" /*** *** Elementary functions dealing with OPCODE structures diff --git a/avrpart.h b/avrpart.h deleted file mode 100644 index 71c91218..00000000 --- a/avrpart.h +++ /dev/null @@ -1,236 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2003-2004 Brian S. Dean - * Copyright (C) 2006 Joerg Wunsch - * - * 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, see . - */ - -/* $Id$ */ - -#ifndef avrpart_h -#define avrpart_h - -#include - -#include "lists.h" - - -/* - * AVR serial programming instructions - */ -enum { - AVR_OP_READ, - AVR_OP_WRITE, - AVR_OP_READ_LO, - AVR_OP_READ_HI, - AVR_OP_WRITE_LO, - AVR_OP_WRITE_HI, - AVR_OP_LOADPAGE_LO, - AVR_OP_LOADPAGE_HI, - AVR_OP_LOAD_EXT_ADDR, - AVR_OP_WRITEPAGE, - AVR_OP_CHIP_ERASE, - AVR_OP_PGM_ENABLE, - AVR_OP_MAX -}; - - -enum { - AVR_CMDBIT_IGNORE, /* bit is ignored on input and output */ - AVR_CMDBIT_VALUE, /* bit is set to 0 or 1 for input or output */ - AVR_CMDBIT_ADDRESS, /* this bit represents an input address bit */ - AVR_CMDBIT_INPUT, /* this bit is an input bit */ - AVR_CMDBIT_OUTPUT /* this bit is an output bit */ -}; - -enum { /* these are assigned to reset_disposition of AVRPART */ - RESET_DEDICATED, /* reset pin is dedicated */ - RESET_IO /* reset pin might be configured as an I/O pin */ -}; - -enum ctl_stack_t { - CTL_STACK_NONE, /* no control stack defined */ - CTL_STACK_PP, /* parallel programming control stack */ - CTL_STACK_HVSP /* high voltage serial programming control stack */ -}; - -/* - * serial programming instruction bit specifications - */ -typedef struct cmdbit { - int type; /* AVR_CMDBIT_* */ - int bitno; /* which input bit to use for this command bit */ - int value; /* bit value if type == AVR_CMDBIT_VALUD */ -} CMDBIT; - -typedef struct opcode { - CMDBIT bit[32]; /* opcode bit specs */ -} OPCODE; - - -#define AVRPART_SERIALOK 0x0001 /* part supports serial programming */ -#define AVRPART_PARALLELOK 0x0002 /* part supports parallel programming */ -#define AVRPART_PSEUDOPARALLEL 0x0004 /* part has pseudo parallel support */ -#define AVRPART_HAS_JTAG 0x0008 /* part has a JTAG i/f */ -#define AVRPART_ALLOWFULLPAGEBITSTREAM 0x0010 /* JTAG ICE mkII param. */ -#define AVRPART_ENABLEPAGEPROGRAMMING 0x0020 /* JTAG ICE mkII param. */ -#define AVRPART_HAS_DW 0x0040 /* part has a debugWire i/f */ -#define AVRPART_HAS_PDI 0x0080 /* part has PDI i/f rather than ISP (ATxmega) */ -#define AVRPART_AVR32 0x0100 /* part is in AVR32 family */ -#define AVRPART_INIT_SMC 0x0200 /* part will undergo chip erase */ -#define AVRPART_WRITE 0x0400 /* at least one write operation specified */ -#define AVRPART_HAS_TPI 0x0800 /* part has TPI i/f rather than ISP (ATtiny4/5/9/10) */ -#define AVRPART_IS_AT90S1200 0x1000 /* part is an AT90S1200 (needs special treatment) */ - -#define AVR_DESCLEN 64 -#define AVR_IDLEN 32 -#define CTL_STACK_SIZE 32 -#define FLASH_INSTR_SIZE 3 -#define EEPROM_INSTR_SIZE 20 - -#define TAG_ALLOCATED 1 /* memory byte is allocated */ - -typedef struct avrpart { - char desc[AVR_DESCLEN]; /* long part name */ - char id[AVR_IDLEN]; /* short part name */ - int stk500_devcode; /* stk500 device code */ - int avr910_devcode; /* avr910 device code */ - int chip_erase_delay; /* microseconds */ - unsigned char pagel; /* for parallel programming */ - unsigned char bs2; /* for parallel programming */ - unsigned char signature[3]; /* expected value of signature bytes */ - unsigned short usbpid; /* USB DFU product ID (0 = none) */ - int reset_disposition; /* see RESET_ enums */ - int retry_pulse; /* retry program enable by pulsing - this pin (PIN_AVR_*) */ - unsigned flags; /* see AVRPART_ masks */ - - int timeout; /* stk500 v2 xml file parameter */ - int stabdelay; /* stk500 v2 xml file parameter */ - int cmdexedelay; /* stk500 v2 xml file parameter */ - int synchloops; /* stk500 v2 xml file parameter */ - int bytedelay; /* stk500 v2 xml file parameter */ - int pollindex; /* stk500 v2 xml file parameter */ - unsigned char pollvalue; /* stk500 v2 xml file parameter */ - int predelay; /* stk500 v2 xml file parameter */ - int postdelay; /* stk500 v2 xml file parameter */ - int pollmethod; /* stk500 v2 xml file parameter */ - - enum ctl_stack_t ctl_stack_type; /* what to use the ctl stack for */ - unsigned char controlstack[CTL_STACK_SIZE]; /* stk500v2 PP/HVSP ctl stack */ - unsigned char flash_instr[FLASH_INSTR_SIZE]; /* flash instructions (debugWire, JTAG) */ - unsigned char eeprom_instr[EEPROM_INSTR_SIZE]; /* EEPROM instructions (debugWire, JTAG) */ - - int hventerstabdelay; /* stk500 v2 hv mode parameter */ - int progmodedelay; /* stk500 v2 hv mode parameter */ - int latchcycles; /* stk500 v2 hv mode parameter */ - int togglevtg; /* stk500 v2 hv mode parameter */ - int poweroffdelay; /* stk500 v2 hv mode parameter */ - int resetdelayms; /* stk500 v2 hv mode parameter */ - int resetdelayus; /* stk500 v2 hv mode parameter */ - int hvleavestabdelay; /* stk500 v2 hv mode parameter */ - int resetdelay; /* stk500 v2 hv mode parameter */ - int chiperasepulsewidth; /* stk500 v2 hv mode parameter */ - int chiperasepolltimeout; /* stk500 v2 hv mode parameter */ - int chiperasetime; /* stk500 v2 hv mode parameter */ - int programfusepulsewidth; /* stk500 v2 hv mode parameter */ - int programfusepolltimeout; /* stk500 v2 hv mode parameter */ - int programlockpulsewidth; /* stk500 v2 hv mode parameter */ - int programlockpolltimeout; /* stk500 v2 hv mode parameter */ - int synchcycles; /* stk500 v2 hv mode parameter */ - int hvspcmdexedelay; /* stk500 v2 xml file parameter */ - - unsigned char idr; /* JTAG ICE mkII XML file parameter */ - unsigned char rampz; /* JTAG ICE mkII XML file parameter */ - unsigned char spmcr; /* JTAG ICE mkII XML file parameter */ - unsigned short eecr; /* JTAC ICE mkII XML file parameter */ - unsigned int mcu_base; /* Base address of MCU control block in ATxmega devices */ - unsigned int nvm_base; /* Base address of NVM controller in ATxmega devices */ - int ocdrev; /* OCD revision (JTAGICE3 parameter, from AS6 XML files) */ - - OPCODE * op[AVR_OP_MAX]; /* opcodes */ - - LISTID mem; /* avr memory definitions */ - char config_file[PATH_MAX]; /* config file where defined */ - int lineno; /* config file line number */ -} AVRPART; - -#define AVR_MEMDESCLEN 64 -typedef struct avrmem { - char desc[AVR_MEMDESCLEN]; /* memory description ("flash", "eeprom", etc) */ - int paged; /* page addressed (e.g. ATmega flash) */ - int size; /* total memory size in bytes */ - int page_size; /* size of memory page (if page addressed) */ - int num_pages; /* number of pages (if page addressed) */ - unsigned int offset; /* offset in IO memory (ATxmega) */ - int min_write_delay; /* microseconds */ - int max_write_delay; /* microseconds */ - int pwroff_after_write; /* after this memory type is written to, - the device must be powered off and - back on, see errata - http://www.atmel.com/dyn/resources/prod_documents/doc1280.pdf */ - unsigned char readback[2]; /* polled read-back values */ - - int mode; /* stk500 v2 xml file parameter */ - int delay; /* stk500 v2 xml file parameter */ - int blocksize; /* stk500 v2 xml file parameter */ - int readsize; /* stk500 v2 xml file parameter */ - int pollindex; /* stk500 v2 xml file parameter */ - - unsigned char * buf; /* pointer to memory buffer */ - unsigned char * tags; /* allocation tags */ - OPCODE * op[AVR_OP_MAX]; /* opcodes */ -} AVRMEM; - -#ifdef __cplusplus -extern "C" { -#endif - -/* Functions for OPCODE structures */ -OPCODE * avr_new_opcode(void); -void avr_free_opcode(OPCODE * op); -int avr_set_bits(OPCODE * op, unsigned char * cmd); -int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr); -int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data); -int avr_get_output(OPCODE * op, unsigned char * res, unsigned char * data); -int avr_get_output_index(OPCODE * op); - -/* Functions for AVRMEM structures */ -AVRMEM * avr_new_memtype(void); -int avr_initmem(AVRPART * p); -AVRMEM * avr_dup_mem(AVRMEM * m); -void avr_free_mem(AVRMEM * m); -AVRMEM * avr_locate_mem(AVRPART * p, char * desc); -void avr_mem_display(const char * prefix, FILE * f, AVRMEM * m, int type, - int verbose); - -/* Functions for AVRPART structures */ -AVRPART * avr_new_part(void); -AVRPART * avr_dup_part(AVRPART * d); -void avr_free_part(AVRPART * d); -AVRPART * locate_part(LISTID parts, char * partdesc); -AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode); -void avr_display(FILE * f, AVRPART * p, const char * prefix, int verbose); - -typedef void (*walk_avrparts_cb)(const char *name, const char *desc, - const char *cfgname, int cfglineno, - void *cookie); -void walk_avrparts(LISTID avrparts, walk_avrparts_cb cb, void *cookie); -void sort_avrparts(LISTID avrparts); -#ifdef __cplusplus -} -#endif - -#endif /* avrpart_h */ diff --git a/bitbang.c b/bitbang.c index 29561144..cc73b783 100644 --- a/bitbang.c +++ b/bitbang.c @@ -34,9 +34,8 @@ #endif #include "avrdude.h" -#include "avr.h" -#include "pindefs.h" -#include "pgm.h" +#include "libavrdude.h" + #include "par.h" #include "serbb.h" #include "tpi.h" diff --git a/buspirate.c b/buspirate.c index bfdd1e32..29b3fbd7 100644 --- a/buspirate.c +++ b/buspirate.c @@ -46,9 +46,8 @@ #endif #include "avrdude.h" -#include "avr.h" -#include "pgm.h" -#include "serial.h" +#include "libavrdude.h" + #include "bitbang.h" #include "buspirate.h" diff --git a/butterfly.c b/butterfly.c index 9217efcb..216f261c 100644 --- a/butterfly.c +++ b/butterfly.c @@ -45,10 +45,9 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pgm.h" +#include "libavrdude.h" + #include "butterfly.h" -#include "serial.h" /* * Private data for this programmer. diff --git a/config.c b/config.c index 193c0b02..9dfe5bd6 100644 --- a/config.c +++ b/config.c @@ -27,8 +27,8 @@ #include #include "avrdude.h" -#include "avr.h" -#include "config.h" +#include "libavrdude.h" + #include "config_gram.h" char default_programmer[MAX_STR_CONST]; diff --git a/config.h b/config.h deleted file mode 100644 index 137bc558..00000000 --- a/config.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2000-2004 Brian S. Dean - * - * 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, see . - */ - -/* $Id$ */ - -#ifndef config_h -#define config_h - -#include "lists.h" -#include "pindefs.h" -#include "avr.h" - - -#define MAX_STR_CONST 1024 - -enum { V_NONE, V_NUM, V_NUM_REAL, V_STR }; -typedef struct value_t { - int type; - /*union { TODO: use an anonymous union here ? */ - int number; - double number_real; - char * string; - /*};*/ -} VALUE; - - -typedef struct token_t { - int primary; - VALUE value; -} TOKEN; -typedef struct token_t *token_p; - - -extern FILE * yyin; -extern PROGRAMMER * current_prog; -extern AVRPART * current_part; -extern AVRMEM * current_mem; -extern int lineno; -extern const char * infile; -extern LISTID string_list; -extern LISTID number_list; -extern LISTID part_list; -extern LISTID programmers; -extern char default_programmer[]; -extern char default_parallel[]; -extern char default_serial[]; -extern double default_bitclock; -extern int default_safemode; - -/* This name is fixed, it's only here for symmetry with - * default_parallel and default_serial. */ -#define DEFAULT_USB "usb" - - -#if !defined(HAS_YYSTYPE) -#define YYSTYPE token_p -#endif -extern YYSTYPE yylval; - -extern char string_buf[MAX_STR_CONST]; -extern char *string_buf_ptr; - -#ifdef __cplusplus -extern "C" { -#endif - -int yyparse(void); - - -int init_config(void); - -void cleanup_config(void); - -TOKEN * new_token(int primary); - -void free_token(TOKEN * tkn); - -void free_tokens(int n, ...); - -TOKEN * number(char * text); - -TOKEN * number_real(char * text); - -TOKEN * hexnumber(char * text); - -TOKEN * string(char * text); - -TOKEN * keyword(int primary); - -void print_token(TOKEN * tkn); - -void pyytext(void); - -char * dup_string(const char * str); - -int read_config(const char * file); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/config_gram.y b/config_gram.y index 900676e3..2fbda131 100644 --- a/config_gram.y +++ b/config_gram.y @@ -27,16 +27,11 @@ #include #include "avrdude.h" +#include "libavrdude.h" -#include "config.h" -#include "lists.h" #include "par.h" #include "serbb.h" -#include "pindefs.h" #include "ppi.h" -#include "pgm.h" -#include "pgm_type.h" -#include "avr.h" #if defined(WIN32NATIVE) #define strtok_r( _s, _sep, _lasts ) \ diff --git a/configure.ac b/configure.ac index 69f24abd..97a6d023 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.60) -AC_INIT(avrdude, 6.1-20140516, avrdude-dev@nongnu.org) +AC_INIT(avrdude, 6.1-20140519, avrdude-dev@nongnu.org) AC_CANONICAL_BUILD AC_CANONICAL_HOST diff --git a/confwin.c b/confwin.c index 971870e6..95446156 100644 --- a/confwin.c +++ b/confwin.c @@ -18,6 +18,7 @@ #include "avrdude.h" +#include "libavrdude.h" #if defined(WIN32NATIVE) diff --git a/confwin.h b/confwin.h deleted file mode 100644 index 88a0d7a5..00000000 --- a/confwin.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2003-2004 Eric B. Weddington - * - * 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, see . - */ - - - -#if defined(WIN32NATIVE) -#ifndef confwin_h -#define confwin_h - -#ifdef __cplusplus -extern "C" { -#endif - -void win_sys_config_set(char sys_config[PATH_MAX]); -void win_usr_config_set(char usr_config[PATH_MAX]); - -#ifdef __cplusplus -} -#endif - -#endif -#endif - - diff --git a/dfu.c b/dfu.c index 04ac6a28..8ea86e26 100644 --- a/dfu.c +++ b/dfu.c @@ -19,9 +19,6 @@ /* $Id$ */ #include "ac_cfg.h" -#include "dfu.h" - -#include "avrdude.h" #include #include @@ -30,6 +27,11 @@ #include #include +#include "avrdude.h" +#include "libavrdude.h" + +#include "dfu.h" + #include "usbdevs.h" /* for USB_VENDOR_ATMEL */ /* If we don't have LibUSB, define dummy functions that report an error. */ diff --git a/fileio.c b/fileio.c index bdf99134..951dd555 100644 --- a/fileio.c +++ b/fileio.c @@ -38,8 +38,7 @@ #endif #include "avrdude.h" -#include "avr.h" -#include "fileio.h" +#include "libavrdude.h" #define IHEX_MAXDATA 256 diff --git a/fileio.h b/fileio.h deleted file mode 100644 index 0855b017..00000000 --- a/fileio.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2000-2004 Brian S. Dean - * - * 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, see . - */ - -/* $Id$ */ - -#ifndef fileio_h -#define fileio_h - -typedef enum { - FMT_AUTO, - FMT_SREC, - FMT_IHEX, - FMT_RBIN, - FMT_IMM, - FMT_HEX, - FMT_DEC, - FMT_OCT, - FMT_BIN, - FMT_ELF -} FILEFMT; - -struct fioparms { - int op; - char * mode; - char * iodesc; - char * dir; - char * rw; - unsigned int fileoffset; -}; - -enum { - FIO_READ, - FIO_WRITE -}; - -#ifdef __cplusplus -extern "C" { -#endif - -char * fmtstr(FILEFMT format); - -int fileio(int op, char * filename, FILEFMT format, - struct avrpart * p, char * memtype, int size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flip1.c b/flip1.c index 965e5ab1..8e56b7f7 100644 --- a/flip1.c +++ b/flip1.c @@ -36,13 +36,12 @@ #include #endif -#include "flip1.h" -#include "dfu.h" #include "avrdude.h" -#include "avr.h" -#include "pgm.h" +#include "libavrdude.h" +#include "flip1.h" +#include "dfu.h" #include "usbdevs.h" /* for USB_VENDOR_ATMEL */ /* There are three versions of the FLIP protocol: diff --git a/flip1.h b/flip1.h index b3ab2374..c5f4986b 100644 --- a/flip1.h +++ b/flip1.h @@ -21,8 +21,6 @@ #ifndef flip1_h #define flip1_h -#include "pgm.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/flip2.c b/flip2.c index c2156e09..66e21a35 100644 --- a/flip2.c +++ b/flip2.c @@ -33,13 +33,11 @@ #include #endif +#include "avrdude.h" +#include "libavrdude.h" + #include "flip2.h" #include "dfu.h" - -#include "avrdude.h" -#include "avr.h" -#include "pgm.h" - #include "usbdevs.h" /* for USB_VENDOR_ATMEL */ /* There are three versions of the FLIP protocol: diff --git a/flip2.h b/flip2.h index a8c76753..4b1e576d 100644 --- a/flip2.h +++ b/flip2.h @@ -21,8 +21,6 @@ #ifndef flip2_h #define flip2_h -#include "pgm.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/ft245r.c b/ft245r.c index d99855a5..94e03552 100644 --- a/ft245r.c +++ b/ft245r.c @@ -61,11 +61,8 @@ #include #include "avrdude.h" -#include "avr.h" -#include "avrpart.h" -#include "pindefs.h" -#include "pgm.h" -#include "config.h" +#include "libavrdude.h" + #include "bitbang.h" #include "ft245r.h" #include "usbdevs.h" diff --git a/ft245r.h b/ft245r.h index 81479496..40602e22 100644 --- a/ft245r.h +++ b/ft245r.h @@ -1,8 +1,6 @@ #ifndef ft245r_h #define ft245r_h -#include "pgm.h" - extern const char ft245r_desc[]; void ft245r_initpgm (PROGRAMMER * pgm); diff --git a/jtag3.c b/jtag3.c index 552b94aa..35a9f6d8 100644 --- a/jtag3.c +++ b/jtag3.c @@ -36,12 +36,11 @@ #include #include "avrdude.h" -#include "avr.h" +#include "libavrdude.h" + #include "crc16.h" -#include "pgm.h" #include "jtag3.h" #include "jtag3_private.h" -#include "serial.h" #include "usbdevs.h" /* diff --git a/jtagmkI.c b/jtagmkI.c index b1f19046..296c88ce 100644 --- a/jtagmkI.c +++ b/jtagmkI.c @@ -33,12 +33,11 @@ #include #include "avrdude.h" -#include "avr.h" +#include "libavrdude.h" + #include "crc16.h" -#include "pgm.h" #include "jtagmkI.h" #include "jtagmkI_private.h" -#include "serial.h" /* * Private data for this programmer. diff --git a/jtagmkII.c b/jtagmkII.c index 0bac91ea..2be60c9d 100644 --- a/jtagmkII.c +++ b/jtagmkII.c @@ -43,12 +43,11 @@ #include #include "avrdude.h" -#include "avr.h" +#include "libavrdude.h" + #include "crc16.h" -#include "pgm.h" #include "jtagmkII.h" #include "jtagmkII_private.h" -#include "serial.h" #include "usbdevs.h" /* diff --git a/lexer.l b/lexer.l index 23d7a090..fd3955d2 100644 --- a/lexer.l +++ b/lexer.l @@ -29,10 +29,9 @@ #include #include "avrdude.h" +#include "libavrdude.h" -#include "config.h" #include "config_gram.h" -#include "lists.h" #ifndef YYERRCODE #define YYERRCODE 256 diff --git a/libavrdude.h b/libavrdude.h new file mode 100644 index 00000000..56dea2e6 --- /dev/null +++ b/libavrdude.h @@ -0,0 +1,1003 @@ +/* + * avrdude - A Downloader/Uploader for AVR device programmers + * Copyright (C) Joerg Wunsch + * + * 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, see . + */ + +/* $Id$ */ + +#ifndef libavrdude_h +#define libavrdude_h + +/* XXX should go away */ +#include "ac_cfg.h" + +#include +#include +#include + +/* lets try to select at least 32 bits */ +#ifdef HAVE_STDINT_H +#include +typedef uint32_t pinmask_t; +#else +#if UINT_MAX >= 0xFFFFFFFF +typedef unsigned int pinmask_t; +#else +typedef unsigned long pinmask_t; +#endif +#endif + + +/* formerly lists.h */ + +/*---------------------------------------------------------------------- + General purpose linked list routines - header file declarations. + + Author : Brian Dean + Date : 10 January, 1990 + ----------------------------------------------------------------------*/ + +typedef void * LISTID; +typedef void * LNODEID; + + +/*---------------------------------------------------------------------- + several defines to access the LIST structure as as stack or a queue + --- use for program readability + ----------------------------------------------------------------------*/ +#define STACKID LISTID +#define SNODEID LNODEID +#define QUEUEID LISTID +#define QNODEID LNODEID + + +#define PUSH(s,d) lins_n(s,d,1) /* push 'd' onto the stack */ +#define POP(s) lrmv_n(s,1) /* pop the stack */ +#define LOOKSTACK(s) lget_n(s,1) /* look at the top of the stack, + but don't pop */ + + +#define ENQUEUE(q,d) lins_n(q,d,1) /* put 'd' on the end of the queue */ +#define DEQUEUE(q) lrmv(q) /* remove next item from the front of + the queue */ +#define REQUEUE(q,d) ladd(q,d) /* re-insert (push) item back on the + front of the queue */ +#define LOOKQUEUE(q) lget(q) /* return next item on the queue, + but don't dequeue */ +#define QUEUELEN(q) lsize(q) /* length of the queue */ + + +#define LISTADD(l,d) ladd(l,d) /* add to end of the list */ +#define LISTRMV(l,d) lrmv_d(l,d) /* remove from end of the list */ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* .................... Function Prototypes .................... */ + +LISTID lcreat ( void * liststruct, int poolsize ); +void ldestroy ( LISTID lid ); +void ldestroy_cb ( LISTID lid, void (*ucleanup)(void * data_ptr) ); + +LNODEID lfirst ( LISTID ); /* head of the list */ +LNODEID llast ( LISTID ); /* tail of the list */ +LNODEID lnext ( LNODEID ); /* next item in the list */ +LNODEID lprev ( LNODEID ); /* previous item in the list */ +void * ldata ( LNODEID ); /* data at the current position */ +int lsize ( LISTID ); /* number of elements in the list */ + +int ladd ( LISTID lid, void * p ); +int laddo ( LISTID lid, void *p, + int (*compare)(const void *p1,const void *p2), + LNODEID * firstdup ); +int laddu ( LISTID lid, void * p, + int (*compare)(const void *p1,const void *p2)); +int lins_n ( LISTID lid, void * d, unsigned int n ); +int lins_ln ( LISTID lid, LNODEID lnid, void * data_ptr ); + +void * lget ( LISTID lid ); +void * lget_n ( LISTID lid, unsigned int n ); +LNODEID lget_ln ( LISTID lid, unsigned int n ); + +void * lrmv ( LISTID lid ); +void * lrmv_n ( LISTID lid, unsigned int n ); +void * lrmv_ln ( LISTID lid, LNODEID lnid ); +void * lrmv_d ( LISTID lid, void * data_ptr ); + +LISTID lcat ( LISTID lid1, LISTID lid2 ); + +void lsort ( LISTID lid, int (*compare)(void * p1, void * p2)); + +void * lsrch ( LISTID lid, void * p, int (*compare)(void *p1,void *p2)); + +int lprint ( FILE * f, LISTID lid ); + +#ifdef __cplusplus +} +#endif + +/* formerly avrpart.h */ + +/* + * AVR serial programming instructions + */ +enum { + AVR_OP_READ, + AVR_OP_WRITE, + AVR_OP_READ_LO, + AVR_OP_READ_HI, + AVR_OP_WRITE_LO, + AVR_OP_WRITE_HI, + AVR_OP_LOADPAGE_LO, + AVR_OP_LOADPAGE_HI, + AVR_OP_LOAD_EXT_ADDR, + AVR_OP_WRITEPAGE, + AVR_OP_CHIP_ERASE, + AVR_OP_PGM_ENABLE, + AVR_OP_MAX +}; + + +enum { + AVR_CMDBIT_IGNORE, /* bit is ignored on input and output */ + AVR_CMDBIT_VALUE, /* bit is set to 0 or 1 for input or output */ + AVR_CMDBIT_ADDRESS, /* this bit represents an input address bit */ + AVR_CMDBIT_INPUT, /* this bit is an input bit */ + AVR_CMDBIT_OUTPUT /* this bit is an output bit */ +}; + +enum { /* these are assigned to reset_disposition of AVRPART */ + RESET_DEDICATED, /* reset pin is dedicated */ + RESET_IO /* reset pin might be configured as an I/O pin */ +}; + +enum ctl_stack_t { + CTL_STACK_NONE, /* no control stack defined */ + CTL_STACK_PP, /* parallel programming control stack */ + CTL_STACK_HVSP /* high voltage serial programming control stack */ +}; + +/* + * serial programming instruction bit specifications + */ +typedef struct cmdbit { + int type; /* AVR_CMDBIT_* */ + int bitno; /* which input bit to use for this command bit */ + int value; /* bit value if type == AVR_CMDBIT_VALUD */ +} CMDBIT; + +typedef struct opcode { + CMDBIT bit[32]; /* opcode bit specs */ +} OPCODE; + + +#define AVRPART_SERIALOK 0x0001 /* part supports serial programming */ +#define AVRPART_PARALLELOK 0x0002 /* part supports parallel programming */ +#define AVRPART_PSEUDOPARALLEL 0x0004 /* part has pseudo parallel support */ +#define AVRPART_HAS_JTAG 0x0008 /* part has a JTAG i/f */ +#define AVRPART_ALLOWFULLPAGEBITSTREAM 0x0010 /* JTAG ICE mkII param. */ +#define AVRPART_ENABLEPAGEPROGRAMMING 0x0020 /* JTAG ICE mkII param. */ +#define AVRPART_HAS_DW 0x0040 /* part has a debugWire i/f */ +#define AVRPART_HAS_PDI 0x0080 /* part has PDI i/f rather than ISP (ATxmega) */ +#define AVRPART_AVR32 0x0100 /* part is in AVR32 family */ +#define AVRPART_INIT_SMC 0x0200 /* part will undergo chip erase */ +#define AVRPART_WRITE 0x0400 /* at least one write operation specified */ +#define AVRPART_HAS_TPI 0x0800 /* part has TPI i/f rather than ISP (ATtiny4/5/9/10) */ +#define AVRPART_IS_AT90S1200 0x1000 /* part is an AT90S1200 (needs special treatment) */ + +#define AVR_DESCLEN 64 +#define AVR_IDLEN 32 +#define CTL_STACK_SIZE 32 +#define FLASH_INSTR_SIZE 3 +#define EEPROM_INSTR_SIZE 20 + +#define TAG_ALLOCATED 1 /* memory byte is allocated */ + +typedef struct avrpart { + char desc[AVR_DESCLEN]; /* long part name */ + char id[AVR_IDLEN]; /* short part name */ + int stk500_devcode; /* stk500 device code */ + int avr910_devcode; /* avr910 device code */ + int chip_erase_delay; /* microseconds */ + unsigned char pagel; /* for parallel programming */ + unsigned char bs2; /* for parallel programming */ + unsigned char signature[3]; /* expected value of signature bytes */ + unsigned short usbpid; /* USB DFU product ID (0 = none) */ + int reset_disposition; /* see RESET_ enums */ + int retry_pulse; /* retry program enable by pulsing + this pin (PIN_AVR_*) */ + unsigned flags; /* see AVRPART_ masks */ + + int timeout; /* stk500 v2 xml file parameter */ + int stabdelay; /* stk500 v2 xml file parameter */ + int cmdexedelay; /* stk500 v2 xml file parameter */ + int synchloops; /* stk500 v2 xml file parameter */ + int bytedelay; /* stk500 v2 xml file parameter */ + int pollindex; /* stk500 v2 xml file parameter */ + unsigned char pollvalue; /* stk500 v2 xml file parameter */ + int predelay; /* stk500 v2 xml file parameter */ + int postdelay; /* stk500 v2 xml file parameter */ + int pollmethod; /* stk500 v2 xml file parameter */ + + enum ctl_stack_t ctl_stack_type; /* what to use the ctl stack for */ + unsigned char controlstack[CTL_STACK_SIZE]; /* stk500v2 PP/HVSP ctl stack */ + unsigned char flash_instr[FLASH_INSTR_SIZE]; /* flash instructions (debugWire, JTAG) */ + unsigned char eeprom_instr[EEPROM_INSTR_SIZE]; /* EEPROM instructions (debugWire, JTAG) */ + + int hventerstabdelay; /* stk500 v2 hv mode parameter */ + int progmodedelay; /* stk500 v2 hv mode parameter */ + int latchcycles; /* stk500 v2 hv mode parameter */ + int togglevtg; /* stk500 v2 hv mode parameter */ + int poweroffdelay; /* stk500 v2 hv mode parameter */ + int resetdelayms; /* stk500 v2 hv mode parameter */ + int resetdelayus; /* stk500 v2 hv mode parameter */ + int hvleavestabdelay; /* stk500 v2 hv mode parameter */ + int resetdelay; /* stk500 v2 hv mode parameter */ + int chiperasepulsewidth; /* stk500 v2 hv mode parameter */ + int chiperasepolltimeout; /* stk500 v2 hv mode parameter */ + int chiperasetime; /* stk500 v2 hv mode parameter */ + int programfusepulsewidth; /* stk500 v2 hv mode parameter */ + int programfusepolltimeout; /* stk500 v2 hv mode parameter */ + int programlockpulsewidth; /* stk500 v2 hv mode parameter */ + int programlockpolltimeout; /* stk500 v2 hv mode parameter */ + int synchcycles; /* stk500 v2 hv mode parameter */ + int hvspcmdexedelay; /* stk500 v2 xml file parameter */ + + unsigned char idr; /* JTAG ICE mkII XML file parameter */ + unsigned char rampz; /* JTAG ICE mkII XML file parameter */ + unsigned char spmcr; /* JTAG ICE mkII XML file parameter */ + unsigned short eecr; /* JTAC ICE mkII XML file parameter */ + unsigned int mcu_base; /* Base address of MCU control block in ATxmega devices */ + unsigned int nvm_base; /* Base address of NVM controller in ATxmega devices */ + int ocdrev; /* OCD revision (JTAGICE3 parameter, from AS6 XML files) */ + + OPCODE * op[AVR_OP_MAX]; /* opcodes */ + + LISTID mem; /* avr memory definitions */ + char config_file[PATH_MAX]; /* config file where defined */ + int lineno; /* config file line number */ +} AVRPART; + +#define AVR_MEMDESCLEN 64 +typedef struct avrmem { + char desc[AVR_MEMDESCLEN]; /* memory description ("flash", "eeprom", etc) */ + int paged; /* page addressed (e.g. ATmega flash) */ + int size; /* total memory size in bytes */ + int page_size; /* size of memory page (if page addressed) */ + int num_pages; /* number of pages (if page addressed) */ + unsigned int offset; /* offset in IO memory (ATxmega) */ + int min_write_delay; /* microseconds */ + int max_write_delay; /* microseconds */ + int pwroff_after_write; /* after this memory type is written to, + the device must be powered off and + back on, see errata + http://www.atmel.com/dyn/resources/prod_documents/doc1280.pdf */ + unsigned char readback[2]; /* polled read-back values */ + + int mode; /* stk500 v2 xml file parameter */ + int delay; /* stk500 v2 xml file parameter */ + int blocksize; /* stk500 v2 xml file parameter */ + int readsize; /* stk500 v2 xml file parameter */ + int pollindex; /* stk500 v2 xml file parameter */ + + unsigned char * buf; /* pointer to memory buffer */ + unsigned char * tags; /* allocation tags */ + OPCODE * op[AVR_OP_MAX]; /* opcodes */ +} AVRMEM; + +#ifdef __cplusplus +extern "C" { +#endif + +/* Functions for OPCODE structures */ +OPCODE * avr_new_opcode(void); +void avr_free_opcode(OPCODE * op); +int avr_set_bits(OPCODE * op, unsigned char * cmd); +int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr); +int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data); +int avr_get_output(OPCODE * op, unsigned char * res, unsigned char * data); +int avr_get_output_index(OPCODE * op); + +/* Functions for AVRMEM structures */ +AVRMEM * avr_new_memtype(void); +int avr_initmem(AVRPART * p); +AVRMEM * avr_dup_mem(AVRMEM * m); +void avr_free_mem(AVRMEM * m); +AVRMEM * avr_locate_mem(AVRPART * p, char * desc); +void avr_mem_display(const char * prefix, FILE * f, AVRMEM * m, int type, + int verbose); + +/* Functions for AVRPART structures */ +AVRPART * avr_new_part(void); +AVRPART * avr_dup_part(AVRPART * d); +void avr_free_part(AVRPART * d); +AVRPART * locate_part(LISTID parts, char * partdesc); +AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode); +void avr_display(FILE * f, AVRPART * p, const char * prefix, int verbose); + +typedef void (*walk_avrparts_cb)(const char *name, const char *desc, + const char *cfgname, int cfglineno, + void *cookie); +void walk_avrparts(LISTID avrparts, walk_avrparts_cb cb, void *cookie); +void sort_avrparts(LISTID avrparts); +#ifdef __cplusplus +} +#endif + +/* formerly pindefs.h */ + +enum { + PPI_AVR_VCC = 1, + PPI_AVR_BUFF, + PIN_AVR_RESET, + PIN_AVR_SCK, + PIN_AVR_MOSI, + PIN_AVR_MISO, + PIN_LED_ERR, + PIN_LED_RDY, + PIN_LED_PGM, + PIN_LED_VFY, + N_PINS +}; + +#define PIN_MASK (UINT_MAX>>1) +#define PIN_INVERSE (~(PIN_MASK)) /* flag for inverted pin in serbb */ +#define PIN_MIN 0 /* smallest allowed pin number */ +#define PIN_MAX 31 /* largest allowed pin number */ + +#ifdef HAVE_LINUXGPIO +/* Embedded systems might have a lot more gpio than only 0-31 */ +#undef PIN_MAX +#define PIN_MAX 255 /* largest allowed pin number */ +#endif + +/** Number of pins in each element of the bitfield */ +#define PIN_FIELD_ELEMENT_SIZE (sizeof(pinmask_t) * 8) +/** Numer of elements to store the complete bitfield of all pins */ +#define PIN_FIELD_SIZE ((PIN_MAX + PIN_FIELD_ELEMENT_SIZE)/PIN_FIELD_ELEMENT_SIZE) + +/** + * This sets the corresponding bits to 1 or 0, the inverse mask is used to invert the value in necessary. + * It uses only the lowest element (index=0) of the bitfield, which should be enough for most + * programmers. + * + * @param[in] x input value + * @param[in] pgm the programmer whose pin definitions to use + * @param[in] pinname the logical name of the pin (PIN_AVR_*, ...) + * @param[in] level the logical level (level != 0 => 1, level == 0 => 0), + * if the pin is defined as inverted the resulting bit is also inverted + * @returns the input value with the relevant bits modified + */ +#define SET_BITS_0(x,pgm,pinname,level) (((x) & ~(pgm)->pin[pinname].mask[0]) \ + | (\ + (pgm)->pin[pinname].mask[0] & ( \ + (level) \ + ?~((pgm)->pin[pinname].inverse[0]) \ + : ((pgm)->pin[pinname].inverse[0]) \ + ) \ + ) \ +) + +/** + * Check if the corresponding bit is set (returns != 0) or cleared. + * The inverse mask is used, to invert the relevant bits. + * If the pin definition contains multiple pins, then a single set pin leads to return value != 0. + * Then you have to check the relevant bits of the returned value, if you need more information. + * It uses only the lowest element (index=0) of the bitfield, which should be enough for most + * programmers. + * + * @param[in] x input value + * @param[in] pgm the programmer whose pin definitions to use + * @param[in] pinname the logical name of the pin (PIN_AVR_*, ...) + * @returns the input value with only the relevant bits (which are already inverted, + * so you get always the logical level) + */ +#define GET_BITS_0(x,pgm,pinname) (((x) ^ (pgm)->pin[pinname].inverse[0]) & (pgm)->pin[pinname].mask[0]) + +/** + * Data structure to hold used pins by logical function (PIN_AVR_*, ...) + */ +struct pindef_t { + pinmask_t mask[PIN_FIELD_SIZE]; ///< bitfield of used pins + pinmask_t inverse[PIN_FIELD_SIZE]; ///< bitfield of inverse/normal usage of used pins +}; + +/** + * Data structure to define a checklist of valid pins for each function. + */ +struct pin_checklist_t { + int pinname; ///< logical pinname eg. PIN_AVR_SCK + int mandatory; ///< is this a mandatory pin + const struct pindef_t* valid_pins; ///< mask defines allowed pins, inverse define is they might be used inverted +}; + +/** + * Adds a pin in the pin definition as normal or inverse pin. + * + * @param[out] pindef pin definition to update + * @param[in] pin number of pin [0..PIN_MAX] + * @param[in] inverse inverse (true) or normal (false) pin + */ +void pin_set_value(struct pindef_t * const pindef, const int pin, const bool inverse); + +/** + * Clear all defined pins in pindef. + * + * @param[out] pindef pin definition to clear + */ +void pin_clear_all(struct pindef_t * const pindef); + +struct programmer_t; /* forward declaration */ + +/** + * Convert for given programmer new pin definitions to old pin definitions. + * + * @param[inout] pgm programmer whose pins shall be converted. + */ +int pgm_fill_old_pins(struct programmer_t * const pgm); + +/** + * This function checks all pin of pgm against the constraints given in the checklist. + * It checks if + * @li any invalid pins are used + * @li valid pins are used inverted when not allowed + * @li any pins are used by more than one function + * @li any mandatory pin is not set all. + * + * In case of any error it report the wrong function and the pin numbers. + * For verbose >= 2 it also reports the possible correct values. + * For verbose >=3 it shows also which pins were ok. + * + * @param[in] pgm the programmer to check + * @param[in] checklist the constraint for the pins + * @param[in] size the number of entries in checklist + * @param[in] output false suppresses error messages to the user + * @returns 0 if all pin definitions are valid, -1 otherwise + */ +int pins_check(const struct programmer_t * const pgm, const struct pin_checklist_t * const checklist, const int size, const bool output); + +/** + * Returns the name of the pin as string. + * + * @param pinname the pinname which we want as string. + * @returns a string with the pinname, or if pinname is invalid. + */ +const char * avr_pin_name(int pinname); + +/** + * This function returns a string representation of defined pins eg. ~1,2,~4,~5,7 + * Another execution of this function will overwrite the previous result in the static buffer. + * + * @param[in] pindef the pin definition for which we want the string representation + * @returns pointer to a static string. + */ +const char * pins_to_str(const struct pindef_t * const pindef); + +/** + * This function returns a string representation of pins in the mask eg. 1,3,5-7,9,12 + * Another execution of this function will overwrite the previous result in the static buffer. + * Consecutive pin number are representated as start-end. + * + * @param[in] pinmask the pin mask for which we want the string representation + * @returns pointer to a static string. + */ +const char * pinmask_to_str(const pinmask_t * const pinmask); + +/* formerly serial.h */ + +/* This is the API for the generic serial interface. The implementations are + actually provided by the target dependant files: + + ser_posix.c : posix serial interface. + ser_win32.c : native win32 serial interface. + + The target file will be selected at configure time. */ + +extern long serial_recv_timeout; +union filedescriptor +{ + int ifd; + void *pfd; + struct + { + void *handle; + int rep; /* bulk read endpoint */ + int wep; /* bulk write endpoint */ + int eep; /* event read endpoint */ + int max_xfer; /* max transfer size */ + int use_interrupt_xfer; /* device uses interrupt transfers */ + } usb; +}; + +union pinfo +{ + long baud; + struct + { + unsigned short vid; + unsigned short pid; + unsigned short flags; +#define PINFO_FL_USEHID 0x0001 +#define PINFO_FL_SILENT 0x0002 /* don't complain if not found */ + } usbinfo; +}; + + +struct serial_device +{ + // open should return -1 on error, other values on success + int (*open)(char * port, union pinfo pinfo, union filedescriptor *fd); + int (*setspeed)(union filedescriptor *fd, long baud); + void (*close)(union filedescriptor *fd); + + int (*send)(union filedescriptor *fd, unsigned char * buf, size_t buflen); + int (*recv)(union filedescriptor *fd, unsigned char * buf, size_t buflen); + int (*drain)(union filedescriptor *fd, int display); + + int (*set_dtr_rts)(union filedescriptor *fd, int is_on); + + int flags; +#define SERDEV_FL_NONE 0x0000 /* no flags */ +#define SERDEV_FL_CANSETSPEED 0x0001 /* device can change speed */ +}; + +extern struct serial_device *serdev; +extern struct serial_device serial_serdev; +extern struct serial_device usb_serdev; +extern struct serial_device usb_serdev_frame; +extern struct serial_device avrdoper_serdev; + +#define serial_open (serdev->open) +#define serial_setspeed (serdev->setspeed) +#define serial_close (serdev->close) +#define serial_send (serdev->send) +#define serial_recv (serdev->recv) +#define serial_drain (serdev->drain) +#define serial_set_dtr_rts (serdev->set_dtr_rts) + +/* formerly pgm.h */ + +#define ON 1 +#define OFF 0 + +#define PGM_DESCLEN 80 +#define PGM_PORTLEN PATH_MAX +#define PGM_TYPELEN 32 +#define PGM_USBSTRINGLEN 256 + +typedef enum { + EXIT_VCC_UNSPEC, + EXIT_VCC_ENABLED, + EXIT_VCC_DISABLED +} exit_vcc_t; + +typedef enum { + EXIT_RESET_UNSPEC, + EXIT_RESET_ENABLED, + EXIT_RESET_DISABLED +} exit_reset_t; + +typedef enum { + EXIT_DATAHIGH_UNSPEC, + EXIT_DATAHIGH_ENABLED, + EXIT_DATAHIGH_DISABLED +} exit_datahigh_t; + +typedef enum { + CONNTYPE_PARALLEL, + CONNTYPE_SERIAL, + CONNTYPE_USB +} conntype_t; + +typedef struct programmer_t { + LISTID id; + char desc[PGM_DESCLEN]; + char type[PGM_TYPELEN]; + char port[PGM_PORTLEN]; + void (*initpgm)(struct programmer_t * pgm); + unsigned int pinno[N_PINS]; + struct pindef_t pin[N_PINS]; + exit_vcc_t exit_vcc; + exit_reset_t exit_reset; + exit_datahigh_t exit_datahigh; + conntype_t conntype; + int ppidata; + int ppictrl; + int baudrate; + int usbvid; + LISTID usbpid; + char usbdev[PGM_USBSTRINGLEN], usbsn[PGM_USBSTRINGLEN]; + char usbvendor[PGM_USBSTRINGLEN], usbproduct[PGM_USBSTRINGLEN]; + double bitclock; /* JTAG ICE clock period in microseconds */ + int ispdelay; /* ISP clock delay */ + union filedescriptor fd; + 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); + int (*pgm_led) (struct programmer_t * pgm, int value); + int (*vfy_led) (struct programmer_t * pgm, int value); + int (*initialize) (struct programmer_t * pgm, AVRPART * p); + void (*display) (struct programmer_t * pgm, const char * p); + void (*enable) (struct programmer_t * pgm); + void (*disable) (struct programmer_t * pgm); + void (*powerup) (struct programmer_t * pgm); + void (*powerdown) (struct programmer_t * pgm); + int (*program_enable) (struct programmer_t * pgm, AVRPART * p); + int (*chip_erase) (struct programmer_t * pgm, AVRPART * p); + int (*cmd) (struct programmer_t * pgm, const unsigned char *cmd, + unsigned char *res); + int (*cmd_tpi) (struct programmer_t * pgm, const unsigned char *cmd, + int cmd_len, unsigned char res[], int res_len); + int (*spi) (struct programmer_t * pgm, const unsigned char *cmd, + unsigned char *res, int count); + int (*open) (struct programmer_t * pgm, char * port); + void (*close) (struct programmer_t * pgm); + int (*paged_write) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, + unsigned int page_size, unsigned int baseaddr, + unsigned int n_bytes); + int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, + unsigned int page_size, unsigned int baseaddr, + unsigned int n_bytes); + int (*page_erase) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, + unsigned int baseaddr); + void (*write_setup) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m); + int (*write_byte) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, + unsigned long addr, unsigned char value); + int (*read_byte) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, + unsigned long addr, unsigned char * value); + int (*read_sig_bytes) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m); + void (*print_parms) (struct programmer_t * pgm); + int (*set_vtarget) (struct programmer_t * pgm, double v); + int (*set_varef) (struct programmer_t * pgm, unsigned int chan, double v); + int (*set_fosc) (struct programmer_t * pgm, double v); + int (*set_sck_period) (struct programmer_t * pgm, double v); + int (*setpin) (struct programmer_t * pgm, int pinfunc, int value); + int (*getpin) (struct programmer_t * pgm, int pinfunc); + int (*highpulsepin) (struct programmer_t * pgm, int pinfunc); + int (*parseexitspecs) (struct programmer_t * pgm, char *s); + int (*perform_osccal) (struct programmer_t * pgm); + int (*parseextparams) (struct programmer_t * pgm, LISTID xparams); + void (*setup) (struct programmer_t * pgm); + void (*teardown) (struct programmer_t * pgm); + char config_file[PATH_MAX]; /* config file where defined */ + int lineno; /* config file line number */ + void *cookie; /* for private use by the programmer */ + char flag; /* for private use of the programmer */ +} PROGRAMMER; + +#ifdef __cplusplus +extern "C" { +#endif + +PROGRAMMER * pgm_new(void); +PROGRAMMER * pgm_dup(const PROGRAMMER * const src); +void pgm_free(PROGRAMMER * const p); + +void programmer_display(PROGRAMMER * pgm, const char * p); + +/* show is a mask like this (1< #include "avrdude.h" -#include "avr.h" -#include "pindefs.h" -#include "pgm.h" +#include "libavrdude.h" + #include "bitbang.h" #if HAVE_LINUXGPIO diff --git a/lists.c b/lists.c index 71e8b232..cab88364 100644 --- a/lists.c +++ b/lists.c @@ -40,7 +40,7 @@ #include #include -#include "lists.h" +#include "libavrdude.h" #define MAGIC 0xb05b05b0 diff --git a/lists.h b/lists.h deleted file mode 100644 index e9ddfffa..00000000 --- a/lists.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 1990-2004 Brian S. Dean - * - * 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, see . - */ - -/* $Id$ */ - -/*---------------------------------------------------------------------- - Id: lists.h,v 1.2 2001/08/19 23:13:17 bsd Exp $ - ----------------------------------------------------------------------*/ -/*---------------------------------------------------------------------- - General purpose linked list routines - header file declarations. - - Author : Brian Dean - Date : 10 January, 1990 - ----------------------------------------------------------------------*/ -#ifndef lists_h -#define lists_h - -#include - -typedef void * LISTID; -typedef void * LNODEID; - - -/*---------------------------------------------------------------------- - several defines to access the LIST structure as as stack or a queue - --- use for program readability - ----------------------------------------------------------------------*/ -#define STACKID LISTID -#define SNODEID LNODEID -#define QUEUEID LISTID -#define QNODEID LNODEID - - -#define PUSH(s,d) lins_n(s,d,1) /* push 'd' onto the stack */ -#define POP(s) lrmv_n(s,1) /* pop the stack */ -#define LOOKSTACK(s) lget_n(s,1) /* look at the top of the stack, - but don't pop */ - - -#define ENQUEUE(q,d) lins_n(q,d,1) /* put 'd' on the end of the queue */ -#define DEQUEUE(q) lrmv(q) /* remove next item from the front of - the queue */ -#define REQUEUE(q,d) ladd(q,d) /* re-insert (push) item back on the - front of the queue */ -#define LOOKQUEUE(q) lget(q) /* return next item on the queue, - but don't dequeue */ -#define QUEUELEN(q) lsize(q) /* length of the queue */ - - -#define LISTADD(l,d) ladd(l,d) /* add to end of the list */ -#define LISTRMV(l,d) lrmv_d(l,d) /* remove from end of the list */ - - -#ifdef __cplusplus -extern "C" { -#endif - -/* .................... Function Prototypes .................... */ - -LISTID lcreat ( void * liststruct, int poolsize ); -void ldestroy ( LISTID lid ); -void ldestroy_cb ( LISTID lid, void (*ucleanup)(void * data_ptr) ); - -LNODEID lfirst ( LISTID ); /* head of the list */ -LNODEID llast ( LISTID ); /* tail of the list */ -LNODEID lnext ( LNODEID ); /* next item in the list */ -LNODEID lprev ( LNODEID ); /* previous item in the list */ -void * ldata ( LNODEID ); /* data at the current position */ -int lsize ( LISTID ); /* number of elements in the list */ - -int ladd ( LISTID lid, void * p ); -int laddo ( LISTID lid, void *p, - int (*compare)(const void *p1,const void *p2), - LNODEID * firstdup ); -int laddu ( LISTID lid, void * p, - int (*compare)(const void *p1,const void *p2)); -int lins_n ( LISTID lid, void * d, unsigned int n ); -int lins_ln ( LISTID lid, LNODEID lnid, void * data_ptr ); - -void * lget ( LISTID lid ); -void * lget_n ( LISTID lid, unsigned int n ); -LNODEID lget_ln ( LISTID lid, unsigned int n ); - -void * lrmv ( LISTID lid ); -void * lrmv_n ( LISTID lid, unsigned int n ); -void * lrmv_ln ( LISTID lid, LNODEID lnid ); -void * lrmv_d ( LISTID lid, void * data_ptr ); - -LISTID lcat ( LISTID lid1, LISTID lid2 ); - -void lsort ( LISTID lid, int (*compare)(void * p1, void * p2)); - -void * lsrch ( LISTID lid, void * p, int (*compare)(void *p1,void *p2)); - -int lprint ( FILE * f, LISTID lid ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/main.c b/main.c index f5c4d865..7fe01790 100644 --- a/main.c +++ b/main.c @@ -45,15 +45,10 @@ #include #include -#include "avr.h" -#include "config.h" -#include "confwin.h" -#include "fileio.h" -#include "lists.h" +#include "avrdude.h" +#include "libavrdude.h" + #include "term.h" -#include "safemode.h" -#include "update.h" -#include "pgm_type.h" /* Get VERSION from ac_cfg.h */ diff --git a/par.c b/par.c index 1829f325..f539062c 100644 --- a/par.c +++ b/par.c @@ -36,9 +36,8 @@ #endif #include "avrdude.h" -#include "avr.h" -#include "pindefs.h" -#include "pgm.h" +#include "libavrdude.h" + #include "ppi.h" #include "bitbang.h" #include "par.h" diff --git a/pgm.c b/pgm.c index e9c3567b..31b831d8 100644 --- a/pgm.c +++ b/pgm.c @@ -26,7 +26,7 @@ #include #include "avrdude.h" -#include "pgm.h" +#include "libavrdude.h" static int pgm_default_2 (struct programmer_t *, AVRPART *); static int pgm_default_3 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem, diff --git a/pgm_type.c b/pgm_type.c index c950d86d..02c6337a 100644 --- a/pgm_type.c +++ b/pgm_type.c @@ -26,10 +26,9 @@ #include #include "avrdude.h" -#include "pgm_type.h" +#include "libavrdude.h" #include "arduino.h" -#include "avr.h" #include "avr910.h" #include "avrftdi.h" #include "buspirate.h" diff --git a/pgm_type.h b/pgm_type.h deleted file mode 100644 index 8eba3507..00000000 --- a/pgm_type.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2002-2004 Brian S. Dean - * Copyright 2007 Joerg Wunsch - * - * 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, see . - */ - -/* $Id: pgm.h 1007 2011-09-14 21:49:42Z joerg_wunsch $ */ - -#ifndef pgm_type_h -#define pgm_type_h - -#include "lists.h" -#include "pgm.h" - -/*LISTID programmer_types;*/ - -typedef struct programmer_type_t { - const char * const id; - void (*initpgm)(struct programmer_t * pgm); - const char * const desc; -} PROGRAMMER_TYPE; - -#ifdef __cplusplus -extern "C" { -#endif - -const PROGRAMMER_TYPE * locate_programmer_type(/*LISTID programmer_types, */const char * id); - -typedef void (*walk_programmer_types_cb)(const char *id, const char *desc, - void *cookie); -void walk_programmer_types(/*LISTID programmer_types,*/ walk_programmer_types_cb cb, void *cookie); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/pickit2.c b/pickit2.c index a71ea154..b6def46a 100644 --- a/pickit2.c +++ b/pickit2.c @@ -52,8 +52,7 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pgm.h" +#include "libavrdude.h" #if defined(HAVE_LIBUSB) || (defined(WIN32NATIVE) && defined(HAVE_LIBHID)) diff --git a/pickit2.h b/pickit2.h index 9128598c..cdd58d96 100644 --- a/pickit2.h +++ b/pickit2.h @@ -21,8 +21,6 @@ #ifndef pickit2_h #define pickit2_h -#include "avrpart.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/pindefs.c b/pindefs.c index 4711fcb2..27ef1fb7 100644 --- a/pindefs.c +++ b/pindefs.c @@ -21,9 +21,9 @@ #include #include #include + #include "avrdude.h" -#include "pindefs.h" -#include "pgm.h" +#include "libavrdude.h" /** * Adds a pin in the pin definition as normal or inverse pin. diff --git a/pindefs.h b/pindefs.h deleted file mode 100644 index 8e1421cd..00000000 --- a/pindefs.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2000-2004 Brian S. Dean - * - * 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, see . - */ - -/* $Id$ */ - -#ifndef __pindefs_h__ -#define __pindefs_h__ - -#include - -#include "ac_cfg.h" - -/* lets try to select at least 32 bits */ -#ifdef HAVE_STDINT_H -#include -typedef uint32_t pinmask_t; -#else -#if UINT_MAX >= 0xFFFFFFFF -typedef unsigned int pinmask_t; -#else -typedef unsigned long pinmask_t; -#endif -#endif - -#include - - -enum { - PPI_AVR_VCC = 1, - PPI_AVR_BUFF, - PIN_AVR_RESET, - PIN_AVR_SCK, - PIN_AVR_MOSI, - PIN_AVR_MISO, - PIN_LED_ERR, - PIN_LED_RDY, - PIN_LED_PGM, - PIN_LED_VFY, - N_PINS -}; - -#define PIN_MASK (UINT_MAX>>1) -#define PIN_INVERSE (~(PIN_MASK)) /* flag for inverted pin in serbb */ -#define PIN_MIN 0 /* smallest allowed pin number */ -#define PIN_MAX 31 /* largest allowed pin number */ - -#ifdef HAVE_LINUXGPIO -/* Embedded systems might have a lot more gpio than only 0-31 */ -#undef PIN_MAX -#define PIN_MAX 255 /* largest allowed pin number */ -#endif - -/** Number of pins in each element of the bitfield */ -#define PIN_FIELD_ELEMENT_SIZE (sizeof(pinmask_t) * 8) -/** Numer of elements to store the complete bitfield of all pins */ -#define PIN_FIELD_SIZE ((PIN_MAX + PIN_FIELD_ELEMENT_SIZE)/PIN_FIELD_ELEMENT_SIZE) - -/** - * This sets the corresponding bits to 1 or 0, the inverse mask is used to invert the value in necessary. - * It uses only the lowest element (index=0) of the bitfield, which should be enough for most - * programmers. - * - * @param[in] x input value - * @param[in] pgm the programmer whose pin definitions to use - * @param[in] pinname the logical name of the pin (PIN_AVR_*, ...) - * @param[in] level the logical level (level != 0 => 1, level == 0 => 0), - * if the pin is defined as inverted the resulting bit is also inverted - * @returns the input value with the relevant bits modified - */ -#define SET_BITS_0(x,pgm,pinname,level) (((x) & ~(pgm)->pin[pinname].mask[0]) \ - | (\ - (pgm)->pin[pinname].mask[0] & ( \ - (level) \ - ?~((pgm)->pin[pinname].inverse[0]) \ - : ((pgm)->pin[pinname].inverse[0]) \ - ) \ - ) \ -) - -/** - * Check if the corresponding bit is set (returns != 0) or cleared. - * The inverse mask is used, to invert the relevant bits. - * If the pin definition contains multiple pins, then a single set pin leads to return value != 0. - * Then you have to check the relevant bits of the returned value, if you need more information. - * It uses only the lowest element (index=0) of the bitfield, which should be enough for most - * programmers. - * - * @param[in] x input value - * @param[in] pgm the programmer whose pin definitions to use - * @param[in] pinname the logical name of the pin (PIN_AVR_*, ...) - * @returns the input value with only the relevant bits (which are already inverted, - * so you get always the logical level) - */ -#define GET_BITS_0(x,pgm,pinname) (((x) ^ (pgm)->pin[pinname].inverse[0]) & (pgm)->pin[pinname].mask[0]) - -/** - * Data structure to hold used pins by logical function (PIN_AVR_*, ...) - */ -struct pindef_t { - pinmask_t mask[PIN_FIELD_SIZE]; ///< bitfield of used pins - pinmask_t inverse[PIN_FIELD_SIZE]; ///< bitfield of inverse/normal usage of used pins -}; - -/** - * Data structure to define a checklist of valid pins for each function. - */ -struct pin_checklist_t { - int pinname; ///< logical pinname eg. PIN_AVR_SCK - int mandatory; ///< is this a mandatory pin - const struct pindef_t* valid_pins; ///< mask defines allowed pins, inverse define is they might be used inverted -}; - -/** - * Adds a pin in the pin definition as normal or inverse pin. - * - * @param[out] pindef pin definition to update - * @param[in] pin number of pin [0..PIN_MAX] - * @param[in] inverse inverse (true) or normal (false) pin - */ -void pin_set_value(struct pindef_t * const pindef, const int pin, const bool inverse); - -/** - * Clear all defined pins in pindef. - * - * @param[out] pindef pin definition to clear - */ -void pin_clear_all(struct pindef_t * const pindef); - -struct programmer_t; /* forward declaration */ - -/** - * Convert for given programmer new pin definitions to old pin definitions. - * - * @param[inout] pgm programmer whose pins shall be converted. - */ -int pgm_fill_old_pins(struct programmer_t * const pgm); - -/** - * This function checks all pin of pgm against the constraints given in the checklist. - * It checks if - * @li any invalid pins are used - * @li valid pins are used inverted when not allowed - * @li any pins are used by more than one function - * @li any mandatory pin is not set all. - * - * In case of any error it report the wrong function and the pin numbers. - * For verbose >= 2 it also reports the possible correct values. - * For verbose >=3 it shows also which pins were ok. - * - * @param[in] pgm the programmer to check - * @param[in] checklist the constraint for the pins - * @param[in] size the number of entries in checklist - * @param[in] output false suppresses error messages to the user - * @returns 0 if all pin definitions are valid, -1 otherwise - */ -int pins_check(const struct programmer_t * const pgm, const struct pin_checklist_t * const checklist, const int size, const bool output); - -/** - * Returns the name of the pin as string. - * - * @param pinname the pinname which we want as string. - * @returns a string with the pinname, or if pinname is invalid. - */ -const char * avr_pin_name(int pinname); - -/** - * This function returns a string representation of defined pins eg. ~1,2,~4,~5,7 - * Another execution of this function will overwrite the previous result in the static buffer. - * - * @param[in] pindef the pin definition for which we want the string representation - * @returns pointer to a static string. - */ -const char * pins_to_str(const struct pindef_t * const pindef); - -/** - * This function returns a string representation of pins in the mask eg. 1,3,5-7,9,12 - * Another execution of this function will overwrite the previous result in the static buffer. - * Consecutive pin number are representated as start-end. - * - * @param[in] pinmask the pin mask for which we want the string representation - * @returns pointer to a static string. - */ -const char * pinmask_to_str(const pinmask_t * const pinmask); - - -#endif - diff --git a/ppi.c b/ppi.c index b40b1270..d0536cb9 100644 --- a/ppi.c +++ b/ppi.c @@ -41,9 +41,8 @@ #endif #include "avrdude.h" -#include "avr.h" -#include "pindefs.h" -#include "pgm.h" +#include "libavrdude.h" + #include "ppi.h" enum { diff --git a/ppiwin.c b/ppiwin.c index 6fa6d5ce..684be673 100644 --- a/ppiwin.c +++ b/ppiwin.c @@ -31,7 +31,6 @@ reg = register as defined in an enum in ppi.h. This must be converted #include "ac_cfg.h" -#include "avrdude.h" #if defined (WIN32NATIVE) @@ -45,7 +44,9 @@ reg = register as defined in an enum in ppi.h. This must be converted #include #include -#include "serial.h" +#include "avrdude.h" +#include "libavrdude.h" + #include "ppi.h" #define DEVICE_LPT1 "lpt1" diff --git a/safemode.c b/safemode.c index c8875471..c36b0f7f 100644 --- a/safemode.c +++ b/safemode.c @@ -22,10 +22,9 @@ #include #include "ac_cfg.h" + #include "avrdude.h" -#include "avr.h" -#include "pgm.h" -#include "safemode.h" +#include "libavrdude.h" /* This value from ac_cfg.h */ /* diff --git a/safemode.h b/safemode.h deleted file mode 100644 index 38d9a506..00000000 --- a/safemode.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * avrdude is Copyright (C) 2000-2004 Brian S. Dean - * - * This file: Copyright (C) 2005 Colin O'Flynn - * - * 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, see . - */ - - -#ifndef safemode_h -#define safemode_h - -#ifdef __cplusplus -extern "C" { -#endif - -/* Writes the specified fuse in fusename (can be "lfuse", "hfuse", or "efuse") and verifies it. Will try up to tries -amount of times before giving up */ -int safemode_writefuse (unsigned char fuse, char * fusename, PROGRAMMER * pgm, AVRPART * p, int tries, int verbose); - -/* Reads the fuses three times, checking that all readings are the same. This will ensure that the before values aren't in error! */ -int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse, unsigned char * efuse, unsigned char * fuse, PROGRAMMER * pgm, AVRPART * p, int verbose); - -/* This routine will store the current values pointed to by lfuse, hfuse, and efuse into an internal buffer in this routine -when save is set to 1. When save is 0 (or not 1 really) it will copy the values from the internal buffer into the locations -pointed to be lfuse, hfuse, and efuse. This allows you to change the fuse bits if needed from another routine (ie: have it so -if user requests fuse bits are changed, the requested value is now verified */ -int safemode_memfuses (int save, unsigned char * lfuse, unsigned char * hfuse, unsigned char * efuse, unsigned char * fuse); - -#ifdef __cplusplus -} -#endif - -#endif /* safemode_h */ diff --git a/ser_avrdoper.c b/ser_avrdoper.c index 30653da0..b65dbafa 100644 --- a/ser_avrdoper.c +++ b/ser_avrdoper.c @@ -33,7 +33,7 @@ #include #include "avrdude.h" -#include "serial.h" +#include "libavrdude.h" /* ------------------------------------------------------------------------ */ diff --git a/ser_posix.c b/ser_posix.c index fd5daaa5..4754e9f6 100644 --- a/ser_posix.c +++ b/ser_posix.c @@ -43,7 +43,7 @@ #include #include "avrdude.h" -#include "serial.h" +#include "libavrdude.h" long serial_recv_timeout = 5000; /* ms */ diff --git a/ser_win32.c b/ser_win32.c index 81ea20dc..49f7a229 100644 --- a/ser_win32.c +++ b/ser_win32.c @@ -23,15 +23,14 @@ * Native Win32 serial interface for avrdude. */ -#include "avrdude.h" - #if defined(WIN32NATIVE) #include #include #include /* for isprint */ -#include "serial.h" +#include "avrdude.h" +#include "libavrdude.h" long serial_recv_timeout = 5000; /* ms */ diff --git a/serbb_posix.c b/serbb_posix.c index 0a899c64..d4c4767e 100644 --- a/serbb_posix.c +++ b/serbb_posix.c @@ -37,9 +37,8 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pindefs.h" -#include "pgm.h" +#include "libavrdude.h" + #include "bitbang.h" #include "serbb.h" diff --git a/serbb_win32.c b/serbb_win32.c index 2d17915e..f87e592b 100644 --- a/serbb_win32.c +++ b/serbb_win32.c @@ -33,9 +33,9 @@ #include #include -#include "avr.h" -#include "pindefs.h" -#include "pgm.h" +#include "avrdude.h" +#include "libavrdude.h" + #include "bitbang.h" #include "serbb.h" diff --git a/serial.h b/serial.h deleted file mode 100644 index a814818d..00000000 --- a/serial.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2003-2004 Theodore A. Roth - * - * 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, see . - */ - -/* $Id$ */ - -/* This is the API for the generic serial interface. The implementations are - actually provided by the target dependant files: - - ser_posix.c : posix serial interface. - ser_win32.c : native win32 serial interface. - - The target file will be selected at configure time. */ - -#ifndef serial_h -#define serial_h - -extern long serial_recv_timeout; -union filedescriptor -{ - int ifd; - void *pfd; - struct - { - void *handle; - int rep; /* bulk read endpoint */ - int wep; /* bulk write endpoint */ - int eep; /* event read endpoint */ - int max_xfer; /* max transfer size */ - int use_interrupt_xfer; /* device uses interrupt transfers */ - } usb; -}; - -union pinfo -{ - long baud; - struct - { - unsigned short vid; - unsigned short pid; - unsigned short flags; -#define PINFO_FL_USEHID 0x0001 -#define PINFO_FL_SILENT 0x0002 /* don't complain if not found */ - } usbinfo; -}; - - -struct serial_device -{ - // open should return -1 on error, other values on success - int (*open)(char * port, union pinfo pinfo, union filedescriptor *fd); - int (*setspeed)(union filedescriptor *fd, long baud); - void (*close)(union filedescriptor *fd); - - int (*send)(union filedescriptor *fd, unsigned char * buf, size_t buflen); - int (*recv)(union filedescriptor *fd, unsigned char * buf, size_t buflen); - int (*drain)(union filedescriptor *fd, int display); - - int (*set_dtr_rts)(union filedescriptor *fd, int is_on); - - int flags; -#define SERDEV_FL_NONE 0x0000 /* no flags */ -#define SERDEV_FL_CANSETSPEED 0x0001 /* device can change speed */ -}; - -extern struct serial_device *serdev; -extern struct serial_device serial_serdev; -extern struct serial_device usb_serdev; -extern struct serial_device usb_serdev_frame; -extern struct serial_device avrdoper_serdev; - -#define serial_open (serdev->open) -#define serial_setspeed (serdev->setspeed) -#define serial_close (serdev->close) -#define serial_send (serdev->send) -#define serial_recv (serdev->recv) -#define serial_drain (serdev->drain) -#define serial_set_dtr_rts (serdev->set_dtr_rts) - -#endif /* serial_h */ diff --git a/stk500.c b/stk500.c index 595de309..679e3388 100644 --- a/stk500.c +++ b/stk500.c @@ -37,11 +37,10 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pgm.h" +#include "libavrdude.h" + #include "stk500.h" #include "stk500_private.h" -#include "serial.h" #define STK500_XTAL 7372800U #define MAX_SYNC_ATTEMPTS 10 diff --git a/stk500generic.c b/stk500generic.c index 7bfc3262..f21147a4 100644 --- a/stk500generic.c +++ b/stk500generic.c @@ -32,7 +32,8 @@ #include #include "avrdude.h" -#include "pgm.h" +#include "libavrdude.h" + #include "stk500generic.h" #include "stk500.h" #include "stk500v2.h" diff --git a/stk500v2.c b/stk500v2.c index ec0a8f0b..23f956c3 100644 --- a/stk500v2.c +++ b/stk500v2.c @@ -48,12 +48,11 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pgm.h" +#include "libavrdude.h" + #include "stk500_private.h" // temp until all code converted #include "stk500v2.h" #include "stk500v2_private.h" -#include "serial.h" #include "usbdevs.h" /* diff --git a/stk500v2_private.h b/stk500v2_private.h index 94c21723..2ac0d05c 100644 --- a/stk500v2_private.h +++ b/stk500v2_private.h @@ -9,8 +9,6 @@ //* //************************************************************************** -#include "pgm.h" - // *****************[ STK message constants ]*************************** #define MESSAGE_START 0x1B //= ESC = 27 decimal diff --git a/term.c b/term.c index cb5cbae3..873a62f3 100644 --- a/term.c +++ b/term.c @@ -34,12 +34,7 @@ #endif #include "avrdude.h" -#include "avr.h" -#include "config.h" -#include "lists.h" -#include "pgm.h" -#include "pindefs.h" -#include "ppi.h" +#include "term.h" struct command { char * name; diff --git a/term.h b/term.h index 961199a2..fca3aac8 100644 --- a/term.h +++ b/term.h @@ -21,8 +21,7 @@ #ifndef term_h #define term_h -#include "avr.h" -#include "pgm.h" +#include "libavrdude.h" #ifdef __cplusplus extern "C" { diff --git a/update.c b/update.c index 2f77401d..7c324659 100644 --- a/update.c +++ b/update.c @@ -26,11 +26,7 @@ #include #include "avrdude.h" -#include "avr.h" -#include "config.h" -#include "confwin.h" -#include "fileio.h" -#include "update.h" +#include "libavrdude.h" UPDATE * parse_op(char * s) { diff --git a/update.h b/update.h deleted file mode 100644 index 44e46d76..00000000 --- a/update.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2000-2005 Brian S. Dean - * Copyright (C) 2007 Joerg Wunsch - * - * 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, see . - */ - -/* $Id$ */ - -#ifndef update_h -#define update_h - -enum { - DEVICE_READ, - DEVICE_WRITE, - DEVICE_VERIFY -}; - -enum updateflags { - UF_NONE = 0, - UF_NOWRITE = 1, - UF_AUTO_ERASE = 2, -}; - - -typedef struct update_t { - char * memtype; - int op; - char * filename; - int format; -} UPDATE; - -#ifdef __cplusplus -extern "C" { -#endif - -extern UPDATE * parse_op(char * s); -extern UPDATE * dup_update(UPDATE * upd); -extern UPDATE * new_update(int op, char * memtype, int filefmt, - char * filename); -extern void free_update(UPDATE * upd); -extern int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, - enum updateflags flags); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usb_libusb.c b/usb_libusb.c index b247e190..ec7b7829 100644 --- a/usb_libusb.c +++ b/usb_libusb.c @@ -44,7 +44,8 @@ #endif #include "avrdude.h" -#include "serial.h" +#include "libavrdude.h" + #include "usbdevs.h" #if defined(WIN32NATIVE) diff --git a/usbasp.c b/usbasp.c index 40bc958e..eb746d69 100644 --- a/usbasp.c +++ b/usbasp.c @@ -35,8 +35,8 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pgm.h" +#include "libavrdude.h" + #include "usbasp.h" #include "usbdevs.h" diff --git a/usbasp.h b/usbasp.h index 98e300da..573d2b85 100644 --- a/usbasp.h +++ b/usbasp.h @@ -21,8 +21,6 @@ #ifndef usbasp_h #define usbasp_h -#include "avrpart.h" - /* USB function call identifiers */ #define USBASP_FUNC_CONNECT 1 #define USBASP_FUNC_DISCONNECT 2 diff --git a/usbtiny.c b/usbtiny.c index 92ef6d2c..4f23eb89 100644 --- a/usbtiny.c +++ b/usbtiny.c @@ -33,9 +33,8 @@ #include #include "avrdude.h" -#include "avr.h" -#include "pgm.h" -#include "config.h" +#include "libavrdude.h" + #include "usbtiny.h" #include "usbdevs.h" diff --git a/usbtiny.h b/usbtiny.h index 5cae7e5c..3a258b9f 100644 --- a/usbtiny.h +++ b/usbtiny.h @@ -20,9 +20,6 @@ #ifndef usbtiny_h #define usbtiny_h -#include "avrpart.h" - - // Generic requests to the USBtiny #define USBTINY_ECHO 0 // echo test #define USBTINY_READ 1 // read byte (wIndex:address) diff --git a/wiring.c b/wiring.c index aee82583..dc0b407d 100644 --- a/wiring.c +++ b/wiring.c @@ -46,10 +46,10 @@ #include #include "avrdude.h" -#include "pgm.h" +#include "libavrdude.h" + #include "stk500v2_private.h" #include "stk500v2.h" -#include "serial.h" #include "wiring.h" /*