Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libavrdude.h File Reference
#include "ac_cfg.h"
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <alloca.h>
+ Include dependency graph for libavrdude.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cmdbit
 
struct  opcode
 
struct  avrpart
 
struct  avrmem
 
struct  pindef_t
 
struct  pin_checklist_t
 
union  filedescriptor
 
union  pinfo
 
struct  serial_device
 
struct  programmer_t
 
struct  fioparms
 
struct  update_t
 
struct  programmer_type_t
 
struct  filedescriptor.usb
 
struct  pinfo.usbinfo
 

Macros

#define PATH_MAX   4096
 
#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)
 
#define ENQUEUE(q, d)   lins_n(q,d,1) /* put 'd' on the end of the queue */
 
#define DEQUEUE(q)
 
#define REQUEUE(q, d)
 
#define LOOKQUEUE(q)
 
#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 */
 
#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 */
 
#define AVR_MEMDESCLEN   64
 
#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 */
 
#define PIN_FIELD_ELEMENT_SIZE   (sizeof(pinmask_t) * 8)
 
#define PIN_FIELD_SIZE   ((PIN_MAX + PIN_FIELD_ELEMENT_SIZE)/PIN_FIELD_ELEMENT_SIZE)
 
#define SET_BITS_0(x, pgm, pinname, level)
 
#define GET_BITS_0(x, pgm, pinname)   (((x) ^ (pgm)->pin[pinname].inverse[0]) & (pgm)->pin[pinname].mask[0])
 
#define PINFO_FL_USEHID   0x0001
 
#define PINFO_FL_SILENT   0x0002 /* don't complain if not found */
 
#define SERDEV_FL_NONE   0x0000 /* no flags */
 
#define SERDEV_FL_CANSETSPEED   0x0001 /* device can change speed */
 
#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)
 
#define ON   1
 
#define OFF   0
 
#define PGM_DESCLEN   80
 
#define PGM_PORTLEN   PATH_MAX
 
#define PGM_TYPELEN   32
 
#define PGM_USBSTRINGLEN   256
 
#define SHOW_ALL_PINS   (~0u)
 
#define SHOW_PPI_PINS   ((1<<PPI_AVR_VCC)|(1<<PPI_AVR_BUFF))
 
#define SHOW_AVR_PINS   ((1<<PIN_AVR_RESET)|(1<<PIN_AVR_SCK)|(1<<PIN_AVR_MOSI)|(1<<PIN_AVR_MISO))
 
#define SHOW_LED_PINS   ((1<<PIN_LED_ERR)|(1<<PIN_LED_RDY)|(1<<PIN_LED_PGM)|(1<<PIN_LED_VFY))
 
#define RETURN_IF_CANCEL()
 
#define DEFAULT_USB   "usb"
 

Typedefs

typedef uint32_t pinmask_t
 
typedef voidLISTID
 
typedef voidLNODEID
 
typedef struct cmdbit CMDBIT
 
typedef struct opcode OPCODE
 
typedef struct avrpart AVRPART
 
typedef struct avrmem AVRMEM
 
typedef void(* walk_avrparts_cb) (const char *name, const char *desc, const char *cfgname, int cfglineno, void *cookie)
 
typedef struct programmer_t PROGRAMMER
 
typedef void(* walk_programmers_cb) (const char *name, const char *desc, const char *cfgname, int cfglineno, void *cookie)
 
typedef void(* FP_UpdateProgress) (int percent, double etime, char *hdr)
 
typedef struct update_t UPDATE
 
typedef struct programmer_type_t PROGRAMMER_TYPE
 
typedef void(* walk_programmer_types_cb) (const char *id, const char *desc, void *cookie)
 

Enumerations

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 , AVR_CMDBIT_VALUE , AVR_CMDBIT_ADDRESS , AVR_CMDBIT_INPUT ,
  AVR_CMDBIT_OUTPUT
}
 
enum  { RESET_DEDICATED , RESET_IO }
 
enum  ctl_stack_t { CTL_STACK_NONE , CTL_STACK_PP , CTL_STACK_HVSP }
 
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
}
 
enum  exit_vcc_t { EXIT_VCC_UNSPEC , EXIT_VCC_ENABLED , EXIT_VCC_DISABLED }
 
enum  exit_reset_t { EXIT_RESET_UNSPEC , EXIT_RESET_ENABLED , EXIT_RESET_DISABLED }
 
enum  exit_datahigh_t { EXIT_DATAHIGH_UNSPEC , EXIT_DATAHIGH_ENABLED , EXIT_DATAHIGH_DISABLED }
 
enum  conntype_t { CONNTYPE_PARALLEL , CONNTYPE_SERIAL , CONNTYPE_USB }
 
enum  FILEFMT {
  FMT_AUTO , FMT_SREC , FMT_IHEX , FMT_RBIN ,
  FMT_IMM , FMT_HEX , FMT_DEC , FMT_OCT ,
  FMT_BIN , FMT_ELF
}
 
enum  { FIO_READ , FIO_WRITE }
 
enum  { DEVICE_READ , DEVICE_WRITE , DEVICE_VERIFY }
 
enum  updateflags { UF_NONE = 0 , UF_NOWRITE = 1 , UF_AUTO_ERASE = 2 }
 

Functions

LISTID lcreat (void *liststruct, int poolsize)
 
void ldestroy (LISTID lid)
 
void ldestroy_cb (LISTID lid, void(*ucleanup)(void *data_ptr))
 
LNODEID lfirst (LISTID)
 
LNODEID llast (LISTID)
 
LNODEID lnext (LNODEID)
 
LNODEID lprev (LNODEID)
 
voidldata (LNODEID)
 
int lsize (LISTID)
 
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)
 
voidlget (LISTID lid)
 
voidlget_n (LISTID lid, unsigned int n)
 
LNODEID lget_ln (LISTID lid, unsigned int n)
 
voidlrmv (LISTID lid)
 
voidlrmv_n (LISTID lid, unsigned int n)
 
voidlrmv_ln (LISTID lid, LNODEID lnid)
 
voidlrmv_d (LISTID lid, void *data_ptr)
 
LISTID lcat (LISTID lid1, LISTID lid2)
 
void lsort (LISTID lid, int(*compare)(void *p1, void *p2))
 
voidlsrch (LISTID lid, void *p, int(*compare)(void *p1, void *p2))
 
int lprint (FILE *f, LISTID lid)
 
OPCODEavr_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)
 
AVRMEMavr_new_memtype (void)
 
int avr_initmem (AVRPART *p)
 
AVRMEMavr_dup_mem (AVRMEM *m)
 
void avr_free_mem (AVRMEM *m)
 
AVRMEMavr_locate_mem (AVRPART *p, char *desc)
 
void avr_mem_display (const char *prefix, FILE *f, AVRMEM *m, int type, int verbose)
 
AVRPARTavr_new_part (void)
 
AVRPARTavr_dup_part (AVRPART *d)
 
void avr_free_part (AVRPART *d)
 
AVRPARTlocate_part (LISTID parts, char *partdesc)
 
AVRPARTlocate_part_by_avr910_devcode (LISTID parts, int devcode)
 
AVRPARTlocate_part_by_signature (LISTID parts, unsigned char *sig, int sigsize)
 
void avr_display (FILE *f, AVRPART *p, const char *prefix, int verbose)
 
void walk_avrparts (LISTID avrparts, walk_avrparts_cb cb, void *cookie)
 
void sort_avrparts (LISTID avrparts)
 
void pin_set_value (struct pindef_t *const pindef, const int pin, const bool inverse)
 
void pin_clear_all (struct pindef_t *const pindef)
 
int pgm_fill_old_pins (struct programmer_t *const pgm)
 
int pins_check (const struct programmer_t *const pgm, const struct pin_checklist_t *const checklist, const int size, const bool output)
 
const char * avr_pin_name (int pinname)
 
const char * pins_to_str (const struct pindef_t *const pindef)
 
const char * pinmask_to_str (const pinmask_t *const pinmask)
 
PROGRAMMERpgm_new (void)
 
PROGRAMMERpgm_dup (const PROGRAMMER *const src)
 
void pgm_free (PROGRAMMER *const p)
 
void programmer_display (PROGRAMMER *pgm, const char *p)
 
void pgm_display_generic_mask (PROGRAMMER *pgm, const char *p, unsigned int show)
 
void pgm_display_generic (PROGRAMMER *pgm, const char *p)
 
PROGRAMMERlocate_programmer (LISTID programmers, const char *configid)
 
void walk_programmers (LISTID programmers, walk_programmers_cb cb, void *cookie)
 
void sort_programmers (LISTID programmers)
 
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)
 
char * fmtstr (FILEFMT format)
 
FILE * fopen_utf8 (const char *filename, const char *mode)
 
int fileio (int op, char *filename, FILEFMT format, struct avrpart *p, char *memtype, int size, unsigned section)
 
int safemode_writefuse (unsigned char fuse, char *fusename, PROGRAMMER *pgm, AVRPART *p, int tries)
 
int safemode_readfuses (unsigned char *lfuse, unsigned char *hfuse, unsigned char *efuse, unsigned char *fuse, PROGRAMMER *pgm, AVRPART *p)
 
int safemode_memfuses (int save, unsigned char *lfuse, unsigned char *hfuse, unsigned char *efuse, unsigned char *fuse)
 
UPDATEparse_op (char *s)
 
UPDATEdup_update (UPDATE *upd)
 
UPDATEnew_update (int op, char *memtype, int filefmt, char *filename, unsigned section)
 
void free_update (UPDATE *upd)
 
int do_op (PROGRAMMER *pgm, struct avrpart *p, UPDATE *upd, enum updateflags flags)
 
const PROGRAMMER_TYPElocate_programmer_type (const char *id)
 
void walk_programmer_types (walk_programmer_types_cb cb, void *cookie)
 
int init_config (void)
 
void cleanup_config (void)
 
int read_config (const char *file)
 
int read_config_builtin ()
 

Variables

long serial_recv_timeout
 
struct serial_deviceserdev
 
struct serial_device serial_serdev
 
struct serial_device usb_serdev
 
struct serial_device usb_serdev_frame
 
struct serial_device avrdoper_serdev
 
struct serial_device usbhid_serdev
 
struct avrpart parts []
 
FP_UpdateProgress update_progress
 
bool cancel_flag
 
LISTID part_list
 
LISTID programmers
 
char default_programmer []
 
char default_parallel []
 
char default_serial []
 
double default_bitclock
 
int default_safemode
 

Class Documentation

◆ cmdbit

struct cmdbit
Class Members
int bitno
int type
int value

◆ opcode

struct opcode
+ Collaboration diagram for opcode:
Class Members
CMDBIT bit[32]

◆ avrpart

struct avrpart
+ Collaboration diagram for avrpart:
Class Members
int avr910_devcode
unsigned char bs2
int bytedelay
int chip_erase_delay
int chiperasepolltimeout
int chiperasepulsewidth
int chiperasetime
int cmdexedelay
char config_file[PATH_MAX]
unsigned char controlstack[CTL_STACK_SIZE]
enum ctl_stack_t ctl_stack_type
char desc[AVR_DESCLEN]
unsigned short eecr
unsigned char eeprom_instr[EEPROM_INSTR_SIZE]
unsigned flags
unsigned char flash_instr[FLASH_INSTR_SIZE]
int hventerstabdelay
int hvleavestabdelay
int hvspcmdexedelay
char id[AVR_IDLEN]
unsigned char idr
int latchcycles
int lineno
unsigned int mcu_base
LISTID mem
unsigned int nvm_base
int ocdrev
OPCODE * op[AVR_OP_MAX]
unsigned char pagel
int pollindex
int pollmethod
unsigned char pollvalue
int postdelay
int poweroffdelay
int predelay
int progmodedelay
int programfusepolltimeout
int programfusepulsewidth
int programlockpolltimeout
int programlockpulsewidth
unsigned char rampz
int reset_disposition
int resetdelay
int resetdelayms
int resetdelayus
int retry_pulse
unsigned char signature[3]
unsigned char spmcr
int stabdelay
int stk500_devcode
int synchcycles
int synchloops
int timeout
int togglevtg
unsigned short usbpid

◆ avrmem

struct avrmem
+ Collaboration diagram for avrmem:
Class Members
int blocksize
unsigned char * buf
int delay
char desc[AVR_MEMDESCLEN]
int max_write_delay
int min_write_delay
int mode
int num_pages
unsigned int offset
OPCODE * op[AVR_OP_MAX]
int page_size
int paged
int pollindex
int pwroff_after_write
unsigned char readback[2]
int readsize
int size
unsigned char * tags

◆ pindef_t

struct pindef_t

Data structure to hold used pins by logical function (PIN_AVR_*, ...)

Class Members
pinmask_t inverse[PIN_FIELD_SIZE] bitfield of inverse/normal usage of used pins
pinmask_t mask[PIN_FIELD_SIZE] bitfield of used pins

◆ pin_checklist_t

struct pin_checklist_t

Data structure to define a checklist of valid pins for each function.

+ Collaboration diagram for pin_checklist_t:
Class Members
int mandatory is this a mandatory pin
int pinname logical pinname eg. PIN_AVR_SCK
const struct pindef_t * valid_pins mask defines allowed pins, inverse define is they might be used inverted

◆ filedescriptor

union filedescriptor
Class Members
int ifd
void * pfd
struct filedescriptor.usb usb

◆ pinfo

union pinfo
Class Members
long baud
struct pinfo.usbinfo usbinfo

◆ fioparms

struct fioparms
Class Members
char * dir
unsigned int fileoffset
char * iodesc
char * mode
int op
char * rw

◆ update_t

struct update_t
Class Members
char * filename
int format
char * memtype
int op
unsigned section

◆ filedescriptor.usb

struct filedescriptor.usb
Class Members
int eep
void * handle
int max_xfer
int rep
int use_interrupt_xfer
int wep

◆ pinfo.usbinfo

struct pinfo.usbinfo
Class Members
unsigned short flags
unsigned short pid
unsigned short vid

Macro Definition Documentation

◆ AVR_DESCLEN

#define AVR_DESCLEN   64

◆ AVR_IDLEN

#define AVR_IDLEN   32

◆ AVR_MEMDESCLEN

#define AVR_MEMDESCLEN   64

◆ AVRPART_ALLOWFULLPAGEBITSTREAM

#define AVRPART_ALLOWFULLPAGEBITSTREAM   0x0010 /* JTAG ICE mkII param. */

◆ AVRPART_AVR32

#define AVRPART_AVR32   0x0100 /* part is in AVR32 family */

◆ AVRPART_ENABLEPAGEPROGRAMMING

#define AVRPART_ENABLEPAGEPROGRAMMING   0x0020 /* JTAG ICE mkII param. */

◆ AVRPART_HAS_DW

#define AVRPART_HAS_DW   0x0040 /* part has a debugWire i/f */

◆ AVRPART_HAS_JTAG

#define AVRPART_HAS_JTAG   0x0008 /* part has a JTAG i/f */

◆ AVRPART_HAS_PDI

#define AVRPART_HAS_PDI   0x0080 /* part has PDI i/f rather than ISP (ATxmega) */

◆ AVRPART_HAS_TPI

#define AVRPART_HAS_TPI   0x0800 /* part has TPI i/f rather than ISP (ATtiny4/5/9/10) */

◆ AVRPART_INIT_SMC

#define AVRPART_INIT_SMC   0x0200 /* part will undergo chip erase */

◆ AVRPART_IS_AT90S1200

#define AVRPART_IS_AT90S1200   0x1000 /* part is an AT90S1200 (needs special treatment) */

◆ AVRPART_PARALLELOK

#define AVRPART_PARALLELOK   0x0002 /* part supports parallel programming */

◆ AVRPART_PSEUDOPARALLEL

#define AVRPART_PSEUDOPARALLEL   0x0004 /* part has pseudo parallel support */

◆ AVRPART_SERIALOK

#define AVRPART_SERIALOK   0x0001 /* part supports serial programming */

◆ AVRPART_WRITE

#define AVRPART_WRITE   0x0400 /* at least one write operation specified */

◆ CTL_STACK_SIZE

#define CTL_STACK_SIZE   32

◆ DEFAULT_USB

#define DEFAULT_USB   "usb"

◆ DEQUEUE

#define DEQUEUE (   q)
Value:
lrmv(q) /* remove next item from the front of
the queue */
void * lrmv(LISTID lid)
Definition lists.c:1226

◆ EEPROM_INSTR_SIZE

#define EEPROM_INSTR_SIZE   20

◆ ENQUEUE

#define ENQUEUE (   q,
 
)    lins_n(q,d,1) /* put 'd' on the end of the queue */

◆ FLASH_INSTR_SIZE

#define FLASH_INSTR_SIZE   3

◆ GET_BITS_0

#define GET_BITS_0 (   x,
  pgm,
  pinname 
)    (((x) ^ (pgm)->pin[pinname].inverse[0]) & (pgm)->pin[pinname].mask[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.

Parameters
[in]xinput value
[in]pgmthe programmer whose pin definitions to use
[in]pinnamethe 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)

◆ LISTADD

#define LISTADD (   l,
 
)    ladd(l,d) /* add to end of the list */

◆ LISTRMV

#define LISTRMV (   l,
 
)    lrmv_d(l,d) /* remove from end of the list */

◆ LOOKQUEUE

#define LOOKQUEUE (   q)
Value:
lget(q) /* return next item on the queue,
but don't dequeue */
void * lget(LISTID lid)
Definition lists.c:766

◆ LOOKSTACK

#define LOOKSTACK (   s)
Value:
lget_n(s,1) /* look at the top of the stack,
but don't pop */
void * lget_n(LISTID lid, unsigned int n)
Definition lists.c:796

◆ OFF

#define OFF   0

◆ ON

#define ON   1

◆ PATH_MAX

#define PATH_MAX   4096

◆ PGM_DESCLEN

#define PGM_DESCLEN   80

◆ PGM_PORTLEN

#define PGM_PORTLEN   PATH_MAX

◆ PGM_TYPELEN

#define PGM_TYPELEN   32

◆ PGM_USBSTRINGLEN

#define PGM_USBSTRINGLEN   256

◆ PIN_FIELD_ELEMENT_SIZE

#define PIN_FIELD_ELEMENT_SIZE   (sizeof(pinmask_t) * 8)

Number of pins in each element of the bitfield

◆ PIN_FIELD_SIZE

#define PIN_FIELD_SIZE   ((PIN_MAX + PIN_FIELD_ELEMENT_SIZE)/PIN_FIELD_ELEMENT_SIZE)

Numer of elements to store the complete bitfield of all pins

◆ PIN_INVERSE

#define PIN_INVERSE   (~(PIN_MASK)) /* flag for inverted pin in serbb */

◆ PIN_MASK

#define PIN_MASK   (UINT_MAX>>1)

◆ PIN_MAX

#define PIN_MAX   31 /* largest allowed pin number */

◆ PIN_MIN

#define PIN_MIN   0 /* smallest allowed pin number */

◆ PINFO_FL_SILENT

#define PINFO_FL_SILENT   0x0002 /* don't complain if not found */

◆ PINFO_FL_USEHID

#define PINFO_FL_USEHID   0x0001

◆ POP

#define POP (   s)    lrmv_n(s,1) /* pop the stack */

◆ PUSH

#define PUSH (   s,
 
)    lins_n(s,d,1) /* push 'd' onto the stack */

◆ QNODEID

#define QNODEID   LNODEID

◆ QUEUEID

#define QUEUEID   LISTID

◆ QUEUELEN

#define QUEUELEN (   q)    lsize(q) /* length of the queue */

◆ REQUEUE

#define REQUEUE (   q,
 
)
Value:
ladd(q,d) /* re-insert (push) item back on the
front of the queue */
int ladd(LISTID lid, void *p)
Definition lists.c:547

◆ RETURN_IF_CANCEL

#define RETURN_IF_CANCEL ( )
Value:
do { \
if (cancel_flag) { \
avrdude_message(MSG_INFO, "avrdude: %s(): Cancelled, exiting...\n", __func__); \
return -99; \
} \
} while (0)
#define MSG_INFO
Definition avrdude.h:51
bool cancel_flag
Definition main.c:69
#define __func__
Definition unistd.h:26

◆ SERDEV_FL_CANSETSPEED

#define SERDEV_FL_CANSETSPEED   0x0001 /* device can change speed */

◆ SERDEV_FL_NONE

#define SERDEV_FL_NONE   0x0000 /* no flags */

◆ serial_close

#define serial_close   (serdev->close)

◆ serial_drain

#define serial_drain   (serdev->drain)

◆ serial_open

#define serial_open   (serdev->open)

◆ serial_recv

#define serial_recv   (serdev->recv)

◆ serial_send

#define serial_send   (serdev->send)

◆ serial_set_dtr_rts

#define serial_set_dtr_rts   (serdev->set_dtr_rts)

◆ serial_setspeed

#define serial_setspeed   (serdev->setspeed)

◆ SET_BITS_0

#define SET_BITS_0 (   x,
  pgm,
  pinname,
  level 
)
Value:
(((x) & ~(pgm)->pin[pinname].mask[0]) \
| (\
(pgm)->pin[pinname].mask[0] & ( \
(level) \
?~((pgm)->pin[pinname].inverse[0]) \
: ((pgm)->pin[pinname].inverse[0]) \
) \
) \
)
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
Definition ArrayCwiseUnaryOps.h:332
static PROGRAMMER * pgm
Definition main.c:192

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.

Parameters
[in]xinput value
[in]pgmthe programmer whose pin definitions to use
[in]pinnamethe logical name of the pin (PIN_AVR_*, ...)
[in]levelthe 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

◆ SHOW_ALL_PINS

#define SHOW_ALL_PINS   (~0u)

◆ SHOW_AVR_PINS

#define SHOW_AVR_PINS   ((1<<PIN_AVR_RESET)|(1<<PIN_AVR_SCK)|(1<<PIN_AVR_MOSI)|(1<<PIN_AVR_MISO))

◆ SHOW_LED_PINS

#define SHOW_LED_PINS   ((1<<PIN_LED_ERR)|(1<<PIN_LED_RDY)|(1<<PIN_LED_PGM)|(1<<PIN_LED_VFY))

◆ SHOW_PPI_PINS

#define SHOW_PPI_PINS   ((1<<PPI_AVR_VCC)|(1<<PPI_AVR_BUFF))

◆ SNODEID

#define SNODEID   LNODEID

◆ STACKID

#define STACKID   LISTID

◆ TAG_ALLOCATED

#define TAG_ALLOCATED   1 /* memory byte is allocated */

Typedef Documentation

◆ AVRMEM

typedef struct avrmem AVRMEM

◆ AVRPART

typedef struct avrpart AVRPART

◆ CMDBIT

typedef struct cmdbit CMDBIT

◆ FP_UpdateProgress

typedef void(* FP_UpdateProgress) (int percent, double etime, char *hdr)

◆ LISTID

typedef void* LISTID

◆ LNODEID

typedef void* LNODEID

◆ OPCODE

typedef struct opcode OPCODE

◆ pinmask_t

◆ PROGRAMMER

typedef struct programmer_t PROGRAMMER

◆ PROGRAMMER_TYPE

◆ UPDATE

typedef struct update_t UPDATE

◆ walk_avrparts_cb

typedef void(* walk_avrparts_cb) (const char *name, const char *desc, const char *cfgname, int cfglineno, void *cookie)

◆ walk_programmer_types_cb

typedef void(* walk_programmer_types_cb) (const char *id, const char *desc, void *cookie)

◆ walk_programmers_cb

typedef void(* walk_programmers_cb) (const char *name, const char *desc, const char *cfgname, int cfglineno, void *cookie)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FIO_READ 
FIO_WRITE 
812 {
813 FIO_READ,
815};
816
817#ifdef __cplusplus
818extern "C" {
819#endif
820
821char * fmtstr(FILEFMT format);
822
823FILE *fopen_utf8(const char *filename, const char *mode);
824
825int fileio(int op, char * filename, FILEFMT format,
826 struct avrpart * p, char * memtype, int size, unsigned section);
827
828#ifdef __cplusplus
829}
830#endif
831
832
833/* formerly safemode.h */
834
835#ifdef __cplusplus
836extern "C" {
837#endif
838
839/* Writes the specified fuse in fusename (can be "lfuse", "hfuse", or "efuse") and verifies it. Will try up to tries
840amount of times before giving up */
841int safemode_writefuse (unsigned char fuse, char * fusename, PROGRAMMER * pgm, AVRPART * p, int tries);
842
843/* Reads the fuses three times, checking that all readings are the same. This will ensure that the before values aren't in error! */
844int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse, unsigned char * efuse, unsigned char * fuse, PROGRAMMER * pgm, AVRPART * p);
845
846/* This routine will store the current values pointed to by lfuse, hfuse, and efuse into an internal buffer in this routine
847when 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
848pointed to be lfuse, hfuse, and efuse. This allows you to change the fuse bits if needed from another routine (ie: have it so
849if user requests fuse bits are changed, the requested value is now verified */
850int safemode_memfuses (int save, unsigned char * lfuse, unsigned char * hfuse, unsigned char * efuse, unsigned char * fuse);
851
852#ifdef __cplusplus
853}
854#endif
855
856
857/* formerly update.h */
858
859enum {
863};
864
865enum updateflags {
866 UF_NONE = 0,
867 UF_NOWRITE = 1,
868 UF_AUTO_ERASE = 2,
869};
870
871
872typedef struct update_t {
873 char * memtype;
874 int op;
875 unsigned section;
876 char * filename;
877 int format;
878} UPDATE;
879
880#ifdef __cplusplus
881extern "C" {
882#endif
883
884extern UPDATE * parse_op(char * s);
885extern UPDATE * dup_update(UPDATE * upd);
886extern UPDATE * new_update(int op, char * memtype, int filefmt,
887 char * filename, unsigned section);
888extern void free_update(UPDATE * upd);
889extern int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd,
890 enum updateflags flags);
891
892#ifdef __cplusplus
893}
894#endif
895
896
897/* formerly pgm_type.h */
898
899/*LISTID programmer_types;*/
900
901typedef struct programmer_type_t {
902 const char * const id;
903 void (*initpgm)(struct programmer_t * pgm);
904 const char * const desc;
906
907#ifdef __cplusplus
908extern "C" {
909#endif
910
911const PROGRAMMER_TYPE * locate_programmer_type(/*LISTID programmer_types, */const char * id);
912
913typedef void (*walk_programmer_types_cb)(const char *id, const char *desc,
914 void *cookie);
915void walk_programmer_types(/*LISTID programmer_types,*/ walk_programmer_types_cb cb, void *cookie);
916
917#ifdef __cplusplus
918}
919#endif
920
921/* formerly config.h */
922
923extern LISTID part_list;
924extern LISTID programmers;
925extern char default_programmer[];
926extern char default_parallel[];
927extern char default_serial[];
928extern double default_bitclock;
929extern int default_safemode;
930
931/* This name is fixed, it's only here for symmetry with
932 * default_parallel and default_serial. */
933#define DEFAULT_USB "usb"
934
935#ifdef __cplusplus
936extern "C" {
937#endif
938
939int init_config(void);
940
941void cleanup_config(void);
942
943int read_config(const char * file);
945
946#ifdef __cplusplus
947}
948#endif
949
950// Header file for alloca()
951#if defined(WIN32NATIVE)
952# include <malloc.h>
953#else
954# include <alloca.h>
955#endif
956
957
958/* formerly confwin.h */
959
960// #if defined(WIN32NATIVE)
961
962// #ifdef __cplusplus
963// extern "C" {
964// #endif
965
966// void win_sys_config_set(char sys_config[PATH_MAX]);
967// void win_usr_config_set(char usr_config[PATH_MAX]);
968
969// #ifdef __cplusplus
970// }
971// #endif
972
973// #endif /* WIN32NATIVE */
974
975
976#endif /* libavrdude_h */
void save(Archive &archive, wxString const &d)
Definition GLGizmoEmboss.cpp:1557
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
void * LISTID
Definition libavrdude.h:63
int op
Definition libavrdude.h:870
void free_update(UPDATE *upd)
Definition update.c:221
int init_config(void)
Definition config.c:69
char default_serial[]
Definition config.c:39
struct update_t UPDATE
char default_programmer[]
Definition config.c:37
int do_op(PROGRAMMER *pgm, struct avrpart *p, UPDATE *upd, enum updateflags flags)
Definition update.c:237
char * filename
Definition libavrdude.h:872
LISTID part_list
Definition config.c:51
char default_parallel[]
Definition config.c:38
void walk_programmer_types(walk_programmer_types_cb cb, void *cookie)
Definition pgm_type.c:142
double default_bitclock
Definition config.c:40
char * fmtstr(FILEFMT format)
Definition fileio.c:166
UPDATE * dup_update(UPDATE *upd)
Definition update.c:179
@ FIO_WRITE
Definition libavrdude.h:810
@ FIO_READ
Definition libavrdude.h:809
int safemode_memfuses(int save, unsigned char *lfuse, unsigned char *hfuse, unsigned char *efuse, unsigned char *fuse)
Definition safemode.c:290
int fileio(int op, char *filename, FILEFMT format, struct avrpart *p, char *memtype, int size, unsigned section)
Definition fileio.c:1512
void(* walk_programmer_types_cb)(const char *id, const char *desc, void *cookie)
Definition libavrdude.h:909
unsigned section
Definition libavrdude.h:871
LISTID programmers
Definition config.c:52
char * memtype
Definition libavrdude.h:869
int read_config(const char *file)
Definition config.c:325
FILE * fopen_utf8(const char *filename, const char *mode)
Definition fileio.c:108
updateflags
Definition libavrdude.h:861
@ UF_NONE
Definition libavrdude.h:862
@ UF_AUTO_ERASE
Definition libavrdude.h:864
@ UF_NOWRITE
Definition libavrdude.h:863
int read_config_builtin()
Definition config.c:357
int format
Definition libavrdude.h:873
int safemode_writefuse(unsigned char fuse, char *fusename, PROGRAMMER *pgm, AVRPART *p, int tries)
Definition safemode.c:35
@ DEVICE_VERIFY
Definition libavrdude.h:858
@ DEVICE_WRITE
Definition libavrdude.h:857
@ DEVICE_READ
Definition libavrdude.h:856
void cleanup_config(void)
Definition config.c:61
struct programmer_type_t PROGRAMMER_TYPE
int default_safemode
Definition config.c:41
FILEFMT
Definition libavrdude.h:786
const PROGRAMMER_TYPE * locate_programmer_type(const char *id)
Definition pgm_type.c:99
int safemode_readfuses(unsigned char *lfuse, unsigned char *hfuse, unsigned char *efuse, unsigned char *fuse, PROGRAMMER *pgm, AVRPART *p)
Definition safemode.c:77
UPDATE * new_update(int op, char *memtype, int filefmt, char *filename, unsigned section)
Definition update.c:201
UPDATE * parse_op(char *s)
Definition update.c:31
Definition libavrdude.h:868
Definition libavrdude.h:217
Definition libavrdude.h:616
char desc[PGM_DESCLEN]
Definition libavrdude.h:618
LISTID id
Definition libavrdude.h:617
void * cookie
Definition libavrdude.h:689
Definition libavrdude.h:897
const char *const id
Definition libavrdude.h:898
const char *const desc
Definition libavrdude.h:900
void(* initpgm)(struct programmer_t *pgm)
Definition libavrdude.h:899

◆ anonymous enum

anonymous enum
Enumerator
DEVICE_READ 
DEVICE_WRITE 
DEVICE_VERIFY 
859 {

◆ anonymous enum

anonymous enum
Enumerator
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 
149 {
@ AVR_OP_WRITE_LO
Definition libavrdude.h:150
@ AVR_OP_WRITEPAGE
Definition libavrdude.h:155
@ AVR_OP_READ
Definition libavrdude.h:146
@ AVR_OP_LOADPAGE_LO
Definition libavrdude.h:152
@ AVR_OP_READ_LO
Definition libavrdude.h:148
@ AVR_OP_WRITE_HI
Definition libavrdude.h:151
@ AVR_OP_LOAD_EXT_ADDR
Definition libavrdude.h:154
@ AVR_OP_LOADPAGE_HI
Definition libavrdude.h:153
@ AVR_OP_READ_HI
Definition libavrdude.h:149
@ AVR_OP_WRITE
Definition libavrdude.h:147

◆ anonymous enum

anonymous enum
Enumerator
AVR_CMDBIT_IGNORE 
AVR_CMDBIT_VALUE 
AVR_CMDBIT_ADDRESS 
AVR_CMDBIT_INPUT 
AVR_CMDBIT_OUTPUT 
166 {
167 AVR_CMDBIT_IGNORE, /* bit is ignored on input and output */
168 AVR_CMDBIT_VALUE, /* bit is set to 0 or 1 for input or output */
@ AVR_CMDBIT_VALUE
Definition libavrdude.h:164
@ AVR_CMDBIT_IGNORE
Definition libavrdude.h:163

◆ anonymous enum

anonymous enum
Enumerator
RESET_DEDICATED 
RESET_IO 

◆ anonymous enum

anonymous enum
Enumerator
PPI_AVR_VCC 
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 
356 {
357 PPI_AVR_VCC = 1,
@ PIN_AVR_RESET
Definition libavrdude.h:355
@ PIN_AVR_MISO
Definition libavrdude.h:358
@ PIN_LED_RDY
Definition libavrdude.h:360
@ PIN_LED_ERR
Definition libavrdude.h:359
@ PIN_AVR_SCK
Definition libavrdude.h:356
@ PIN_AVR_MOSI
Definition libavrdude.h:357
@ PPI_AVR_BUFF
Definition libavrdude.h:354
@ PPI_AVR_VCC
Definition libavrdude.h:353

◆ conntype_t

enum conntype_t
Enumerator
CONNTYPE_PARALLEL 
CONNTYPE_SERIAL 
CONNTYPE_USB 
614 {

◆ ctl_stack_t

Enumerator
CTL_STACK_NONE 
CTL_STACK_PP 
CTL_STACK_HVSP 
179 {

◆ exit_datahigh_t

Enumerator
EXIT_DATAHIGH_UNSPEC 
EXIT_DATAHIGH_ENABLED 
EXIT_DATAHIGH_DISABLED 
608 {

◆ exit_reset_t

Enumerator
EXIT_RESET_UNSPEC 
EXIT_RESET_ENABLED 
EXIT_RESET_DISABLED 
602 {

◆ exit_vcc_t

enum exit_vcc_t
Enumerator
EXIT_VCC_UNSPEC 
EXIT_VCC_ENABLED 
EXIT_VCC_DISABLED 
596 {

◆ FILEFMT

enum FILEFMT
Enumerator
FMT_AUTO 
FMT_SREC 
FMT_IHEX 
FMT_RBIN 
FMT_IMM 
FMT_HEX 
FMT_DEC 
FMT_OCT 
FMT_BIN 
FMT_ELF 
790 {
791 FMT_AUTO,
792 FMT_SREC,
793 FMT_IHEX,
794 FMT_RBIN,
795 FMT_IMM,
796 FMT_HEX,
797 FMT_DEC,
@ FMT_AUTO
Definition libavrdude.h:787
@ FMT_RBIN
Definition libavrdude.h:790
@ FMT_HEX
Definition libavrdude.h:792
@ FMT_IHEX
Definition libavrdude.h:789
@ FMT_IMM
Definition libavrdude.h:791
@ FMT_DEC
Definition libavrdude.h:793
@ FMT_SREC
Definition libavrdude.h:788

◆ updateflags

Enumerator
UF_NONE 
UF_NOWRITE 
UF_AUTO_ERASE 
865 {

Function Documentation

◆ avr_chip_erase()

int avr_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
1197{
1198 int rc;
1199
1200 rc = pgm->chip_erase(pgm, p);
1201
1202 return rc;
1203}
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650

References programmer_t::chip_erase, and pgm.

Referenced by avrdude_main().

+ Here is the caller graph for this function:

◆ avr_display()

void avr_display ( FILE *  f,
AVRPART p,
const char *  prefix,
int  verbose 
)
622{
623 int i;
624 char * buf;
625 const char * px;
626 LNODEID ln;
627 AVRMEM * m;
628
630 "%sAVR Part : %s\n"
631 "%sChip Erase delay : %d us\n"
632 "%sPAGEL : P%02X\n"
633 "%sBS2 : P%02X\n"
634 "%sRESET disposition : %s\n"
635 "%sRETRY pulse : %s\n"
636 "%sserial program mode : %s\n"
637 "%sparallel program mode : %s\n"
638 "%sTimeout : %d\n"
639 "%sStabDelay : %d\n"
640 "%sCmdexeDelay : %d\n"
641 "%sSyncLoops : %d\n"
642 "%sByteDelay : %d\n"
643 "%sPollIndex : %d\n"
644 "%sPollValue : 0x%02x\n"
645 "%sMemory Detail :\n\n",
646 prefix, p->desc,
647 prefix, p->chip_erase_delay,
648 prefix, p->pagel,
649 prefix, p->bs2,
651 prefix, avr_pin_name(p->retry_pulse),
652 prefix, (p->flags & AVRPART_SERIALOK) ? "yes" : "no",
653 prefix, (p->flags & AVRPART_PARALLELOK) ?
654 ((p->flags & AVRPART_PSEUDOPARALLEL) ? "psuedo" : "yes") : "no",
655 prefix, p->timeout,
656 prefix, p->stabdelay,
657 prefix, p->cmdexedelay,
658 prefix, p->synchloops,
659 prefix, p->bytedelay,
660 prefix, p->pollindex,
661 prefix, p->pollvalue,
662 prefix);
663
664 px = prefix;
665 i = (int)strlen(prefix) + 5;
666 buf = (char *)malloc(i);
667 if (buf == NULL) {
668 /* ugh, this is not important enough to bail, just ignore it */
669 }
670 else {
671 strcpy(buf, prefix);
672 strcat(buf, " ");
673 px = buf;
674 }
675
676 if (verbose <= 2) {
677 avr_mem_display(px, f, NULL, 0, verbose);
678 }
679 for (ln=lfirst(p->mem); ln; ln=lnext(ln)) {
680 m = ldata(ln);
681 avr_mem_display(px, f, m, i, verbose);
682 }
683
684 if (buf)
685 free(buf);
686}
int verbose
Definition main.c:198
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
static char * reset_disp_str(int r)
Definition avrpart.c:611
void avr_mem_display(const char *prefix, FILE *f, AVRMEM *m, int type, int verbose)
Definition avrpart.c:379
void * malloc(YYSIZE_T)
void free(void *)
#define AVRPART_PSEUDOPARALLEL
Definition libavrdude.h:197
unsigned char pagel
Definition libavrdude.h:223
const char * avr_pin_name(int pinname)
Definition pindefs.c:354
void * ldata(LNODEID)
Definition lists.c:720
#define AVRPART_PARALLELOK
Definition libavrdude.h:196
void * LNODEID
Definition libavrdude.h:64
int chip_erase_delay
Definition libavrdude.h:222
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
LNODEID lnext(LNODEID)
Definition lists.c:704
#define AVRPART_SERIALOK
Definition libavrdude.h:195
LNODEID lfirst(LISTID)
Definition lists.c:688
int reset_disposition
Definition libavrdude.h:227
unsigned char bs2
Definition libavrdude.h:224
unsigned flags
Definition libavrdude.h:230
int retry_pulse
Definition libavrdude.h:228
LISTID mem
Definition libavrdude.h:277
Definition libavrdude.h:283

References avr_mem_display(), avr_pin_name(), avrdude_message(), AVRPART_PARALLELOK, AVRPART_PSEUDOPARALLEL, AVRPART_SERIALOK, avrpart::bs2, avrpart::bytedelay, avrpart::chip_erase_delay, avrpart::cmdexedelay, avrpart::desc, avrpart::flags, free(), ldata(), lfirst(), lnext(), malloc(), avrpart::mem, MSG_INFO, avrpart::pagel, avrpart::pollindex, avrpart::pollvalue, reset_disp_str(), avrpart::reset_disposition, avrpart::retry_pulse, avrpart::stabdelay, avrpart::synchloops, avrpart::timeout, and verbose.

Referenced by avrdude_main(), and cmd_part().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_dup_mem()

AVRMEM * avr_dup_mem ( AVRMEM m)
295{
296 AVRMEM * n;
297 int i;
298
299 n = avr_new_memtype();
300
301 *n = *m;
302
303 if (m->buf != NULL) {
304 n->buf = (unsigned char *)malloc(n->size);
305 if (n->buf == NULL) {
306 // avrdude_message(MSG_INFO, "avr_dup_mem(): out of memory (memsize=%d)\n",
307 // n->size);
308 // exit(1);
309 avrdude_oom("avr_dup_mem(): out of memory");
310 }
311 memcpy(n->buf, m->buf, n->size);
312 }
313
314 if (m->tags != NULL) {
315 n->tags = (unsigned char *)malloc(n->size);
316 if (n->tags == NULL) {
317 // avrdude_message(MSG_INFO, "avr_dup_mem(): out of memory (memsize=%d)\n",
318 // n->size);
319 // exit(1);
320 avrdude_oom("avr_dup_mem(): out of memory");
321 }
322 memcpy(n->tags, m->tags, n->size);
323 }
324
325 for (i = 0; i < AVR_OP_MAX; i++) {
326 n->op[i] = avr_dup_opcode(n->op[i]);
327 }
328
329 return n;
330}
void avrdude_oom(const char *context)
Definition main.c:169
AVRMEM * avr_new_memtype(void)
Definition avrpart.c:248
static OPCODE * avr_dup_opcode(OPCODE *op)
Definition avrpart.c:49
unsigned char * tags
Definition libavrdude.h:305
int size
Definition libavrdude.h:286
@ AVR_OP_MAX
Definition libavrdude.h:158
unsigned char * buf
Definition libavrdude.h:304
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:306

References avr_dup_opcode(), avr_new_memtype(), AVR_OP_MAX, avrdude_oom(), avrmem::buf, malloc(), avrmem::op, avrmem::size, and avrmem::tags.

Referenced by avr_dup_part().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_dup_part()

AVRPART * avr_dup_part ( AVRPART d)
474{
475 AVRPART * p;
476 LISTID save;
477 LNODEID ln;
478 int i;
479
480 p = avr_new_part();
481 save = p->mem;
482
483 *p = *d;
484
485 p->mem = save;
486
487 for (ln=lfirst(d->mem); ln; ln=lnext(ln)) {
488 ladd(p->mem, avr_dup_mem(ldata(ln)));
489 }
490
491 for (i = 0; i < AVR_OP_MAX; i++) {
492 p->op[i] = avr_dup_opcode(p->op[i]);
493 }
494
495 return p;
496}
AVRMEM * avr_dup_mem(AVRMEM *m)
Definition avrpart.c:294
AVRPART * avr_new_part(void)
Definition avrpart.c:443
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:275

References avr_dup_mem(), avr_dup_opcode(), avr_new_part(), AVR_OP_MAX, ladd(), ldata(), lfirst(), lnext(), avrpart::mem, avrpart::op, and save().

Referenced by do_op(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_free_mem()

void avr_free_mem ( AVRMEM m)
333{
334 int i;
335 if (m->buf != NULL) {
336 free(m->buf);
337 m->buf = NULL;
338 }
339 if (m->tags != NULL) {
340 free(m->tags);
341 m->tags = NULL;
342 }
343 for(i=0;i<sizeof(m->op)/sizeof(m->op[0]);i++)
344 {
345 if (m->op[i] != NULL)
346 {
347 avr_free_opcode(m->op[i]);
348 m->op[i] = NULL;
349 }
350 }
351 free(m);
352}
void avr_free_opcode(OPCODE *op)
Definition avrpart.c:70

References avr_free_opcode(), avrmem::buf, free(), avrmem::op, and avrmem::tags.

Referenced by avr_free_part(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_free_opcode()

void avr_free_opcode ( OPCODE op)
71{
72 free(op);
73}

References free().

Referenced by avr_free_mem(), avr_free_part(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_free_part()

void avr_free_part ( AVRPART d)
499{
500int i;
501 ldestroy_cb(d->mem, (void(*)(void *))avr_free_mem);
502 d->mem = NULL;
503 for(i=0;i<sizeof(d->op)/sizeof(d->op[0]);i++)
504 {
505 if (d->op[i] != NULL)
506 {
507 avr_free_opcode(d->op[i]);
508 d->op[i] = NULL;
509 }
510 }
511 free(d);
512}
void avr_free_mem(AVRMEM *m)
Definition avrpart.c:332
void ldestroy_cb(LISTID lid, void(*ucleanup)(void *data_ptr))
Definition lists.c:480

References avr_free_mem(), avr_free_opcode(), free(), and ldestroy_cb().

Referenced by cleanup_config(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_get_cycle_count()

int avr_get_cycle_count ( PROGRAMMER pgm,
AVRPART p,
int *  cycles 
)
1131{
1132 AVRMEM * a;
1133 unsigned int cycle_count = 0;
1134 unsigned char v1;
1135 int rc;
1136 int i;
1137
1138 a = avr_locate_mem(p, "eeprom");
1139 if (a == NULL) {
1140 return -1;
1141 }
1142
1143 for (i=4; i>0; i--) {
1144 rc = pgm->read_byte(pgm, p, a, a->size-i, &v1);
1145 if (rc < 0) {
1146 avrdude_message(MSG_INFO, "%s: WARNING: can't read memory for cycle count, rc=%d\n",
1147 progname, rc);
1148 return -1;
1149 }
1150 cycle_count = (cycle_count << 8) | v1;
1151 }
1152
1153 /*
1154 * If the EEPROM is erased, the cycle count reads 0xffffffff.
1155 * In this case we return a cycle_count of zero.
1156 * So, the calling function don't have to care about whether or not
1157 * the cycle count was initialized.
1158 */
1159 if (cycle_count == 0xffffffff) {
1160 cycle_count = 0;
1161 }
1162
1163 *cycles = (int) cycle_count;
1164
1165 return 0;
1166}
char * progname
Definition main.c:61
AVRMEM * avr_locate_mem(AVRPART *p, char *desc)
Definition avrpart.c:354
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670

References avr_locate_mem(), avrdude_message(), MSG_INFO, pgm, progname, and programmer_t::read_byte.

+ Here is the call graph for this function:

◆ avr_get_output()

int avr_get_output ( OPCODE op,
unsigned char *  res,
unsigned char *  data 
)
166{
167 int i, j, bit;
168 unsigned char value;
169 unsigned char mask;
170
171 for (i=0; i<32; i++) {
172 if (op->bit[i].type == AVR_CMDBIT_OUTPUT) {
173 j = 3 - i / 8;
174 bit = i % 8;
175 mask = 1 << bit;
176 value = ((res[j] & mask) >> bit) & 0x01;
177 value = value << op->bit[i].bitno;
178 if (value)
179 *data = *data | value;
180 else
181 *data = *data & ~value;
182 }
183 }
184
185 return 0;
186}
@ AVR_CMDBIT_OUTPUT
Definition libavrdude.h:167
int bitno
Definition libavrdude.h:186
CMDBIT bit[32]
Definition libavrdude.h:191
int type
Definition libavrdude.h:185
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195

References AVR_CMDBIT_OUTPUT, opcode::bit, cmdbit::bitno, and cmdbit::type.

Referenced by avr_read_byte_default().

+ Here is the caller graph for this function:

◆ avr_get_output_index()

int avr_get_output_index ( OPCODE op)
196{
197 int i, j;
198
199 for (i=0; i<32; i++) {
200 if (op->bit[i].type == AVR_CMDBIT_OUTPUT) {
201 j = 3 - i / 8;
202 return j;
203 }
204 }
205
206 return -1;
207}

References AVR_CMDBIT_OUTPUT, opcode::bit, and cmdbit::type.

Referenced by stk500isp_read_byte().

+ Here is the caller graph for this function:

◆ avr_initmem()

int avr_initmem ( AVRPART p)
270{
271 LNODEID ln;
272 AVRMEM * m;
273
274 for (ln=lfirst(p->mem); ln; ln=lnext(ln)) {
275 m = ldata(ln);
276 m->buf = (unsigned char *) malloc(m->size);
277 if (m->buf == NULL) {
278 avrdude_message(MSG_INFO, "%s: can't alloc buffer for %s size of %d bytes\n",
279 progname, m->desc, m->size);
280 return -1;
281 }
282 m->tags = (unsigned char *) malloc(m->size);
283 if (m->tags == NULL) {
284 avrdude_message(MSG_INFO, "%s: can't alloc buffer for %s size of %d bytes\n",
285 progname, m->desc, m->size);
286 return -1;
287 }
288 }
289
290 return 0;
291}
char desc[AVR_MEMDESCLEN]
Definition libavrdude.h:284

References avrdude_message(), avrmem::buf, avrmem::desc, ldata(), lfirst(), lnext(), malloc(), avrpart::mem, MSG_INFO, progname, avrmem::size, and avrmem::tags.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_locate_mem()

AVRMEM * avr_locate_mem ( AVRPART p,
char *  desc 
)
355{
356 AVRMEM * m, * match;
357 LNODEID ln;
358 int matches;
359 int l;
360
361 l = (int)strlen(desc);
362 matches = 0;
363 match = NULL;
364 for (ln=lfirst(p->mem); ln; ln=lnext(ln)) {
365 m = ldata(ln);
366 if (strncmp(desc, m->desc, l) == 0) {
367 match = m;
368 matches++;
369 }
370 }
371
372 if (matches == 1)
373 return match;
374
375 return NULL;
376}

References avrmem::desc, ldata(), lfirst(), lnext(), and avrpart::mem.

Referenced by avr_get_cycle_count(), avr_put_cycle_count(), avr_read(), avr_tpi_chip_erase(), avr_verify(), avr_write(), avrdude_main(), bitbang_chip_erase(), cmd_dump(), cmd_sig(), cmd_write(), do_op(), fileio(), jtag3_initialize(), jtagmkII_initialize(), safemode_readfuses(), safemode_writefuse(), stk500_initialize(), stk500v2_initialize(), stk600_xprog_chip_erase(), stk600_xprog_program_enable(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_mem_display()

void avr_mem_display ( const char *  prefix,
FILE *  f,
AVRMEM m,
int  type,
int  verbose 
)
381{
382 int i, j;
383 char * optr;
384
385 if (m == NULL) {
387 "%s Block Poll Page Polled\n"
388 "%sMemory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack\n"
389 "%s----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------\n",
390 prefix, prefix, prefix);
391 }
392 else {
393 if (verbose > 2) {
395 "%s Block Poll Page Polled\n"
396 "%sMemory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack\n"
397 "%s----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------\n",
398 prefix, prefix, prefix);
399 }
401 "%s%-11s %4d %5d %5d %4d %-6s %6d %4d %6d %5d %5d 0x%02x 0x%02x\n",
402 prefix, m->desc, m->mode, m->delay, m->blocksize, m->pollindex,
403 m->paged ? "yes" : "no",
404 m->size,
405 m->page_size,
406 m->num_pages,
407 m->min_write_delay,
408 m->max_write_delay,
409 m->readback[0],
410 m->readback[1]);
411 if (verbose > 4) {
412 avrdude_message(MSG_TRACE2, "%s Memory Ops:\n"
413 "%s Oeration Inst Bit Bit Type Bitno Value\n"
414 "%s ----------- -------- -------- ----- -----\n",
415 prefix, prefix, prefix);
416 for (i=0; i<AVR_OP_MAX; i++) {
417 if (m->op[i]) {
418 for (j=31; j>=0; j--) {
419 if (j==31)
420 optr = avr_op_str(i);
421 else
422 optr = " ";
424 "%s %-11s %8d %8s %5d %5d\n",
425 prefix, optr, j,
426 bittype(m->op[i]->bit[j].type),
427 m->op[i]->bit[j].bitno,
428 m->op[i]->bit[j].value);
429 }
430 }
431 }
432 }
433 }
434}
#define MSG_TRACE2
Definition avrdude.h:56
static char * avr_op_str(int op)
Definition avrpart.c:210
static char * bittype(int type)
Definition avrpart.c:230
int blocksize
Definition libavrdude.h:300
int value
Definition libavrdude.h:187
int pollindex
Definition libavrdude.h:302
int paged
Definition libavrdude.h:285
int mode
Definition libavrdude.h:298
int delay
Definition libavrdude.h:299
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183

References AVR_OP_MAX, avr_op_str(), avrdude_message(), opcode::bit, cmdbit::bitno, bittype(), avrmem::blocksize, avrmem::delay, avrmem::desc, avrmem::max_write_delay, avrmem::min_write_delay, avrmem::mode, MSG_INFO, MSG_TRACE2, avrmem::num_pages, avrmem::op, avrmem::page_size, avrmem::paged, avrmem::pollindex, avrmem::readback, avrmem::size, cmdbit::type, cmdbit::value, and verbose.

Referenced by avr_display().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_mem_hiaddr()

int avr_mem_hiaddr ( AVRMEM mem)
285{
286 int i, n;
287
288 /* return the highest non-0xff address regardless of how much
289 memory was read */
290 for (i=mem->size-1; i>0; i--) {
291 if (mem->buf[i] != 0xff) {
292 n = i+1;
293 if (n & 0x01)
294 return n+1;
295 else
296 return n;
297 }
298 }
299
300 return 0;
301}

References avrmem::buf, and avrmem::size.

Referenced by avr_read(), and fileio().

+ Here is the caller graph for this function:

◆ avr_new_memtype()

AVRMEM * avr_new_memtype ( void  )
249{
250 AVRMEM * m;
251
252 m = (AVRMEM *)malloc(sizeof(*m));
253 if (m == NULL) {
254 // avrdude_message(MSG_INFO, "avr_new_memtype(): out of memory\n");
255 // exit(1);
256 avrdude_oom("avr_new_memtype(): out of memory\n");
257 }
258
259 memset(m, 0, sizeof(*m));
260
261 return m;
262}

References avrdude_oom(), and malloc().

Referenced by avr_dup_mem(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_new_opcode()

OPCODE * avr_new_opcode ( void  )
34{
35 OPCODE * m;
36
37 m = (OPCODE *)malloc(sizeof(*m));
38 if (m == NULL) {
39 // avrdude_message(MSG_INFO, "avr_new_opcode(): out of memory\n");
40 // exit(1);
41 avrdude_oom("avr_new_opcode(): out of memory\n");
42 }
43
44 memset(m, 0, sizeof(*m));
45
46 return m;
47}
Definition libavrdude.h:190

References avrdude_oom(), and malloc().

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_new_part()

AVRPART * avr_new_part ( void  )
444{
445 AVRPART * p;
446
447 p = (AVRPART *)malloc(sizeof(AVRPART));
448 if (p == NULL) {
449 // avrdude_message(MSG_INFO, "new_part(): out of memory\n");
450 // exit(1);
451 avrdude_oom("new_part(): out of memory\n");
452 }
453
454 memset(p, 0, sizeof(*p));
455
456 p->id[0] = 0;
457 p->desc[0] = 0;
461 p->config_file[0] = 0;
462 p->lineno = 0;
463 memset(p->signature, 0xFF, 3);
465 p->ocdrev = -1;
466
467 p->mem = lcreat(NULL, 0);
468
469 return p;
470}
enum ctl_stack_t ctl_stack_type
Definition libavrdude.h:243
int ocdrev
Definition libavrdude.h:273
LISTID lcreat(void *liststruct, int poolsize)
Definition lists.c:410
char id[AVR_IDLEN]
Definition libavrdude.h:219
@ CTL_STACK_NONE
Definition libavrdude.h:176
char config_file[PATH_MAX]
Definition libavrdude.h:278
unsigned char signature[3]
Definition libavrdude.h:225
int lineno
Definition libavrdude.h:279
@ RESET_DEDICATED
Definition libavrdude.h:171
#define AVRPART_ENABLEPAGEPROGRAMMING
Definition libavrdude.h:200

References avrdude_oom(), AVRPART_ENABLEPAGEPROGRAMMING, AVRPART_PARALLELOK, AVRPART_SERIALOK, avrpart::config_file, CTL_STACK_NONE, avrpart::ctl_stack_type, avrpart::desc, avrpart::flags, avrpart::id, lcreat(), avrpart::lineno, malloc(), avrpart::mem, avrpart::ocdrev, PIN_AVR_SCK, RESET_DEDICATED, avrpart::reset_disposition, avrpart::retry_pulse, and avrpart::signature.

Referenced by avr_dup_part(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_pin_name()

const char * avr_pin_name ( int  pinname)

Returns the name of the pin as string.

Parameters
pinnamethe pinname which we want as string.
Returns
a string with the pinname, or <unknown> if pinname is invalid.
354 {
355 switch(pinname) {
356 case PPI_AVR_VCC : return "VCC";
357 case PPI_AVR_BUFF : return "BUFF";
358 case PIN_AVR_RESET : return "RESET";
359 case PIN_AVR_SCK : return "SCK";
360 case PIN_AVR_MOSI : return "MOSI";
361 case PIN_AVR_MISO : return "MISO";
362 case PIN_LED_ERR : return "ERRLED";
363 case PIN_LED_RDY : return "RDYLED";
364 case PIN_LED_PGM : return "PGMLED";
365 case PIN_LED_VFY : return "VFYLED";
366 default : return "<unknown>";
367 }
368}
@ PIN_LED_VFY
Definition libavrdude.h:362
@ PIN_LED_PGM
Definition libavrdude.h:361

References PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, PIN_LED_ERR, PIN_LED_PGM, PIN_LED_RDY, PIN_LED_VFY, PPI_AVR_BUFF, and PPI_AVR_VCC.

Referenced by avr_display(), and pins_check().

+ Here is the caller graph for this function:

◆ avr_put_cycle_count()

int avr_put_cycle_count ( PROGRAMMER pgm,
AVRPART p,
int  cycles 
)
1170{
1171 AVRMEM * a;
1172 unsigned char v1;
1173 int rc;
1174 int i;
1175
1176 a = avr_locate_mem(p, "eeprom");
1177 if (a == NULL) {
1178 return -1;
1179 }
1180
1181 for (i=1; i<=4; i++) {
1182 v1 = cycles & 0xff;
1183 cycles = cycles >> 8;
1184
1185 rc = avr_write_byte(pgm, p, a, a->size-i, v1);
1186 if (rc < 0) {
1187 avrdude_message(MSG_INFO, "%s: WARNING: can't write memory for cycle count, rc=%d\n",
1188 progname, rc);
1189 return -1;
1190 }
1191 }
1192
1193 return 0;
1194 }
int avr_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition avr.c:791

References avr_locate_mem(), avr_write_byte(), avrdude_message(), MSG_INFO, pgm, and progname.

+ Here is the call graph for this function:

◆ avr_read()

int avr_read ( PROGRAMMER pgm,
AVRPART p,
char *  memtype,
AVRPART v 
)
314{
315 unsigned long i, lastaddr;
316 unsigned char cmd[4];
317 AVRMEM * mem, * vmem = NULL;
318 int rc;
319
320 mem = avr_locate_mem(p, memtype);
321 if (v != NULL)
322 vmem = avr_locate_mem(v, memtype);
323 if (mem == NULL) {
324 avrdude_message(MSG_INFO, "No \"%s\" memory for part %s\n",
325 memtype, p->desc);
326 return -1;
327 }
328
329 /*
330 * start with all 0xff
331 */
332 memset(mem->buf, 0xff, mem->size);
333
334 /* supports "paged load" thru post-increment */
335 if ((p->flags & AVRPART_HAS_TPI) && mem->page_size != 0 &&
336 pgm->cmd_tpi != NULL) {
337
338 while (avr_tpi_poll_nvmbsy(pgm));
339
340 /* setup for read (NOOP) */
342
343 /* load bytes */
344 for (lastaddr = i = 0; i < (unsigned)mem->size; i++) {
346 if (vmem == NULL ||
347 (vmem->tags[i] & TAG_ALLOCATED) != 0)
348 {
349 if (lastaddr != i) {
350 /* need to setup new address */
352 lastaddr = i;
353 }
354 cmd[0] = TPI_CMD_SLD_PI;
355 rc = pgm->cmd_tpi(pgm, cmd, 1, mem->buf + i, 1);
356 lastaddr++;
357 if (rc == -1) {
358 avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i);
359 return -1;
360 }
361 }
362 report_progress(i, mem->size, NULL);
363 }
364 return avr_mem_hiaddr(mem);
365 }
366
367 if (pgm->paged_load != NULL && mem->page_size != 0) {
368 /*
369 * the programmer supports a paged mode read
370 */
371 int need_read, failure;
372 unsigned int pageaddr;
373 unsigned int npages, nread;
374
375 /* quickly scan number of pages to be written to first */
376 for (pageaddr = 0, npages = 0;
377 pageaddr < (unsigned)mem->size;
378 pageaddr += mem->page_size) {
379 /* check whether this page must be read */
380 for (i = pageaddr;
381 i < pageaddr + mem->page_size;
382 i++)
383 if (vmem == NULL /* no verify, read everything */ ||
384 (mem->tags[i] & TAG_ALLOCATED) != 0 /* verify, do only
385 read pages that
386 are needed in
387 input file */) {
388 npages++;
389 break;
390 }
391 }
392
393 for (pageaddr = 0, failure = 0, nread = 0;
394 !failure && pageaddr < (unsigned)mem->size;
395 pageaddr += mem->page_size) {
397 /* check whether this page must be read */
398 for (i = pageaddr, need_read = 0;
399 i < pageaddr + mem->page_size;
400 i++)
401 if (vmem == NULL /* no verify, read everything */ ||
402 (vmem->tags[i] & TAG_ALLOCATED) != 0 /* verify, do only
403 read pages that
404 are needed in
405 input file */) {
406 need_read = 1;
407 break;
408 }
409 if (need_read) {
410 rc = pgm->paged_load(pgm, p, mem, mem->page_size,
411 pageaddr, mem->page_size);
412 if (rc < 0)
413 /* paged load failed, fall back to byte-at-a-time read below */
414 failure = 1;
415 } else {
416 avrdude_message(MSG_DEBUG, "%s: avr_read(): skipping page %u: no interesting data\n",
417 progname, pageaddr / mem->page_size);
418 }
419 nread++;
420 report_progress(nread, npages, NULL);
421 }
422 if (!failure) {
423 if (strcasecmp(mem->desc, "flash") == 0 ||
424 strcasecmp(mem->desc, "application") == 0 ||
425 strcasecmp(mem->desc, "apptable") == 0 ||
426 strcasecmp(mem->desc, "boot") == 0)
427 return avr_mem_hiaddr(mem);
428 else
429 return mem->size;
430 }
431 /* else: fall back to byte-at-a-time write, for historical reasons */
432 }
433
434 if (strcmp(mem->desc, "signature") == 0) {
435 if (pgm->read_sig_bytes) {
436 return pgm->read_sig_bytes(pgm, p, mem);
437 }
438 }
439
440 for (i = 0; i < (unsigned)mem->size; i++) {
442 if (vmem == NULL ||
443 (vmem->tags[i] & TAG_ALLOCATED) != 0)
444 {
445 rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
446 if (rc != 0) {
447 avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i);
448 if (rc == -1)
449 avrdude_message(MSG_INFO, " read operation not supported for memory \"%s\"\n",
450 memtype);
451 return -2;
452 }
453 }
454 report_progress(i, mem->size, NULL);
455 }
456
457 if (strcasecmp(mem->desc, "flash") == 0 ||
458 strcasecmp(mem->desc, "application") == 0 ||
459 strcasecmp(mem->desc, "apptable") == 0 ||
460 strcasecmp(mem->desc, "boot") == 0)
461 return avr_mem_hiaddr(mem);
462 else
463 return i;
464}
int avr_mem_hiaddr(AVRMEM *mem)
Definition avr.c:284
void report_progress(int completed, int total, char *hdr)
Definition avr.c:1224
static int avr_tpi_setup_rw(PROGRAMMER *pgm, AVRMEM *mem, unsigned long addr, unsigned char nvmcmd)
Definition avr.c:154
int avr_tpi_poll_nvmbsy(PROGRAMMER *pgm)
Definition avr.c:44
#define MSG_DEBUG
Definition avrdude.h:54
#define TAG_ALLOCATED
Definition libavrdude.h:215
int page_size
Definition libavrdude.h:287
#define AVRPART_HAS_TPI
Definition libavrdude.h:206
#define RETURN_IF_CANCEL()
Definition libavrdude.h:733
int(* read_sig_bytes)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m)
Definition libavrdude.h:672
int(* paged_load)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:662
int(* cmd_tpi)(struct programmer_t *pgm, const unsigned char *cmd, int cmd_len, unsigned char res[], int res_len)
Definition libavrdude.h:653
struct command cmd[]
Definition term.c:94
#define TPI_CMD_SLD_PI
Definition tpi.h:42
#define TPI_NVMCMD_NO_OPERATION
Definition tpi.h:64
#define strcasecmp
Definition unistd.h:52

References avr_locate_mem(), avr_mem_hiaddr(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avrdude_message(), AVRPART_HAS_TPI, avrmem::buf, cmd, programmer_t::cmd_tpi, avrpart::desc, avrmem::desc, avrpart::flags, MSG_DEBUG, MSG_INFO, avrmem::page_size, programmer_t::paged_load, pgm, progname, programmer_t::read_byte, programmer_t::read_sig_bytes, report_progress(), RETURN_IF_CANCEL, avrmem::size, strcasecmp, TAG_ALLOCATED, avrmem::tags, TPI_CMD_SLD_PI, and TPI_NVMCMD_NO_OPERATION.

Referenced by avr_signature(), and do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_read_byte_default()

int avr_read_byte_default ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
185{
186 unsigned char cmd[4];
187 unsigned char res[4];
188 unsigned char data;
189 int r;
190 OPCODE * readop, * lext;
191
192 if (pgm->cmd == NULL) {
193 avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_read_byte_default() but does not\n"
194 "provide a cmd() method.\n",
195 progname, pgm->type);
196 return -1;
197 }
198
199 pgm->pgm_led(pgm, ON);
200 pgm->err_led(pgm, OFF);
201
202 if (p->flags & AVRPART_HAS_TPI) {
203 if (pgm->cmd_tpi == NULL) {
204 avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
205 progname, pgm->type);
206 return -1;
207 }
208
209 while (avr_tpi_poll_nvmbsy(pgm));
210
211 /* setup for read */
213
214 /* load byte */
215 cmd[0] = TPI_CMD_SLD;
216 r = pgm->cmd_tpi(pgm, cmd, 1, value, 1);
217 if (r == -1)
218 return -1;
219
220 return 0;
221 }
222
223 /*
224 * figure out what opcode to use
225 */
226 if (mem->op[AVR_OP_READ_LO]) {
227 if (addr & 0x00000001)
228 readop = mem->op[AVR_OP_READ_HI];
229 else
230 readop = mem->op[AVR_OP_READ_LO];
231 addr = addr / 2;
232 }
233 else {
234 readop = mem->op[AVR_OP_READ];
235 }
236
237 if (readop == NULL) {
238#if DEBUG
239 avrdude_message(MSG_INFO, "avr_read_byte(): operation not supported on memory type \"%s\"\n",
240 mem->desc);
241#endif
242 return -1;
243 }
244
245 /*
246 * If this device has a "load extended address" command, issue it.
247 */
248 lext = mem->op[AVR_OP_LOAD_EXT_ADDR];
249 if (lext != NULL) {
250 memset(cmd, 0, sizeof(cmd));
251
252 avr_set_bits(lext, cmd);
253 avr_set_addr(lext, cmd, addr);
254 r = pgm->cmd(pgm, cmd, res);
255 if (r < 0)
256 return r;
257 }
258
259 memset(cmd, 0, sizeof(cmd));
260
261 avr_set_bits(readop, cmd);
262 avr_set_addr(readop, cmd, addr);
263 r = pgm->cmd(pgm, cmd, res);
264 if (r < 0)
265 return r;
266 data = 0;
267 avr_get_output(readop, res, &data);
268
269 pgm->pgm_led(pgm, OFF);
270
271 *value = data;
272
273 return 0;
274}
int avr_get_output(OPCODE *op, unsigned char *res, unsigned char *data)
Definition avrpart.c:165
int avr_set_addr(OPCODE *op, unsigned char *cmd, unsigned long addr)
Definition avrpart.c:107
int avr_set_bits(OPCODE *op, unsigned char *cmd)
Definition avrpart.c:80
#define OFF
Definition libavrdude.h:585
#define ON
Definition libavrdude.h:584
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651
int(* pgm_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:641
int(* err_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:640
char type[PGM_TYPELEN]
Definition libavrdude.h:619
#define TPI_CMD_SLD
Definition tpi.h:41

References avr_get_output(), AVR_OP_LOAD_EXT_ADDR, AVR_OP_READ, AVR_OP_READ_HI, AVR_OP_READ_LO, avr_set_addr(), avr_set_bits(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avrdude_message(), AVRPART_HAS_TPI, programmer_t::cmd, cmd, programmer_t::cmd_tpi, avrmem::desc, programmer_t::err_led, avrpart::flags, MSG_INFO, OFF, ON, avrmem::op, pgm, programmer_t::pgm_led, progname, TPI_CMD_SLD, TPI_NVMCMD_NO_OPERATION, and programmer_t::type.

Referenced by avr910_read_byte(), buspirate_bb_initpgm(), buspirate_initpgm(), serbb_initpgm(), and stk500_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_set_addr()

int avr_set_addr ( OPCODE op,
unsigned char *  cmd,
unsigned long  addr 
)
108{
109 int i, j, bit;
110 unsigned long value;
111 unsigned char mask;
112
113 for (i=0; i<32; i++) {
114 if (op->bit[i].type == AVR_CMDBIT_ADDRESS) {
115 j = 3 - i / 8;
116 bit = i % 8;
117 mask = 1 << bit;
118 value = addr >> op->bit[i].bitno & 0x01;
119 if (value)
120 cmd[j] = cmd[j] | mask;
121 else
122 cmd[j] = cmd[j] & ~mask;
123 }
124 }
125
126 return 0;
127}
@ AVR_CMDBIT_ADDRESS
Definition libavrdude.h:165

References AVR_CMDBIT_ADDRESS, opcode::bit, cmdbit::bitno, cmd, and cmdbit::type.

Referenced by avr_read_byte_default(), avr_write_byte_default(), avr_write_page(), buspirate_paged_write(), stk500_loadaddr(), stk500isp_read_byte(), and stk500isp_write_byte().

+ Here is the caller graph for this function:

◆ avr_set_bits()

int avr_set_bits ( OPCODE op,
unsigned char *  cmd 
)
81{
82 int i, j, bit;
83 unsigned char mask;
84
85 for (i=0; i<32; i++) {
86 if (op->bit[i].type == AVR_CMDBIT_VALUE) {
87 j = 3 - i / 8;
88 bit = i % 8;
89 mask = 1 << bit;
90 if (op->bit[i].value)
91 cmd[j] = cmd[j] | mask;
92 else
93 cmd[j] = cmd[j] & ~mask;
94 }
95 }
96
97 return 0;
98}

References AVR_CMDBIT_VALUE, opcode::bit, cmd, cmdbit::type, and cmdbit::value.

Referenced by avr_read_byte_default(), avr_write_byte_default(), avr_write_page(), bitbang_chip_erase(), bitbang_program_enable(), buspirate_chip_erase(), buspirate_paged_write(), buspirate_program_enable(), stk500_chip_erase(), stk500_loadaddr(), stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_chip_erase(), stk500v2_paged_load(), stk500v2_paged_write(), and stk500v2_program_enable().

+ Here is the caller graph for this function:

◆ avr_set_input()

int avr_set_input ( OPCODE op,
unsigned char *  cmd,
unsigned char  data 
)
137{
138 int i, j, bit;
139 unsigned char value;
140 unsigned char mask;
141
142 for (i=0; i<32; i++) {
143 if (op->bit[i].type == AVR_CMDBIT_INPUT) {
144 j = 3 - i / 8;
145 bit = i % 8;
146 mask = 1 << bit;
147 value = data >> op->bit[i].bitno & 0x01;
148 if (value)
149 cmd[j] = cmd[j] | mask;
150 else
151 cmd[j] = cmd[j] & ~mask;
152 }
153 }
154
155 return 0;
156}
@ AVR_CMDBIT_INPUT
Definition libavrdude.h:166

References AVR_CMDBIT_INPUT, opcode::bit, cmdbit::bitno, cmd, and cmdbit::type.

Referenced by avr_write_byte_default(), buspirate_paged_write(), and stk500isp_write_byte().

+ Here is the caller graph for this function:

◆ avr_signature()

int avr_signature ( PROGRAMMER pgm,
AVRPART p 
)
1056{
1057 int rc;
1058
1059 report_progress(0,1,"Reading");
1060 rc = avr_read(pgm, p, "signature", 0);
1061 if (rc < 0) {
1062 avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n",
1063 progname, p->desc, rc);
1064 return -1;
1065 }
1066 report_progress(1,1,NULL);
1067
1068 return 0;
1069}
int avr_read(PROGRAMMER *pgm, AVRPART *p, char *memtype, AVRPART *v)
Definition avr.c:312

References avr_read(), avrdude_message(), avrpart::desc, MSG_INFO, pgm, progname, and report_progress().

Referenced by avrdude_main(), and cmd_sig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_tpi_chip_erase()

int avr_tpi_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
56{
57 int err;
58 AVRMEM *mem;
59
60 if (p->flags & AVRPART_HAS_TPI) {
61 pgm->pgm_led(pgm, ON);
62
63 /* Set Pointer Register */
64 mem = avr_locate_mem(p, "flash");
65 if (mem == NULL) {
66 avrdude_message(MSG_INFO, "No flash memory to erase for part %s\n",
67 p->desc);
68 return -1;
69 }
70
71 unsigned char cmd[] = {
72 /* write pointer register high byte */
73 (TPI_CMD_SSTPR | 0),
74 ((mem->offset & 0xFF) | 1),
75 /* and low byte */
76 (TPI_CMD_SSTPR | 1),
77 ((mem->offset >> 8) & 0xFF),
78 /* write CHIP_ERASE command to NVMCMD register */
81 /* write dummy value to start erase */
83 0xFF
84 };
85
86 while (avr_tpi_poll_nvmbsy(pgm));
87
88 err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
89 if(err)
90 return err;
91
92 while (avr_tpi_poll_nvmbsy(pgm));
93
94 pgm->pgm_led(pgm, OFF);
95
96 return 0;
97 } else {
98 avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
99 return -1;
100 }
101}
unsigned int offset
Definition libavrdude.h:289
#define TPI_CMD_SSTPR
Definition tpi.h:50
#define TPI_SIO_ADDR(x)
Definition tpi.h:54
#define TPI_IOREG_NVMCMD
Definition tpi.h:58
#define TPI_CMD_SST
Definition tpi.h:46
#define TPI_CMD_SOUT
Definition tpi.h:44
#define TPI_NVMCMD_CHIP_ERASE
Definition tpi.h:65

References __func__, avr_locate_mem(), avr_tpi_poll_nvmbsy(), avrdude_message(), AVRPART_HAS_TPI, cmd, programmer_t::cmd_tpi, avrpart::desc, avrpart::flags, MSG_INFO, OFF, avrmem::offset, ON, pgm, programmer_t::pgm_led, TPI_CMD_SOUT, TPI_CMD_SST, TPI_CMD_SSTPR, TPI_IOREG_NVMCMD, TPI_NVMCMD_CHIP_ERASE, and TPI_SIO_ADDR.

+ Here is the call graph for this function:

◆ avr_tpi_poll_nvmbsy()

int avr_tpi_poll_nvmbsy ( PROGRAMMER pgm)
45{
46 unsigned char cmd;
47 unsigned char res;
48
50 (void)pgm->cmd_tpi(pgm, &cmd, 1, &res, 1);
51 return (res & TPI_IOREG_NVMCSR_NVMBSY);
52}
#define TPI_CMD_SIN
Definition tpi.h:43
#define TPI_IOREG_NVMCSR
Definition tpi.h:57
#define TPI_IOREG_NVMCSR_NVMBSY
Definition tpi.h:61

References cmd, programmer_t::cmd_tpi, pgm, TPI_CMD_SIN, TPI_IOREG_NVMCSR, TPI_IOREG_NVMCSR_NVMBSY, TPI_SIO_ADDR, and void().

Referenced by avr_read(), avr_read_byte_default(), avr_tpi_chip_erase(), avr_write(), avr_write_byte_default(), and bitbang_chip_erase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_tpi_program_enable()

int avr_tpi_program_enable ( PROGRAMMER pgm,
AVRPART p,
unsigned char  guard_time 
)
105{
106 int err, retry;
107 unsigned char cmd[2];
108 unsigned char response;
109
110 if(p->flags & AVRPART_HAS_TPI) {
111 /* set guard time */
113 cmd[1] = guard_time;
114
115 err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
116 if(err)
117 return err;
118
119 /* read TPI ident reg */
121 err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
122 if (err || response != TPI_IDENT_CODE) {
123 avrdude_message(MSG_INFO, "TPIIR not correct\n");
124 return -1;
125 }
126
127 /* send SKEY command + SKEY */
128 err = pgm->cmd_tpi(pgm, tpi_skey_cmd, sizeof(tpi_skey_cmd), NULL, 0);
129 if(err)
130 return err;
131
132 /* check if device is ready */
133 for(retry = 0; retry < 10; retry++)
134 {
136 err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
137 if(err || !(response & TPI_REG_TPISR_NVMEN))
138 continue;
139
140 return 0;
141 }
142
143 avrdude_message(MSG_INFO, "Error enabling TPI external programming mode:");
144 avrdude_message(MSG_INFO, "Target does not reply\n");
145 return -1;
146
147 } else {
148 avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
149 return -1;
150 }
151}
#define TPI_REG_TPIPCR
Definition tpi.h:35
#define TPI_CMD_SLDCS
Definition tpi.h:49
#define TPI_REG_TPIIR
Definition tpi.h:31
#define TPI_IDENT_CODE
Definition tpi.h:33
static const unsigned char tpi_skey_cmd[]
Definition tpi.h:69
#define TPI_REG_TPISR_NVMEN
Definition tpi.h:38
#define TPI_REG_TPISR
Definition tpi.h:36
#define TPI_CMD_SSTCS
Definition tpi.h:45

References __func__, avrdude_message(), AVRPART_HAS_TPI, cmd, programmer_t::cmd_tpi, avrpart::flags, MSG_INFO, pgm, TPI_CMD_SLDCS, TPI_CMD_SSTCS, TPI_IDENT_CODE, TPI_REG_TPIIR, TPI_REG_TPIPCR, TPI_REG_TPISR, TPI_REG_TPISR_NVMEN, and tpi_skey_cmd.

+ Here is the call graph for this function:

◆ avr_verify()

int avr_verify ( AVRPART p,
AVRPART v,
char *  memtype,
int  size 
)
1080{
1081 int i;
1082 unsigned char * buf1, * buf2;
1083 int vsize;
1084 AVRMEM * a, * b;
1085
1086 a = avr_locate_mem(p, memtype);
1087 if (a == NULL) {
1088 avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
1089 memtype, p->desc);
1090 return -1;
1091 }
1092
1093 b = avr_locate_mem(v, memtype);
1094 if (b == NULL) {
1095 avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
1096 memtype, v->desc);
1097 return -1;
1098 }
1099
1100 buf1 = a->buf;
1101 buf2 = b->buf;
1102 vsize = a->size;
1103
1104 if (vsize < size) {
1105 avrdude_message(MSG_INFO, "%s: WARNING: requested verification for %d bytes\n"
1106 "%s%s memory region only contains %d bytes\n"
1107 "%sOnly %d bytes will be verified.\n",
1108 progname, size,
1109 progbuf, memtype, vsize,
1110 progbuf, vsize);
1111 size = vsize;
1112 }
1113
1114 for (i=0; i<size; i++) {
1116 if ((b->tags[i] & TAG_ALLOCATED) != 0 &&
1117 buf1[i] != buf2[i]) {
1118 avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n"
1119 "%s0x%02x != 0x%02x\n",
1120 progname, i,
1121 progbuf, buf1[i], buf2[i]);
1122 return -1;
1123 }
1124 }
1125
1126 return size;
1127}
char progbuf[]
Definition main.c:62

References avr_locate_mem(), avrdude_message(), avrpart::desc, MSG_INFO, progbuf, progname, RETURN_IF_CANCEL, and TAG_ALLOCATED.

Referenced by do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write()

int avr_write ( PROGRAMMER pgm,
AVRPART p,
char *  memtype,
int  size,
int  auto_erase 
)
833{
834 int rc;
835 int newpage, page_tainted, flush_page, do_write;
836 int wsize;
837 unsigned int i, lastaddr;
838 unsigned char data;
839 int werror;
840 unsigned char cmd[4];
841 AVRMEM * m;
842
843 m = avr_locate_mem(p, memtype);
844 if (m == NULL) {
845 avrdude_message(MSG_INFO, "No \"%s\" memory for part %s\n",
846 memtype, p->desc);
847 return -1;
848 }
849
850 pgm->err_led(pgm, OFF);
851
852 werror = 0;
853
854 wsize = m->size;
855 if (size < wsize) {
856 wsize = size;
857 }
858 else if (size > wsize) {
859 avrdude_message(MSG_INFO, "%s: WARNING: %d bytes requested, but memory region is only %d"
860 "bytes\n"
861 "%sOnly %d bytes will actually be written\n",
862 progname, size, wsize,
863 progbuf, wsize);
864 }
865
866
867 if ((p->flags & AVRPART_HAS_TPI) && m->page_size != 0 &&
868 pgm->cmd_tpi != NULL) {
869
870 while (avr_tpi_poll_nvmbsy(pgm));
871
872 /* setup for WORD_WRITE */
874
875 /* make sure it's aligned to a word boundary */
876 if (wsize & 0x1) {
877 wsize++;
878 }
879
880 /* write words, low byte first */
881 for (lastaddr = i = 0; i < (unsigned)wsize; i += 2) {
883 if ((m->tags[i] & TAG_ALLOCATED) != 0 ||
884 (m->tags[i + 1] & TAG_ALLOCATED) != 0) {
885
886 if (lastaddr != i) {
887 /* need to setup new address */
889 lastaddr = i;
890 }
891
892 cmd[0] = TPI_CMD_SST_PI;
893 cmd[1] = m->buf[i];
894 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
895
896 cmd[1] = m->buf[i + 1];
897 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
898
899 lastaddr += 2;
900
901 while (avr_tpi_poll_nvmbsy(pgm));
902 }
903 report_progress(i, wsize, NULL);
904 }
905 return i;
906 }
907
908 if (pgm->paged_write != NULL && m->page_size != 0) {
909 /*
910 * the programmer supports a paged mode write
911 */
912 int need_write, failure;
913 unsigned int pageaddr;
914 unsigned int npages, nwritten;
915
916 /* quickly scan number of pages to be written to first */
917 for (pageaddr = 0, npages = 0;
918 pageaddr < (unsigned)wsize;
919 pageaddr += m->page_size) {
920 /* check whether this page must be written to */
921 for (i = pageaddr;
922 i < pageaddr + m->page_size;
923 i++)
924 if ((m->tags[i] & TAG_ALLOCATED) != 0) {
925 npages++;
926 break;
927 }
928 }
929
930 for (pageaddr = 0, failure = 0, nwritten = 0;
931 !failure && pageaddr < (unsigned)wsize;
932 pageaddr += m->page_size) {
934 /* check whether this page must be written to */
935 for (i = pageaddr, need_write = 0;
936 i < pageaddr + m->page_size;
937 i++)
938 if ((m->tags[i] & TAG_ALLOCATED) != 0) {
939 need_write = 1;
940 break;
941 }
942 if (need_write) {
943 rc = 0;
944 if (auto_erase)
945 rc = pgm->page_erase(pgm, p, m, pageaddr);
946 if (rc >= 0)
947 rc = pgm->paged_write(pgm, p, m, m->page_size, pageaddr, m->page_size);
948 if (rc < 0)
949 /* paged write failed, fall back to byte-at-a-time write below */
950 failure = 1;
951 } else {
952 avrdude_message(MSG_DEBUG, "%s: avr_write(): skipping page %u: no interesting data\n",
953 progname, pageaddr / m->page_size);
954 }
955 nwritten++;
956 report_progress(nwritten, npages, NULL);
957 }
958 if (!failure)
959 return wsize;
960 /* else: fall back to byte-at-a-time write, for historical reasons */
961 }
962
963 if (pgm->write_setup) {
964 pgm->write_setup(pgm, p, m);
965 }
966
967 newpage = 1;
968 page_tainted = 0;
969 flush_page = 0;
970
971 for (i = 0; i < (unsigned)wsize; i++) {
973 data = m->buf[i];
974 report_progress(i, wsize, NULL);
975
976 /*
977 * Find out whether the write action must be invoked for this
978 * byte.
979 *
980 * For non-paged memory, this only happens if TAG_ALLOCATED is
981 * set for the byte.
982 *
983 * For paged memory, TAG_ALLOCATED also invokes the write
984 * operation, which is actually a page buffer fill only. This
985 * "taints" the page, and upon encountering the last byte of each
986 * tainted page, the write operation must also be invoked in order
987 * to actually write the page buffer to memory.
988 */
989 do_write = (m->tags[i] & TAG_ALLOCATED) != 0;
990 if (m->paged) {
991 if (newpage) {
992 page_tainted = do_write;
993 } else {
994 page_tainted |= do_write;
995 }
996 if (i % m->page_size == m->page_size - 1 ||
997 i == wsize - 1) {
998 /* last byte this page */
999 flush_page = page_tainted;
1000 newpage = 1;
1001 } else {
1002 flush_page = newpage = 0;
1003 }
1004 }
1005
1006 if (!do_write && !flush_page) {
1007 continue;
1008 }
1009
1010 if (do_write) {
1011 rc = avr_write_byte(pgm, p, m, i, data);
1012 if (rc) {
1013 avrdude_message(MSG_INFO, " ***failed; ");
1015 pgm->err_led(pgm, ON);
1016 werror = 1;
1017 }
1018 }
1019
1020 /*
1021 * check to see if it is time to flush the page with a page
1022 * write
1023 */
1024 if (flush_page) {
1025 rc = avr_write_page(pgm, p, m, i);
1026 if (rc) {
1027 avrdude_message(MSG_INFO, " *** page %d (addresses 0x%04x - 0x%04x) failed "
1028 "to write\n",
1029 i % m->page_size,
1030 i - m->page_size + 1, i);
1032 pgm->err_led(pgm, ON);
1033 werror = 1;
1034 }
1035 }
1036
1037 if (werror) {
1038 /*
1039 * make sure the error led stay on if there was a previous write
1040 * error, otherwise it gets cleared in avr_write_byte()
1041 */
1042 pgm->err_led(pgm, ON);
1043 return -1;
1044 }
1045 }
1046
1047 return i;
1048}
int avr_write_page(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr)
Definition avr.c:470
int(* paged_write)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:659
void(* write_setup)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m)
Definition libavrdude.h:667
int(* page_erase)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int baseaddr)
Definition libavrdude.h:665
#define TPI_NVMCMD_WORD_WRITE
Definition tpi.h:67
#define TPI_CMD_SST_PI
Definition tpi.h:47

References avr_locate_mem(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avr_write_byte(), avr_write_page(), avrdude_message(), AVRPART_HAS_TPI, avrmem::buf, cmd, programmer_t::cmd_tpi, avrpart::desc, programmer_t::err_led, avrpart::flags, MSG_DEBUG, MSG_INFO, OFF, ON, programmer_t::page_erase, avrmem::page_size, avrmem::paged, programmer_t::paged_write, pgm, progbuf, progname, report_progress(), RETURN_IF_CANCEL, avrmem::size, TAG_ALLOCATED, avrmem::tags, TPI_CMD_SST_PI, TPI_NVMCMD_WORD_WRITE, and programmer_t::write_setup.

Referenced by do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write_byte()

int avr_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
793{
794
795 unsigned char safemode_lfuse;
796 unsigned char safemode_hfuse;
797 unsigned char safemode_efuse;
798 unsigned char safemode_fuse;
799
800 /* If we write the fuses, then we need to tell safemode that they *should* change */
801 safemode_memfuses(0, &safemode_lfuse, &safemode_hfuse, &safemode_efuse, &safemode_fuse);
802
803 if (strcmp(mem->desc, "fuse")==0) {
804 safemode_fuse = data;
805 }
806 if (strcmp(mem->desc, "lfuse")==0) {
807 safemode_lfuse = data;
808 }
809 if (strcmp(mem->desc, "hfuse")==0) {
810 safemode_hfuse = data;
811 }
812 if (strcmp(mem->desc, "efuse")==0) {
813 safemode_efuse = data;
814 }
815
816 safemode_memfuses(1, &safemode_lfuse, &safemode_hfuse, &safemode_efuse, &safemode_fuse);
817
818 return pgm->write_byte(pgm, p, mem, addr, data);
819}
int(* write_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition libavrdude.h:668

References avrmem::desc, pgm, safemode_memfuses(), and programmer_t::write_byte.

Referenced by avr_put_cycle_count(), avr_write(), cmd_write(), and safemode_writefuse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write_byte_default()

int avr_write_byte_default ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
532{
533 unsigned char cmd[4];
534 unsigned char res[4];
535 unsigned char r;
536 int ready;
537 int tries;
538 unsigned long start_time;
539 unsigned long prog_time;
540 unsigned char b;
541 unsigned short caddr;
542 OPCODE * writeop;
543 int rc;
544 int readok=0;
545 struct timeval tv;
546
547 if (pgm->cmd == NULL) {
548 avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_byte_default() but does not\n"
549 "provide a cmd() method.\n",
550 progname, pgm->type);
551 return -1;
552 }
553
554 if (p->flags & AVRPART_HAS_TPI) {
555 if (pgm->cmd_tpi == NULL) {
556 avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
557 progname, pgm->type);
558 return -1;
559 }
560
561 if (strcmp(mem->desc, "flash") == 0) {
562 avrdude_message(MSG_INFO, "Writing a byte to flash is not supported for %s\n", p->desc);
563 return -1;
564 } else if ((mem->offset + addr) & 1) {
565 avrdude_message(MSG_INFO, "Writing a byte to an odd location is not supported for %s\n", p->desc);
566 return -1;
567 }
568
569 while (avr_tpi_poll_nvmbsy(pgm));
570
571 /* must erase fuse first */
572 if (strcmp(mem->desc, "fuse") == 0) {
573 /* setup for SECTION_ERASE (high byte) */
575
576 /* write dummy byte */
577 cmd[0] = TPI_CMD_SST;
578 cmd[1] = 0xFF;
579 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
580
581 while (avr_tpi_poll_nvmbsy(pgm));
582 }
583
584 /* setup for WORD_WRITE */
586
587 cmd[0] = TPI_CMD_SST_PI;
588 cmd[1] = data;
589 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
590 /* dummy high byte to start WORD_WRITE */
591 cmd[0] = TPI_CMD_SST_PI;
592 cmd[1] = data;
593 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
594
595 while (avr_tpi_poll_nvmbsy(pgm));
596
597 return 0;
598 }
599
600 if (!mem->paged &&
601 (p->flags & AVRPART_IS_AT90S1200) == 0) {
602 /*
603 * check to see if the write is necessary by reading the existing
604 * value and only write if we are changing the value; we can't
605 * use this optimization for paged addressing.
606 *
607 * For mysterious reasons, on the AT90S1200, this read operation
608 * sometimes causes the high byte of the same word to be
609 * programmed to the value of the low byte that has just been
610 * programmed before. Avoid that optimization on this device.
611 */
612 rc = pgm->read_byte(pgm, p, mem, addr, &b);
613 if (rc != 0) {
614 if (rc != -1) {
615 return -2;
616 }
617 /*
618 * the read operation is not support on this memory type
619 */
620 }
621 else {
622 readok = 1;
623 if (b == data) {
624 return 0;
625 }
626 }
627 }
628
629 /*
630 * determine which memory opcode to use
631 */
632 if (mem->op[AVR_OP_WRITE_LO]) {
633 if (addr & 0x01)
634 writeop = mem->op[AVR_OP_WRITE_HI];
635 else
636 writeop = mem->op[AVR_OP_WRITE_LO];
637 caddr = (unsigned short)(addr / 2);
638 }
639 else if (mem->paged && mem->op[AVR_OP_LOADPAGE_LO]) {
640 if (addr & 0x01)
641 writeop = mem->op[AVR_OP_LOADPAGE_HI];
642 else
643 writeop = mem->op[AVR_OP_LOADPAGE_LO];
644 caddr = (unsigned short)(addr / 2);
645 }
646 else {
647 writeop = mem->op[AVR_OP_WRITE];
648 caddr = (unsigned short)addr;
649 }
650
651 if (writeop == NULL) {
652#if DEBUG
653 avrdude_message(MSG_INFO, "avr_write_byte(): write not supported for memory type \"%s\"\n",
654 mem->desc);
655#endif
656 return -1;
657 }
658
659
660 pgm->pgm_led(pgm, ON);
661 pgm->err_led(pgm, OFF);
662
663 memset(cmd, 0, sizeof(cmd));
664
665 avr_set_bits(writeop, cmd);
666 avr_set_addr(writeop, cmd, caddr);
667 avr_set_input(writeop, cmd, data);
668 pgm->cmd(pgm, cmd, res);
669
670 if (mem->paged) {
671 /*
672 * in paged addressing, single bytes to be written to the memory
673 * page complete immediately, we only need to delay when we commit
674 * the whole page via the avr_write_page() routine.
675 */
676 pgm->pgm_led(pgm, OFF);
677 return 0;
678 }
679
680 if (readok == 0) {
681 /*
682 * read operation not supported for this memory type, just wait
683 * the max programming time and then return
684 */
685 usleep(mem->max_write_delay); /* maximum write delay */
686 pgm->pgm_led(pgm, OFF);
687 return 0;
688 }
689
690 tries = 0;
691 ready = 0;
692 while (!ready) {
693
694 if ((data == mem->readback[0]) ||
695 (data == mem->readback[1])) {
696 /*
697 * use an extra long delay when we happen to be writing values
698 * used for polled data read-back. In this case, polling
699 * doesn't work, and we need to delay the worst case write time
700 * specified for the chip.
701 */
703 rc = pgm->read_byte(pgm, p, mem, addr, &r);
704 if (rc != 0) {
705 pgm->pgm_led(pgm, OFF);
706 pgm->err_led(pgm, OFF);
707 return -5;
708 }
709 }
710 else {
711 gettimeofday (&tv, NULL);
712 start_time = (tv.tv_sec * 1000000) + tv.tv_usec;
713 do {
714 /*
715 * Do polling, but timeout after max_write_delay.
716 */
717 rc = pgm->read_byte(pgm, p, mem, addr, &r);
718 if (rc != 0) {
719 pgm->pgm_led(pgm, OFF);
720 pgm->err_led(pgm, ON);
721 return -4;
722 }
723 gettimeofday (&tv, NULL);
724 prog_time = (tv.tv_sec * 1000000) + tv.tv_usec;
725 } while ((r != data) &&
726 ((prog_time - start_time) < (unsigned long)mem->max_write_delay));
727 }
728
729 /*
730 * At this point we either have a valid readback or the
731 * max_write_delay is expired.
732 */
733
734 if (r == data) {
735 ready = 1;
736 }
737 else if (mem->pwroff_after_write) {
738 /*
739 * The device has been flagged as power-off after write to this
740 * memory type. The reason we don't just blindly follow the
741 * flag is that the power-off advice may only apply to some
742 * memory bits but not all. We only actually power-off the
743 * device if the data read back does not match what we wrote.
744 */
745 pgm->pgm_led(pgm, OFF);
746 avrdude_message(MSG_INFO, "%s: this device must be powered off and back on to continue\n",
747 progname);
748 if (pgm->pinno[PPI_AVR_VCC]) {
749 avrdude_message(MSG_INFO, "%s: attempting to do this now ...\n", progname);
750 pgm->powerdown(pgm);
751 usleep(250000);
752 rc = pgm->initialize(pgm, p);
753 if (rc < 0) {
754 avrdude_message(MSG_INFO, "%s: initialization failed, rc=%d\n", progname, rc);
755 avrdude_message(MSG_INFO, "%s: can't re-initialize device after programming the "
756 "%s bits\n", progname, mem->desc);
757 avrdude_message(MSG_INFO, "%s: you must manually power-down the device and restart\n"
758 "%s: %s to continue.\n",
760 return -3;
761 }
762
763 avrdude_message(MSG_INFO, "%s: device was successfully re-initialized\n",
764 progname);
765 return 0;
766 }
767 }
768
769 tries++;
770 if (!ready && tries > 5) {
771 /*
772 * we wrote the data, but after waiting for what should have
773 * been plenty of time, the memory cell still doesn't match what
774 * we wrote. Indicate a write error.
775 */
776 pgm->pgm_led(pgm, OFF);
777 pgm->err_led(pgm, ON);
778
779 return -6;
780 }
781 }
782
783 pgm->pgm_led(pgm, OFF);
784 return 0;
785}
int avr_set_input(OPCODE *op, unsigned char *cmd, unsigned char data)
Definition avrpart.c:136
#define AVRPART_IS_AT90S1200
Definition libavrdude.h:207
unsigned char readback[2]
Definition libavrdude.h:296
int max_write_delay
Definition libavrdude.h:291
int pwroff_after_write
Definition libavrdude.h:292
unsigned int pinno[N_PINS]
Definition libavrdude.h:622
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
void(* powerdown)(struct programmer_t *pgm)
Definition libavrdude.h:648
#define TPI_NVMCMD_SECTION_ERASE
Definition tpi.h:66
int usleep(unsigned usec)
Definition unistd.cpp:13
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition unistd.cpp:21

References AVR_OP_LOADPAGE_HI, AVR_OP_LOADPAGE_LO, AVR_OP_WRITE, AVR_OP_WRITE_HI, AVR_OP_WRITE_LO, avr_set_addr(), avr_set_bits(), avr_set_input(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avrdude_message(), AVRPART_HAS_TPI, AVRPART_IS_AT90S1200, programmer_t::cmd, cmd, programmer_t::cmd_tpi, avrpart::desc, avrmem::desc, programmer_t::err_led, avrpart::flags, gettimeofday(), programmer_t::initialize, avrmem::max_write_delay, MSG_INFO, OFF, avrmem::offset, ON, avrmem::op, avrmem::paged, pgm, programmer_t::pgm_led, programmer_t::pinno, programmer_t::powerdown, PPI_AVR_VCC, progname, avrmem::pwroff_after_write, programmer_t::read_byte, avrmem::readback, TPI_CMD_SST, TPI_CMD_SST_PI, TPI_NVMCMD_SECTION_ERASE, TPI_NVMCMD_WORD_WRITE, programmer_t::type, and usleep().

Referenced by avr910_write_byte(), buspirate_bb_initpgm(), buspirate_initpgm(), serbb_initpgm(), and stk500_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write_page()

int avr_write_page ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr 
)
472{
473 unsigned char cmd[4];
474 unsigned char res[4];
475 OPCODE * wp, * lext;
476
477 if (pgm->cmd == NULL) {
478 avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_page() but does not\n"
479 "provide a cmd() method.\n",
480 progname, pgm->type);
481 return -1;
482 }
483
484 wp = mem->op[AVR_OP_WRITEPAGE];
485 if (wp == NULL) {
486 avrdude_message(MSG_INFO, "avr_write_page(): memory \"%s\" not configured for page writes\n",
487 mem->desc);
488 return -1;
489 }
490
491 /*
492 * if this memory is word-addressable, adjust the address
493 * accordingly
494 */
495 if ((mem->op[AVR_OP_LOADPAGE_LO]) || (mem->op[AVR_OP_READ_LO]))
496 addr = addr / 2;
497
498 pgm->pgm_led(pgm, ON);
499 pgm->err_led(pgm, OFF);
500
501 /*
502 * If this device has a "load extended address" command, issue it.
503 */
504 lext = mem->op[AVR_OP_LOAD_EXT_ADDR];
505 if (lext != NULL) {
506 memset(cmd, 0, sizeof(cmd));
507
508 avr_set_bits(lext, cmd);
509 avr_set_addr(lext, cmd, addr);
510 pgm->cmd(pgm, cmd, res);
511 }
512
513 memset(cmd, 0, sizeof(cmd));
514
515 avr_set_bits(wp, cmd);
516 avr_set_addr(wp, cmd, addr);
517 pgm->cmd(pgm, cmd, res);
518
519 /*
520 * since we don't know what voltage the target AVR is powered by, be
521 * conservative and delay the max amount the spec says to wait
522 */
524
525 pgm->pgm_led(pgm, OFF);
526 return 0;
527}

References AVR_OP_LOAD_EXT_ADDR, AVR_OP_LOADPAGE_LO, AVR_OP_READ_LO, AVR_OP_WRITEPAGE, avr_set_addr(), avr_set_bits(), avrdude_message(), programmer_t::cmd, cmd, avrmem::desc, programmer_t::err_led, avrmem::max_write_delay, MSG_INFO, OFF, ON, avrmem::op, pgm, programmer_t::pgm_led, progname, programmer_t::type, and usleep().

Referenced by avr_write(), and buspirate_paged_write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanup_config()

void cleanup_config ( void  )
62{
63 ldestroy_cb(part_list, (void(*)(void*))avr_free_part);
64 ldestroy_cb(programmers, (void(*)(void*))pgm_free);
65 ldestroy_cb(string_list, (void(*)(void*))free_token);
66 ldestroy_cb(number_list, (void(*)(void*))free_token);
67}
void avr_free_part(AVRPART *d)
Definition avrpart.c:498
LISTID number_list
Definition config.c:47
LISTID part_list
Definition config.c:51
LISTID string_list
Definition config.c:46
LISTID programmers
Definition config.c:52
void free_token(TOKEN *tkn)
Definition config.c:145
void pgm_free(PROGRAMMER *const p)
Definition pgm.c:141

References avr_free_part(), free_token(), ldestroy_cb(), number_list, part_list, pgm_free(), programmers, and string_list.

Referenced by cleanup_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_op()

int do_op ( PROGRAMMER pgm,
struct avrpart p,
UPDATE upd,
enum updateflags  flags 
)
238{
239 struct avrpart * v;
240 AVRMEM * mem;
241 int size, vsize;
242 int rc;
243
244 mem = avr_locate_mem(p, upd->memtype);
245 if (mem == NULL) {
246 avrdude_message(MSG_INFO, "\"%s\" memory type not defined for part \"%s\"\n",
247 upd->memtype, p->desc);
248 return -1;
249 }
250
251 if (upd->op == DEVICE_READ) {
252 /*
253 * read out the specified device memory and write it to a file
254 */
255 if (quell_progress < 2) {
256 avrdude_message(MSG_INFO, "%s: reading %s memory:\n",
257 progname, mem->desc);
258 }
259 report_progress(0,1,"Reading");
260 rc = avr_read(pgm, p, upd->memtype, 0);
261 if (rc < 0) {
262 avrdude_message(MSG_INFO, "%s: failed to read all of %s memory, rc=%d\n",
263 progname, mem->desc, rc);
264 return -1;
265 }
266 report_progress(1,1,NULL);
267 size = rc;
268
269 if (quell_progress < 2) {
270 if (rc == 0)
271 avrdude_message(MSG_INFO, "%s: Flash is empty, resulting file has no contents.\n",
272 progname);
273 avrdude_message(MSG_INFO, "%s: writing output file \"%s\"\n",
274 progname,
275 strcmp(upd->filename, "-")==0 ? "<stdout>" : upd->filename);
276 }
277 rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size, 0);
278 if (rc < 0) {
279 avrdude_message(MSG_INFO, "%s: write to file '%s' failed\n",
280 progname, upd->filename);
281 return -1;
282 }
283 }
284 else if (upd->op == DEVICE_WRITE) {
285 /*
286 * write the selected device memory using data from a file; first
287 * read the data from the specified file
288 */
289 if (quell_progress < 2) {
290 avrdude_message(MSG_INFO, "%s: reading input file \"%s\"\n",
291 progname,
292 strcmp(upd->filename, "-")==0 ? "<stdin>" : upd->filename);
293 }
294 rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1, upd->section);
295 if (rc < 0) {
296 avrdude_message(MSG_INFO, "%s: read from file '%s' failed\n",
297 progname, upd->filename);
298 return -1;
299 }
300 size = rc;
301
302 /*
303 * write the buffer contents to the selected memory type
304 */
305 if (quell_progress < 2) {
306 avrdude_message(MSG_INFO, "%s: writing %s (%d bytes):\n",
307 progname, mem->desc, size);
308 }
309
310 //Prusa3D bootloader progress on lcd
311 if (strcmp(pgm->type, "Wiring") == 0)
312 {
313 if (pgm->set_upload_size != 0)
314 pgm->set_upload_size(pgm, size);
315 }
316
317 if (!(flags & UF_NOWRITE)) {
318 report_progress(0,1,"Writing");
319 rc = avr_write(pgm, p, upd->memtype, size, (flags & UF_AUTO_ERASE) != 0);
320 report_progress(1,1,NULL);
321 }
322 else {
323 // /*
324 // * test mode, don't actually write to the chip, output the buffer
325 // * to stdout in intel hex instead
326 // */
327 // rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, upd->memtype, size, 0);
328 }
329
330 if (rc < 0) {
331 avrdude_message(MSG_INFO, "%s: failed to write %s memory, rc=%d\n",
332 progname, mem->desc, rc);
333 return -1;
334 }
335
336 vsize = rc;
337
338 if (quell_progress < 2) {
339 avrdude_message(MSG_INFO, "%s: %d bytes of %s written\n", progname,
340 vsize, mem->desc);
341 }
342
343 }
344 else if (upd->op == DEVICE_VERIFY) {
345 /*
346 * verify that the in memory file (p->mem[AVR_M_FLASH|AVR_M_EEPROM])
347 * is the same as what is on the chip
348 */
349 pgm->vfy_led(pgm, ON);
350
351 if (quell_progress < 2) {
352 avrdude_message(MSG_INFO, "%s: verifying %s memory against %s:\n",
353 progname, mem->desc, upd->filename);
354
355 avrdude_message(MSG_INFO, "%s: load data %s data from input file %s:\n",
356 progname, mem->desc, upd->filename);
357 }
358
359 rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1, upd->section);
360 if (rc < 0) {
361 avrdude_message(MSG_INFO, "%s: read from file '%s' failed\n",
362 progname, upd->filename);
363 return -1;
364 }
365 v = avr_dup_part(p);
366 size = rc;
367 if (quell_progress < 2) {
368 avrdude_message(MSG_INFO, "%s: input file %s contains %d bytes\n",
369 progname, upd->filename, size);
370 avrdude_message(MSG_INFO, "%s: reading on-chip %s data:\n",
371 progname, mem->desc);
372 }
373
374 report_progress (0,1,"Reading");
375 rc = avr_read(pgm, p, upd->memtype, v);
376 if (rc < 0) {
377 avrdude_message(MSG_INFO, "%s: failed to read all of %s memory, rc=%d\n",
378 progname, mem->desc, rc);
379 pgm->err_led(pgm, ON);
380 return -1;
381 }
382 report_progress (1,1,NULL);
383
384
385
386 if (quell_progress < 2) {
387 avrdude_message(MSG_INFO, "%s: verifying ...\n", progname);
388 }
389 rc = avr_verify(p, v, upd->memtype, size);
390 if (rc < 0) {
391 avrdude_message(MSG_INFO, "%s: verification error; content mismatch\n",
392 progname);
393 pgm->err_led(pgm, ON);
394 return -1;
395 }
396
397 if (quell_progress < 2) {
398 avrdude_message(MSG_INFO, "%s: %d bytes of %s verified\n",
399 progname, rc, mem->desc);
400 }
401
402 pgm->vfy_led(pgm, OFF);
403 }
404 else {
405 avrdude_message(MSG_INFO, "%s: invalid update operation (%d) requested\n",
406 progname, upd->op);
407 return -1;
408 }
409
410 return 0;
411}
int avr_write(PROGRAMMER *pgm, AVRPART *p, char *memtype, int size, int auto_erase)
Definition avr.c:831
int avr_verify(AVRPART *p, AVRPART *v, char *memtype, int size)
Definition avr.c:1079
int quell_progress
Definition main.c:199
AVRPART * avr_dup_part(AVRPART *d)
Definition avrpart.c:473
int fileio(int op, char *filename, FILEFMT format, struct avrpart *p, char *memtype, int size, unsigned section)
Definition fileio.c:1512
int(* vfy_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:642
void(* set_upload_size)(struct programmer_t *pgm, int size)
Definition libavrdude.h:686

References avr_dup_part(), avr_locate_mem(), avr_read(), avr_verify(), avr_write(), avrdude_message(), avrpart::desc, DEVICE_READ, DEVICE_VERIFY, DEVICE_WRITE, programmer_t::err_led, fileio(), update_t::filename, FIO_READ, FIO_WRITE, avrpart::flags, update_t::format, avrpart::mem, update_t::memtype, MSG_INFO, OFF, ON, update_t::op, pgm, progname, quell_progress, report_progress(), update_t::section, programmer_t::set_upload_size, programmer_t::type, UF_AUTO_ERASE, UF_NOWRITE, and programmer_t::vfy_led.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dup_update()

UPDATE * dup_update ( UPDATE upd)
180{
181 UPDATE * u;
182
183 u = (UPDATE *)malloc(sizeof(UPDATE));
184 if (u == NULL) {
185 // avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
186 // exit(1);
187 avrdude_oom("dup_update: out of memory\n");
188 }
189
190 memcpy(u, upd, sizeof(UPDATE));
191
192 if (upd->memtype != NULL)
193 u->memtype = strdup(upd->memtype);
194 else
195 u->memtype = NULL;
196 u->filename = strdup(upd->filename);
197
198 return u;
199}

References avrdude_oom(), update_t::filename, malloc(), and update_t::memtype.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fileio()

int fileio ( int  op,
char *  filename,
FILEFMT  format,
struct avrpart p,
char *  memtype,
int  size,
unsigned  section 
)
1514{
1515 int rc;
1516 FILE * f;
1517 char * fname;
1518 struct fioparms fio;
1519 AVRMEM * mem;
1520 int using_stdio;
1521
1522 mem = avr_locate_mem(p, memtype);
1523 if (mem == NULL) {
1524 avrdude_message(MSG_INFO, "fileio(): memory type \"%s\" not configured for device \"%s\"\n",
1525 memtype, p->desc);
1526 return -1;
1527 }
1528
1529 rc = fileio_setparms(op, &fio, p, mem);
1530 if (rc < 0)
1531 return -1;
1532
1533 if (fio.op == FIO_READ)
1534 size = mem->size;
1535
1536 if (fio.op == FIO_READ) {
1537 /* 0xff fill unspecified memory */
1538 memset(mem->buf, 0xff, size);
1539 }
1540 memset(mem->tags, 0, size);
1541
1542 using_stdio = 0;
1543
1544 if (strcmp(filename, "-")==0) {
1545 return -1;
1546 // Note: we don't want to read stdin or write to stdout as part of Slic3r
1547 // if (fio.op == FIO_READ) {
1548 // fname = "<stdin>";
1549 // f = stdin;
1550 // }
1551 // else {
1552 // fname = "<stdout>";
1553 // f = stdout;
1554 // }
1555 // using_stdio = 1;
1556 }
1557 else {
1558 fname = filename;
1559 f = NULL;
1560 }
1561
1562 if (format == FMT_AUTO) {
1563 int format_detect;
1564
1565 if (using_stdio) {
1566 avrdude_message(MSG_INFO, "%s: can't auto detect file format when using stdin/out.\n"
1567 "%s Please specify a file format and try again.\n",
1568 progname, progbuf);
1569 return -1;
1570 }
1571
1572 format_detect = fmt_autodetect(fname, section);
1573 if (format_detect < 0) {
1574 avrdude_message(MSG_INFO, "%s: can't determine file format for %s, specify explicitly\n",
1575 progname, fname);
1576 return -1;
1577 }
1578 format = format_detect;
1579
1580 if (quell_progress < 2) {
1581 avrdude_message(MSG_INFO, "%s: %s file %s auto detected as %s\n",
1582 progname, fio.iodesc, fname, fmtstr(format));
1583 }
1584 }
1585
1586#if defined(WIN32NATIVE)
1587 /* Open Raw Binary and ELF format in binary mode on Windows.*/
1588 if(format == FMT_RBIN || format == FMT_ELF)
1589 {
1590 if(fio.op == FIO_READ)
1591 {
1592 fio.mode = "rb";
1593 }
1594 if(fio.op == FIO_WRITE)
1595 {
1596 fio.mode = "wb";
1597 }
1598 }
1599#endif
1600
1601 if (format != FMT_IMM) {
1602 if (!using_stdio) {
1603 f = fopen_and_seek(fname, fio.mode, section);
1604 if (f == NULL) {
1605 avrdude_message(MSG_INFO, "%s: can't open %s file %s: %s\n",
1606 progname, fio.iodesc, fname, strerror(errno));
1607 return -1;
1608 }
1609 }
1610 }
1611
1612 switch (format) {
1613 case FMT_IHEX:
1614 rc = fileio_ihex(&fio, fname, f, mem, size);
1615 break;
1616
1617 case FMT_SREC:
1618 rc = fileio_srec(&fio, fname, f, mem, size);
1619 break;
1620
1621 case FMT_RBIN:
1622 rc = fileio_rbin(&fio, fname, f, mem, size);
1623 break;
1624
1625 case FMT_ELF:
1626#ifdef HAVE_LIBELF
1627 rc = fileio_elf(&fio, fname, f, mem, p, size);
1628#else
1629 avrdude_message(MSG_INFO, "%s: can't handle ELF file %s, "
1630 "ELF file support was not compiled in\n",
1631 progname, fname);
1632 rc = -1;
1633#endif
1634 break;
1635
1636 case FMT_IMM:
1637 rc = fileio_imm(&fio, fname, f, mem, size);
1638 break;
1639
1640 case FMT_HEX:
1641 case FMT_DEC:
1642 case FMT_OCT:
1643 case FMT_BIN:
1644 rc = fileio_num(&fio, fname, f, mem, size, format);
1645 break;
1646
1647 default:
1648 avrdude_message(MSG_INFO, "%s: invalid %s file format: %d\n",
1649 progname, fio.iodesc, format);
1650 return -1;
1651 }
1652
1653 if (rc > 0) {
1654 if ((op == FIO_READ) && (strcasecmp(mem->desc, "flash") == 0 ||
1655 strcasecmp(mem->desc, "application") == 0 ||
1656 strcasecmp(mem->desc, "apptable") == 0 ||
1657 strcasecmp(mem->desc, "boot") == 0)) {
1658 /*
1659 * if we are reading flash, just mark the size as being the
1660 * highest non-0xff byte
1661 */
1662 rc = avr_mem_hiaddr(mem);
1663 }
1664 }
1665 if (format != FMT_IMM && !using_stdio) {
1666 fclose(f);
1667 }
1668
1669 return rc;
1670}
static int fileio_imm(struct fioparms *fio, char *filename, FILE *f, AVRMEM *mem, int size)
Definition fileio.c:1171
static int fileio_num(struct fioparms *fio, char *filename, FILE *f, AVRMEM *mem, int size, FILEFMT fmt)
Definition fileio.c:1308
static FILE * fopen_and_seek(const char *filename, const char *mode, unsigned section)
Definition fileio.c:124
char * fmtstr(FILEFMT format)
Definition fileio.c:166
int fileio_setparms(int op, struct fioparms *fp, struct avrpart *p, AVRMEM *m)
Definition fileio.c:1380
static int fileio_rbin(struct fioparms *fio, char *filename, FILE *f, AVRMEM *mem, int size)
Definition fileio.c:1139
static int fileio_ihex(struct fioparms *fio, char *filename, FILE *f, AVRMEM *mem, int size)
Definition fileio.c:1217
static int fmt_autodetect(char *fname, unsigned section)
Definition fileio.c:1425
static int fileio_srec(struct fioparms *fio, char *filename, FILE *f, AVRMEM *mem, int size)
Definition fileio.c:1247
int op
Definition libavrdude.h:800
@ FMT_BIN
Definition libavrdude.h:795
@ FMT_OCT
Definition libavrdude.h:794
@ FMT_ELF
Definition libavrdude.h:796
Definition libavrdude.h:799
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:44

References avr_locate_mem(), avr_mem_hiaddr(), avrdude_message(), avrpart::desc, fileio_ihex(), fileio_imm(), fileio_num(), fileio_rbin(), fileio_setparms(), fileio_srec(), FIO_READ, FIO_WRITE, FMT_AUTO, fmt_autodetect(), FMT_BIN, FMT_DEC, FMT_ELF, FMT_HEX, FMT_IHEX, FMT_IMM, FMT_OCT, FMT_RBIN, FMT_SREC, fmtstr(), fopen_and_seek(), fioparms::iodesc, fioparms::mode, MSG_INFO, fioparms::op, progbuf, progname, quell_progress, and strcasecmp.

Referenced by do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fmtstr()

char * fmtstr ( FILEFMT  format)
167{
168 switch (format) {
169 case FMT_AUTO : return "auto-detect"; break;
170 case FMT_SREC : return "Motorola S-Record"; break;
171 case FMT_IHEX : return "Intel Hex"; break;
172 case FMT_RBIN : return "raw binary"; break;
173 case FMT_ELF : return "ELF"; break;
174 default : return "invalid format"; break;
175 };
176}

References FMT_AUTO, FMT_ELF, FMT_IHEX, FMT_RBIN, and FMT_SREC.

Referenced by fileio(), Slic3r::Utils::anonymous_namespace{Time.cpp}::process_format(), Slic3r::Utils::str2time(), and Slic3r::Utils::time2str().

+ Here is the caller graph for this function:

◆ fopen_utf8()

FILE * fopen_utf8 ( const char *  filename,
const char *  mode 
)
109{
110 // On Windows we need to convert the filename to UTF-16
111#if defined(WIN32NATIVE)
112 static wchar_t fname_buffer[PATH_MAX];
113 static wchar_t mode_buffer[MAX_MODE_LEN];
114
115 if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, fname_buffer, PATH_MAX) == 0) { return NULL; }
116 if (MultiByteToWideChar(CP_UTF8, 0, mode, -1, mode_buffer, MAX_MODE_LEN) == 0) { return NULL; }
117
118 return _wfopen(fname_buffer, mode_buffer);
119#else
120 return fopen(filename, mode);
121#endif
122}
#define MAX_MODE_LEN
Definition fileio.c:51
#define PATH_MAX
Definition libavrdude.h:51

References MAX_MODE_LEN, and PATH_MAX.

Referenced by fopen_and_seek(), and read_config().

+ Here is the caller graph for this function:

◆ free_update()

void free_update ( UPDATE upd)
222{
223 if (u != NULL) {
224 if(u->memtype != NULL) {
225 free(u->memtype);
226 u->memtype = NULL;
227 }
228 if(u->filename != NULL) {
229 free(u->filename);
230 u->filename = NULL;
231 }
232 free(u);
233 }
234}

References update_t::filename, free(), and update_t::memtype.

Referenced by cleanup_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_config()

int init_config ( void  )
70{
71 string_list = lcreat(NULL, 0);
72 number_list = lcreat(NULL, 0);
73 current_prog = NULL;
74 current_part = NULL;
75 current_mem = NULL;
76 part_list = lcreat(NULL, 0);
77 programmers = lcreat(NULL, 0);
78
79 lineno = 1;
80 infile = NULL;
81
82 return 0;
83}
AVRPART * current_part
Definition config.c:49
const char * infile
Definition config.c:55
int lineno
Definition config.c:54
AVRMEM * current_mem
Definition config.c:50
PROGRAMMER * current_prog
Definition config.c:48

References current_mem, current_part, current_prog, infile, lcreat(), lineno, number_list, part_list, programmers, and string_list.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ladd()

int ladd ( LISTID  lid,
void p 
)
548{
549 LIST * l;
550 LISTNODE *lnptr;
551
552 l = (LIST *)lid;
553
554 CKLMAGIC(l);
555
556 lnptr = get_listnode(l);
557 if (lnptr==NULL) {
558#ifdef BOS
559 breakpoint();
560#endif
561 return -1;
562 }
563
564 CKMAGIC(lnptr);
565
566 lnptr->data = p;
567
568 if (l->top == NULL) {
569 l->top = lnptr;
570 l->bottom = lnptr;
571 lnptr->next = NULL;
572 lnptr->prev = NULL;
573 }
574 else {
575 lnptr->prev = l->bottom;
576 lnptr->next = NULL;
577 l->bottom->next = lnptr;
578 l->bottom = lnptr;
579 }
580 l->num++;
581
582 CKLMAGIC(l);
583
584 return 0;
585}
static LISTNODE * get_listnode(LIST *l)
Definition lists.c:291
LISTNODE * top
Definition lists.c:94
void * data
Definition lists.c:67
struct LISTNODE * prev
Definition lists.c:66
struct LISTNODE * next
Definition lists.c:65
#define CKMAGIC(p)
Definition lists.c:119
#define CKLMAGIC(p)
Definition lists.c:125
LISTNODE * bottom
Definition lists.c:95
int num
Definition lists.c:90
Definition lists.c:61
Definition lists.c:86

References LIST::bottom, CKLMAGIC, CKMAGIC, LISTNODE::data, get_listnode(), LISTNODE::next, LIST::num, LISTNODE::prev, and LIST::top.

Referenced by avr_dup_part(), avrdude_main(), insert_ln(), jtag3_open_common(), laddo(), laddu(), lcat(), lins_n(), pgm_dup(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ laddo()

int laddo ( LISTID  lid,
void p,
int(*)(const void *p1, const void *p2)  compare,
LNODEID firstdup 
)
601{
602 LIST * l;
603 LISTNODE * ln;
604 int dup, cmp;
605
606 l = (LIST *)lid;
607
608 CKLMAGIC(l);
609
610 dup = 0;
611 ln = l->top;
612
613 while (ln!=NULL) {
614 CKMAGIC(ln);
615 cmp = compare(p,ln->data);
616 if (cmp == 0) {
617 dup = 1;
618 if (firstdup)
619 *firstdup = ln;
620 }
621 if (cmp < 0) {
622 insert_ln(l,ln,p);
623 CKLMAGIC(l);
624 return dup;
625 }
626 else {
627 ln = ln->next;
628 }
629 }
630
631 ladd(l,p);
632
633 CKLMAGIC(l);
634
635 return dup;
636}
int ladd(LISTID lid, void *p)
Definition lists.c:547
static int insert_ln(LIST *l, LISTNODE *ln, void *data_ptr)
Definition lists.c:878

References CKLMAGIC, CKMAGIC, LISTNODE::data, insert_ln(), ladd(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ laddu()

int laddu ( LISTID  lid,
void p,
int(*)(const void *p1, const void *p2)  compare 
)
649{
650 LIST * l;
651 LISTNODE * ln;
652 int cmp;
653
654 l = (LIST *)lid;
655
656 CKLMAGIC(l);
657
658 ln = l->top;
659
660 while (ln!=NULL) {
661 CKMAGIC(ln);
662 cmp = compare(p,ln->data);
663 if (cmp == 0) {
664 CKLMAGIC(l);
665 return 0;
666 }
667 if (cmp < 0) {
668 insert_ln(l,ln,p);
669 CKLMAGIC(l);
670 return 1;
671 }
672 else {
673 ln = ln->next;
674 }
675 }
676
677 ladd(l,p);
678
679 CKLMAGIC(l);
680
681 return 1;
682}

References CKLMAGIC, CKMAGIC, LISTNODE::data, insert_ln(), ladd(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lcat()

LISTID lcat ( LISTID  lid1,
LISTID  lid2 
)
744{
745 CKLMAGIC(((LIST *)lid1));
746 CKLMAGIC(((LIST *)lid2));
747 while (lsize(lid2)) {
748 ladd ( lid1, lrmv_n(lid2,1) );
749 }
750
751 CKLMAGIC(((LIST *)lid1));
752 CKLMAGIC(((LIST *)lid2));
753
754 return lid1;
755}
int lsize(LISTID lid)
Definition lists.c:729
void * lrmv_n(LISTID lid, unsigned int n)
Definition lists.c:1186

References CKLMAGIC, ladd(), lrmv_n(), and lsize().

+ Here is the call graph for this function:

◆ lcreat()

LISTID lcreat ( void liststruct,
int  poolsize 
)
411{
412 LIST * l;
413
414 if (liststruct == NULL) {
415 /*--------------------------------------------------
416 allocate memory for the list itself
417 --------------------------------------------------*/
418 l = (LIST *) MALLOC ( sizeof(LIST), "list struct" );
419 if (l == NULL) {
420 return NULL;
421 }
422 l->free_on_close = 1;
423 }
424 else {
425 /*-----------------------------------------------------------------
426 use the memory given to us for the list structure
427 -----------------------------------------------------------------*/
428 l = liststruct;
429 l->free_on_close = 0;
430 }
431
432 /*--------------------------------------------------
433 | initialize the list
434 --------------------------------------------------*/
435#if CHECK_MAGIC
436 l->magic1 = MAGIC;
437 l->magic2 = MAGIC;
438#endif
439 l->top = NULL;
440 l->bottom = NULL;
441 l->num = 0;
442
443 if (elements == 0) {
445 }
446 else {
447 l->poolsize = (short)(elements*sizeof(LISTNODE)+sizeof(NODEPOOL));
448 }
449
450 l->n_ln_pool = (l->poolsize-sizeof(NODEPOOL))/sizeof(LISTNODE);
451
452 if (l->n_ln_pool < 5) {
453 if (!liststruct) {
454 FREE(l);
455 }
456 return NULL;
457 }
458
459 l->np_top = NULL;
460 l->np_bottom = NULL;
461 l->next_ln = NULL;
462
463 CKLMAGIC(l);
464
465 return (LISTID)l;
466}
short int poolsize
Definition lists.c:92
NODEPOOL * np_bottom
Definition lists.c:98
short int free_on_close
Definition lists.c:91
LISTNODE * next_ln
Definition lists.c:96
#define MALLOC(size, x)
Definition lists.c:53
int n_ln_pool
Definition lists.c:93
#define MAGIC
Definition lists.c:45
#define FREE
Definition lists.c:54
NODEPOOL * np_top
Definition lists.c:97
#define DEFAULT_POOLSIZE
Definition lists.c:106
Definition lists.c:74

References LIST::bottom, CKLMAGIC, DEFAULT_POOLSIZE, FREE, LIST::free_on_close, MAGIC, MALLOC, LIST::n_ln_pool, LIST::next_ln, LIST::np_bottom, LIST::np_top, LIST::num, LIST::poolsize, and LIST::top.

Referenced by avr_new_part(), avrdude_main(), init_config(), pgm_dup(), pgm_new(), and yyparse().

+ Here is the caller graph for this function:

◆ ldata()

◆ ldestroy()

void ldestroy ( LISTID  lid)
510{
511 LIST * l;
512 NODEPOOL * p1, * p2;
513
514 l = (LIST *)lid;
515
516 CKLMAGIC(l);
517
518 /*--------------------------------------------------
519 | free each node pool - start at the first node
520 | pool and free each successive until there are
521 | no more.
522 --------------------------------------------------*/
523 p1 = l->np_top;
524 while (p1 != NULL) {
525 p2 = p1->chain_next;
526 FREE(p1);
527 p1 = p2;
528 }
529
530 /*--------------------------------------------------
531 | now free the memory occupied by the list itself
532 --------------------------------------------------*/
533 if (l->free_on_close) {
534 FREE ( l );
535 }
536}
struct NODEPOOL * chain_next
Definition lists.c:78

References NODEPOOL::chain_next, CKLMAGIC, FREE, LIST::free_on_close, and LIST::np_top.

Referenced by cleanup_main(), and ldestroy_cb().

+ Here is the caller graph for this function:

◆ ldestroy_cb()

void ldestroy_cb ( LISTID  lid,
void(*)(void *data_ptr)  ucleanup 
)
481{
482 LIST * l;
483 LISTNODE * ln;
484
485 l = (LIST *)lid;
486
487 CKLMAGIC(l);
488
489 ln = l->top;
490 while (ln != NULL) {
491 ucleanup ( ln->data );
492 ln = ln->next;
493 }
494
495 ldestroy ( l );
496}
void ldestroy(LISTID lid)
Definition lists.c:509

References CKLMAGIC, LISTNODE::data, ldestroy(), LISTNODE::next, and LIST::top.

Referenced by avr_free_part(), cleanup_config(), cleanup_main(), pgm_free(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lfirst()

◆ lget()

void * lget ( LISTID  lid)
767{
768 LIST * l;
769 LISTNODE * p;
770
771 l = (LIST *)lid;
772
773 CKLMAGIC(l);
774
775 p = l->bottom;
776
777 if (p == NULL) {
778 CKLMAGIC(l);
779 return NULL;
780 }
781 else {
782 CKLMAGIC(l);
783 return p->data;
784 }
785}

References LIST::bottom, CKLMAGIC, and LISTNODE::data.

◆ lget_ln()

LNODEID lget_ln ( LISTID  lid,
unsigned int  n 
)
838{
839 int i;
840 LIST * l;
841 LISTNODE * ln;
842
843 l = (LIST *)lid;
844
845 CKLMAGIC(l);
846
847 if ((n < 1) || (n > (unsigned)lsize(l))) {
848 return NULL;
849 }
850
851 ln = l->top;
852 i = 1;
853 while (i!=n) {
854 CKMAGIC(ln);
855 ln = ln->next;
856 i++;
857 }
858
859 CKLMAGIC(l);
860 return (LNODEID)ln;
861}

References CKLMAGIC, CKMAGIC, lsize(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lget_n()

void * lget_n ( LISTID  lid,
unsigned int  n 
)
797{
798 int i;
799 LIST * l;
800 LISTNODE * ln;
801
802 l = (LIST *)lid;
803
804 CKLMAGIC(l);
805
806 if ((n < 1) || (n > (unsigned)lsize(l))) {
807 return NULL;
808 }
809
810 ln = l->top;
811 i = 1;
812 while (ln && (i!=n)) {
813 CKMAGIC(ln);
814 ln = ln->next;
815 i++;
816 }
817
818 if (ln) {
819 CKLMAGIC(l);
820 return ln->data;
821 }
822 else {
823 CKLMAGIC(l);
824 return NULL;
825 }
826}

References CKLMAGIC, CKMAGIC, LISTNODE::data, lsize(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lins_ln()

int lins_ln ( LISTID  lid,
LNODEID  lnid,
void data_ptr 
)
995{
996 LIST * l;
997 LISTNODE * ln;
998 LISTNODE * ln_ptr;
999
1000 l = (LIST *)lid;
1001 ln = (LISTNODE *)lnid;
1002
1003 CKLMAGIC(l);
1004
1005 CKMAGIC(ln);
1006
1007 /*-----------------------------------------
1008 | validate that ln is indeed in the list
1009 -----------------------------------------*/
1010 ln_ptr = l->top;
1011 while ((ln_ptr!=NULL)&&(ln_ptr!=ln)) {
1012 CKMAGIC(ln_ptr);
1013 ln_ptr = ln_ptr->next;
1014 }
1015
1016 if (ln_ptr == NULL) {
1017 CKLMAGIC(l);
1018 return -1;
1019 }
1020
1021 CKLMAGIC(l);
1022
1023 /*--------------------------------
1024 | insert the data into the list
1025 --------------------------------*/
1026 return insert_ln ( l, ln, data_ptr );
1027}

References CKLMAGIC, CKMAGIC, insert_ln(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lins_n()

int lins_n ( LISTID  lid,
void d,
unsigned int  n 
)
946{
947 int i;
948 LIST * l;
949 LISTNODE * ln;
950
951 l = (LIST *)lid;
952
953 CKLMAGIC(l);
954
955 if ((n < 1) || (n > (unsigned)(l->num+1))) {
956 return -1;
957 }
958
959 if (l->num == 0) {
960 return ladd ( lid, data_ptr );
961 }
962
963 /*----------------------------------
964 | locate the nth item in the list
965 ----------------------------------*/
966 ln = l->top;
967 i = 1;
968 while (ln && (i!=n)) {
969 CKMAGIC(ln);
970 ln = ln->next;
971 i++;
972 }
973
974 if (!ln) {
975 CKLMAGIC(l);
976 return -1;
977 }
978
979 CKLMAGIC(l);
980
981 /*-----------------------------------------
982 | insert before the nth item in the list
983 -----------------------------------------*/
984 return insert_ln ( l, ln, data_ptr );
985}

References CKLMAGIC, CKMAGIC, insert_ln(), ladd(), LISTNODE::next, LIST::num, and LIST::top.

+ Here is the call graph for this function:

◆ llast()

LNODEID llast ( LISTID  lid)
697{
698 CKLMAGIC(((LIST *)lid));
699 return ((LIST *)lid)->bottom;
700}

References CKLMAGIC.

◆ lnext()

◆ locate_part()

AVRPART * locate_part ( LISTID  parts,
char *  partdesc 
)
515{
516 LNODEID ln1;
517 AVRPART * p = NULL;
518 int found;
519
520 found = 0;
521
522 for (ln1=lfirst(parts); ln1 && !found; ln1=lnext(ln1)) {
523 p = ldata(ln1);
524 if ((strcasecmp(partdesc, p->id) == 0) ||
525 (strcasecmp(partdesc, p->desc) == 0))
526 found = 1;
527 }
528
529 if (found)
530 return p;
531
532 return NULL;
533}
struct avrpart parts[]

References avrpart::desc, avrpart::id, ldata(), lfirst(), lnext(), parts, and strcasecmp.

Referenced by avrdude_main(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locate_part_by_avr910_devcode()

AVRPART * locate_part_by_avr910_devcode ( LISTID  parts,
int  devcode 
)
536{
537 LNODEID ln1;
538 AVRPART * p = NULL;
539
540 for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
541 p = ldata(ln1);
542 if (p->avr910_devcode == devcode)
543 return p;
544 }
545
546 return NULL;
547}
int avr910_devcode
Definition libavrdude.h:221

References avrpart::avr910_devcode, ldata(), lfirst(), lnext(), and parts.

Referenced by avr910_initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locate_part_by_signature()

AVRPART * locate_part_by_signature ( LISTID  parts,
unsigned char *  sig,
int  sigsize 
)
551{
552 LNODEID ln1;
553 AVRPART * p = NULL;
554 int i;
555
556 if (sigsize == 3) {
557 for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
558 p = ldata(ln1);
559 for (i=0; i<3; i++)
560 if (p->signature[i] != sig[i])
561 break;
562 if (i == 3)
563 return p;
564 }
565 }
566
567 return NULL;
568}

References ldata(), lfirst(), lnext(), parts, and avrpart::signature.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locate_programmer()

PROGRAMMER * locate_programmer ( LISTID  programmers,
const char *  configid 
)
264{
265 LNODEID ln1, ln2;
266 PROGRAMMER * p = NULL;
267 const char * id;
268 int found;
269
270 found = 0;
271
272 for (ln1=lfirst(programmers); ln1 && !found; ln1=lnext(ln1)) {
273 p = ldata(ln1);
274 for (ln2=lfirst(p->id); ln2 && !found; ln2=lnext(ln2)) {
275 id = ldata(ln2);
276 if (strcasecmp(configid, id) == 0)
277 found = 1;
278 }
279 }
280
281 if (found)
282 return p;
283
284 return NULL;
285}

References programmer_t::id, ldata(), lfirst(), lnext(), programmers, and strcasecmp.

Referenced by avrdude_main(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locate_programmer_type()

const PROGRAMMER_TYPE * locate_programmer_type ( const char *  id)
100{
101 const PROGRAMMER_TYPE * p = NULL;
102 int i;
103 int found;
104
105 found = 0;
106
107 for (i = 0; i < sizeof(programmers_types)/sizeof(programmers_types[0]) && !found; i++) {
108 p = &(programmers_types[i]);
109 if (strcasecmp(id, p->id) == 0)
110 found = 1;
111 }
112
113 if (found)
114 return p;
115
116 return NULL;
117}
const PROGRAMMER_TYPE programmers_types[]
Definition pgm_type.c:55

References programmer_type_t::id, programmers_types, and strcasecmp.

Referenced by yyparse().

+ Here is the caller graph for this function:

◆ lprev()

LNODEID lprev ( LNODEID  lnid)
713{
714 CKMAGIC(((LISTNODE *)lnid));
715 return ((LISTNODE *)lnid)->prev;
716}

References CKMAGIC.

Referenced by Slic3r::take_ccw_limited(), and Slic3r::take_cw_limited().

+ Here is the caller graph for this function:

◆ lprint()

int lprint ( FILE *  f,
LISTID  lid 
)
1321{
1322 LIST * l;
1323 LISTNODE * ln;
1324 NODEPOOL * np;
1325 int count;
1326
1327 l = (LIST *)lid;
1328
1329 fprintf ( f, "list id %p internal data structures:\n",
1330 lid );
1331#if CHECK_MAGIC
1332 if ((l->magic1 != MAGIC) || (l->magic2 != MAGIC)) {
1333 fprintf ( f, " *** WARNING: LIST MAGIC IS CORRUPT ***\n" );
1334 }
1335 fprintf ( f,
1336 " magic1=0x%08x\n"
1337 " magic2=0x%08x\n",
1338 l->magic1, l->magic2 );
1339#endif
1340 fprintf ( f, " num f pool n_ln top bottom next_ln np_top np_bottom\n" );
1341 fprintf ( f, " ---- - ---- ---- ---------- ---------- ---------- ---------- ----------\n" );
1342 fprintf ( f, " %4d %1d %4d %4d %10p %10p %10p %10p %10p\n",
1343 l->num, l->free_on_close, l->poolsize, l->n_ln_pool,
1344 l->top, l->bottom,
1345 l->next_ln, l->np_top, l->np_bottom );
1346
1347
1348 fprintf ( f,
1349 " node pools:\n"
1350 " idx np magic1 next prev magic2\n"
1351 " ---- ---------- ---------- ---------- ---------- ----------\n" );
1352 count = 0;
1353 np = l->np_top;
1354 while (np != NULL) {
1355 count++;
1356 fprintf ( f, " %4d %10p 0x%08x %10p %10p 0x%08x\n",
1357 count, np,
1358#if CHECK_MAGIC
1359 np->magic1,
1360#else
1361 0,
1362#endif
1363 np->chain_next, np->chain_prev,
1364#if CHECK_MAGIC
1365 np->magic2
1366#else
1367 0
1368#endif
1369 );
1370 np = np->chain_next;
1371 }
1372
1373 if (f) {
1374 fprintf ( f,
1375 " list elements:\n"
1376 " n ln magic1 next prev data magic2\n"
1377 " ---- ---------- ---------- ---------- ---------- ---------- ----------\n" );
1378 count = 0;
1379 ln = l->top;
1380 while (ln != NULL) {
1381 count++;
1382 fprintf ( f, " %4d %10p %10x %10p %10p %10p %10x\n",
1383 count, ln,
1384#if CHECK_MAGIC
1385 ln->magic1,
1386#else
1387 0,
1388#endif
1389 ln->next, ln->prev, ln->data,
1390#if CHECK_MAGIC
1391 ln->magic2
1392#else
1393 0
1394#endif
1395 );
1396 ln = lnext(ln);
1397 }
1398 if (count != l->num) {
1399 fprintf ( f,
1400 " *** list count is not correct\n"
1401 " *** list id indicates %d, counted items = %d\n",
1402 l->num, count );
1403 }
1404 }
1405
1406 return 0;
1407}
struct NODEPOOL * chain_prev
Definition lists.c:79
LNODEID lnext(LNODEID lnid)
Definition lists.c:704
#define CHECK_MAGIC
Definition lists.c:47
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12

References LIST::bottom, NODEPOOL::chain_next, NODEPOOL::chain_prev, CHECK_MAGIC, LISTNODE::data, LIST::free_on_close, lnext(), MAGIC, LIST::n_ln_pool, LISTNODE::next, LIST::next_ln, LIST::np_bottom, LIST::np_top, LIST::num, LIST::poolsize, LISTNODE::prev, and LIST::top.

+ Here is the call graph for this function:

◆ lrmv()

void * lrmv ( LISTID  lid)
1227{
1228 LIST * l;
1229 LISTNODE * p;
1230
1231 l = (LIST *)lid;
1232
1233 CKLMAGIC(l);
1234
1235 p = l->bottom;
1236
1237 if (p == NULL) {
1238 CKLMAGIC(l);
1239 return NULL;
1240 }
1241 else {
1242 CKLMAGIC(l);
1243 return remove_ln ( l, p );
1244 }
1245}
static void * remove_ln(LIST *l, LISTNODE *ln)
Definition lists.c:1042

References LIST::bottom, CKLMAGIC, and remove_ln().

+ Here is the call graph for this function:

◆ lrmv_d()

void * lrmv_d ( LISTID  lid,
void data_ptr 
)
1112{
1113 LIST * l;
1114 LISTNODE * ln;
1115 int i;
1116
1117 l = (LIST *)lid;
1118
1119 CKLMAGIC(l);
1120
1121 i = 0;
1122 ln = l->top;
1123 while (ln && (ln->data != data_ptr)) {
1124 i++;
1125 CKMAGIC(ln);
1126 ln = ln->next;
1127 }
1128
1129 if (ln == NULL) {
1130 CKLMAGIC(l);
1131 return NULL;
1132 }
1133 else {
1134 CKLMAGIC(l);
1135 return remove_ln ( l, ln );
1136 }
1137}

References CKLMAGIC, CKMAGIC, LISTNODE::data, LISTNODE::next, remove_ln(), and LIST::top.

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lrmv_ln()

void * lrmv_ln ( LISTID  lid,
LNODEID  lnid 
)
1149{
1150 LIST * l;
1151 LISTNODE * ln;
1152 LISTNODE * p;
1153
1154 l = (LIST *)lid;
1155 ln = (LISTNODE *)lnid;
1156
1157 CKLMAGIC(l);
1158
1159 CKMAGIC(ln);
1160
1161 p = l->top;
1162 while ((p!=NULL)&&(p!=ln)) {
1163 CKMAGIC(p);
1164 p = p->next;
1165 }
1166
1167 if (p==NULL) {
1168 CKLMAGIC(l);
1169 return NULL;
1170 }
1171 else {
1172 CKLMAGIC(l);
1173 return remove_ln ( l, p );
1174 }
1175}

References CKLMAGIC, CKMAGIC, LISTNODE::next, remove_ln(), and LIST::top.

+ Here is the call graph for this function:

◆ lrmv_n()

void * lrmv_n ( LISTID  lid,
unsigned int  n 
)
1187{
1188 int i;
1189 LIST * l;
1190 LISTNODE * ln;
1191
1192 l = (LIST *)lid;
1193
1194 CKLMAGIC(l);
1195
1196 if ((n < 1) || (n > (unsigned)l->num)) {
1197 return NULL;
1198 }
1199
1200 ln = l->top;
1201 i = 1;
1202 while (ln && (i!=n)) {
1203 CKMAGIC(ln);
1204 ln = ln->next;
1205 i++;
1206 }
1207
1208 if (ln) {
1209 CKLMAGIC(l);
1210 return remove_ln ( l, ln );
1211 }
1212 else {
1213 CKLMAGIC(l);
1214 return NULL;
1215 }
1216}

References CKLMAGIC, CKMAGIC, LISTNODE::next, LIST::num, remove_ln(), and LIST::top.

Referenced by assign_pin_list(), lcat(), parse_cmdbits(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lsize()

int lsize ( LISTID  lid)
730{
731 CKLMAGIC(((LIST *)lid));
732 return ((LIST *)lid)->num;
733}

References CKLMAGIC.

Referenced by assign_pin_list(), avrdude_main(), lcat(), lget_ln(), lget_n(), parse_cmdbits(), and yyparse().

+ Here is the caller graph for this function:

◆ lsort()

void lsort ( LISTID  lid,
int(*)(void *p1, void *p2)  compare 
)
1290{
1291 LIST * l;
1292 LISTNODE * lt; /* this */
1293 LISTNODE * ln; /* next */
1294 int unsorted = 1;
1295
1296 l = (LIST *)lid;
1297
1298 CKLMAGIC(l);
1299
1300 while(unsorted){
1301 lt = l->top;
1302 unsorted = 0;
1303 while (lt!=NULL) {
1304 CKMAGIC(lt);
1305 ln = lt->next;
1306 if (ln!= NULL && compare(lt->data,ln->data) > 0) {
1307 void * p = ln->data;
1308 ln->data = lt->data;
1309 lt->data = p;
1310 unsorted = 1;
1311 }
1312 lt = ln;
1313 }
1314 }
1315
1316 CKLMAGIC(l);
1317}

References CKLMAGIC, CKMAGIC, LISTNODE::data, LISTNODE::next, and LIST::top.

Referenced by sort_avrparts(), and sort_programmers().

+ Here is the caller graph for this function:

◆ lsrch()

void * lsrch ( LISTID  lid,
void p,
int(*)(void *p1, void *p2)  compare 
)
1257{
1258 LIST * l;
1259 LISTNODE * ln;
1260
1261 l = (LIST *)lid;
1262
1263 CKLMAGIC(l);
1264
1265 ln = l->top;
1266
1267 while (ln!=NULL) {
1268 CKMAGIC(ln);
1269 if (compare(p,ln->data) == 0) {
1270 CKLMAGIC(l);
1271 return ln->data;
1272 }
1273 else {
1274 ln = ln->next;
1275 }
1276 }
1277
1278 CKLMAGIC(l);
1279 return NULL;
1280}

References CKLMAGIC, CKMAGIC, LISTNODE::data, LISTNODE::next, and LIST::top.

◆ new_update()

UPDATE * new_update ( int  op,
char *  memtype,
int  filefmt,
char *  filename,
unsigned  section 
)
202{
203 UPDATE * u;
204
205 u = (UPDATE *)malloc(sizeof(UPDATE));
206 if (u == NULL) {
207 // avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
208 // exit(1);
209 avrdude_oom("new_update: out of memory\n");
210 }
211
212 u->memtype = strdup(memtype);
213 u->filename = strdup(filename);
214 u->op = op;
215 u->format = filefmt;
216 u->section = section;
217
218 return u;
219}

References avrdude_oom(), update_t::filename, update_t::format, malloc(), update_t::memtype, update_t::op, and update_t::section.

Referenced by Slic3r::PresetUpdater::priv::get_config_updates().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_op()

UPDATE * parse_op ( char *  s)
32{
33 char buf[1024];
34 char * p, * cp, c;
35 UPDATE * upd;
36 int i;
37 size_t fnlen;
38
39 upd = (UPDATE *)malloc(sizeof(UPDATE));
40 if (upd == NULL) {
41 // avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
42 // exit(1);
43 avrdude_oom("parse_op: out of memory\n");
44 }
45
46 i = 0;
47 p = s;
48 while ((i < (sizeof(buf)-1) && *p && (*p != ':')))
49 buf[i++] = *p++;
50 buf[i] = 0;
51
52 if (*p != ':') {
53 upd->memtype = NULL; /* default memtype, "flash", or "application" */
54 upd->op = DEVICE_WRITE;
55 upd->filename = (char *)malloc(strlen(buf) + 1);
56 if (upd->filename == NULL) {
57 // avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
58 // exit(1);
59 avrdude_oom("parse_op: out of memory\n");
60 }
61 strcpy(upd->filename, buf);
62 upd->format = FMT_AUTO;
63 return upd;
64 }
65
66 upd->memtype = (char *)malloc(strlen(buf)+1);
67 if (upd->memtype == NULL) {
68 // avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
69 // exit(1);
70 avrdude_oom("parse_op: out of memory\n");
71 }
72 strcpy(upd->memtype, buf);
73
74 p++;
75 if (*p == 'r') {
76 upd->op = DEVICE_READ;
77 }
78 else if (*p == 'w') {
79 upd->op = DEVICE_WRITE;
80 }
81 else if (*p == 'v') {
82 upd->op = DEVICE_VERIFY;
83 }
84 else {
85 avrdude_message(MSG_INFO, "%s: invalid I/O mode '%c' in update specification\n",
86 progname, *p);
87 avrdude_message(MSG_INFO, " allowed values are:\n"
88 " r = read device\n"
89 " w = write device\n"
90 " v = verify device\n");
91 free(upd->memtype);
92 free(upd);
93 return NULL;
94 }
95
96 p++;
97
98 if (*p != ':') {
99 avrdude_message(MSG_INFO, "%s: invalid update specification\n", progname);
100 free(upd->memtype);
101 free(upd);
102 return NULL;
103 }
104
105 p++;
106
107 // Extension: Parse file section number
108 unsigned section = 0;
109
110 for (; *p != ':'; p++) {
111 if (*p >= '0' && *p <= '9') {
112 section *= 10;
113 section += *p - 0x30;
114 } else {
115 avrdude_message(MSG_INFO, "%s: invalid update specification: <section> is not a number\n", progname);
116 free(upd->memtype);
117 free(upd);
118 return NULL;
119 }
120 }
121
122 upd->section = section;
123 p++;
124
125 /*
126 * Now, parse the filename component. Instead of looking for the
127 * leftmost possible colon delimiter, we look for the rightmost one.
128 * If we found one, we do have a trailing :format specifier, and
129 * process it. Otherwise, the remainder of the string is our file
130 * name component. That way, the file name itself is allowed to
131 * contain a colon itself (e. g. C:/some/file.hex), except the
132 * optional format specifier becomes mandatory then.
133 */
134 cp = p;
135 p = strrchr(cp, ':');
136 if (p == NULL) {
137 upd->format = FMT_AUTO;
138 fnlen = strlen(cp);
139 upd->filename = (char *)malloc(fnlen + 1);
140 } else {
141 fnlen = p - cp;
142 upd->filename = (char *)malloc(fnlen +1);
143 c = *++p;
144 if (c && p[1])
145 /* More than one char - force failure below. */
146 c = '?';
147 switch (c) {
148 case 'a': upd->format = FMT_AUTO; break;
149 case 's': upd->format = FMT_SREC; break;
150 case 'i': upd->format = FMT_IHEX; break;
151 case 'r': upd->format = FMT_RBIN; break;
152 case 'e': upd->format = FMT_ELF; break;
153 case 'm': upd->format = FMT_IMM; break;
154 case 'b': upd->format = FMT_BIN; break;
155 case 'd': upd->format = FMT_DEC; break;
156 case 'h': upd->format = FMT_HEX; break;
157 case 'o': upd->format = FMT_OCT; break;
158 default:
159 avrdude_message(MSG_INFO, "%s: invalid file format '%s' in update specifier\n",
160 progname, p);
161 free(upd->memtype);
162 free(upd);
163 return NULL;
164 }
165 }
166
167 if (upd->filename == NULL) {
168 avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
169 free(upd->memtype);
170 free(upd);
171 return NULL;
172 }
173 memcpy(upd->filename, cp, fnlen);
174 upd->filename[fnlen] = 0;
175
176 return upd;
177}

References avrdude_message(), avrdude_oom(), DEVICE_READ, DEVICE_VERIFY, DEVICE_WRITE, update_t::filename, FMT_AUTO, FMT_BIN, FMT_DEC, FMT_ELF, FMT_HEX, FMT_IHEX, FMT_IMM, FMT_OCT, FMT_RBIN, FMT_SREC, update_t::format, free(), malloc(), update_t::memtype, MSG_INFO, update_t::op, progname, and update_t::section.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgm_display_generic()

void pgm_display_generic ( PROGRAMMER pgm,
const char *  p 
)
259{
261}
#define SHOW_ALL_PINS
Definition libavrdude.h:704
void pgm_display_generic_mask(PROGRAMMER *pgm, const char *p, unsigned int show)
Definition pgm.c:234

References pgm, pgm_display_generic_mask(), and SHOW_ALL_PINS.

+ Here is the call graph for this function:

◆ pgm_display_generic_mask()

void pgm_display_generic_mask ( PROGRAMMER pgm,
const char *  p,
unsigned int  show 
)
235{
236 if(show & (1<<PPI_AVR_VCC))
237 avrdude_message(MSG_INFO, "%s VCC = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_VCC]));
238 if(show & (1<<PPI_AVR_BUFF))
239 avrdude_message(MSG_INFO, "%s BUFF = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_BUFF]));
240 if(show & (1<<PIN_AVR_RESET))
241 avrdude_message(MSG_INFO, "%s RESET = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_RESET]));
242 if(show & (1<<PIN_AVR_SCK))
243 avrdude_message(MSG_INFO, "%s SCK = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SCK]));
244 if(show & (1<<PIN_AVR_MOSI))
245 avrdude_message(MSG_INFO, "%s MOSI = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MOSI]));
246 if(show & (1<<PIN_AVR_MISO))
247 avrdude_message(MSG_INFO, "%s MISO = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MISO]));
248 if(show & (1<<PIN_LED_ERR))
249 avrdude_message(MSG_INFO, "%s ERR LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_ERR]));
250 if(show & (1<<PIN_LED_RDY))
251 avrdude_message(MSG_INFO, "%s RDY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_RDY]));
252 if(show & (1<<PIN_LED_PGM))
253 avrdude_message(MSG_INFO, "%s PGM LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_PGM]));
254 if(show & (1<<PIN_LED_VFY))
255 avrdude_message(MSG_INFO, "%s VFY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_VFY]));
256}
const char * pins_to_str(const struct pindef_t *const pindef)
Definition pindefs.c:320
struct pindef_t pin[N_PINS]
Definition libavrdude.h:623

References avrdude_message(), MSG_INFO, pgm, programmer_t::pin, PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, PIN_LED_ERR, PIN_LED_PGM, PIN_LED_RDY, PIN_LED_VFY, pins_to_str(), PPI_AVR_BUFF, and PPI_AVR_VCC.

Referenced by pgm_display_generic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgm_dup()

PROGRAMMER * pgm_dup ( const PROGRAMMER *const  src)
156{
157 PROGRAMMER * pgm;
158 LNODEID ln;
159
160 pgm = (PROGRAMMER *)malloc(sizeof(*pgm));
161 if (pgm == NULL) {
162 avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n",
163 progname);
164 return NULL;
165 }
166
167 memcpy(pgm, src, sizeof(*pgm));
168
169 pgm->id = lcreat(NULL, 0);
170 pgm->usbpid = lcreat(NULL, 0);
171
172 for (ln = lfirst(src->usbpid); ln; ln = lnext(ln)) {
173 int *ip = malloc(sizeof(int));
174 if (ip == NULL) {
175 // avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n",
176 // progname);
177 // exit(1);
178 avrdude_oom("out of memory allocating programmer structure\n");
179 }
180 *ip = *(int *) ldata(ln);
181 ladd(pgm->usbpid, ip);
182 }
183
184 return pgm;
185}
LISTID usbpid
Definition libavrdude.h:632

References avrdude_message(), avrdude_oom(), programmer_t::id, ladd(), lcreat(), ldata(), lfirst(), lnext(), malloc(), MSG_INFO, pgm, progname, and programmer_t::usbpid.

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgm_fill_old_pins()

int pgm_fill_old_pins ( struct programmer_t *const  pgm)

Convert for given programmer new pin definitions to old pin definitions.

Parameters
[in,out]pgmprogrammer whose pins shall be converted.
120 {
121
123 return -1;
125 return -1;
127 return -1;
129 return -1;
131 return -1;
133 return -1;
135 return -1;
137 return -1;
139 return -1;
141 return -1;
142
143 return 0;
144}
static int pin_fill_old_pinno(const struct pindef_t *const pindef, unsigned int *const pinno)
Definition pindefs.c:60
static int pin_fill_old_pinlist(const struct pindef_t *const pindef, unsigned int *const pinno)
Definition pindefs.c:85

References pgm, programmer_t::pin, PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, pin_fill_old_pinlist(), pin_fill_old_pinno(), PIN_LED_ERR, PIN_LED_PGM, PIN_LED_RDY, PIN_LED_VFY, programmer_t::pinno, PPI_AVR_BUFF, and PPI_AVR_VCC.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgm_free()

void pgm_free ( PROGRAMMER *const  p)
142{
143 ldestroy_cb(p->id, free);
145 p->id = NULL;
146 p->usbpid = NULL;
147 /* this is done by pgm_teardown, but usually cookie is not set to NULL */
148 /* if (p->cookie !=NULL) {
149 free(p->cookie);
150 p->cookie = NULL;
151 }*/
152 free(p);
153}

References free(), programmer_t::id, ldestroy_cb(), and programmer_t::usbpid.

Referenced by cleanup_config(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgm_new()

PROGRAMMER * pgm_new ( void  )
65{
66 int i;
68
69 pgm = (PROGRAMMER *)malloc(sizeof(*pgm));
70 if (pgm == NULL) {
71 avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n",
72 progname);
73 return NULL;
74 }
75
76 memset(pgm, 0, sizeof(*pgm));
77
78 pgm->id = lcreat(NULL, 0);
79 pgm->usbpid = lcreat(NULL, 0);
80 pgm->desc[0] = 0;
81 pgm->type[0] = 0;
82 pgm->config_file[0] = 0;
83 pgm->lineno = 0;
84 pgm->baudrate = 0;
85 pgm->initpgm = NULL;
86
87 for (i=0; i<N_PINS; i++) {
88 pgm->pinno[i] = 0;
89 pin_clear_all(&(pgm->pin[i]));
90 }
91
92 /*
93 * mandatory functions - these are called without checking to see
94 * whether they are assigned or not
95 */
108
109 /*
110 * predefined functions - these functions have a valid default
111 * implementation. Hence, they don't need to be defined in
112 * the programmer.
113 */
118
119 /*
120 * optional functions - these are checked to make sure they are
121 * assigned before they are called
122 */
123 pgm->cmd = NULL;
124 pgm->cmd_tpi = NULL;
125 pgm->spi = NULL;
126 pgm->paged_write = NULL;
127 pgm->paged_load = NULL;
128 pgm->write_setup = NULL;
129 pgm->read_sig_bytes = NULL;
130 pgm->set_vtarget = NULL;
131 pgm->set_varef = NULL;
132 pgm->set_fosc = NULL;
133 pgm->perform_osccal = NULL;
134 pgm->parseextparams = NULL;
135 pgm->setup = NULL;
136 pgm->teardown = NULL;
137
138 return pgm;
139}
void pin_clear_all(struct pindef_t *const pindef)
Definition pindefs.c:50
@ N_PINS
Definition libavrdude.h:363
static int pgm_default_3(struct programmer_t *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition pgm.c:200
static int pgm_default_led(struct programmer_t *pgm, int value)
Definition pgm.c:47
static int pgm_default_2(struct programmer_t *, AVRPART *)
Definition pgm.c:194
static int pgm_default_5(struct programmer_t *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition pgm.c:212
static void pgm_default_4(struct programmer_t *)
Definition pgm.c:207
static void pgm_default_6(struct programmer_t *, const char *)
Definition pgm.c:219
static void pgm_default_powerup_powerdown(struct programmer_t *pgm)
Definition pgm.c:56
static int pgm_default_open(struct programmer_t *pgm, char *name)
Definition pgm.c:40
void(* display)(struct programmer_t *pgm, const char *p)
Definition libavrdude.h:644
int(* open)(struct programmer_t *pgm, char *port)
Definition libavrdude.h:657
void(* powerup)(struct programmer_t *pgm)
Definition libavrdude.h:647
int(* set_vtarget)(struct programmer_t *pgm, double v)
Definition libavrdude.h:674
int(* perform_osccal)(struct programmer_t *pgm)
Definition libavrdude.h:682
char config_file[PATH_MAX]
Definition libavrdude.h:687
int baudrate
Definition libavrdude.h:630
void(* teardown)(struct programmer_t *pgm)
Definition libavrdude.h:685
int(* spi)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res, int count)
Definition libavrdude.h:655
int(* set_varef)(struct programmer_t *pgm, unsigned int chan, double v)
Definition libavrdude.h:675
void(* initpgm)(struct programmer_t *pgm)
Definition libavrdude.h:621
int(* parseextparams)(struct programmer_t *pgm, LISTID xparams)
Definition libavrdude.h:683
void(* enable)(struct programmer_t *pgm)
Definition libavrdude.h:645
int(* rdy_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:639
int(* program_enable)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:649
int lineno
Definition libavrdude.h:688
void(* setup)(struct programmer_t *pgm)
Definition libavrdude.h:684
int(* set_fosc)(struct programmer_t *pgm, double v)
Definition libavrdude.h:676
void(* close)(struct programmer_t *pgm)
Definition libavrdude.h:658
void(* disable)(struct programmer_t *pgm)
Definition libavrdude.h:646

References avrdude_message(), programmer_t::baudrate, programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::cmd_tpi, programmer_t::config_file, programmer_t::desc, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::err_led, programmer_t::id, programmer_t::initialize, programmer_t::initpgm, lcreat(), programmer_t::lineno, malloc(), MSG_INFO, N_PINS, programmer_t::open, programmer_t::paged_load, programmer_t::paged_write, programmer_t::parseextparams, programmer_t::perform_osccal, pgm, pgm_default_2(), pgm_default_3(), pgm_default_4(), pgm_default_5(), pgm_default_6(), pgm_default_led(), pgm_default_open(), pgm_default_powerup_powerdown(), programmer_t::pgm_led, programmer_t::pin, pin_clear_all(), programmer_t::pinno, programmer_t::powerdown, programmer_t::powerup, progname, programmer_t::program_enable, programmer_t::rdy_led, programmer_t::read_byte, programmer_t::read_sig_bytes, programmer_t::set_fosc, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, programmer_t::spi, programmer_t::teardown, programmer_t::type, programmer_t::usbpid, programmer_t::vfy_led, programmer_t::write_byte, and programmer_t::write_setup.

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pin_clear_all()

void pin_clear_all ( struct pindef_t *const  pindef)

Clear all defined pins in pindef.

Parameters
[out]pindefpin definition to clear
50 {
51 memset(pindef, 0, sizeof(struct pindef_t));
52}
Definition libavrdude.h:423

Referenced by pgm_new(), and yyparse().

+ Here is the caller graph for this function:

◆ pin_set_value()

void pin_set_value ( struct pindef_t *const  pindef,
const int  pin,
const bool  inverse 
)

Adds a pin in the pin definition as normal or inverse pin.

Parameters
[out]pindefpin definition to update
[in]pinnumber of pin [0..PIN_MAX]
[in]inverseinverse (true) or normal (false) pin
35 {
36
37 pindef->mask[pin / PIN_FIELD_ELEMENT_SIZE] |= 1 << (pin % PIN_FIELD_ELEMENT_SIZE);
38 if(inverse) {
39 pindef->inverse[pin / PIN_FIELD_ELEMENT_SIZE] |= (1 << (pin % PIN_FIELD_ELEMENT_SIZE));
40 } else {
41 pindef->inverse[pin / PIN_FIELD_ELEMENT_SIZE] &= ~(1 << (pin % PIN_FIELD_ELEMENT_SIZE));
42 }
43}
#define PIN_FIELD_ELEMENT_SIZE
Definition libavrdude.h:378
pinmask_t mask[PIN_FIELD_SIZE]
bitfield of used pins
Definition libavrdude.h:424
pinmask_t inverse[PIN_FIELD_SIZE]
bitfield of inverse/normal usage of used pins
Definition libavrdude.h:425

References inverse(), pindef_t::inverse, pindef_t::mask, and PIN_FIELD_ELEMENT_SIZE.

Referenced by assign_pin(), and assign_pin_list().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pinmask_to_str()

const char * pinmask_to_str ( const pinmask_t *const  pinmask)

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.

Parameters
[in]pinmaskthe pin mask for which we want the string representation
Returns
pointer to a static string.
154 {
155 static char buf[(PIN_MAX + 1) * 5]; // should be enough for PIN_MAX=255
156 char *p = buf;
157 int n;
158 int pin;
159 const char * fmt;
160 int start = -1;
161 int end = -1;
162
163 buf[0] = 0;
164 for(pin = PIN_MIN; pin <= PIN_MAX; pin++) {
165 int index = pin / PIN_FIELD_ELEMENT_SIZE;
166 int bit = pin % PIN_FIELD_ELEMENT_SIZE;
167 if(pinmask[index] & (1 << bit)) {
168 bool output = false;
169 if(start == -1) {
170 output = true;
171 start = pin;
172 end = start;
173 } else if(pin == end + 1) {
174 end = pin;
175 } else {
176 if(start != end) {
177 n = sprintf(p, "-%d", end);
178 p += n;
179 }
180 output = true;
181 start = pin;
182 end = start;
183 }
184 if(output) {
185 fmt = (buf[0] == 0) ? "%d" : ",%d";
186 n = sprintf(p, fmt, pin);
187 p += n;
188 }
189 }
190 }
191 if(start != end) {
192 n = sprintf(p, "-%d", end);
193 p += n;
194 }
195
196 if(buf[0] == 0)
197 return "(no pins)";
198
199 return buf;
200}
#define PIN_MIN
Definition libavrdude.h:368
#define PIN_MAX
Definition libavrdude.h:369
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620

References PIN_FIELD_ELEMENT_SIZE, PIN_MAX, and PIN_MIN.

Referenced by pins_check().

+ Here is the caller graph for this function:

◆ pins_check()

int pins_check ( const struct programmer_t *const  pgm,
const struct pin_checklist_t *const  checklist,
const int  size,
const bool  output 
)

This function checks all pin of pgm against the constraints given in the checklist. It checks if

  • any invalid pins are used
  • valid pins are used inverted when not allowed
  • any pins are used by more than one function
  • 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.

Parameters
[in]pgmthe programmer to check
[in]checklistthe constraint for the pins
[in]sizethe number of entries in checklist
[in]outputfalse suppresses error messages to the user
Returns
0 if all pin definitions are valid, -1 otherwise

This function checks all pin of pgm against the constraints given in the checklist. It checks if

  • any invalid pins are used
  • valid pins are used inverted when not allowed
  • any pins are used by more than one function
  • 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.

Parameters
[in]pgmthe programmer to check
[in]checklistthe constraint for the pins
[in]sizethe number of entries in checklist
Returns
0 if all pin definitions are valid, -1 otherwise
220 {
221 static const struct pindef_t no_valid_pins = {{0}, {0}}; // default value if check list does not contain anything else
222 int rv = 0; // return value
223 int pinname; // loop counter through pinnames
224 pinmask_t already_used_all[PIN_FIELD_SIZE] = {0}; // collect pin definitions of all pin names for check of double use
225 // loop over all possible pinnames
226 for(pinname = 0; pinname < N_PINS; pinname++) {
227 bool used = false;
228 bool invalid = false;
229 bool inverse = false;
230 int index;
231 int segment;
232 bool mandatory_used = false;
233 pinmask_t invalid_used[PIN_FIELD_SIZE] = {0};
234 pinmask_t inverse_used[PIN_FIELD_SIZE] = {0};
235 pinmask_t already_used[PIN_FIELD_SIZE] = {0};
236 const struct pindef_t * valid_pins = &no_valid_pins;
237 bool is_mandatory = false;
238 bool is_ok = true;
239 //find corresponding check pattern
240 for(index = 0; index < size; index++) {
241 if(checklist[index].pinname == pinname) {
242 valid_pins = checklist[index].valid_pins;
243 is_mandatory = checklist[index].mandatory;
244 break;
245 }
246 }
247
248 for(segment = 0; segment < PIN_FIELD_SIZE; segment++) {
249 // check if for mandatory any pin is defined
250 invalid_used[segment] = pgm->pin[pinname].mask[segment] & ~valid_pins->mask[segment];
251 if(is_mandatory && (0 != (pgm->pin[pinname].mask[segment] & valid_pins->mask[segment]))) {
252 mandatory_used = true;
253 }
254 // check if it does not use any non valid pins
255 invalid_used[segment] = pgm->pin[pinname].mask[segment] & ~valid_pins->mask[segment];
256 if(invalid_used[segment]) {
257 invalid = true;
258 }
259 // check if it does not use any valid pins as inverse if not allowed
260 inverse_used[segment] = pgm->pin[pinname].inverse[segment] & valid_pins->mask[segment] & ~valid_pins->inverse[segment];
261 if(inverse_used[segment]) {
262 inverse = true;
263 }
264 // check if it does not use same pins as other function
265 already_used[segment] = pgm->pin[pinname].mask[segment] & already_used_all[segment];
266 if(already_used[segment]) {
267 used = true;
268 }
269 already_used_all[segment] |= pgm->pin[pinname].mask[segment];
270 }
271 if(invalid) {
272 if(output) {
273 avrdude_message(MSG_INFO, "%s: %s: Following pins are not valid pins for this function: %s\n",
274 progname, avr_pin_name(pinname), pinmask_to_str(invalid_used));
275 avrdude_message(MSG_NOTICE2, "%s: %s: Valid pins for this function are: %s\n",
276 progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->mask));
277 }
278 is_ok = false;
279 }
280 if(inverse) {
281 if(output) {
282 avrdude_message(MSG_INFO, "%s: %s: Following pins are not usable as inverse pins for this function: %s\n",
283 progname, avr_pin_name(pinname), pinmask_to_str(inverse_used));
284 avrdude_message(MSG_NOTICE2, "%s: %s: Valid inverse pins for this function are: %s\n",
285 progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->inverse));
286 }
287 is_ok = false;
288 }
289 if(used) {
290 if(output) {
291 avrdude_message(MSG_INFO, "%s: %s: Following pins are set for other functions too: %s\n",
292 progname, avr_pin_name(pinname), pinmask_to_str(already_used));
293 is_ok = false;
294 }
295 }
296 if(!mandatory_used && is_mandatory && !invalid) {
297 if(output) {
298 avrdude_message(MSG_INFO, "%s: %s: Mandatory pin is not defined.\n",
299 progname, avr_pin_name(pinname));
300 }
301 is_ok = false;
302 }
303 if(!is_ok) {
304 rv = -1;
305 } else if(output) {
306 avrdude_message(MSG_DEBUG, "%s: %s: Pin is ok.\n",
307 progname, avr_pin_name(pinname));
308 }
309 }
310 return rv;
311}
EIGEN_DEVICE_FUNC SegmentReturnType segment(Index start, Index n)
This is the const version of segment(Index,Index).
Definition BlockMethods.h:888
#define MSG_NOTICE2
Definition avrdude.h:53
uint32_t pinmask_t
Definition libavrdude.h:34
#define PIN_FIELD_SIZE
Definition libavrdude.h:380
int mandatory
is this a mandatory pin
Definition libavrdude.h:433
const struct pindef_t * valid_pins
mask defines allowed pins, inverse define is they might be used inverted
Definition libavrdude.h:434
const char * avr_pin_name(int pinname)
Definition pindefs.c:354
const char * pinmask_to_str(const pinmask_t *const pinmask)
Definition pindefs.c:154

References avr_pin_name(), avrdude_message(), inverse(), pindef_t::inverse, pin_checklist_t::mandatory, pindef_t::mask, MSG_DEBUG, MSG_INFO, MSG_NOTICE2, N_PINS, pgm, programmer_t::pin, PIN_FIELD_SIZE, pinmask_to_str(), progname, segment(), and pin_checklist_t::valid_pins.

+ Here is the call graph for this function:

◆ pins_to_str()

const char * pins_to_str ( const struct pindef_t *const  pindef)

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.

Parameters
[in]pindefthe pin definition for which we want the string representation
Returns
pointer to a static string.
320 {
321 static char buf[(PIN_MAX + 1) * 5]; // should be enough for PIN_MAX=255
322 char *p = buf;
323 int n;
324 int pin;
325 const char * fmt;
326
327 buf[0] = 0;
328 for(pin = PIN_MIN; pin <= PIN_MAX; pin++) {
329 int index = pin / PIN_FIELD_ELEMENT_SIZE;
330 int bit = pin % PIN_FIELD_ELEMENT_SIZE;
331 if(pindef->mask[index] & (1 << bit)) {
332 if(pindef->inverse[index] & (1 << bit)) {
333 fmt = (buf[0] == 0) ? "~%d" : ",~%d";
334 } else {
335 fmt = (buf[0] == 0) ? " %d" : ",%d";
336 }
337 n = sprintf(p, fmt, pin);
338 p += n;
339 }
340 }
341
342 if(buf[0] == 0)
343 return " (not used)";
344
345 return buf;
346}

References pindef_t::inverse, pindef_t::mask, PIN_FIELD_ELEMENT_SIZE, PIN_MAX, and PIN_MIN.

Referenced by pgm_display_generic_mask().

+ Here is the caller graph for this function:

◆ programmer_display()

void programmer_display ( PROGRAMMER pgm,
const char *  p 
)
226{
227 avrdude_message(MSG_INFO, "%sProgrammer Type : %s\n", p, pgm->type);
228 avrdude_message(MSG_INFO, "%sDescription : %s\n", p, pgm->desc);
229
230 pgm->display(pgm, p);
231}

References avrdude_message(), programmer_t::desc, programmer_t::display, MSG_INFO, pgm, and programmer_t::type.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_config()

int read_config ( const char *  file)
326{
327 FILE * f;
328 int r;
329
330 f = fopen_utf8(file, "r");
331 if (f == NULL) {
332 avrdude_message(MSG_INFO, "%s: can't open config file \"%s\": %s\n",
333 progname, file, strerror(errno));
334 return -1;
335 }
336
337 lineno = 1;
338 infile = file;
339 yyin = f;
340
341 r = yyparse();
342
343#ifdef HAVE_YYLEX_DESTROY
344 /* reset lexer and free any allocated memory */
346#endif
347
348 fclose(f);
349
350 return r;
351}
int yylex_destroy(void)
int yyparse(void)
Definition config_gram.c:1576
FILE * yyin
Definition lexer.c:327
FILE * fopen_utf8(const char *filename, const char *mode)
Definition fileio.c:108

References avrdude_message(), fopen_utf8(), infile, lineno, MSG_INFO, progname, yyin, yylex_destroy(), and yyparse().

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_config_builtin()

int read_config_builtin ( )
358{
359 int r;
360
361 lineno = 1;
362 infile = "(builtin)";
363
364 // Note: Can't use yy_scan_buffer, it's buggy (?), leads to fread from a null FILE*
365 // and so unfortunatelly we have to use the copying variant here
366 YY_BUFFER_STATE buffer = yy_scan_bytes((const char *)avrdude_slic3r_conf, avrdude_slic3r_conf_SIZE);
367 if (buffer == NULL) {
368 avrdude_message(MSG_INFO, "%s: read_config_builtin: Failed to initialize parsing buffer\n", progname);
369 return -1;
370 }
371
372 r = yyparse();
373 yy_delete_buffer(buffer);
374
375#ifdef HAVE_YYLEX_DESTROY
376 /* reset lexer and free any allocated memory */
378#endif
379
380 return r;
381}
YY_BUFFER_STATE yy_scan_bytes(const char *base, size_t size)
void yy_delete_buffer(YY_BUFFER_STATE b)
Definition lexer.c:186

References avrdude_message(), infile, lineno, MSG_INFO, progname, yy_delete_buffer(), yy_scan_bytes(), yylex_destroy(), and yyparse().

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ report_progress()

void report_progress ( int  completed,
int  total,
char *  hdr 
)
1225{
1226 static int last = 0;
1227 static double start_time;
1228 int percent = (total > 0) ? ((completed * 100) / total) : 100;
1229 struct timeval tv;
1230 double t;
1231
1232 if (update_progress == NULL)
1233 return;
1234
1235 gettimeofday(&tv, NULL);
1236 t = tv.tv_sec + ((double)tv.tv_usec)/1000000;
1237
1238 if (hdr) {
1239 last = 0;
1240 start_time = t;
1241 update_progress (percent, t - start_time, hdr);
1242 }
1243
1244 if (percent > 100)
1245 percent = 100;
1246
1247 if (percent > last) {
1248 last = percent;
1249 update_progress (percent, t - start_time, hdr);
1250 }
1251
1252 if (percent == 100)
1253 last = 0; /* Get ready for next time. */
1254}
FP_UpdateProgress update_progress
Definition avr.c:39

References gettimeofday(), and update_progress.

Referenced by avr_read(), avr_signature(), avr_write(), and do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safemode_memfuses()

int safemode_memfuses ( int  save,
unsigned char *  lfuse,
unsigned char *  hfuse,
unsigned char *  efuse,
unsigned char *  fuse 
)
292{
293 static unsigned char safemode_lfuse = 0xff;
294 static unsigned char safemode_hfuse = 0xff;
295 static unsigned char safemode_efuse = 0xff;
296 static unsigned char safemode_fuse = 0xff;
297
298 switch (save) {
299
300 /* Save the fuses as safemode setting */
301 case 1:
302 safemode_lfuse = *lfuse;
303 safemode_hfuse = *hfuse;
304 safemode_efuse = *efuse;
305 safemode_fuse = *fuse;
306
307 break;
308 /* Read back the fuses */
309 default:
310 *lfuse = safemode_lfuse;
311 *hfuse = safemode_hfuse;
312 *efuse = safemode_efuse;
313 *fuse = safemode_fuse;
314 break;
315 }
316
317 return 0;
318}

References save().

Referenced by avr_write_byte(), and avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safemode_readfuses()

int safemode_readfuses ( unsigned char *  lfuse,
unsigned char *  hfuse,
unsigned char *  efuse,
unsigned char *  fuse,
PROGRAMMER pgm,
AVRPART p 
)
80{
81
82 unsigned char value;
83 unsigned char fusegood = 0;
84 unsigned char allowfuseread = 1;
85 unsigned char safemode_lfuse;
86 unsigned char safemode_hfuse;
87 unsigned char safemode_efuse;
88 unsigned char safemode_fuse;
89 AVRMEM * m;
90
91 safemode_lfuse = *lfuse;
92 safemode_hfuse = *hfuse;
93 safemode_efuse = *efuse;
94 safemode_fuse = *fuse;
95
96
97 /* Read fuse three times */
98 fusegood = 2; /* If AVR device doesn't support this fuse, don't want
99 to generate a verify error */
100 m = avr_locate_mem(p, "fuse");
101 if (m != NULL) {
102 fusegood = 0; /* By default fuse is a failure */
103 if(pgm->read_byte(pgm, p, m, 0, &safemode_fuse) != 0)
104 {
105 allowfuseread = 0;
106 }
107 avrdude_message(MSG_DEBUG, "%s: safemode read 1, fuse value: %x\n",progname, safemode_fuse);
108 if(pgm->read_byte(pgm, p, m, 0, &value) != 0)
109 {
110 allowfuseread = 0;
111 }
112 avrdude_message(MSG_DEBUG, "%s: safemode read 2, fuse value: %x\n",progname, value);
113 if (value == safemode_fuse) {
114 if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
115 {
116 allowfuseread = 0;
117 }
118 avrdude_message(MSG_DEBUG, "%s: safemode read 3, fuse value: %x\n",progname, value);
119 if (value == safemode_fuse)
120 {
121 fusegood = 1; /* Fuse read OK three times */
122 }
123 }
124 }
125
126 //Programmer does not allow fuse reading.... no point trying anymore
127 if (allowfuseread == 0)
128 {
129 return -5;
130 }
131
132 if (fusegood == 0) {
133 avrdude_message(MSG_INFO, "%s: safemode: Verify error - unable to read fuse properly. "
134 "Programmer may not be reliable.\n", progname);
135 return -1;
136 }
137 else if (fusegood == 1) {
138 avrdude_message(MSG_NOTICE, "%s: safemode: fuse reads as %X\n", progname, safemode_fuse);
139 }
140
141
142 /* Read lfuse three times */
143 fusegood = 2; /* If AVR device doesn't support this fuse, don't want
144 to generate a verify error */
145 m = avr_locate_mem(p, "lfuse");
146 if (m != NULL) {
147 fusegood = 0; /* By default fuse is a failure */
148 if (pgm->read_byte(pgm, p, m, 0, &safemode_lfuse) != 0)
149 {
150 allowfuseread = 0;
151 }
152 avrdude_message(MSG_DEBUG, "%s: safemode read 1, lfuse value: %x\n",progname, safemode_lfuse);
153 if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
154 {
155 allowfuseread = 0;
156 }
157 avrdude_message(MSG_DEBUG, "%s: safemode read 2, lfuse value: %x\n",progname, value);
158 if (value == safemode_lfuse) {
159 if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
160 {
161 allowfuseread = 0;
162 }
163 avrdude_message(MSG_DEBUG, "%s: safemode read 3, lfuse value: %x\n",progname, value);
164 if (value == safemode_lfuse){
165 fusegood = 1; /* Fuse read OK three times */
166 }
167 }
168 }
169
170 //Programmer does not allow fuse reading.... no point trying anymore
171 if (allowfuseread == 0)
172 {
173 return -5;
174 }
175
176
177 if (fusegood == 0) {
178 avrdude_message(MSG_INFO, "%s: safemode: Verify error - unable to read lfuse properly. "
179 "Programmer may not be reliable.\n", progname);
180 return -1;
181 }
182 else if (fusegood == 1) {
183 avrdude_message(MSG_DEBUG, "%s: safemode: lfuse reads as %X\n", progname, safemode_lfuse);
184 }
185
186 /* Read hfuse three times */
187 fusegood = 2; /* If AVR device doesn't support this fuse, don't want
188 to generate a verify error */
189 m = avr_locate_mem(p, "hfuse");
190 if (m != NULL) {
191 fusegood = 0; /* By default fuse is a failure */
192 if (pgm->read_byte(pgm, p, m, 0, &safemode_hfuse) != 0)
193 {
194 allowfuseread = 0;
195 }
196 avrdude_message(MSG_DEBUG, "%s: safemode read 1, hfuse value: %x\n",progname, safemode_hfuse);
197 if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
198 {
199 allowfuseread = 0;
200 }
201 avrdude_message(MSG_DEBUG, "%s: safemode read 2, hfuse value: %x\n",progname, value);
202 if (value == safemode_hfuse) {
203 if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
204 {
205 allowfuseread = 0;
206 }
207 avrdude_message(MSG_DEBUG, "%s: safemode read 3, hfuse value: %x\n",progname, value);
208 if (value == safemode_hfuse){
209 fusegood = 1; /* Fuse read OK three times */
210 }
211 }
212 }
213
214 //Programmer does not allow fuse reading.... no point trying anymore
215 if (allowfuseread == 0)
216 {
217 return -5;
218 }
219
220 if (fusegood == 0) {
221 avrdude_message(MSG_INFO, "%s: safemode: Verify error - unable to read hfuse properly. "
222 "Programmer may not be reliable.\n", progname);
223 return -2;
224 }
225 else if (fusegood == 1){
226 avrdude_message(MSG_NOTICE, "%s: safemode: hfuse reads as %X\n", progname, safemode_hfuse);
227 }
228
229 /* Read efuse three times */
230 fusegood = 2; /* If AVR device doesn't support this fuse, don't want
231 to generate a verify error */
232 m = avr_locate_mem(p, "efuse");
233 if (m != NULL) {
234 fusegood = 0; /* By default fuse is a failure */
235 if (pgm->read_byte(pgm, p, m, 0, &safemode_efuse) != 0)
236 {
237 allowfuseread = 0;
238 }
239 avrdude_message(MSG_DEBUG, "%s: safemode read 1, efuse value: %x\n",progname, safemode_efuse);
240 if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
241 {
242 allowfuseread = 0;
243 }
244 avrdude_message(MSG_DEBUG, "%s: safemode read 2, efuse value: %x\n",progname, value);
245 if (value == safemode_efuse) {
246 if (pgm->read_byte(pgm, p, m, 0, &value) != 0)
247 {
248 allowfuseread = 0;
249 }
250 avrdude_message(MSG_DEBUG, "%s: safemode read 3, efuse value: %x\n",progname, value);
251 if (value == safemode_efuse){
252 fusegood = 1; /* Fuse read OK three times */
253 }
254 }
255 }
256
257 //Programmer does not allow fuse reading.... no point trying anymore
258 if (allowfuseread == 0)
259 {
260 return -5;
261 }
262
263 if (fusegood == 0) {
264 avrdude_message(MSG_INFO, "%s: safemode: Verify error - unable to read efuse properly. "
265 "Programmer may not be reliable.\n", progname);
266 return -3;
267 }
268 else if (fusegood == 1) {
269 avrdude_message(MSG_NOTICE, "%s: safemode: efuse reads as %X\n", progname, safemode_efuse);
270 }
271
272 *lfuse = safemode_lfuse;
273 *hfuse = safemode_hfuse;
274 *efuse = safemode_efuse;
275 *fuse = safemode_fuse;
276
277 return 0;
278}
#define MSG_NOTICE
Definition avrdude.h:52

References avr_locate_mem(), avrdude_message(), MSG_DEBUG, MSG_INFO, MSG_NOTICE, pgm, progname, and programmer_t::read_byte.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safemode_writefuse()

int safemode_writefuse ( unsigned char  fuse,
char *  fusename,
PROGRAMMER pgm,
AVRPART p,
int  tries 
)
37{
38 AVRMEM * m;
39 unsigned char fuseread;
40 int returnvalue = -1;
41
42 m = avr_locate_mem(p, fusename);
43 if (m == NULL) {
44 return -1;
45 }
46
47 /* Keep trying to write then read back the fuse values */
48 while (tries > 0) {
49 if (avr_write_byte(pgm, p, m, 0, fuse) != 0)
50 {
51 continue;
52 }
53 if (pgm->read_byte(pgm, p, m, 0, &fuseread) != 0)
54 {
55 continue;
56 }
57
58 /* Report information to user if needed */
59 avrdude_message(MSG_NOTICE, "%s: safemode: Wrote %s to %x, read as %x. %d attempts left\n",
60 progname, fusename, fuse, fuseread, tries-1);
61
62 /* If fuse wrote OK, no need to keep going */
63 if (fuse == fuseread) {
64 tries = 0;
65 returnvalue = 0;
66 }
67 tries--;
68 }
69
70 return returnvalue;
71}

References avr_locate_mem(), avr_write_byte(), avrdude_message(), MSG_NOTICE, pgm, progname, and programmer_t::read_byte.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sort_avrparts()

void sort_avrparts ( LISTID  avrparts)
606{
607 lsort(avrparts,(int (*)(void*, void*)) sort_avrparts_compare);
608}
static int sort_avrparts_compare(AVRPART *p1, AVRPART *p2)
Definition avrpart.c:594
void lsort(LISTID lid, int(*compare)(void *p1, void *p2))
Definition lists.c:1289

References lsort(), and sort_avrparts_compare().

Referenced by list_parts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sort_programmers()

void sort_programmers ( LISTID  programmers)
330{
331 lsort(programmers,(int (*)(void*, void*)) sort_programmer_compare);
332}
static int sort_programmer_compare(PROGRAMMER *p1, PROGRAMMER *p2)
Definition pgm.c:314

References lsort(), programmers, and sort_programmer_compare().

Referenced by list_programmers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ walk_avrparts()

void walk_avrparts ( LISTID  avrparts,
walk_avrparts_cb  cb,
void cookie 
)
581{
582 LNODEID ln1;
583 AVRPART * p;
584
585 for (ln1 = lfirst(avrparts); ln1; ln1 = lnext(ln1)) {
586 p = ldata(ln1);
587 cb(p->id, p->desc, p->config_file, p->lineno, cookie);
588 }
589}

References avrpart::config_file, avrpart::desc, avrpart::id, ldata(), lfirst(), avrpart::lineno, and lnext().

Referenced by list_parts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ walk_programmer_types()

void walk_programmer_types ( walk_programmer_types_cb  cb,
void cookie 
)
143{
144 const PROGRAMMER_TYPE * p;
145 int i;
146
147 for (i = 0; i < sizeof(programmers_types)/sizeof(programmers_types[0]); i++) {
148 p = &(programmers_types[i]);
149 cb(p->id, p->desc, cookie);
150 }
151}

References programmer_type_t::desc, programmer_type_t::id, and programmers_types.

Referenced by list_programmer_types().

+ Here is the caller graph for this function:

◆ walk_programmers()

void walk_programmers ( LISTID  programmers,
walk_programmers_cb  cb,
void cookie 
)
298{
299 LNODEID ln1;
300 LNODEID ln2;
301 PROGRAMMER * p;
302
303 for (ln1 = lfirst(programmers); ln1; ln1 = lnext(ln1)) {
304 p = ldata(ln1);
305 for (ln2=lfirst(p->id); ln2; ln2=lnext(ln2)) {
306 cb(ldata(ln2), p->desc, p->config_file, p->lineno, cookie);
307 }
308 }
309}

References programmer_t::config_file, programmer_t::desc, programmer_t::id, ldata(), lfirst(), programmer_t::lineno, lnext(), and programmers.

Referenced by list_programmers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ avrdoper_serdev

struct serial_device avrdoper_serdev
extern

Referenced by stk500v2_open().

◆ cancel_flag

bool cancel_flag
extern

Referenced by avrdude_cancel(), and avrdude_main().

◆ default_bitclock

double default_bitclock
extern

Referenced by avrdude_main(), and yyparse().

◆ default_parallel

char default_parallel[]
extern

Referenced by avrdude_main(), and yyparse().

◆ default_programmer

char default_programmer[]
extern

Referenced by avrdude_main(), and yyparse().

◆ default_safemode

int default_safemode
extern

Referenced by avrdude_main(), and yyparse().

◆ default_serial

char default_serial[]
extern

Referenced by avrdude_main(), and yyparse().

◆ part_list

◆ parts

◆ programmers

◆ serdev

◆ serial_recv_timeout

◆ serial_serdev

struct serial_device serial_serdev
extern

◆ update_progress

FP_UpdateProgress update_progress
extern

Referenced by avrdude_main(), and report_progress().

◆ usb_serdev

◆ usb_serdev_frame

struct serial_device usb_serdev_frame
extern

◆ usbhid_serdev

struct serial_device usbhid_serdev
extern

Referenced by jtag3_open_common().