Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
stk500v2.c File Reference
#include "ac_cfg.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "stk500_private.h"
#include "stk500v2.h"
#include "stk500v2_private.h"
#include "usbdevs.h"
#include "jtagmkII.h"
#include "jtagmkII_private.h"
#include "jtag3.h"
#include "jtag3_private.h"
+ Include dependency graph for stk500v2.c:

Go to the source code of this file.

Classes

struct  carddata
 
struct  jtagispentry
 

Macros

#define JTAGMKII_PRIVATE_EXPORTED
 
#define JTAG3_PRIVATE_EXPORTED
 
#define STK500V2_XTAL   7372800U
 
#define SERIAL_TIMEOUT   2
 
#define RETRIES   0
 
#define DEBUG(...)
 
#define DEBUGRECV(...)
 
#define PDATA(pgm)   ((struct pdata *)(pgm->cookie))
 
#define SZ_READ_FLASH_EE   USHRT_MAX
 
#define SZ_SPI_MULTI   (USHRT_MAX - 1)
 

Enumerations

enum  hvmode { PPMODE , HVSPMODE }
 

Functions

static int stk500v2_getparm (PROGRAMMER *pgm, unsigned char parm, unsigned char *value)
 
static int stk500v2_setparm (PROGRAMMER *pgm, unsigned char parm, unsigned char value)
 
static int stk500v2_getparm2 (PROGRAMMER *pgm, unsigned char parm, unsigned int *value)
 
static int stk500v2_setparm2 (PROGRAMMER *pgm, unsigned char parm, unsigned int value)
 
static int stk500v2_setparm_real (PROGRAMMER *pgm, unsigned char parm, unsigned char value)
 
static void stk500v2_print_parms1 (PROGRAMMER *pgm, const char *p)
 
static int stk500v2_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int stk500v2_paged_write (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static unsigned int stk500v2_mode_for_pagesize (unsigned int pagesize)
 
static double stk500v2_sck_to_us (PROGRAMMER *pgm, unsigned char dur)
 
static int stk500v2_set_sck_period_mk2 (PROGRAMMER *pgm, double v)
 
static int stk600_set_sck_period (PROGRAMMER *pgm, double v)
 
static void stk600_setup_xprog (PROGRAMMER *pgm)
 
static void stk600_setup_isp (PROGRAMMER *pgm)
 
static int stk600_xprog_program_enable (PROGRAMMER *pgm, AVRPART *p)
 
void stk500v2_setup (PROGRAMMER *pgm)
 
static void stk500v2_jtagmkII_setup (PROGRAMMER *pgm)
 
static void stk500v2_jtag3_setup (PROGRAMMER *pgm)
 
void stk500v2_teardown (PROGRAMMER *pgm)
 
static void stk500v2_jtagmkII_teardown (PROGRAMMER *pgm)
 
static void stk500v2_jtag3_teardown (PROGRAMMER *pgm)
 
static int stk500v2_send_mk2 (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
static int stk500v2_jtagmkII_send (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
static int stk500v2_jtag3_send (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
static int stk500v2_send (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
int stk500v2_drain (PROGRAMMER *pgm, int display)
 
static int stk500v2_recv_mk2 (PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
 
static int stk500v2_jtagmkII_recv (PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
 
static int stk500v2_jtag3_recv (PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
 
static int stk500v2_recv (PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
 
int stk500v2_getsync (PROGRAMMER *pgm)
 
static int stk500v2_command (PROGRAMMER *pgm, unsigned char *buf, size_t len, size_t maxlen)
 
static int stk500v2_cmd (PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
 
static int stk500v2_jtag3_cmd (PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
 
static int stk500v2_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500hv_chip_erase (PROGRAMMER *pgm, AVRPART *p, enum hvmode mode)
 
static int stk500pp_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500hvsp_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
static void stk500v2_translate_conn_status (unsigned char status, char *msg)
 
static int stk500v2_program_enable (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500pp_program_enable (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500hvsp_program_enable (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500v2_initialize (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500v2_jtag3_initialize (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500hv_initialize (PROGRAMMER *pgm, AVRPART *p, enum hvmode mode)
 
static int stk500pp_initialize (PROGRAMMER *pgm, AVRPART *p)
 
static int stk500hvsp_initialize (PROGRAMMER *pgm, AVRPART *p)
 
static void stk500v2_jtag3_disable (PROGRAMMER *pgm)
 
static void stk500v2_disable (PROGRAMMER *pgm)
 
static void stk500hv_disable (PROGRAMMER *pgm, enum hvmode mode)
 
static void stk500pp_disable (PROGRAMMER *pgm)
 
static void stk500hvsp_disable (PROGRAMMER *pgm)
 
static void stk500v2_enable (PROGRAMMER *pgm)
 
static int stk500v2_open (PROGRAMMER *pgm, char *port)
 
static int stk600_open (PROGRAMMER *pgm, char *port)
 
static void stk500v2_close (PROGRAMMER *pgm)
 
static int stk500v2_loadaddr (PROGRAMMER *pgm, unsigned int addr)
 
static int stk500hv_read_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value, enum hvmode mode)
 
static int stk500pp_read_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
 
static int stk500hvsp_read_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
 
static int stk500isp_read_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
 
static int stk500hv_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data, enum hvmode mode)
 
static int stk500pp_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
static int stk500hvsp_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
static int stk500isp_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
static int stk500hv_paged_write (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes, enum hvmode mode)
 
static int stk500pp_paged_write (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int stk500hvsp_paged_write (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int stk500hv_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes, enum hvmode mode)
 
static int stk500pp_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int stk500hvsp_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int stk500v2_page_erase (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int addr)
 
static int stk500v2_set_vtarget (PROGRAMMER *pgm, double v)
 
static int stk500v2_set_varef (PROGRAMMER *pgm, unsigned int chan, double v)
 
static int stk500v2_set_fosc (PROGRAMMER *pgm, double v)
 
static int stk500v2_set_sck_period (PROGRAMMER *pgm, double v)
 
static int stk600_set_vtarget (PROGRAMMER *pgm, double v)
 
static int stk600_set_varef (PROGRAMMER *pgm, unsigned int chan, double v)
 
static int stk600_set_fosc (PROGRAMMER *pgm, double v)
 
static int stk500v2_jtag3_set_sck_period (PROGRAMMER *pgm, double v)
 
static const char * stk600_get_cardname (const struct carddata *table, size_t nele, int id)
 
static void stk500v2_display (PROGRAMMER *pgm, const char *p)
 
static double f_to_kHz_MHz (double f, const char **unit)
 
static void stk500v2_print_parms (PROGRAMMER *pgm)
 
static int stk500v2_perform_osccal (PROGRAMMER *pgm)
 
static int stk500v2_jtagmkII_open (PROGRAMMER *pgm, char *port)
 
static void stk500v2_jtagmkII_close (PROGRAMMER *pgm)
 
static void stk500v2_jtag3_close (PROGRAMMER *pgm)
 
static int stk500v2_dragon_isp_open (PROGRAMMER *pgm, char *port)
 
static int stk500v2_dragon_hv_open (PROGRAMMER *pgm, char *port)
 
static int stk500v2_jtag3_open (PROGRAMMER *pgm, char *port)
 
static int stk600_xprog_command (PROGRAMMER *pgm, unsigned char *b, unsigned int cmdsize, unsigned int responsesize)
 
static unsigned char stk600_xprog_memtype (PROGRAMMER *pgm, unsigned long addr)
 
static void stk600_xprog_disable (PROGRAMMER *pgm)
 
static int stk600_xprog_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
static int stk600_xprog_read_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
 
static int stk600_xprog_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int stk600_xprog_paged_write (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int stk600_xprog_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
static int stk600_xprog_page_erase (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int addr)
 
void stk500v2_initpgm (PROGRAMMER *pgm)
 
void stk500pp_initpgm (PROGRAMMER *pgm)
 
void stk500hvsp_initpgm (PROGRAMMER *pgm)
 
void stk500v2_jtagmkII_initpgm (PROGRAMMER *pgm)
 
void stk500v2_dragon_isp_initpgm (PROGRAMMER *pgm)
 
void stk500v2_dragon_pp_initpgm (PROGRAMMER *pgm)
 
void stk500v2_dragon_hvsp_initpgm (PROGRAMMER *pgm)
 
void stk600_initpgm (PROGRAMMER *pgm)
 
void stk600pp_initpgm (PROGRAMMER *pgm)
 
void stk600hvsp_initpgm (PROGRAMMER *pgm)
 
void stk500v2_jtag3_initpgm (PROGRAMMER *pgm)
 
void stk500v2_set_upload_size (PROGRAMMER *pgm, int size)
 

Variables

static const char * pgmname []
 
static const struct carddata routing_cards []
 
static const struct carddata socket_cards []
 
struct { 
 
unsigned int state
 
const char * description
 
connection_status [] 
 
static double avrispmkIIfreqs []
 
const char stk500v2_desc [] = "Atmel STK500 Version 2.x firmware"
 
const char stk500pp_desc [] = "Atmel STK500 V2 in parallel programming mode"
 
const char stk500hvsp_desc [] = "Atmel STK500 V2 in high-voltage serial programming mode"
 
const char stk500v2_jtagmkII_desc [] = "Atmel JTAG ICE mkII in ISP mode"
 
const char stk500v2_dragon_isp_desc [] = "Atmel AVR Dragon in ISP mode"
 
const char stk500v2_dragon_pp_desc [] = "Atmel AVR Dragon in PP mode"
 
const char stk500v2_dragon_hvsp_desc [] = "Atmel AVR Dragon in HVSP mode"
 
const char stk600_desc [] = "Atmel STK600"
 
const char stk600pp_desc [] = "Atmel STK600 in parallel programming mode"
 
const char stk600hvsp_desc [] = "Atmel STK600 in high-voltage serial programming mode"
 
const char stk500v2_jtag3_desc [] = "Atmel JTAGICE3 in ISP mode"
 

Class Documentation

◆ carddata

struct carddata
Class Members
int id
const char * name

◆ jtagispentry

struct jtagispentry
Class Members
unsigned char cmd
unsigned short size

Macro Definition Documentation

◆ DEBUG

#define DEBUG (   ...)

◆ DEBUGRECV

#define DEBUGRECV (   ...)

◆ JTAG3_PRIVATE_EXPORTED

#define JTAG3_PRIVATE_EXPORTED

◆ JTAGMKII_PRIVATE_EXPORTED

#define JTAGMKII_PRIVATE_EXPORTED

◆ PDATA

#define PDATA (   pgm)    ((struct pdata *)(pgm->cookie))

◆ RETRIES

#define RETRIES   0

◆ SERIAL_TIMEOUT

#define SERIAL_TIMEOUT   2

◆ STK500V2_XTAL

#define STK500V2_XTAL   7372800U

◆ SZ_READ_FLASH_EE

#define SZ_READ_FLASH_EE   USHRT_MAX

◆ SZ_SPI_MULTI

#define SZ_SPI_MULTI   (USHRT_MAX - 1)

Enumeration Type Documentation

◆ hvmode

enum hvmode
Enumerator
PPMODE 
HVSPMODE 
97{
99};
@ HVSPMODE
Definition stk500v2.c:98
@ PPMODE
Definition stk500v2.c:98

Function Documentation

◆ f_to_kHz_MHz()

static double f_to_kHz_MHz ( double  f,
const char **  unit 
)
static
3290{
3291 if (f > 1e6) {
3292 f /= 1e6;
3293 *unit = "MHz";
3294 } else if (f > 1e3) {
3295 f /= 1000;
3296 *unit = "kHz";
3297 } else
3298 *unit = "Hz";
3299
3300 return f;
3301}

Referenced by stk500v2_print_parms1().

+ Here is the caller graph for this function:

◆ stk500hv_chip_erase()

static int stk500hv_chip_erase ( PROGRAMMER pgm,
AVRPART p,
enum hvmode  mode 
)
static
1040{
1041 int result;
1042 unsigned char buf[3];
1043
1044 pgm->pgm_led(pgm, ON);
1045
1046 if (mode == PPMODE) {
1047 buf[0] = CMD_CHIP_ERASE_PP;
1048 buf[1] = p->chiperasepulsewidth;
1049 buf[2] = p->chiperasepolltimeout;
1050 } else {
1051 buf[0] = CMD_CHIP_ERASE_HVSP;
1052 buf[1] = p->chiperasepolltimeout;
1053 buf[2] = p->chiperasetime;
1054 }
1055 result = stk500v2_command(pgm, buf, 3, sizeof(buf));
1057 pgm->initialize(pgm, p);
1058
1059 pgm->pgm_led(pgm, OFF);
1060
1061 return result >= 0? 0: -1;
1062}
int chiperasepulsewidth
Definition libavrdude.h:257
#define OFF
Definition libavrdude.h:585
int chiperasepolltimeout
Definition libavrdude.h:258
int chip_erase_delay
Definition libavrdude.h:222
int chiperasetime
Definition libavrdude.h:259
#define ON
Definition libavrdude.h:584
static PROGRAMMER * pgm
Definition main.c:192
static int stk500v2_command(PROGRAMMER *pgm, unsigned char *buf, size_t len, size_t maxlen)
Definition stk500v2.c:837
#define CMD_CHIP_ERASE_HVSP
Definition stk500v2_private.h:71
#define CMD_CHIP_ERASE_PP
Definition stk500v2_private.h:53
int(* pgm_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:641
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
int usleep(unsigned usec)
Definition unistd.cpp:13

References avrpart::chip_erase_delay, avrpart::chiperasepolltimeout, avrpart::chiperasepulsewidth, avrpart::chiperasetime, CMD_CHIP_ERASE_HVSP, CMD_CHIP_ERASE_PP, programmer_t::initialize, OFF, ON, pgm, programmer_t::pgm_led, PPMODE, stk500v2_command(), and usleep().

Referenced by stk500hvsp_chip_erase(), and stk500pp_chip_erase().

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

◆ stk500hv_disable()

static void stk500hv_disable ( PROGRAMMER pgm,
enum hvmode  mode 
)
static
1590{
1591 unsigned char buf[16];
1592 int result;
1593
1594 free(PDATA(pgm)->flash_pagecache);
1595 PDATA(pgm)->flash_pagecache = NULL;
1596 free(PDATA(pgm)->eeprom_pagecache);
1597 PDATA(pgm)->eeprom_pagecache = NULL;
1598
1599 buf[0] = mode == PPMODE? CMD_LEAVE_PROGMODE_PP:
1600 (PDATA(pgm)->pgmtype == PGMTYPE_STK600?
1603 buf[1] = 15; // p->hvleavestabdelay;
1604 buf[2] = 15; // p->resetdelay;
1605
1606 result = stk500v2_command(pgm, buf, 3, sizeof(buf));
1607
1608 if (result < 0) {
1609 avrdude_message(MSG_INFO, "%s: stk500hv_disable(): "
1610 "failed to leave programming mode\n",
1611 progname);
1612 }
1613
1614 return;
1615}
#define MSG_INFO
Definition avrdude.h:51
char * progname
Definition main.c:61
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
void free(void *)
IGL_INLINE void mode(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &X, const int d, Eigen::Matrix< T, Eigen::Dynamic, 1 > &M)
Definition mode.cpp:14
#define PDATA(pgm)
Definition stk500v2.c:102
#define CMD_LEAVE_PROGMODE_HVSP_STK600
Definition stk500v2_private.h:85
#define CMD_LEAVE_PROGMODE_HVSP
Definition stk500v2_private.h:70
#define CMD_LEAVE_PROGMODE_PP
Definition stk500v2_private.h:52

References avrdude_message(), CMD_LEAVE_PROGMODE_HVSP, CMD_LEAVE_PROGMODE_HVSP_STK600, CMD_LEAVE_PROGMODE_PP, free(), MSG_INFO, PDATA, pgm, PPMODE, progname, and stk500v2_command().

Referenced by stk500hvsp_disable(), and stk500pp_disable().

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

◆ stk500hv_initialize()

static int stk500hv_initialize ( PROGRAMMER pgm,
AVRPART p,
enum hvmode  mode 
)
static
1461{
1462 unsigned char buf[CTL_STACK_SIZE + 1];
1463 int result;
1464 LNODEID ln;
1465 AVRMEM * m;
1466
1467 if (p->ctl_stack_type != (mode == PPMODE? CTL_STACK_PP: CTL_STACK_HVSP)) {
1468 avrdude_message(MSG_INFO, "%s: stk500hv_initialize(): "
1469 "%s programming control stack not defined for part \"%s\"\n",
1470 progname,
1471 (mode == PPMODE? "parallel": "high-voltage serial"),
1472 p->desc);
1473 return -1;
1474 }
1475
1476 buf[0] = CMD_SET_CONTROL_STACK;
1477 memcpy(buf + 1, p->controlstack, CTL_STACK_SIZE);
1478
1479 result = stk500v2_command(pgm, buf, CTL_STACK_SIZE + 1, sizeof(buf));
1480
1481 if (result < 0) {
1482 avrdude_message(MSG_INFO, "%s: stk500hv_initalize(): "
1483 "failed to set control stack\n",
1484 progname);
1485 return -1;
1486 }
1487
1488 /*
1489 * Examine the avrpart's memory definitions, and initialize the page
1490 * caches. For devices/memory that are not page oriented, treat
1491 * them as page size 1 for EEPROM, and 2 for flash.
1492 */
1493 PDATA(pgm)->flash_pagesize = 2;
1494 PDATA(pgm)->eeprom_pagesize = 1;
1495 for (ln = lfirst(p->mem); ln; ln = lnext(ln)) {
1496 m = ldata(ln);
1497 if (strcmp(m->desc, "flash") == 0) {
1498 if (m->page_size > 0) {
1499 if (m->page_size > 256)
1500 PDATA(pgm)->flash_pagesize = 256;
1501 else
1502 PDATA(pgm)->flash_pagesize = m->page_size;
1503 }
1504 } else if (strcmp(m->desc, "eeprom") == 0) {
1505 if (m->page_size > 0)
1506 PDATA(pgm)->eeprom_pagesize = m->page_size;
1507 }
1508 }
1509 free(PDATA(pgm)->flash_pagecache);
1510 free(PDATA(pgm)->eeprom_pagecache);
1511 if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) {
1512 avrdude_message(MSG_INFO, "%s: stk500hv_initialize(): Out of memory\n",
1513 progname);
1514 return -1;
1515 }
1516 if ((PDATA(pgm)->eeprom_pagecache = malloc(PDATA(pgm)->eeprom_pagesize)) == NULL) {
1517 avrdude_message(MSG_INFO, "%s: stk500hv_initialize(): Out of memory\n",
1518 progname);
1519 free(PDATA(pgm)->flash_pagecache);
1520 return -1;
1521 }
1522 PDATA(pgm)->flash_pageaddr = PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
1523
1524 return pgm->program_enable(pgm, p);
1525}
void * malloc(YYSIZE_T)
enum ctl_stack_t ctl_stack_type
Definition libavrdude.h:243
@ CTL_STACK_HVSP
Definition libavrdude.h:178
@ CTL_STACK_PP
Definition libavrdude.h:177
#define CTL_STACK_SIZE
Definition libavrdude.h:211
void * ldata(LNODEID)
Definition lists.c:720
unsigned char controlstack[CTL_STACK_SIZE]
Definition libavrdude.h:244
void * LNODEID
Definition libavrdude.h:64
LNODEID lnext(LNODEID)
Definition lists.c:704
int page_size
Definition libavrdude.h:287
LNODEID lfirst(LISTID)
Definition lists.c:688
char desc[AVR_MEMDESCLEN]
Definition libavrdude.h:284
LISTID mem
Definition libavrdude.h:277
Definition libavrdude.h:283
#define CMD_SET_CONTROL_STACK
Definition stk500v2_private.h:65
int(* program_enable)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:649
wchar_t const wchar_t unsigned long
Definition windows.hpp:29

References avrdude_message(), CMD_SET_CONTROL_STACK, avrpart::controlstack, CTL_STACK_HVSP, CTL_STACK_PP, CTL_STACK_SIZE, avrpart::ctl_stack_type, avrpart::desc, avrmem::desc, free(), ldata(), lfirst(), lnext(), long, malloc(), avrpart::mem, MSG_INFO, avrmem::page_size, PDATA, pgm, PPMODE, progname, programmer_t::program_enable, and stk500v2_command().

Referenced by stk500hvsp_initialize(), and stk500pp_initialize().

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

◆ stk500hv_paged_load()

static int stk500hv_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes,
enum hvmode  mode 
)
static
2665{
2666 unsigned int block_size, hiaddr, addrshift, use_ext_addr;
2667 unsigned int maxaddr = addr + n_bytes;
2668 unsigned char commandbuf[3], buf[266];
2669 int result;
2670
2671 DEBUG("STK500V2: stk500hv_paged_load(..,%s,%u,%u,%u)\n",
2672 m->desc, page_size, addr, n_bytes);
2673
2674 page_size = m->readsize;
2675
2676 hiaddr = UINT_MAX;
2677 addrshift = 0;
2678 use_ext_addr = 0;
2679
2680 // determine which command is to be used
2681 if (strcmp(m->desc, "flash") == 0) {
2682 commandbuf[0] = mode == PPMODE? CMD_READ_FLASH_PP: CMD_READ_FLASH_HVSP;
2683 addrshift = 1;
2684 /*
2685 * If bit 31 is set, this indicates that the following read/write
2686 * operation will be performed on a memory that is larger than
2687 * 64KBytes. This is an indication to STK500 that a load extended
2688 * address must be executed.
2689 */
2690 if (m->op[AVR_OP_LOAD_EXT_ADDR] != NULL) {
2691 use_ext_addr = (1U << 31);
2692 }
2693 }
2694 else if (strcmp(m->desc, "eeprom") == 0) {
2696 }
2697
2698 for (; addr < maxaddr; addr += page_size) {
2699 if ((maxaddr - addr) < page_size)
2700 block_size = maxaddr - addr;
2701 else
2702 block_size = page_size;
2703 DEBUG("block_size at addr %d is %d\n",addr,block_size);
2704
2705 memcpy(buf, commandbuf, sizeof(commandbuf));
2706
2707 buf[1] = block_size >> 8;
2708 buf[2] = block_size & 0xff;
2709
2710 // Ensure a new "load extended address" will be issued
2711 // when crossing a 64 KB boundary in flash.
2712 if (hiaddr != (addr & ~0xFFFF)) {
2713 hiaddr = addr & ~0xFFFF;
2714 if (stk500v2_loadaddr(pgm, use_ext_addr | (addr >> addrshift)) < 0)
2715 return -1;
2716 }
2717
2718 result = stk500v2_command(pgm, buf, 3, sizeof(buf));
2719 if (result < 0) {
2720 avrdude_message(MSG_INFO, "%s: stk500hv_paged_load: read command failed\n",
2721 progname);
2722 return -1;
2723 }
2724#if 0
2725 for (i = 0; i < page_size; i++) {
2726 avrdude_message(MSG_INFO, "%02X", buf[2 + i]);
2727 if (i % 16 == 15) avrdude_message(MSG_INFO, "\n");
2728 }
2729#endif
2730
2731 memcpy(&m->buf[addr], &buf[2], block_size);
2732 }
2733
2734 return n_bytes;
2735}
@ AVR_OP_LOAD_EXT_ADDR
Definition libavrdude.h:154
unsigned char * buf
Definition libavrdude.h:304
int readsize
Definition libavrdude.h:301
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:306
static int stk500v2_loadaddr(PROGRAMMER *pgm, unsigned int addr)
Definition stk500v2.c:1778
#define DEBUG(...)
Definition stk500v2.c:87
#define CMD_READ_EEPROM_PP
Definition stk500v2_private.h:57
#define CMD_READ_FLASH_PP
Definition stk500v2_private.h:55
#define CMD_READ_EEPROM_HVSP
Definition stk500v2_private.h:75
#define CMD_READ_FLASH_HVSP
Definition stk500v2_private.h:73

References AVR_OP_LOAD_EXT_ADDR, avrdude_message(), avrmem::buf, CMD_READ_EEPROM_HVSP, CMD_READ_EEPROM_PP, CMD_READ_FLASH_HVSP, CMD_READ_FLASH_PP, DEBUG, avrmem::desc, MSG_INFO, avrmem::op, pgm, PPMODE, progname, avrmem::readsize, stk500v2_command(), and stk500v2_loadaddr().

Referenced by stk500hvsp_paged_load(), and stk500pp_paged_load().

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

◆ stk500hv_paged_write()

static int stk500hv_paged_write ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes,
enum hvmode  mode 
)
static
2459{
2460 unsigned int block_size, last_addr, addrshift, use_ext_addr;
2461 unsigned int maxaddr = addr + n_bytes;
2462 unsigned char commandbuf[5], buf[266];
2463 int result;
2464
2465 DEBUG("STK500V2: stk500hv_paged_write(..,%s,%u,%u)\n",
2466 m->desc, page_size, addr, n_bytes);
2467
2468 addrshift = 0;
2469 use_ext_addr = 0;
2470
2471 // determine which command is to be used
2472 if (strcmp(m->desc, "flash") == 0) {
2473 addrshift = 1;
2474 PDATA(pgm)->flash_pageaddr = (unsigned long)-1L;
2476 /*
2477 * If bit 31 is set, this indicates that the following read/write
2478 * operation will be performed on a memory that is larger than
2479 * 64KBytes. This is an indication to STK500 that a load extended
2480 * address must be executed.
2481 */
2482 if (m->op[AVR_OP_LOAD_EXT_ADDR] != NULL) {
2483 use_ext_addr = (1U << 31);
2484 }
2485 } else if (strcmp(m->desc, "eeprom") == 0) {
2486 PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
2488 }
2489 /*
2490 * Synthesize the mode byte. This is simpler than adding yet
2491 * another parameter to the avrdude.conf file. We calculate the
2492 * bits corresponding to the page size, as explained in AVR068. We
2493 * set bit 7, to indicate this is to actually write the page to the
2494 * target device. We set bit 6 to indicate this is the very last
2495 * page to be programmed, whatever this means -- we just pretend we
2496 * don't know any better. ;-) Finally, we set bit 0 to say this is
2497 * a paged memory, after all, that's why we got here at all.
2498 */
2499 commandbuf[3] = 0x80 | 0x40;
2500 if (page_size > 2) {
2501 unsigned int rv = stk500v2_mode_for_pagesize(page_size);
2502 if (rv == 0)
2503 return -1;
2504 commandbuf[3] |= rv;
2505 commandbuf[3] |= 0x01;
2506 }
2507 commandbuf[4] = m->delay;
2508
2509 if (page_size == 0) page_size = 256;
2510
2511 last_addr = UINT_MAX; /* impossible address */
2512
2513 for (; addr < maxaddr; addr += page_size) {
2514 if ((maxaddr - addr) < page_size)
2515 block_size = maxaddr - addr;
2516 else
2517 block_size = page_size;
2518
2519 DEBUG("block_size at addr %d is %d\n",addr,block_size);
2520
2521 memcpy(buf, commandbuf, sizeof(commandbuf));
2522
2523 buf[1] = page_size >> 8;
2524 buf[2] = page_size & 0xff;
2525
2526 if ((last_addr == UINT_MAX) || (last_addr + block_size != addr)) {
2527 if (stk500v2_loadaddr(pgm, use_ext_addr | (addr >> addrshift)) < 0)
2528 return -1;
2529 }
2530 last_addr=addr;
2531
2532 memcpy(buf + 5, m->buf + addr, block_size);
2533 if (block_size != page_size)
2534 memset(buf + 5 + block_size, 0xff, page_size - block_size);
2535
2536 result = stk500v2_command(pgm, buf, page_size + 5, sizeof(buf));
2537 if (result < 0) {
2538 avrdude_message(MSG_INFO, "%s: stk500hv_paged_write: write command failed\n",
2539 progname);
2540 return -1;
2541 }
2542 }
2543
2544 return n_bytes;
2545}
int delay
Definition libavrdude.h:299
static unsigned int stk500v2_mode_for_pagesize(unsigned int pagesize)
Definition stk500v2.c:2904
#define CMD_PROGRAM_EEPROM_PP
Definition stk500v2_private.h:56
#define CMD_PROGRAM_FLASH_HVSP
Definition stk500v2_private.h:72
#define CMD_PROGRAM_FLASH_PP
Definition stk500v2_private.h:54
#define CMD_PROGRAM_EEPROM_HVSP
Definition stk500v2_private.h:74

References AVR_OP_LOAD_EXT_ADDR, avrdude_message(), avrmem::buf, CMD_PROGRAM_EEPROM_HVSP, CMD_PROGRAM_EEPROM_PP, CMD_PROGRAM_FLASH_HVSP, CMD_PROGRAM_FLASH_PP, DEBUG, avrmem::delay, avrmem::desc, long, MSG_INFO, avrmem::op, PDATA, pgm, PPMODE, progname, stk500v2_command(), stk500v2_loadaddr(), and stk500v2_mode_for_pagesize().

Referenced by stk500hvsp_paged_write(), and stk500pp_paged_write().

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

◆ stk500hv_read_byte()

static int stk500hv_read_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value,
enum hvmode  mode 
)
static
1809{
1810 int result, cmdlen = 2;
1811 unsigned char buf[266];
1812 unsigned long paddr = 0UL, *paddr_ptr = NULL;
1813 unsigned int pagesize = 0, use_ext_addr = 0, addrshift = 0;
1814 unsigned char *cache_ptr = NULL;
1815
1816 avrdude_message(MSG_NOTICE2, "%s: stk500hv_read_byte(.., %s, 0x%lx, ...)\n",
1817 progname, mem->desc, addr);
1818
1819 if (strcmp(mem->desc, "flash") == 0) {
1821 cmdlen = 3;
1822 pagesize = PDATA(pgm)->flash_pagesize;
1823 paddr = addr & ~(pagesize - 1);
1824 paddr_ptr = &PDATA(pgm)->flash_pageaddr;
1825 cache_ptr = PDATA(pgm)->flash_pagecache;
1826 addrshift = 1;
1827 /*
1828 * If bit 31 is set, this indicates that the following read/write
1829 * operation will be performed on a memory that is larger than
1830 * 64KBytes. This is an indication to STK500 that a load extended
1831 * address must be executed.
1832 */
1833 if (mem->op[AVR_OP_LOAD_EXT_ADDR] != NULL) {
1834 use_ext_addr = (1U << 31);
1835 }
1836 } else if (strcmp(mem->desc, "eeprom") == 0) {
1838 cmdlen = 3;
1839 pagesize = mem->page_size;
1840 if (pagesize == 0)
1841 pagesize = 1;
1842 paddr = addr & ~(pagesize - 1);
1843 paddr_ptr = &PDATA(pgm)->eeprom_pageaddr;
1844 cache_ptr = PDATA(pgm)->eeprom_pagecache;
1845 } else if (strcmp(mem->desc, "lfuse") == 0 ||
1846 strcmp(mem->desc, "fuse") == 0) {
1848 addr = 0;
1849 } else if (strcmp(mem->desc, "hfuse") == 0) {
1851 addr = 1;
1852 } else if (strcmp(mem->desc, "efuse") == 0) {
1854 addr = 2;
1855 } else if (strcmp(mem->desc, "lock") == 0) {
1857 } else if (strcmp(mem->desc, "calibration") == 0) {
1859 } else if (strcmp(mem->desc, "signature") == 0) {
1861 }
1862
1863 /*
1864 * In HV mode, we have to use paged reads for flash and
1865 * EEPROM, and cache the results in a page cache.
1866 *
1867 * Page cache validation is based on "{flash,eeprom}_pageaddr"
1868 * (holding the base address of the most recent cache fill
1869 * operation). This variable is set to (unsigned long)-1L when the
1870 * cache needs to be invalidated.
1871 */
1872 if (pagesize && paddr == *paddr_ptr) {
1873 *value = cache_ptr[addr & (pagesize - 1)];
1874 return 0;
1875 }
1876
1877 if (cmdlen == 3) {
1878 /* long command, fill in # of bytes */
1879 buf[1] = (pagesize >> 8) & 0xff;
1880 buf[2] = pagesize & 0xff;
1881
1882 /* flash and EEPROM reads require the load address command */
1883 if (stk500v2_loadaddr(pgm, use_ext_addr | (paddr >> addrshift)) < 0)
1884 return -1;
1885 } else {
1886 buf[1] = (char)addr;
1887 }
1888
1889 avrdude_message(MSG_NOTICE2, "%s: stk500hv_read_byte(): Sending read memory command: ",
1890 progname);
1891
1892 result = stk500v2_command(pgm, buf, cmdlen, sizeof(buf));
1893
1894 if (result < 0) {
1895 avrdude_message(MSG_INFO, "%s: stk500hv_read_byte(): "
1896 "timeout/error communicating with programmer\n",
1897 progname);
1898 return -1;
1899 }
1900
1901 if (pagesize) {
1902 *paddr_ptr = paddr;
1903 memcpy(cache_ptr, buf + 2, pagesize);
1904 *value = cache_ptr[addr & (pagesize - 1)];
1905 } else {
1906 *value = buf[2];
1907 }
1908
1909 return 0;
1910}
#define MSG_NOTICE2
Definition avrdude.h:53
#define CMD_READ_LOCK_HVSP
Definition stk500v2_private.h:79
#define CMD_READ_SIGNATURE_HVSP
Definition stk500v2_private.h:80
#define CMD_READ_SIGNATURE_PP
Definition stk500v2_private.h:62
#define CMD_READ_FUSE_HVSP
Definition stk500v2_private.h:77
#define CMD_READ_OSCCAL_PP
Definition stk500v2_private.h:63
#define CMD_READ_OSCCAL_HVSP
Definition stk500v2_private.h:81
#define CMD_READ_FUSE_PP
Definition stk500v2_private.h:59
#define CMD_READ_LOCK_PP
Definition stk500v2_private.h:61

References AVR_OP_LOAD_EXT_ADDR, avrdude_message(), CMD_READ_EEPROM_HVSP, CMD_READ_EEPROM_PP, CMD_READ_FLASH_HVSP, CMD_READ_FLASH_PP, CMD_READ_FUSE_HVSP, CMD_READ_FUSE_PP, CMD_READ_LOCK_HVSP, CMD_READ_LOCK_PP, CMD_READ_OSCCAL_HVSP, CMD_READ_OSCCAL_PP, CMD_READ_SIGNATURE_HVSP, CMD_READ_SIGNATURE_PP, avrmem::desc, MSG_INFO, MSG_NOTICE2, avrmem::op, avrmem::page_size, PDATA, pgm, PPMODE, progname, stk500v2_command(), and stk500v2_loadaddr().

Referenced by stk500hvsp_read_byte(), and stk500pp_read_byte().

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

◆ stk500hv_write_byte()

static int stk500hv_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data,
enum hvmode  mode 
)
static
2037{
2038 int result, cmdlen, timeout = 0, pulsewidth = 0;
2039 unsigned char buf[266];
2040 unsigned long paddr = 0UL, *paddr_ptr = NULL;
2041 unsigned int pagesize = 0, use_ext_addr = 0, addrshift = 0;
2042 unsigned char *cache_ptr = NULL;
2043
2044 avrdude_message(MSG_NOTICE2, "%s: stk500hv_write_byte(.., %s, 0x%lx, ...)\n",
2045 progname, mem->desc, addr);
2046
2047 if (strcmp(mem->desc, "flash") == 0) {
2049 pagesize = PDATA(pgm)->flash_pagesize;
2050 paddr = addr & ~(pagesize - 1);
2051 paddr_ptr = &PDATA(pgm)->flash_pageaddr;
2052 cache_ptr = PDATA(pgm)->flash_pagecache;
2053 addrshift = 1;
2054 /*
2055 * If bit 31 is set, this indicates that the following read/write
2056 * operation will be performed on a memory that is larger than
2057 * 64KBytes. This is an indication to STK500 that a load extended
2058 * address must be executed.
2059 */
2060 if (mem->op[AVR_OP_LOAD_EXT_ADDR] != NULL) {
2061 use_ext_addr = (1U << 31);
2062 }
2063 } else if (strcmp(mem->desc, "eeprom") == 0) {
2065 pagesize = mem->page_size;
2066 if (pagesize == 0)
2067 pagesize = 1;
2068 paddr = addr & ~(pagesize - 1);
2069 paddr_ptr = &PDATA(pgm)->eeprom_pageaddr;
2070 cache_ptr = PDATA(pgm)->eeprom_pagecache;
2071 } else if (strcmp(mem->desc, "lfuse") == 0 ||
2072 strcmp(mem->desc, "fuse") == 0) {
2074 addr = 0;
2075 pulsewidth = p->programfusepulsewidth;
2076 timeout = p->programfusepolltimeout;
2077 } else if (strcmp(mem->desc, "hfuse") == 0) {
2079 addr = 1;
2080 pulsewidth = p->programfusepulsewidth;
2081 timeout = p->programfusepolltimeout;
2082 } else if (strcmp(mem->desc, "efuse") == 0) {
2084 addr = 2;
2085 pulsewidth = p->programfusepulsewidth;
2086 timeout = p->programfusepolltimeout;
2087 } else if (strcmp(mem->desc, "lock") == 0) {
2089 pulsewidth = p->programlockpulsewidth;
2090 timeout = p->programlockpolltimeout;
2091 } else {
2092 avrdude_message(MSG_INFO, "%s: stk500hv_write_byte(): "
2093 "unsupported memory type: %s\n",
2094 progname, mem->desc);
2095 return -1;
2096 }
2097
2098 cmdlen = 5 + pagesize;
2099
2100 /*
2101 * In HV mode, we have to use paged writes for flash and
2102 * EEPROM. As both, flash and EEPROM cells can only be programmed
2103 * from `1' to `0' bits (even EEPROM does not support auto-erase in
2104 * parallel mode), we just pre-fill the page cache with 0xff, so all
2105 * those cells that are outside our current address will remain
2106 * unaffected.
2107 */
2108 if (pagesize) {
2109 memset(cache_ptr, 0xff, pagesize);
2110 cache_ptr[addr & (pagesize - 1)] = data;
2111
2112 /* long command, fill in # of bytes */
2113 buf[1] = (pagesize >> 8) & 0xff;
2114 buf[2] = pagesize & 0xff;
2115
2116 /*
2117 * Synthesize the mode byte. This is simpler than adding yet
2118 * another parameter to the avrdude.conf file. We calculate the
2119 * bits corresponding to the page size, as explained in AVR068.
2120 * We set bit 7, to indicate this is to actually write the page to
2121 * the target device. We set bit 6 to indicate this is the very
2122 * last page to be programmed, whatever this means -- we just
2123 * pretend we don't know any better. ;-) Bit 0 is set if this is
2124 * a paged memory, which means it has a page size of more than 2.
2125 */
2126 buf[3] = 0x80 | 0x40;
2127 if (pagesize > 2) {
2128 unsigned int rv = stk500v2_mode_for_pagesize(pagesize);
2129 if (rv == 0)
2130 return -1;
2131 buf[3] |= rv;
2132 buf[3] |= 0x01;
2133 }
2134 buf[4] = mem->delay;
2135 memcpy(buf + 5, cache_ptr, pagesize);
2136
2137 /* flash and EEPROM reads require the load address command */
2138 if (stk500v2_loadaddr(pgm, use_ext_addr | (paddr >> addrshift)) < 0)
2139 return -1;
2140 } else {
2141 buf[1] = (char)addr;
2142 buf[2] = data;
2143 if (mode == PPMODE) {
2144 buf[3] = pulsewidth;
2145 buf[4] = timeout;
2146 } else {
2147 buf[3] = timeout;
2148 cmdlen--;
2149 }
2150 }
2151
2152 avrdude_message(MSG_NOTICE2, "%s: stk500hv_write_byte(): Sending write memory command: ",
2153 progname);
2154
2155 result = stk500v2_command(pgm, buf, cmdlen, sizeof(buf));
2156
2157 if (result < 0) {
2158 avrdude_message(MSG_INFO, "%s: stk500hv_write_byte(): "
2159 "timeout/error communicating with programmer\n",
2160 progname);
2161 return -1;
2162 }
2163
2164 if (pagesize) {
2165 /* Invalidate the page cache. */
2166 *paddr_ptr = (unsigned long)-1L;
2167 }
2168
2169 return 0;
2170}
int programfusepolltimeout
Definition libavrdude.h:261
int programlockpulsewidth
Definition libavrdude.h:262
int programfusepulsewidth
Definition libavrdude.h:260
int programlockpolltimeout
Definition libavrdude.h:263
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195
#define CMD_PROGRAM_FUSE_HVSP
Definition stk500v2_private.h:76
#define CMD_PROGRAM_LOCK_HVSP
Definition stk500v2_private.h:78
#define CMD_PROGRAM_FUSE_PP
Definition stk500v2_private.h:58
#define CMD_PROGRAM_LOCK_PP
Definition stk500v2_private.h:60

References AVR_OP_LOAD_EXT_ADDR, avrdude_message(), CMD_PROGRAM_EEPROM_HVSP, CMD_PROGRAM_EEPROM_PP, CMD_PROGRAM_FLASH_HVSP, CMD_PROGRAM_FLASH_PP, CMD_PROGRAM_FUSE_HVSP, CMD_PROGRAM_FUSE_PP, CMD_PROGRAM_LOCK_HVSP, CMD_PROGRAM_LOCK_PP, avrmem::delay, avrmem::desc, long, MSG_INFO, MSG_NOTICE2, avrmem::op, avrmem::page_size, PDATA, pgm, PPMODE, progname, avrpart::programfusepolltimeout, avrpart::programfusepulsewidth, avrpart::programlockpolltimeout, avrpart::programlockpulsewidth, stk500v2_command(), stk500v2_loadaddr(), and stk500v2_mode_for_pagesize().

Referenced by stk500hvsp_write_byte(), and stk500pp_write_byte().

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

◆ stk500hvsp_chip_erase()

static int stk500hvsp_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
static
1076{
1077 return stk500hv_chip_erase(pgm, p, HVSPMODE);
1078}
static int stk500hv_chip_erase(PROGRAMMER *pgm, AVRPART *p, enum hvmode mode)
Definition stk500v2.c:1039

References HVSPMODE, pgm, and stk500hv_chip_erase().

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500hvsp_disable()

static void stk500hvsp_disable ( PROGRAMMER pgm)
static
1629{
1631}
static void stk500hv_disable(PROGRAMMER *pgm, enum hvmode mode)
Definition stk500v2.c:1589

References HVSPMODE, pgm, and stk500hv_disable().

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500hvsp_initialize()

static int stk500hvsp_initialize ( PROGRAMMER pgm,
AVRPART p 
)
static
1539{
1540 return stk500hv_initialize(pgm, p, HVSPMODE);
1541}
static int stk500hv_initialize(PROGRAMMER *pgm, AVRPART *p, enum hvmode mode)
Definition stk500v2.c:1460

References HVSPMODE, pgm, and stk500hv_initialize().

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500hvsp_initpgm()

void stk500hvsp_initpgm ( PROGRAMMER pgm)
4494{
4495 strcpy(pgm->type, "STK500HVSP");
4496
4497 /*
4498 * mandatory functions
4499 */
4510
4511 /*
4512 * optional functions
4513 */
4523 pgm->page_size = 256;
4524}
static void stk500v2_close(PROGRAMMER *pgm)
Definition stk500v2.c:1769
static void stk500v2_print_parms(PROGRAMMER *pgm)
Definition stk500v2.c:3421
static int stk500v2_open(PROGRAMMER *pgm, char *port)
Definition stk500v2.c:1639
static int stk500hvsp_program_enable(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1260
static int stk500hvsp_read_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition stk500v2.c:1924
static int stk500hvsp_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition stk500v2.c:2184
static int stk500v2_set_fosc(PROGRAMMER *pgm, double v)
Definition stk500v2.c:2812
static int stk500v2_set_sck_period(PROGRAMMER *pgm, double v)
Definition stk500v2.c:2933
static void stk500v2_display(PROGRAMMER *pgm, const char *p)
Definition stk500v2.c:3216
static int stk500v2_set_varef(PROGRAMMER *pgm, unsigned int chan, double v)
Definition stk500v2.c:2789
void stk500v2_setup(PROGRAMMER *pgm)
Definition stk500v2.c:295
static void stk500v2_enable(PROGRAMMER *pgm)
Definition stk500v2.c:1633
static void stk500hvsp_disable(PROGRAMMER *pgm)
Definition stk500v2.c:1628
static int stk500hvsp_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:2750
static int stk500v2_set_vtarget(PROGRAMMER *pgm, double v)
Definition stk500v2.c:2766
static int stk500hvsp_paged_write(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:2560
void stk500v2_teardown(PROGRAMMER *pgm)
Definition stk500v2.c:354
static int stk500hvsp_chip_erase(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1075
static int stk500hvsp_initialize(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1538
void(* display)(struct programmer_t *pgm, const char *p)
Definition libavrdude.h:644
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
int(* open)(struct programmer_t *pgm, char *port)
Definition libavrdude.h:657
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670
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(* set_vtarget)(struct programmer_t *pgm, double v)
Definition libavrdude.h:674
void(* teardown)(struct programmer_t *pgm)
Definition libavrdude.h:685
int(* set_varef)(struct programmer_t *pgm, unsigned int chan, double v)
Definition libavrdude.h:675
void(* enable)(struct programmer_t *pgm)
Definition libavrdude.h:645
int(* write_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition libavrdude.h:668
void(* setup)(struct programmer_t *pgm)
Definition libavrdude.h:684
int(* set_fosc)(struct programmer_t *pgm, double v)
Definition libavrdude.h:676
void(* print_parms)(struct programmer_t *pgm)
Definition libavrdude.h:673
char type[PGM_TYPELEN]
Definition libavrdude.h:619
void(* close)(struct programmer_t *pgm)
Definition libavrdude.h:658
int(* set_sck_period)(struct programmer_t *pgm, double v)
Definition libavrdude.h:677
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650
void(* disable)(struct programmer_t *pgm)
Definition libavrdude.h:646
int page_size
Definition libavrdude.h:638

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500hvsp_chip_erase(), stk500hvsp_disable(), stk500hvsp_initialize(), stk500hvsp_paged_load(), stk500hvsp_paged_write(), stk500hvsp_program_enable(), stk500hvsp_read_byte(), stk500hvsp_write_byte(), stk500v2_close(), stk500v2_display(), stk500v2_enable(), stk500v2_open(), stk500v2_print_parms(), stk500v2_set_fosc(), stk500v2_set_sck_period(), stk500v2_set_varef(), stk500v2_set_vtarget(), stk500v2_setup(), stk500v2_teardown(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk500hvsp_paged_load()

static int stk500hvsp_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
2753{
2754 return stk500hv_paged_load(pgm, p, m, page_size, addr, n_bytes, HVSPMODE);
2755}
static int stk500hv_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes, enum hvmode mode)
Definition stk500v2.c:2661

References HVSPMODE, pgm, and stk500hv_paged_load().

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500hvsp_paged_write()

static int stk500hvsp_paged_write ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
2563{
2564 return stk500hv_paged_write(pgm, p, m, page_size, addr, n_bytes, HVSPMODE);
2565}
static int stk500hv_paged_write(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes, enum hvmode mode)
Definition stk500v2.c:2455

References HVSPMODE, pgm, and stk500hv_paged_write().

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500hvsp_program_enable()

static int stk500hvsp_program_enable ( PROGRAMMER pgm,
AVRPART p 
)
static
1261{
1262 unsigned char buf[16];
1263
1264 PDATA(pgm)->lastpart = p;
1265
1266 buf[0] = PDATA(pgm)->pgmtype == PGMTYPE_STK600?
1269 buf[1] = p->hventerstabdelay;
1270 buf[2] = p->hvspcmdexedelay;
1271 buf[3] = p->synchcycles;
1272 buf[4] = p->latchcycles;
1273 buf[5] = p->togglevtg;
1274 buf[6] = p->poweroffdelay;
1275 buf[7] = p->resetdelayms;
1276 buf[8] = p->resetdelayus;
1277
1278 return stk500v2_command(pgm, buf, 9, sizeof(buf));
1279}
int poweroffdelay
Definition libavrdude.h:252
int resetdelayus
Definition libavrdude.h:254
int resetdelayms
Definition libavrdude.h:253
int synchcycles
Definition libavrdude.h:264
int hventerstabdelay
Definition libavrdude.h:248
int togglevtg
Definition libavrdude.h:251
int hvspcmdexedelay
Definition libavrdude.h:265
int latchcycles
Definition libavrdude.h:250
#define CMD_ENTER_PROGMODE_HVSP
Definition stk500v2_private.h:69
#define CMD_ENTER_PROGMODE_HVSP_STK600
Definition stk500v2_private.h:84

References CMD_ENTER_PROGMODE_HVSP, CMD_ENTER_PROGMODE_HVSP_STK600, avrpart::hventerstabdelay, avrpart::hvspcmdexedelay, avrpart::latchcycles, PDATA, pgm, avrpart::poweroffdelay, avrpart::resetdelayms, avrpart::resetdelayus, stk500v2_command(), avrpart::synchcycles, and avrpart::togglevtg.

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500hvsp_read_byte()

static int stk500hvsp_read_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
static
1926{
1927 return stk500hv_read_byte(pgm, p, mem, addr, value, HVSPMODE);
1928}
static int stk500hv_read_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value, enum hvmode mode)
Definition stk500v2.c:1806

References HVSPMODE, pgm, and stk500hv_read_byte().

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500hvsp_write_byte()

static int stk500hvsp_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
static
2186{
2187 return stk500hv_write_byte(pgm, p, mem, addr, data, HVSPMODE);
2188}
static int stk500hv_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data, enum hvmode mode)
Definition stk500v2.c:2034

References HVSPMODE, pgm, and stk500hv_write_byte().

Referenced by stk500hvsp_initpgm(), stk500v2_dragon_hvsp_initpgm(), and stk600hvsp_initpgm().

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

◆ stk500isp_read_byte()

static int stk500isp_read_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
static
1938{
1939 int result, pollidx;
1940 unsigned char buf[6];
1941 unsigned long paddr = 0UL, *paddr_ptr = NULL;
1942 unsigned int pagesize = 0;
1943 unsigned char *cache_ptr = NULL;
1944 OPCODE *op;
1945
1946 avrdude_message(MSG_NOTICE2, "%s: stk500isp_read_byte(.., %s, 0x%lx, ...)\n",
1947 progname, mem->desc, addr);
1948
1949 if (strcmp(mem->desc, "flash") == 0 ||
1950 strcmp(mem->desc, "eeprom") == 0) {
1951 // use paged access, and cache result
1952 if (strcmp(mem->desc, "flash") == 0) {
1953 pagesize = PDATA(pgm)->flash_pagesize;
1954 paddr = addr & ~(pagesize - 1);
1955 paddr_ptr = &PDATA(pgm)->flash_pageaddr;
1956 cache_ptr = PDATA(pgm)->flash_pagecache;
1957 } else {
1958 pagesize = mem->page_size;
1959 if (pagesize == 0)
1960 pagesize = 1;
1961 paddr = addr & ~(pagesize - 1);
1962 paddr_ptr = &PDATA(pgm)->eeprom_pageaddr;
1963 cache_ptr = PDATA(pgm)->eeprom_pagecache;
1964 }
1965
1966 if (paddr == *paddr_ptr) {
1967 *value = cache_ptr[addr & (pagesize - 1)];
1968 return 0;
1969 }
1970
1971 if (stk500v2_paged_load(pgm, p, mem, pagesize, paddr, pagesize) < 0)
1972 return -1;
1973
1974 *paddr_ptr = paddr;
1975 memcpy(cache_ptr, &mem->buf[paddr], pagesize);
1976 *value = cache_ptr[addr & (pagesize - 1)];
1977
1978 return 0;
1979 }
1980
1981 if (strcmp(mem->desc, "lfuse") == 0 ||
1982 strcmp(mem->desc, "fuse") == 0) {
1983 buf[0] = CMD_READ_FUSE_ISP;
1984 addr = 0;
1985 } else if (strcmp(mem->desc, "hfuse") == 0) {
1986 buf[0] = CMD_READ_FUSE_ISP;
1987 addr = 1;
1988 } else if (strcmp(mem->desc, "efuse") == 0) {
1989 buf[0] = CMD_READ_FUSE_ISP;
1990 addr = 2;
1991 } else if (strcmp(mem->desc, "lock") == 0) {
1992 buf[0] = CMD_READ_LOCK_ISP;
1993 } else if (strcmp(mem->desc, "calibration") == 0) {
1994 buf[0] = CMD_READ_OSCCAL_ISP;
1995 } else if (strcmp(mem->desc, "signature") == 0) {
1996 buf[0] = CMD_READ_SIGNATURE_ISP;
1997 }
1998
1999 memset(buf + 1, 0, 5);
2000 if ((op = mem->op[AVR_OP_READ]) == NULL) {
2001 avrdude_message(MSG_INFO, "%s: stk500isp_read_byte(): invalid operation AVR_OP_READ on %s memory\n",
2002 progname, mem->desc);
2003 return -1;
2004 }
2005 avr_set_bits(op, buf + 2);
2006 if ((pollidx = avr_get_output_index(op)) == -1) {
2007 avrdude_message(MSG_INFO, "%s: stk500isp_read_byte(): cannot determine pollidx to read %s memory\n",
2008 progname, mem->desc);
2009 pollidx = 3;
2010 }
2011 buf[1] = pollidx + 1;
2012 avr_set_addr(op, buf + 2, addr);
2013
2014 avrdude_message(MSG_NOTICE2, "%s: stk500isp_read_byte(): Sending read memory command: ",
2015 progname);
2016
2017 result = stk500v2_command(pgm, buf, 6, sizeof(buf));
2018
2019 if (result < 0) {
2020 avrdude_message(MSG_INFO, "%s: stk500isp_read_byte(): "
2021 "timeout/error communicating with programmer\n",
2022 progname);
2023 return -1;
2024 }
2025
2026 *value = buf[2];
2027
2028 return 0;
2029}
int avr_get_output_index(OPCODE *op)
Definition avrpart.c:195
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
@ AVR_OP_READ
Definition libavrdude.h:146
Definition libavrdude.h:190
static int stk500v2_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:2567
#define CMD_READ_FUSE_ISP
Definition stk500v2_private.h:40
#define CMD_READ_OSCCAL_ISP
Definition stk500v2_private.h:44
#define CMD_READ_LOCK_ISP
Definition stk500v2_private.h:42
#define CMD_READ_SIGNATURE_ISP
Definition stk500v2_private.h:43

References avr_get_output_index(), AVR_OP_READ, avr_set_addr(), avr_set_bits(), avrdude_message(), avrmem::buf, CMD_READ_FUSE_ISP, CMD_READ_LOCK_ISP, CMD_READ_OSCCAL_ISP, CMD_READ_SIGNATURE_ISP, avrmem::desc, MSG_INFO, MSG_NOTICE2, avrmem::op, avrmem::page_size, PDATA, pgm, progname, stk500v2_command(), and stk500v2_paged_load().

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500isp_write_byte()

static int stk500isp_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
static
2196{
2197 int result;
2198 unsigned char buf[5];
2199 unsigned long paddr = 0UL, *paddr_ptr = NULL;
2200 unsigned int pagesize = 0;
2201 unsigned char *cache_ptr = NULL;
2202 OPCODE *op;
2203
2204 avrdude_message(MSG_NOTICE2, "%s: stk500isp_write_byte(.., %s, 0x%lx, ...)\n",
2205 progname, mem->desc, addr);
2206
2207 if (strcmp(mem->desc, "flash") == 0 ||
2208 strcmp(mem->desc, "eeprom") == 0) {
2209 if (strcmp(mem->desc, "flash") == 0) {
2210 pagesize = PDATA(pgm)->flash_pagesize;
2211 paddr = addr & ~(pagesize - 1);
2212 paddr_ptr = &PDATA(pgm)->flash_pageaddr;
2213 cache_ptr = PDATA(pgm)->flash_pagecache;
2214 } else {
2215 pagesize = mem->page_size;
2216 if (pagesize == 0)
2217 pagesize = 1;
2218 paddr = addr & ~(pagesize - 1);
2219 paddr_ptr = &PDATA(pgm)->eeprom_pageaddr;
2220 cache_ptr = PDATA(pgm)->eeprom_pagecache;
2221 }
2222
2223 /*
2224 * We use paged writes for flash and EEPROM, reading back the
2225 * current page first, modify the byte to write, and write out the
2226 * entire page.
2227 */
2228 if (stk500v2_paged_load(pgm, p, mem, pagesize, paddr, pagesize) < 0)
2229 return -1;
2230
2231 memcpy(cache_ptr, mem->buf + paddr, pagesize);
2232 *paddr_ptr = paddr;
2233 cache_ptr[addr & (pagesize - 1)] = data;
2234 memcpy(mem->buf + paddr, cache_ptr, pagesize);
2235
2236 stk500v2_paged_write(pgm, p, mem, pagesize, paddr, pagesize);
2237
2238 return 0;
2239 }
2240
2241 memset(buf, 0, sizeof buf);
2242 if (strcmp(mem->desc, "lfuse") == 0 ||
2243 strcmp(mem->desc, "fuse") == 0) {
2244 buf[0] = CMD_PROGRAM_FUSE_ISP;
2245 addr = 0;
2246 } else if (strcmp(mem->desc, "hfuse") == 0) {
2247 buf[0] = CMD_PROGRAM_FUSE_ISP;
2248 addr = 1;
2249 } else if (strcmp(mem->desc, "efuse") == 0) {
2250 buf[0] = CMD_PROGRAM_FUSE_ISP;
2251 addr = 2;
2252 } else if (strcmp(mem->desc, "lock") == 0) {
2253 buf[0] = CMD_PROGRAM_LOCK_ISP;
2254 } else {
2255 avrdude_message(MSG_INFO, "%s: stk500isp_write_byte(): "
2256 "unsupported memory type: %s\n",
2257 progname, mem->desc);
2258 return -1;
2259 }
2260
2261 if ((op = mem->op[AVR_OP_WRITE]) == NULL) {
2262 avrdude_message(MSG_INFO, "%s: stk500isp_write_byte(): "
2263 "no AVR_OP_WRITE for %s memory\n",
2264 progname, mem->desc);
2265 return -1;
2266 }
2267
2268 avr_set_bits(op, buf + 1);
2269 avr_set_addr(op, buf + 1, addr);
2270 avr_set_input(op, buf + 1, data);
2271
2272 avrdude_message(MSG_NOTICE2, "%s: stk500isp_write_byte(): Sending write memory command: ",
2273 progname);
2274
2275 result = stk500v2_command(pgm, buf, 5, sizeof(buf));
2276
2277 if (result < 0) {
2278 avrdude_message(MSG_INFO, "%s: stk500isp_write_byte(): "
2279 "timeout/error communicating with programmer\n",
2280 progname);
2281 return -1;
2282 }
2283
2284 /*
2285 * Prevent verification readback to be too fast, see
2286 * https://savannah.nongnu.org/bugs/index.php?42267
2287 *
2288 * After all, this is just an ugly hack working around some
2289 * brokeness in the Atmel firmware starting with the AVRISPmkII (the
2290 * old JTAGICEmkII isn't affected). Let's hope 10 ms of additional
2291 * delay are good enough for everyone.
2292 */
2293 usleep(10000);
2294
2295 return 0;
2296}
int avr_set_input(OPCODE *op, unsigned char *cmd, unsigned char data)
Definition avrpart.c:136
@ AVR_OP_WRITE
Definition libavrdude.h:147
static int stk500v2_paged_write(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:2298
#define CMD_PROGRAM_FUSE_ISP
Definition stk500v2_private.h:39
#define CMD_PROGRAM_LOCK_ISP
Definition stk500v2_private.h:41

References AVR_OP_WRITE, avr_set_addr(), avr_set_bits(), avr_set_input(), avrdude_message(), avrmem::buf, CMD_PROGRAM_FUSE_ISP, CMD_PROGRAM_LOCK_ISP, avrmem::desc, MSG_INFO, MSG_NOTICE2, avrmem::op, avrmem::page_size, PDATA, pgm, progname, stk500v2_command(), stk500v2_paged_load(), stk500v2_paged_write(), and usleep().

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500pp_chip_erase()

static int stk500pp_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
static
1068{
1069 return stk500hv_chip_erase(pgm, p, PPMODE);
1070}

References pgm, PPMODE, and stk500hv_chip_erase().

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500pp_disable()

static void stk500pp_disable ( PROGRAMMER pgm)
static
1621{
1623}

References pgm, PPMODE, and stk500hv_disable().

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500pp_initialize()

static int stk500pp_initialize ( PROGRAMMER pgm,
AVRPART p 
)
static
1531{
1532 return stk500hv_initialize(pgm, p, PPMODE);
1533}

References pgm, PPMODE, and stk500hv_initialize().

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500pp_initpgm()

void stk500pp_initpgm ( PROGRAMMER pgm)
4459{
4460 strcpy(pgm->type, "STK500PP");
4461
4462 /*
4463 * mandatory functions
4464 */
4475
4476 /*
4477 * optional functions
4478 */
4488 pgm->page_size = 256;
4489}
static int stk500pp_read_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition stk500v2.c:1915
static int stk500pp_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:2740
static int stk500pp_paged_write(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:2550
static int stk500pp_initialize(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1530
static int stk500pp_program_enable(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1239
static void stk500pp_disable(PROGRAMMER *pgm)
Definition stk500v2.c:1620
static int stk500pp_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition stk500v2.c:2175
static int stk500pp_chip_erase(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1067

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500pp_chip_erase(), stk500pp_disable(), stk500pp_initialize(), stk500pp_paged_load(), stk500pp_paged_write(), stk500pp_program_enable(), stk500pp_read_byte(), stk500pp_write_byte(), stk500v2_close(), stk500v2_display(), stk500v2_enable(), stk500v2_open(), stk500v2_print_parms(), stk500v2_set_fosc(), stk500v2_set_sck_period(), stk500v2_set_varef(), stk500v2_set_vtarget(), stk500v2_setup(), stk500v2_teardown(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk500pp_paged_load()

static int stk500pp_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
2743{
2744 return stk500hv_paged_load(pgm, p, m, page_size, addr, n_bytes, PPMODE);
2745}

References pgm, PPMODE, and stk500hv_paged_load().

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500pp_paged_write()

static int stk500pp_paged_write ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
2553{
2554 return stk500hv_paged_write(pgm, p, m, page_size, addr, n_bytes, PPMODE);
2555}

References pgm, PPMODE, and stk500hv_paged_write().

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500pp_program_enable()

static int stk500pp_program_enable ( PROGRAMMER pgm,
AVRPART p 
)
static
1240{
1241 unsigned char buf[16];
1242
1243 PDATA(pgm)->lastpart = p;
1244
1245 buf[0] = CMD_ENTER_PROGMODE_PP;
1246 buf[1] = p->hventerstabdelay;
1247 buf[2] = p->progmodedelay;
1248 buf[3] = p->latchcycles;
1249 buf[4] = p->togglevtg;
1250 buf[5] = p->poweroffdelay;
1251 buf[6] = p->resetdelayms;
1252 buf[7] = p->resetdelayus;
1253
1254 return stk500v2_command(pgm, buf, 8, sizeof(buf));
1255}
int progmodedelay
Definition libavrdude.h:249
#define CMD_ENTER_PROGMODE_PP
Definition stk500v2_private.h:51

References CMD_ENTER_PROGMODE_PP, avrpart::hventerstabdelay, avrpart::latchcycles, PDATA, pgm, avrpart::poweroffdelay, avrpart::progmodedelay, avrpart::resetdelayms, avrpart::resetdelayus, stk500v2_command(), and avrpart::togglevtg.

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500pp_read_byte()

static int stk500pp_read_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
static
1917{
1918 return stk500hv_read_byte(pgm, p, mem, addr, value, PPMODE);
1919}

References pgm, PPMODE, and stk500hv_read_byte().

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500pp_write_byte()

static int stk500pp_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
static
2177{
2178 return stk500hv_write_byte(pgm, p, mem, addr, data, PPMODE);
2179}

References pgm, PPMODE, and stk500hv_write_byte().

Referenced by stk500pp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk600pp_initpgm().

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

◆ stk500v2_chip_erase()

static int stk500v2_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
static
1011{
1012 int result;
1013 unsigned char buf[16];
1014
1015 if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
1016 avrdude_message(MSG_INFO, "%s: stk500v2_chip_erase: chip erase instruction not defined for part \"%s\"\n",
1017 progname, p->desc);
1018 return -1;
1019 }
1020
1021 pgm->pgm_led(pgm, ON);
1022
1023 buf[0] = CMD_CHIP_ERASE_ISP;
1024 buf[1] = p->chip_erase_delay / 1000;
1025 buf[2] = 0; // use delay (?)
1026 avr_set_bits(p->op[AVR_OP_CHIP_ERASE], buf+3);
1027 result = stk500v2_command(pgm, buf, 7, sizeof(buf));
1029 pgm->initialize(pgm, p);
1030
1031 pgm->pgm_led(pgm, OFF);
1032
1033 return result >= 0? 0: -1;
1034}
@ AVR_OP_CHIP_ERASE
Definition libavrdude.h:156
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:275
#define CMD_CHIP_ERASE_ISP
Definition stk500v2_private.h:34

References AVR_OP_CHIP_ERASE, avr_set_bits(), avrdude_message(), avrpart::chip_erase_delay, CMD_CHIP_ERASE_ISP, avrpart::desc, programmer_t::initialize, MSG_INFO, OFF, ON, avrpart::op, pgm, programmer_t::pgm_led, progname, stk500v2_command(), and usleep().

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500v2_close()

static void stk500v2_close ( PROGRAMMER pgm)
static
1770{
1771 DEBUG("STK500V2: stk500v2_close()\n");
1772
1773 serial_close(&pgm->fd);
1774 pgm->fd.ifd = -1;
1775}
#define serial_close
Definition libavrdude.h:576
int ifd
Definition libavrdude.h:522
union filedescriptor fd
Definition libavrdude.h:637

References DEBUG, programmer_t::fd, filedescriptor::ifd, pgm, and serial_close.

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_initpgm(), stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_cmd()

static int stk500v2_cmd ( PROGRAMMER pgm,
const unsigned char *  cmd,
unsigned char *  res 
)
static
962{
963 unsigned char buf[8];
964 int result;
965
966 DEBUG("STK500V2: stk500v2_cmd(%02x,%02x,%02x,%02x)\n",cmd[0],cmd[1],cmd[2],cmd[3]);
967
968 buf[0] = CMD_SPI_MULTI;
969 buf[1] = 4;
970 buf[2] = 4;
971 buf[3] = 0;
972 buf[4] = cmd[0];
973 buf[5] = cmd[1];
974 buf[6] = cmd[2];
975 buf[7] = cmd[3];
976
977 result = stk500v2_command(pgm, buf, 8, sizeof(buf));
978 if (result < 0) {
979 avrdude_message(MSG_INFO, "%s: stk500v2_cmd(): failed to send command\n",
980 progname);
981 return -1;
982 } else if (result < 6) {
983 avrdude_message(MSG_INFO, "%s: stk500v2_cmd(): short reply, len = %d\n",
984 progname, result);
985 return -1;
986 }
987
988 res[0] = buf[2];
989 res[1] = buf[3];
990 res[2] = buf[4];
991 res[3] = buf[5];
992
993 return 0;
994}
#define CMD_SPI_MULTI
Definition stk500v2_private.h:45
struct command cmd[]
Definition term.c:94

References avrdude_message(), cmd, CMD_SPI_MULTI, DEBUG, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtagmkII_initpgm(), and stk600_initpgm().

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

◆ stk500v2_command()

static int stk500v2_command ( PROGRAMMER pgm,
unsigned char *  buf,
size_t  len,
size_t  maxlen 
)
static
838 {
839 int i;
840 int tries = 0;
841 int status;
842
843 DEBUG("STK500V2: stk500v2_command(");
844 for (i=0;i<len;i++) DEBUG("0x%02x ",buf[i]);
845 DEBUG(", %d)\n",len);
846
847retry:
848 tries++;
849
851
852 // send the command to the programmer
853 if (stk500v2_send(pgm, buf, len) != 0) {
854 avrdude_message(MSG_INFO, "%s: stk500v2_command(): can't communicate with device\n", progname);
855 return -1;
856 }
857
859
860 // attempt to read the status back
861 status = stk500v2_recv(pgm,buf,maxlen);
862
864
865 // if we got a successful readback, return
866 if (status > 0) {
867 DEBUG(" = %d\n",status);
868 if (status < 2) {
869 avrdude_message(MSG_INFO, "%s: stk500v2_command(): short reply\n", progname);
870 return -1;
871 }
872 if (buf[0] == CMD_XPROG_SETMODE || buf[0] == CMD_XPROG) {
873 /*
874 * Decode XPROG wrapper errors.
875 */
876 const char *msg;
877 int i;
878
879 /*
880 * For CMD_XPROG_SETMODE, the status is returned in buf[1].
881 * For CMD_XPROG, buf[1] contains the XPRG_CMD_* command, and
882 * buf[2] contains the status.
883 */
884 i = buf[0] == CMD_XPROG_SETMODE? 1: 2;
885
886 if (buf[i] != XPRG_ERR_OK) {
887 switch (buf[i]) {
888 case XPRG_ERR_FAILED: msg = "Failed"; break;
889 case XPRG_ERR_COLLISION: msg = "Collision"; break;
890 case XPRG_ERR_TIMEOUT: msg = "Timeout"; break;
891 default: msg = "Unknown"; break;
892 }
893 avrdude_message(MSG_INFO, "%s: stk500v2_command(): error in %s: %s\n",
894 progname,
895 (buf[0] == CMD_XPROG_SETMODE? "CMD_XPROG_SETMODE": "CMD_XPROG"),
896 msg);
897 return -1;
898 }
899 return 0;
900 } else {
901 /*
902 * Decode STK500v2 errors.
903 */
904 if (buf[1] >= STATUS_CMD_TOUT && buf[1] < 0xa0) {
905 const char *msg;
906 char msgbuf[30];
907 switch (buf[1]) {
908 case STATUS_CMD_TOUT:
909 msg = "Command timed out";
910 break;
911
913 msg = "Sampling of the RDY/nBSY pin timed out";
914 break;
915
917 msg = "The `Set Device Parameters' have not been "
918 "executed in advance of this command";
919
920 default:
921 sprintf(msgbuf, "unknown, code 0x%02x", buf[1]);
922 msg = msgbuf;
923 break;
924 }
925 if (quell_progress < 2) {
926 avrdude_message(MSG_INFO, "%s: stk500v2_command(): warning: %s\n",
927 progname, msg);
928 }
929 } else if (buf[1] == STATUS_CMD_OK) {
930 return status;
931 } else if (buf[1] == STATUS_CMD_FAILED) {
932 avrdude_message(MSG_INFO, "%s: stk500v2_command(): command failed\n",
933 progname);
934 } else if (buf[1] == STATUS_CMD_UNKNOWN) {
935 avrdude_message(MSG_INFO, "%s: stk500v2_command(): unknown command\n",
936 progname);
937 } else {
938 avrdude_message(MSG_INFO, "%s: stk500v2_command(): unknown status 0x%02x\n",
939 progname, buf[1]);
940 }
941 return -1;
942 }
943 }
944
945 // otherwise try to sync up again
946 status = stk500v2_getsync(pgm);
947 if (status != 0) {
948 if (tries > RETRIES) {
949 avrdude_message(MSG_INFO, "%s: stk500v2_command(): failed miserably to execute command 0x%02x\n",
950 progname,buf[0]);
951 return -1;
952 } else
953 goto retry;
954 }
955
956 DEBUG(" = 0\n");
957 return 0;
958}
int quell_progress
Definition main.c:199
#define RETURN_IF_CANCEL()
Definition libavrdude.h:733
int stk500v2_getsync(PROGRAMMER *pgm)
Definition stk500v2.c:749
static int stk500v2_send(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition stk500v2.c:492
#define RETRIES
Definition stk500v2.c:82
static int stk500v2_recv(PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
Definition stk500v2.c:628
#define STATUS_CMD_OK
Definition stk500v2_private.h:132
#define STATUS_CMD_FAILED
Definition stk500v2_private.h:140
#define STATUS_CMD_TOUT
Definition stk500v2_private.h:135
#define XPRG_ERR_FAILED
Definition stk500v2_private.h:268
#define XPRG_ERR_COLLISION
Definition stk500v2_private.h:269
#define CMD_XPROG_SETMODE
Definition stk500v2_private.h:90
#define XPRG_ERR_TIMEOUT
Definition stk500v2_private.h:270
#define STATUS_RDY_BSY_TOUT
Definition stk500v2_private.h:136
#define STATUS_CMD_UNKNOWN
Definition stk500v2_private.h:142
#define XPRG_ERR_OK
Definition stk500v2_private.h:267
#define STATUS_SET_PARAM_MISSING
Definition stk500v2_private.h:137
#define CMD_XPROG
Definition stk500v2_private.h:89

References avrdude_message(), CMD_XPROG, CMD_XPROG_SETMODE, DEBUG, MSG_INFO, pgm, progname, quell_progress, RETRIES, RETURN_IF_CANCEL, STATUS_CMD_FAILED, STATUS_CMD_OK, STATUS_CMD_TOUT, STATUS_CMD_UNKNOWN, STATUS_RDY_BSY_TOUT, STATUS_SET_PARAM_MISSING, stk500v2_getsync(), stk500v2_recv(), stk500v2_send(), XPRG_ERR_COLLISION, XPRG_ERR_FAILED, XPRG_ERR_OK, and XPRG_ERR_TIMEOUT.

Referenced by stk500hv_chip_erase(), stk500hv_disable(), stk500hv_initialize(), stk500hv_paged_load(), stk500hv_paged_write(), stk500hv_read_byte(), stk500hv_write_byte(), stk500hvsp_program_enable(), stk500isp_read_byte(), stk500isp_write_byte(), stk500pp_program_enable(), stk500v2_chip_erase(), stk500v2_cmd(), stk500v2_disable(), stk500v2_getparm(), stk500v2_getparm2(), stk500v2_jtag3_disable(), stk500v2_loadaddr(), stk500v2_paged_load(), stk500v2_paged_write(), stk500v2_perform_osccal(), stk500v2_program_enable(), stk500v2_set_upload_size(), stk500v2_setparm2(), stk500v2_setparm_real(), stk600_xprog_command(), and stk600_xprog_program_enable().

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

◆ stk500v2_disable()

static void stk500v2_disable ( PROGRAMMER pgm)
static
1568{
1569 unsigned char buf[16];
1570 int result;
1571
1572 buf[0] = CMD_LEAVE_PROGMODE_ISP;
1573 buf[1] = 1; // preDelay;
1574 buf[2] = 1; // postDelay;
1575
1576 result = stk500v2_command(pgm, buf, 3, sizeof(buf));
1577
1578 if (result < 0) {
1579 avrdude_message(MSG_INFO, "%s: stk500v2_disable(): failed to leave programming mode\n",
1580 progname);
1581 }
1582
1583 return;
1584}
#define CMD_LEAVE_PROGMODE_ISP
Definition stk500v2_private.h:33

References avrdude_message(), CMD_LEAVE_PROGMODE_ISP, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500v2_display()

static void stk500v2_display ( PROGRAMMER pgm,
const char *  p 
)
static
3217{
3218 unsigned char maj = 0;
3219 unsigned char min = 0;
3220 unsigned char hdw = 0;
3221 unsigned char topcard = 0;
3222 unsigned char maj_s1 = 0;
3223 unsigned char min_s1 = 0;
3224 unsigned char maj_s2 = 0;
3225 unsigned char min_s2 = 0;
3226 unsigned int rev = 0;
3227 const char *topcard_name, *pgmname;
3228
3229 switch (PDATA(pgm)->pgmtype) {
3230 case PGMTYPE_UNKNOWN: pgmname = "Unknown"; break;
3231 case PGMTYPE_STK500: pgmname = "STK500"; break;
3232 case PGMTYPE_AVRISP: pgmname = "AVRISP"; break;
3233 case PGMTYPE_AVRISP_MKII: pgmname = "AVRISP mkII"; break;
3234 case PGMTYPE_STK600: pgmname = "STK600"; break;
3235 default: pgmname = "None";
3236 }
3237 if (PDATA(pgm)->pgmtype != PGMTYPE_JTAGICE_MKII &&
3238 PDATA(pgm)->pgmtype != PGMTYPE_JTAGICE3) {
3239 avrdude_message(MSG_INFO, "%sProgrammer Model: %s\n", p, pgmname);
3243 avrdude_message(MSG_INFO, "%sHardware Version: %d\n", p, hdw);
3244 avrdude_message(MSG_INFO, "%sFirmware Version Master : %d.%02d\n", p, maj, min);
3245 if (PDATA(pgm)->pgmtype == PGMTYPE_STK600) {
3250 avrdude_message(MSG_INFO, "%sFirmware Version Slave 1: %d.%02d\n", p, maj_s1, min_s1);
3251 avrdude_message(MSG_INFO, "%sFirmware Version Slave 2: %d.%02d\n", p, maj_s2, min_s2);
3252 }
3253 }
3254
3255 if (PDATA(pgm)->pgmtype == PGMTYPE_STK500) {
3257 switch (topcard) {
3258 case 0xAA: topcard_name = "STK501"; break;
3259 case 0x55: topcard_name = "STK502"; break;
3260 case 0xFA: topcard_name = "STK503"; break;
3261 case 0xEE: topcard_name = "STK504"; break;
3262 case 0xE4: topcard_name = "STK505"; break;
3263 case 0xDD: topcard_name = "STK520"; break;
3264 default: topcard_name = "Unknown"; break;
3265 }
3266 avrdude_message(MSG_INFO, "%sTopcard : %s\n", p, topcard_name);
3267 } else if (PDATA(pgm)->pgmtype == PGMTYPE_STK600) {
3269 avrdude_message(MSG_INFO, "%sRouting card : %s\n", p,
3271 sizeof routing_cards / sizeof routing_cards[0],
3272 topcard));
3274 avrdude_message(MSG_INFO, "%sSocket card : %s\n", p,
3276 sizeof socket_cards / sizeof socket_cards[0],
3277 topcard));
3279 avrdude_message(MSG_INFO, "%sRC_ID table rev : %d\n", p, rev);
3281 avrdude_message(MSG_INFO, "%sEC_ID table rev : %d\n", p, rev);
3282 }
3284
3285 return;
3286}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() min(const half &a, const half &b)
Definition Half.h:507
static int stk500v2_getparm2(PROGRAMMER *pgm, unsigned char parm, unsigned int *value)
Definition stk500v2.c:3163
static const char * pgmname[]
Definition stk500v2.c:114
static const char * stk600_get_cardname(const struct carddata *table, size_t nele, int id)
Definition stk500v2.c:3199
static int stk500v2_getparm(PROGRAMMER *pgm, unsigned char parm, unsigned char *value)
Definition stk500v2.c:3110
static const struct carddata routing_cards[]
Definition stk500v2.c:199
static void stk500v2_print_parms1(PROGRAMMER *pgm, const char *p)
Definition stk500v2.c:3303
static const struct carddata socket_cards[]
Definition stk500v2.c:244
#define PARAM_HW_VER
Definition stk500v2_private.h:176
#define PARAM_ROUTINGCARD_ID
Definition stk500v2_private.h:194
#define PARAM_SW_MAJOR_SLAVE2
Definition stk500v2_private.h:198
#define PARAM_SW_MAJOR
Definition stk500v2_private.h:177
#define PARAM_SOCKETCARD_ID
Definition stk500v2_private.h:193
#define PARAM_SW_MINOR_SLAVE2
Definition stk500v2_private.h:199
#define PARAM2_RC_ID_TABLE_REV
Definition stk500v2_private.h:219
#define PARAM_TOPCARD_DETECT
Definition stk500v2_private.h:184
#define PARAM_SW_MINOR
Definition stk500v2_private.h:178
#define PARAM_SW_MINOR_SLAVE1
Definition stk500v2_private.h:197
#define PARAM2_EC_ID_TABLE_REV
Definition stk500v2_private.h:220
#define PARAM_SW_MAJOR_SLAVE1
Definition stk500v2_private.h:196

References avrdude_message(), MSG_INFO, PARAM2_EC_ID_TABLE_REV, PARAM2_RC_ID_TABLE_REV, PARAM_HW_VER, PARAM_ROUTINGCARD_ID, PARAM_SOCKETCARD_ID, PARAM_SW_MAJOR, PARAM_SW_MAJOR_SLAVE1, PARAM_SW_MAJOR_SLAVE2, PARAM_SW_MINOR, PARAM_SW_MINOR_SLAVE1, PARAM_SW_MINOR_SLAVE2, PARAM_TOPCARD_DETECT, PDATA, pgm, pgmname, routing_cards, socket_cards, stk500v2_getparm(), stk500v2_getparm2(), stk500v2_print_parms1(), and stk600_get_cardname().

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_isp_initpgm(), stk500v2_dragon_pp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

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

◆ stk500v2_dragon_hv_open()

static int stk500v2_dragon_hv_open ( PROGRAMMER pgm,
char *  port 
)
static
3646{
3647 return -1;
3648// union pinfo pinfo;
3649// void *mycookie;
3650
3651// avrdude_message(MSG_NOTICE2, "%s: stk500v2_dragon_hv_open()\n", progname);
3652
3653// /*
3654// * The JTAG ICE mkII always starts with a baud rate of 19200 Bd upon
3655// * attaching. If the config file or command-line parameters specify
3656// * a higher baud rate, we switch to it later on, after establishing
3657// * the connection with the ICE.
3658// */
3659// pinfo.baud = 19200;
3660
3661// /*
3662// * If the port name starts with "usb", divert the serial routines
3663// * to the USB ones. The serial_open() function for USB overrides
3664// * the meaning of the "baud" parameter to be the USB device ID to
3665// * search for.
3666// */
3667// if (strncmp(port, "usb", 3) == 0) {
3668// #if defined(HAVE_LIBUSB)
3669// serdev = &usb_serdev;
3670// pinfo.usbinfo.vid = USB_VENDOR_ATMEL;
3671// pinfo.usbinfo.flags = 0;
3672// pinfo.usbinfo.pid = USB_DEVICE_AVRDRAGON;
3673// pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
3674// pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
3675// pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
3676// pgm->fd.usb.eep = 0; /* no seperate EP for events */
3677// #else
3678// avrdude_message(MSG_INFO, "avrdude was compiled without usb support.\n");
3679// return -1;
3680// #endif
3681// }
3682
3683// strcpy(pgm->port, port);
3684// if (serial_open(port, pinfo, &pgm->fd)==-1) {
3685// return -1;
3686// }
3687
3688// /*
3689// * drain any extraneous input
3690// */
3691// stk500v2_drain(pgm, 0);
3692
3693// mycookie = pgm->cookie;
3694// pgm->cookie = PDATA(pgm)->chained_pdata;
3695// if (jtagmkII_getsync(pgm, EMULATOR_MODE_HV) != 0) {
3696// avrdude_message(MSG_INFO, "%s: failed to sync with the AVR Dragon in HV mode\n",
3697// progname);
3698// pgm->cookie = mycookie;
3699// return -1;
3700// }
3701// pgm->cookie = mycookie;
3702
3703// PDATA(pgm)->pgmtype = PGMTYPE_JTAGICE_MKII;
3704
3705// if (pgm->bitclock != 0.0) {
3706// if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)
3707// return -1;
3708// }
3709
3710// return 0;
3711}

Referenced by stk500v2_dragon_hvsp_initpgm(), and stk500v2_dragon_pp_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_dragon_hvsp_initpgm()

void stk500v2_dragon_hvsp_initpgm ( PROGRAMMER pgm)
4633{
4634 strcpy(pgm->type, "DRAGON_HVSP");
4635
4636 /*
4637 * mandatory functions
4638 */
4649
4650 /*
4651 * optional functions
4652 */
4662 pgm->page_size = 256;
4663}
static int stk500v2_set_sck_period_mk2(PROGRAMMER *pgm, double v)
Definition stk500v2.c:2885
static int stk500v2_dragon_hv_open(PROGRAMMER *pgm, char *port)
Definition stk500v2.c:3645
static void stk500v2_jtagmkII_setup(PROGRAMMER *pgm)
Definition stk500v2.c:308
static void stk500v2_jtagmkII_teardown(PROGRAMMER *pgm)
Definition stk500v2.c:359
static void stk500v2_jtagmkII_close(PROGRAMMER *pgm)
Definition stk500v2.c:3527

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500hvsp_chip_erase(), stk500hvsp_disable(), stk500hvsp_initialize(), stk500hvsp_paged_load(), stk500hvsp_paged_write(), stk500hvsp_program_enable(), stk500hvsp_read_byte(), stk500hvsp_write_byte(), stk500v2_display(), stk500v2_dragon_hv_open(), stk500v2_enable(), stk500v2_jtagmkII_close(), stk500v2_jtagmkII_setup(), stk500v2_jtagmkII_teardown(), stk500v2_print_parms(), stk500v2_set_fosc(), stk500v2_set_sck_period_mk2(), stk500v2_set_varef(), stk500v2_set_vtarget(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk500v2_dragon_isp_initpgm()

void stk500v2_dragon_isp_initpgm ( PROGRAMMER pgm)
4564{
4565 strcpy(pgm->type, "DRAGON_ISP");
4566
4567 /*
4568 * mandatory functions
4569 */
4576 pgm->cmd = stk500v2_cmd;
4581
4582 /*
4583 * optional functions
4584 */
4592 pgm->page_size = 256;
4593}
static int stk500v2_dragon_isp_open(PROGRAMMER *pgm, char *port)
Definition stk500v2.c:3566
static int stk500v2_page_erase(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int addr)
Definition stk500v2.c:2758
static void stk500v2_disable(PROGRAMMER *pgm)
Definition stk500v2.c:1567
static int stk500v2_cmd(PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
Definition stk500v2.c:960
static int stk500v2_initialize(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1285
static int stk500isp_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition stk500v2.c:2194
static int stk500isp_read_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition stk500v2.c:1936
static int stk500v2_chip_erase(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1010
static int stk500v2_program_enable(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1127
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651
int(* page_erase)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int baseaddr)
Definition libavrdude.h:665

References programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_erase, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_sck_period, programmer_t::setup, stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_chip_erase(), stk500v2_cmd(), stk500v2_disable(), stk500v2_display(), stk500v2_dragon_isp_open(), stk500v2_enable(), stk500v2_initialize(), stk500v2_jtagmkII_close(), stk500v2_jtagmkII_setup(), stk500v2_jtagmkII_teardown(), stk500v2_page_erase(), stk500v2_paged_load(), stk500v2_paged_write(), stk500v2_print_parms(), stk500v2_program_enable(), stk500v2_set_sck_period_mk2(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk500v2_dragon_isp_open()

static int stk500v2_dragon_isp_open ( PROGRAMMER pgm,
char *  port 
)
static
3567{
3568 return -1;
3569// union pinfo pinfo;
3570// void *mycookie;
3571
3572// avrdude_message(MSG_NOTICE2, "%s: stk500v2_dragon_isp_open()\n", progname);
3573
3574// /*
3575// * The JTAG ICE mkII always starts with a baud rate of 19200 Bd upon
3576// * attaching. If the config file or command-line parameters specify
3577// * a higher baud rate, we switch to it later on, after establishing
3578// * the connection with the ICE.
3579// */
3580// pinfo.baud = 19200;
3581
3582// /*
3583// * If the port name starts with "usb", divert the serial routines
3584// * to the USB ones. The serial_open() function for USB overrides
3585// * the meaning of the "baud" parameter to be the USB device ID to
3586// * search for.
3587// */
3588// if (strncmp(port, "usb", 3) == 0) {
3589// #if defined(HAVE_LIBUSB)
3590// serdev = &usb_serdev;
3591// pinfo.usbinfo.vid = USB_VENDOR_ATMEL;
3592// pinfo.usbinfo.flags = 0;
3593// pinfo.usbinfo.pid = USB_DEVICE_AVRDRAGON;
3594// pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
3595// pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
3596// pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
3597// pgm->fd.usb.eep = 0; /* no seperate EP for events */
3598// #else
3599// avrdude_message(MSG_INFO, "avrdude was compiled without usb support.\n");
3600// return -1;
3601// #endif
3602// }
3603
3604// strcpy(pgm->port, port);
3605// if (serial_open(port, pinfo, &pgm->fd)==-1) {
3606// return -1;
3607// }
3608
3609// /*
3610// * drain any extraneous input
3611// */
3612// stk500v2_drain(pgm, 0);
3613
3614// mycookie = pgm->cookie;
3615// pgm->cookie = PDATA(pgm)->chained_pdata;
3616// if (jtagmkII_getsync(pgm, EMULATOR_MODE_SPI) != 0) {
3617// avrdude_message(MSG_INFO, "%s: failed to sync with the AVR Dragon in ISP mode\n",
3618// progname);
3619// pgm->cookie = mycookie;
3620// return -1;
3621// }
3622// pgm->cookie = mycookie;
3623
3624// PDATA(pgm)->pgmtype = PGMTYPE_JTAGICE_MKII;
3625
3626// if (pgm->bitclock != 0.0) {
3627// if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)
3628// return -1;
3629// }
3630
3631// return 0;
3632}

Referenced by stk500v2_dragon_isp_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_dragon_pp_initpgm()

void stk500v2_dragon_pp_initpgm ( PROGRAMMER pgm)

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500pp_chip_erase(), stk500pp_disable(), stk500pp_initialize(), stk500pp_paged_load(), stk500pp_paged_write(), stk500pp_program_enable(), stk500pp_read_byte(), stk500pp_write_byte(), stk500v2_display(), stk500v2_dragon_hv_open(), stk500v2_enable(), stk500v2_jtagmkII_close(), stk500v2_jtagmkII_setup(), stk500v2_jtagmkII_teardown(), stk500v2_print_parms(), stk500v2_set_fosc(), stk500v2_set_sck_period_mk2(), stk500v2_set_varef(), stk500v2_set_vtarget(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk500v2_drain()

int stk500v2_drain ( PROGRAMMER pgm,
int  display 
)
531{
532 return serial_drain(&pgm->fd, display);
533}
#define serial_drain
Definition libavrdude.h:579

References programmer_t::fd, pgm, and serial_drain.

Referenced by stk500v2_open(), stk600_open(), and wiring_open().

+ Here is the caller graph for this function:

◆ stk500v2_enable()

static void stk500v2_enable ( PROGRAMMER pgm)
static
1634{
1635 return;
1636}

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_isp_initpgm(), stk500v2_dragon_pp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_getparm()

static int stk500v2_getparm ( PROGRAMMER pgm,
unsigned char  parm,
unsigned char *  value 
)
static
3111{
3112 unsigned char buf[32];
3113
3114 buf[0] = CMD_GET_PARAMETER;
3115 buf[1] = parm;
3116
3117 if (stk500v2_command(pgm, buf, 2, sizeof(buf)) < 0) {
3118 avrdude_message(MSG_INFO, "%s: stk500v2_getparm(): failed to get parameter 0x%02x\n",
3119 progname, parm);
3120 return -1;
3121 }
3122
3123 *value = buf[2];
3124
3125 return 0;
3126}
#define CMD_GET_PARAMETER
Definition stk500v2_private.h:21

References avrdude_message(), CMD_GET_PARAMETER, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk500v2_display(), stk500v2_print_parms1(), stk500v2_program_enable(), stk500v2_set_varef(), stk500v2_set_vtarget(), stk500v2_setparm(), and stk600_set_varef().

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

◆ stk500v2_getparm2()

static int stk500v2_getparm2 ( PROGRAMMER pgm,
unsigned char  parm,
unsigned int *  value 
)
static
3164{
3165 unsigned char buf[32];
3166
3167 buf[0] = CMD_GET_PARAMETER;
3168 buf[1] = parm;
3169
3170 if (stk500v2_command(pgm, buf, 2, sizeof(buf)) < 0) {
3171 avrdude_message(MSG_INFO, "%s: stk500v2_getparm2(): failed to get parameter 0x%02x\n",
3172 progname, parm);
3173 return -1;
3174 }
3175
3176 *value = ((unsigned)buf[2] << 8) | buf[3];
3177
3178 return 0;
3179}

References avrdude_message(), CMD_GET_PARAMETER, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk500v2_display(), stk500v2_print_parms1(), and stk600_set_vtarget().

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

◆ stk500v2_getsync()

int stk500v2_getsync ( PROGRAMMER pgm)
749 {
750 int tries = 0;
751 unsigned char buf[1], resp[32];
752 int status;
753
754 DEBUG("STK500V2: stk500v2_getsync()\n");
755
756 if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE_MKII ||
757 PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE3)
758 return 0;
759
760retry:
761 tries++;
762
764
765 // send the sync command and see if we can get there
766 buf[0] = CMD_SIGN_ON;
767 if (stk500v2_send(pgm, buf, 1) != 0) {
768 avrdude_message(MSG_INFO, "%s: stk500v2_getsync(): can't communicate with device\n", progname);
769 return -1;
770 }
771
773
774 // try to get the response back and see where we got
775 status = stk500v2_recv(pgm, resp, sizeof(resp));
776
778
779 // if we got bytes returned, check to see what came back
780 if (status > 0) {
781 if ((resp[0] == CMD_SIGN_ON) && (resp[1] == STATUS_CMD_OK) &&
782 (status > 3)) {
783 // success!
784 unsigned int siglen = resp[2];
785 if (siglen >= strlen("STK500_2") &&
786 memcmp(resp + 3, "STK500_2", strlen("STK500_2")) == 0) {
787 PDATA(pgm)->pgmtype = PGMTYPE_STK500;
788 } else if (siglen >= strlen("AVRISP_2") &&
789 memcmp(resp + 3, "AVRISP_2", strlen("AVRISP_2")) == 0) {
790 PDATA(pgm)->pgmtype = PGMTYPE_AVRISP;
791 } else if (siglen >= strlen("AVRISP_MK2") &&
792 memcmp(resp + 3, "AVRISP_MK2", strlen("AVRISP_MK2")) == 0) {
793 PDATA(pgm)->pgmtype = PGMTYPE_AVRISP_MKII;
794 } else if (siglen >= strlen("STK600") &&
795 memcmp(resp + 3, "STK600", strlen("STK600")) == 0) {
796 PDATA(pgm)->pgmtype = PGMTYPE_STK600;
797 } else {
798 resp[siglen + 3] = 0;
799 avrdude_message(MSG_NOTICE, "%s: stk500v2_getsync(): got response from unknown "
800 "programmer %s, assuming STK500\n",
801 progname, resp + 3);
802 PDATA(pgm)->pgmtype = PGMTYPE_STK500;
803 }
804 avrdude_message(MSG_DEBUG, "%s: stk500v2_getsync(): found %s programmer\n",
805 progname, pgmname[PDATA(pgm)->pgmtype]);
806 return 0;
807 } else {
808 if (tries > RETRIES) {
809 avrdude_message(MSG_INFO, "%s: stk500v2_getsync(): can't communicate with device: resp=0x%02x\n",
810 progname, resp[0]);
811 return -6;
812 } else
813 goto retry;
814 }
815
816 // or if we got a timeout
817 } else if (status == -1) {
818 if (tries > RETRIES) {
819 avrdude_message(MSG_INFO, "%s: stk500v2_getsync(): timeout communicating with programmer\n",
820 progname);
821 return -1;
822 } else
823 goto retry;
824
825 // or any other error
826 } else {
827 if (tries > RETRIES) {
828 avrdude_message(MSG_INFO, "%s: stk500v2_getsync(): error communicating with programmer: (%d)\n",
829 progname,status);
830 } else
831 goto retry;
832 }
833
834 return 0;
835}
#define MSG_DEBUG
Definition avrdude.h:54
#define MSG_NOTICE
Definition avrdude.h:52
#define CMD_SIGN_ON
Definition stk500v2_private.h:19

References avrdude_message(), CMD_SIGN_ON, DEBUG, MSG_DEBUG, MSG_INFO, MSG_NOTICE, PDATA, pgm, pgmname, progname, RETRIES, RETURN_IF_CANCEL, STATUS_CMD_OK, stk500v2_recv(), and stk500v2_send().

Referenced by stk500v2_command(), stk500v2_open(), stk600_open(), and wiring_open().

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

◆ stk500v2_initialize()

static int stk500v2_initialize ( PROGRAMMER pgm,
AVRPART p 
)
static
1286{
1287
1288 LNODEID ln;
1289 AVRMEM * m;
1290
1291 if ((PDATA(pgm)->pgmtype == PGMTYPE_STK600 ||
1292 PDATA(pgm)->pgmtype == PGMTYPE_AVRISP_MKII ||
1293 PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE_MKII) != 0
1294 && (p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_TPI)) != 0) {
1295 /*
1296 * This is an ATxmega device, must use XPROG protocol for the
1297 * remaining actions.
1298 */
1299 if ((p->flags & AVRPART_HAS_PDI) != 0) {
1300 /*
1301 * Find out where the border between application and boot area
1302 * is.
1303 */
1304 AVRMEM *bootmem = avr_locate_mem(p, "boot");
1305 AVRMEM *flashmem = avr_locate_mem(p, "flash");
1306 if (bootmem == NULL || flashmem == NULL) {
1307 avrdude_message(MSG_INFO, "%s: stk500v2_initialize(): Cannot locate \"flash\" and \"boot\" memories in description\n",
1308 progname);
1309 } else {
1310 PDATA(pgm)->boot_start = bootmem->offset - flashmem->offset;
1311 }
1312 }
1314 } else {
1316 }
1317
1318 /*
1319 * Examine the avrpart's memory definitions, and initialize the page
1320 * caches. For devices/memory that are not page oriented, treat
1321 * them as page size 1 for EEPROM, and 2 for flash.
1322 */
1323 PDATA(pgm)->flash_pagesize = 2;
1324 PDATA(pgm)->eeprom_pagesize = 1;
1325 for (ln = lfirst(p->mem); ln; ln = lnext(ln)) {
1326 m = ldata(ln);
1327 if (strcmp(m->desc, "flash") == 0) {
1328 if (m->page_size > 0) {
1329 if (m->page_size > 256)
1330 PDATA(pgm)->flash_pagesize = 256;
1331 else
1332 PDATA(pgm)->flash_pagesize = m->page_size;
1333 }
1334 } else if (strcmp(m->desc, "eeprom") == 0) {
1335 if (m->page_size > 0)
1336 PDATA(pgm)->eeprom_pagesize = m->page_size;
1337 }
1338 }
1339 free(PDATA(pgm)->flash_pagecache);
1340 free(PDATA(pgm)->eeprom_pagecache);
1341 if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) {
1342 avrdude_message(MSG_INFO, "%s: stk500v2_initialize(): Out of memory\n",
1343 progname);
1344 return -1;
1345 }
1346 if ((PDATA(pgm)->eeprom_pagecache = malloc(PDATA(pgm)->eeprom_pagesize)) == NULL) {
1347 avrdude_message(MSG_INFO, "%s: stk500v2_initialize(): Out of memory\n",
1348 progname);
1349 free(PDATA(pgm)->flash_pagecache);
1350 return -1;
1351 }
1352 PDATA(pgm)->flash_pageaddr = PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
1353
1354 if (p->flags & AVRPART_IS_AT90S1200) {
1355 /*
1356 * AT90S1200 needs a positive reset pulse after a chip erase.
1357 */
1358 pgm->disable(pgm);
1359 usleep(10000);
1360 }
1361 return pgm->program_enable(pgm, p);
1362}
AVRMEM * avr_locate_mem(AVRPART *p, char *desc)
Definition avrpart.c:354
#define AVRPART_IS_AT90S1200
Definition libavrdude.h:207
unsigned int offset
Definition libavrdude.h:289
#define AVRPART_HAS_PDI
Definition libavrdude.h:202
#define AVRPART_HAS_TPI
Definition libavrdude.h:206
unsigned flags
Definition libavrdude.h:230
static void stk600_setup_xprog(PROGRAMMER *pgm)
Definition stk500v2.c:4388
static void stk600_setup_isp(PROGRAMMER *pgm)
Definition stk500v2.c:4404

References avr_locate_mem(), avrdude_message(), AVRPART_HAS_PDI, AVRPART_HAS_TPI, AVRPART_IS_AT90S1200, avrmem::desc, programmer_t::disable, avrpart::flags, free(), ldata(), lfirst(), lnext(), long, malloc(), avrpart::mem, MSG_INFO, avrmem::offset, avrmem::page_size, PDATA, pgm, progname, programmer_t::program_enable, stk600_setup_isp(), stk600_setup_xprog(), and usleep().

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtagmkII_initpgm(), and stk600_initpgm().

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

◆ stk500v2_initpgm()

void stk500v2_initpgm ( PROGRAMMER pgm)
4419{
4420
4421 strcpy(pgm->type, "STK500V2");
4422
4423 /*
4424 * mandatory functions
4425 */
4432 pgm->cmd = stk500v2_cmd;
4437
4438 /*
4439 * optional functions
4440 */
4452 pgm->page_size = 256;
4454}
void stk500v2_set_upload_size(PROGRAMMER *pgm, int size)
Definition stk500v2.c:4808
static int stk500v2_perform_osccal(PROGRAMMER *pgm)
Definition stk500v2.c:3426
int(* perform_osccal)(struct programmer_t *pgm)
Definition libavrdude.h:682
void(* set_upload_size)(struct programmer_t *pgm, int size)
Definition libavrdude.h:686

References programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_erase, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, programmer_t::perform_osccal, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_upload_size, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_chip_erase(), stk500v2_close(), stk500v2_cmd(), stk500v2_disable(), stk500v2_display(), stk500v2_enable(), stk500v2_initialize(), stk500v2_open(), stk500v2_page_erase(), stk500v2_paged_load(), stk500v2_paged_write(), stk500v2_perform_osccal(), stk500v2_print_parms(), stk500v2_program_enable(), stk500v2_set_fosc(), stk500v2_set_sck_period(), stk500v2_set_upload_size(), stk500v2_set_varef(), stk500v2_set_vtarget(), stk500v2_setup(), stk500v2_teardown(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

Referenced by stk500generic_open(), stk500generic_setup(), stk500generic_teardown(), and wiring_initpgm().

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

◆ stk500v2_jtag3_close()

static void stk500v2_jtag3_close ( PROGRAMMER pgm)
static
3544{
3545 // void *mycookie;
3546
3547 // avrdude_message(MSG_NOTICE2, "%s: stk500v2_jtag3_close()\n", progname);
3548
3549 // mycookie = pgm->cookie;
3550 // pgm->cookie = PDATA(pgm)->chained_pdata;
3551 // jtag3_close(pgm);
3552 // pgm->cookie = mycookie;
3553}

Referenced by stk500v2_jtag3_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtag3_cmd()

static int stk500v2_jtag3_cmd ( PROGRAMMER pgm,
const unsigned char *  cmd,
unsigned char *  res 
)
static
999{
1000 avrdude_message(MSG_INFO, "%s: stk500v2_jtag3_cmd(): Not available in JTAGICE3\n",
1001 progname);
1002
1003 return -1;
1004}

References avrdude_message(), MSG_INFO, and progname.

Referenced by stk500v2_jtag3_initpgm().

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

◆ stk500v2_jtag3_disable()

static void stk500v2_jtag3_disable ( PROGRAMMER pgm)
static
1544{
1545 unsigned char buf[16];
1546 int result;
1547
1548 free(PDATA(pgm)->flash_pagecache);
1549 PDATA(pgm)->flash_pagecache = NULL;
1550 free(PDATA(pgm)->eeprom_pagecache);
1551 PDATA(pgm)->eeprom_pagecache = NULL;
1552
1553 buf[0] = CMD_LEAVE_PROGMODE_ISP;
1554 buf[1] = 1; // preDelay;
1555 buf[2] = 1; // postDelay;
1556
1557 result = stk500v2_command(pgm, buf, 3, sizeof(buf));
1558
1559 if (result < 0) {
1560 avrdude_message(MSG_INFO, "%s: stk500v2_disable(): failed to leave programming mode\n",
1561 progname);
1562 }
1563
1564 return;
1565}

References avrdude_message(), CMD_LEAVE_PROGMODE_ISP, free(), MSG_INFO, PDATA, pgm, progname, and stk500v2_command().

Referenced by stk500v2_jtag3_initpgm().

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

◆ stk500v2_jtag3_initialize()

static int stk500v2_jtag3_initialize ( PROGRAMMER pgm,
AVRPART p 
)
static
1370{
1371 return -1;
1372 // unsigned char parm[4], *resp;
1373 // LNODEID ln;
1374 // AVRMEM * m;
1375 // void *mycookie;
1376
1377 // if ((p->flags & AVRPART_HAS_PDI) ||
1378 // (p->flags & AVRPART_HAS_TPI)) {
1379 // avrdude_message(MSG_INFO, "%s: jtag3_initialize(): part %s has no ISP interface\n",
1380 // progname, p->desc);
1381 // return -1;
1382 // }
1383
1384 // mycookie = pgm->cookie;
1385 // pgm->cookie = PDATA(pgm)->chained_pdata;
1386
1387 // if (p->flags & AVRPART_HAS_DW)
1388 // parm[0] = PARM3_ARCH_TINY;
1389 // else
1390 // parm[0] = PARM3_ARCH_MEGA;
1391 // if (jtag3_setparm(pgm, SCOPE_AVR, 0, PARM3_ARCH, parm, 1) < 0) {
1392 // pgm->cookie = mycookie;
1393 // return -1;
1394 // }
1395
1396 // parm[0] = PARM3_SESS_PROGRAMMING;
1397 // if (jtag3_setparm(pgm, SCOPE_AVR, 0, PARM3_SESS_PURPOSE, parm, 1) < 0) {
1398 // pgm->cookie = mycookie;
1399 // return -1;
1400 // }
1401
1402 // parm[0] = PARM3_CONN_ISP;
1403 // if (jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CONNECTION, parm, 1) < 0) {
1404 // pgm->cookie = mycookie;
1405 // return -1;
1406 // }
1407
1408 // parm[0] = SCOPE_AVR_ISP;
1409 // parm[1] = 0x1e;
1410 // jtag3_send(pgm, parm, 2);
1411
1412 // if (jtag3_recv(pgm, &resp) > 0)
1413 // free(resp);
1414
1415 // pgm->cookie = mycookie;
1416
1417 // /*
1418 // * Examine the avrpart's memory definitions, and initialize the page
1419 // * caches. For devices/memory that are not page oriented, treat
1420 // * them as page size 1 for EEPROM, and 2 for flash.
1421 // */
1422 // PDATA(pgm)->flash_pagesize = 2;
1423 // PDATA(pgm)->eeprom_pagesize = 1;
1424 // for (ln = lfirst(p->mem); ln; ln = lnext(ln)) {
1425 // m = ldata(ln);
1426 // if (strcmp(m->desc, "flash") == 0) {
1427 // if (m->page_size > 0) {
1428 // if (m->page_size > 256)
1429 // PDATA(pgm)->flash_pagesize = 256;
1430 // else
1431 // PDATA(pgm)->flash_pagesize = m->page_size;
1432 // }
1433 // } else if (strcmp(m->desc, "eeprom") == 0) {
1434 // if (m->page_size > 0)
1435 // PDATA(pgm)->eeprom_pagesize = m->page_size;
1436 // }
1437 // }
1438 // free(PDATA(pgm)->flash_pagecache);
1439 // free(PDATA(pgm)->eeprom_pagecache);
1440 // if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) {
1441 // avrdude_message(MSG_INFO, "%s: stk500hv_initialize(): Out of memory\n",
1442 // progname);
1443 // return -1;
1444 // }
1445 // if ((PDATA(pgm)->eeprom_pagecache = malloc(PDATA(pgm)->eeprom_pagesize)) == NULL) {
1446 // avrdude_message(MSG_INFO, "%s: stk500hv_initialize(): Out of memory\n",
1447 // progname);
1448 // free(PDATA(pgm)->flash_pagecache);
1449 // return -1;
1450 // }
1451 // PDATA(pgm)->flash_pageaddr = PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
1452
1453 // return pgm->program_enable(pgm, p);
1454}

Referenced by stk500v2_jtag3_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtag3_initpgm()

void stk500v2_jtag3_initpgm ( PROGRAMMER pgm)
4776{
4777 strcpy(pgm->type, "JTAG3_ISP");
4778
4779 /*
4780 * mandatory functions
4781 */
4793
4794 /*
4795 * optional functions
4796 */
4805 pgm->page_size = 256;
4806}
static int stk500v2_jtag3_open(PROGRAMMER *pgm, char *port)
Definition stk500v2.c:3723
static int stk500v2_jtag3_initialize(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:1369
static void stk500v2_jtag3_setup(PROGRAMMER *pgm)
Definition stk500v2.c:331
static int stk500v2_jtag3_set_sck_period(PROGRAMMER *pgm, double v)
Definition stk500v2.c:3087
static void stk500v2_jtag3_teardown(PROGRAMMER *pgm)
Definition stk500v2.c:370
static int stk500v2_jtag3_cmd(PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
Definition stk500v2.c:997
static void stk500v2_jtag3_disable(PROGRAMMER *pgm)
Definition stk500v2.c:1543
static void stk500v2_jtag3_close(PROGRAMMER *pgm)
Definition stk500v2.c:3543

References programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_erase, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, programmer_t::perform_osccal, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_sck_period, programmer_t::setup, stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_chip_erase(), stk500v2_display(), stk500v2_enable(), stk500v2_jtag3_close(), stk500v2_jtag3_cmd(), stk500v2_jtag3_disable(), stk500v2_jtag3_initialize(), stk500v2_jtag3_open(), stk500v2_jtag3_set_sck_period(), stk500v2_jtag3_setup(), stk500v2_jtag3_teardown(), stk500v2_page_erase(), stk500v2_paged_load(), stk500v2_paged_write(), stk500v2_perform_osccal(), stk500v2_print_parms(), stk500v2_program_enable(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk500v2_jtag3_open()

static int stk500v2_jtag3_open ( PROGRAMMER pgm,
char *  port 
)
static
3724{
3725 return -1;
3726 // void *mycookie;
3727 // int rv;
3728
3729 // avrdude_message(MSG_NOTICE2, "%s: stk500v2_jtag3_open()\n", progname);
3730
3731 // if (jtag3_open_common(pgm, port) < 0)
3732 // return -1;
3733
3734 // mycookie = pgm->cookie;
3735 // pgm->cookie = PDATA(pgm)->chained_pdata;
3736 // if ((rv = jtag3_getsync(pgm, 42)) != 0) {
3737 // if (rv != JTAGII_GETSYNC_FAIL_GRACEFUL)
3738 // avrdude_message(MSG_INFO, "%s: failed to sync with the JTAGICE3 in ISP mode\n",
3739 // progname);
3740 // pgm->cookie = mycookie;
3741 // return -1;
3742 // }
3743 // pgm->cookie = mycookie;
3744
3745 // PDATA(pgm)->pgmtype = PGMTYPE_JTAGICE3;
3746
3747 // if (pgm->bitclock != 0.0) {
3748 // if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)
3749 // return -1;
3750 // }
3751
3752 // return 0;
3753}

Referenced by stk500v2_jtag3_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtag3_recv()

static int stk500v2_jtag3_recv ( PROGRAMMER pgm,
unsigned char *  msg,
size_t  maxsize 
)
static
593{
594 return -1;
595 // int rv;
596 // unsigned char *jtagmsg;
597 // void *mycookie;
598
599 // mycookie = pgm->cookie;
600 // pgm->cookie = PDATA(pgm)->chained_pdata;
601 // rv = jtag3_recv(pgm, &jtagmsg);
602 // pgm->cookie = mycookie;
603 // if (rv <= 0) {
604 // avrdude_message(MSG_INFO, "%s: stk500v2_jtag3_recv(): error in jtagmkII_recv()\n",
605 // progname);
606 // return -1;
607 // }
608 // /* Getting more data than expected is a normal case for the EDBG
609 // implementation of JTAGICE3, as they always request a full 512
610 // octets from the ICE. Thus, only complain at high verbose
611 // levels. */
612 // if (rv - 1 > maxsize) {
613 // avrdude_message(MSG_DEBUG, "%s: stk500v2_jtag3_recv(): got %u bytes, have only room for %u bytes\n",
614 // progname, (unsigned)rv - 1, (unsigned)maxsize);
615 // rv = maxsize;
616 // }
617 // if (jtagmsg[0] != SCOPE_AVR_ISP) {
618 // avrdude_message(MSG_INFO, "%s: stk500v2_jtag3_recv(): message is not AVR ISP: 0x%02x\n",
619 // progname, jtagmsg[0]);
620 // free(jtagmsg);
621 // return -1;
622 // }
623 // memcpy(msg, jtagmsg + 1, rv - 1);
624 // free(jtagmsg);
625 // return rv;
626}

Referenced by stk500v2_jtag3_set_sck_period(), stk500v2_print_parms1(), and stk500v2_recv().

+ Here is the caller graph for this function:

◆ stk500v2_jtag3_send()

static int stk500v2_jtag3_send ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
static
470{
471 return -1;
472 // unsigned char *cmdbuf;
473 // int rv;
474 // void *mycookie;
475
476 // if ((cmdbuf = malloc(len + 1)) == NULL) {
477 // avrdude_message(MSG_INFO, "%s: out of memory for command packet\n",
478 // progname);
479 // exit(1);
480 // }
481 // mycookie = pgm->cookie;
482 // pgm->cookie = PDATA(pgm)->chained_pdata;
483 // cmdbuf[0] = SCOPE_AVR_ISP;
484 // memcpy(cmdbuf + 1, data, len);
485 // rv = jtag3_send(pgm, cmdbuf, len + 1);
486 // free(cmdbuf);
487 // pgm->cookie = mycookie;
488
489 // return rv;
490}

Referenced by stk500v2_jtag3_set_sck_period(), stk500v2_print_parms1(), and stk500v2_send().

+ Here is the caller graph for this function:

◆ stk500v2_jtag3_set_sck_period()

static int stk500v2_jtag3_set_sck_period ( PROGRAMMER pgm,
double  v 
)
static
3088{
3089 unsigned char value[3];
3090 unsigned int sck;
3091
3092 if (v < 1E-6)
3093 sck = 0x400;
3094 else if (v > 1E-3)
3095 sck = 1;
3096 else
3097 sck = (unsigned)(1.0 / (1000.0 * v));
3098
3099 value[0] = CMD_SET_SCK;
3100 value[1] = sck & 0xff;
3101 value[2] = (sck >> 8) & 0xff;
3102
3103 if (stk500v2_jtag3_send(pgm, value, 3) < 0)
3104 return -1;
3105 if (stk500v2_jtag3_recv(pgm, value, 3) < 0)
3106 return -1;
3107 return 0;
3108}
static int stk500v2_jtag3_send(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition stk500v2.c:469
static int stk500v2_jtag3_recv(PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
Definition stk500v2.c:591
#define CMD_SET_SCK
Definition stk500v2_private.h:46

References CMD_SET_SCK, pgm, stk500v2_jtag3_recv(), and stk500v2_jtag3_send().

Referenced by stk500v2_jtag3_initpgm().

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

◆ stk500v2_jtag3_setup()

static void stk500v2_jtag3_setup ( PROGRAMMER pgm)
static
332{
333 // void *mycookie, *theircookie;
334
335 // if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
336 // avrdude_message(MSG_INFO, "%s: stk500v2_setup(): Out of memory allocating private data\n",
337 // progname);
338 // exit(1);
339 // }
340 // memset(pgm->cookie, 0, sizeof(struct pdata));
341 // PDATA(pgm)->command_sequence = 1;
342
343 // /*
344 // * Now, have the JTAGICE3 backend allocate its own private
345 // * data. Store our own cookie in a safe place for the time being.
346 // */
347 // mycookie = pgm->cookie;
348 // jtag3_setup(pgm);
349 // theircookie = pgm->cookie;
350 // pgm->cookie = mycookie;
351 // PDATA(pgm)->chained_pdata = theircookie;
352}

Referenced by stk500v2_jtag3_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtag3_teardown()

static void stk500v2_jtag3_teardown ( PROGRAMMER pgm)
static
371{
372 // void *mycookie;
373
374 // mycookie = pgm->cookie;
375 // pgm->cookie = PDATA(pgm)->chained_pdata;
376 // jtag3_teardown(pgm);
377
378 // free(mycookie);
379}

Referenced by stk500v2_jtag3_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtagmkII_close()

static void stk500v2_jtagmkII_close ( PROGRAMMER pgm)
static
3528{
3529 // void *mycookie;
3530
3531 // avrdude_message(MSG_NOTICE2, "%s: stk500v2_jtagmkII_close()\n", progname);
3532
3533 // mycookie = pgm->cookie;
3534 // pgm->cookie = PDATA(pgm)->chained_pdata;
3535 // jtagmkII_close(pgm);
3536 // pgm->cookie = mycookie;
3537}

Referenced by stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_isp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk500v2_jtagmkII_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtagmkII_initpgm()

void stk500v2_jtagmkII_initpgm ( PROGRAMMER pgm)
4529{
4530 strcpy(pgm->type, "JTAGMKII_ISP");
4531
4532 /*
4533 * mandatory functions
4534 */
4541 pgm->cmd = stk500v2_cmd;
4546
4547 /*
4548 * optional functions
4549 */
4558 pgm->page_size = 256;
4559}
static int stk500v2_jtagmkII_open(PROGRAMMER *pgm, char *port)
Definition stk500v2.c:3453

References programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_erase, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, programmer_t::perform_osccal, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_sck_period, programmer_t::setup, stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_chip_erase(), stk500v2_cmd(), stk500v2_disable(), stk500v2_display(), stk500v2_enable(), stk500v2_initialize(), stk500v2_jtagmkII_close(), stk500v2_jtagmkII_open(), stk500v2_jtagmkII_setup(), stk500v2_jtagmkII_teardown(), stk500v2_page_erase(), stk500v2_paged_load(), stk500v2_paged_write(), stk500v2_perform_osccal(), stk500v2_print_parms(), stk500v2_program_enable(), stk500v2_set_sck_period_mk2(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk500v2_jtagmkII_open()

static int stk500v2_jtagmkII_open ( PROGRAMMER pgm,
char *  port 
)
static
3454{
3455 return -1;
3456// union pinfo pinfo;
3457// void *mycookie;
3458// int rv;
3459
3460// avrdude_message(MSG_NOTICE2, "%s: stk500v2_jtagmkII_open()\n", progname);
3461
3462// /*
3463// * The JTAG ICE mkII always starts with a baud rate of 19200 Bd upon
3464// * attaching. If the config file or command-line parameters specify
3465// * a higher baud rate, we switch to it later on, after establishing
3466// * the connection with the ICE.
3467// */
3468// pinfo.baud = 19200;
3469
3470// /*
3471// * If the port name starts with "usb", divert the serial routines
3472// * to the USB ones. The serial_open() function for USB overrides
3473// * the meaning of the "baud" parameter to be the USB device ID to
3474// * search for.
3475// */
3476// if (strncmp(port, "usb", 3) == 0) {
3477// #if defined(HAVE_LIBUSB)
3478// serdev = &usb_serdev;
3479// pinfo.usbinfo.vid = USB_VENDOR_ATMEL;
3480// pinfo.usbinfo.flags = 0;
3481// pinfo.usbinfo.pid = USB_DEVICE_JTAGICEMKII;
3482// pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
3483// pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
3484// pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
3485// pgm->fd.usb.eep = 0; /* no seperate EP for events */
3486// #else
3487// avrdude_message(MSG_INFO, "avrdude was compiled without usb support.\n");
3488// return -1;
3489// #endif
3490// }
3491
3492// strcpy(pgm->port, port);
3493// if (serial_open(port, pinfo, &pgm->fd)==-1) {
3494// return -1;
3495// }
3496
3497// /*
3498// * drain any extraneous input
3499// */
3500// stk500v2_drain(pgm, 0);
3501
3502// mycookie = pgm->cookie;
3503// pgm->cookie = PDATA(pgm)->chained_pdata;
3504// if ((rv = jtagmkII_getsync(pgm, EMULATOR_MODE_SPI)) != 0) {
3505// if (rv != JTAGII_GETSYNC_FAIL_GRACEFUL)
3506// avrdude_message(MSG_INFO, "%s: failed to sync with the JTAG ICE mkII in ISP mode\n",
3507// progname);
3508// pgm->cookie = mycookie;
3509// return -1;
3510// }
3511// pgm->cookie = mycookie;
3512
3513// PDATA(pgm)->pgmtype = PGMTYPE_JTAGICE_MKII;
3514
3515// if (pgm->bitclock != 0.0) {
3516// if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)
3517// return -1;
3518// }
3519
3520// return 0;
3521}

Referenced by stk500v2_jtagmkII_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtagmkII_recv()

static int stk500v2_jtagmkII_recv ( PROGRAMMER pgm,
unsigned char *  msg,
size_t  maxsize 
)
static
551{
552 return -1;
553 // int rv;
554 // unsigned char *jtagmsg;
555 // void *mycookie;
556
557 // mycookie = pgm->cookie;
558 // pgm->cookie = PDATA(pgm)->chained_pdata;
559 // rv = jtagmkII_recv(pgm, &jtagmsg);
560 // pgm->cookie = mycookie;
561 // if (rv <= 0) {
562 // avrdude_message(MSG_INFO, "%s: stk500v2_jtagmkII_recv(): error in jtagmkII_recv()\n",
563 // progname);
564 // return -1;
565 // }
566 // if (rv - 1 > maxsize) {
567 // avrdude_message(MSG_INFO, "%s: stk500v2_jtagmkII_recv(): got %u bytes, have only room for %u bytes\n",
568 // progname, (unsigned)rv - 1, (unsigned)maxsize);
569 // rv = maxsize;
570 // }
571 // switch (jtagmsg[0]) {
572 // case RSP_SPI_DATA:
573 // break;
574 // case RSP_FAILED:
575 // avrdude_message(MSG_INFO, "%s: stk500v2_jtagmkII_recv(): failed\n",
576 // progname);
577 // return -1;
578 // case RSP_ILLEGAL_MCU_STATE:
579 // avrdude_message(MSG_INFO, "%s: stk500v2_jtagmkII_recv(): illegal MCU state\n",
580 // progname);
581 // return -1;
582 // default:
583 // avrdude_message(MSG_INFO, "%s: stk500v2_jtagmkII_recv(): unknown status %d\n",
584 // progname, jtagmsg[0]);
585 // return -1;
586 // }
587 // memcpy(msg, jtagmsg + 1, rv - 1);
588 // return rv;
589}

Referenced by stk500v2_recv().

+ Here is the caller graph for this function:

◆ stk500v2_jtagmkII_send()

static int stk500v2_jtagmkII_send ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
static
420{
421 return -1;
422 // unsigned char *cmdbuf;
423 // int rv;
424 // unsigned short sz;
425 // void *mycookie;
426
427 // sz = get_jtagisp_return_size(data[0]);
428 // if (sz == 0) {
429 // avrdude_message(MSG_INFO, "%s: unsupported encapsulated ISP command: %#x\n",
430 // progname, data[0]);
431 // return -1;
432 // }
433 // if (sz == SZ_READ_FLASH_EE) {
434 // /*
435 // * For CMND_READ_FLASH_ISP and CMND_READ_EEPROM_ISP, extract the
436 // * size of the return data from the request. Note that the
437 // * request itself has the size in big endian format, while we are
438 // * supposed to deliver it in little endian.
439 // */
440 // sz = 3 + (data[1] << 8) + data[2];
441 // } else if (sz == SZ_SPI_MULTI) {
442 // /*
443 // * CMND_SPI_MULTI has the Rx size encoded in its 3rd byte.
444 // */
445 // sz = 3 + data[2];
446 // }
447
448 // if ((cmdbuf = malloc(len + 3)) == NULL) {
449 // avrdude_message(MSG_INFO, "%s: out of memory for command packet\n",
450 // progname);
451 // exit(1);
452 // }
453 // mycookie = pgm->cookie;
454 // pgm->cookie = PDATA(pgm)->chained_pdata;
455 // cmdbuf[0] = CMND_ISP_PACKET;
456 // cmdbuf[1] = sz & 0xff;
457 // cmdbuf[2] = (sz >> 8) & 0xff;
458 // memcpy(cmdbuf + 3, data, len);
459 // rv = jtagmkII_send(pgm, cmdbuf, len + 3);
460 // free(cmdbuf);
461 // pgm->cookie = mycookie;
462
463 // return rv;
464}

Referenced by stk500v2_send().

+ Here is the caller graph for this function:

◆ stk500v2_jtagmkII_setup()

static void stk500v2_jtagmkII_setup ( PROGRAMMER pgm)
static
309{
310 // void *mycookie, *theircookie;
311
312 // if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
313 // avrdude_message(MSG_INFO, "%s: stk500v2_setup(): Out of memory allocating private data\n",
314 // progname);
315 // exit(1);
316 // }
317 // memset(pgm->cookie, 0, sizeof(struct pdata));
318 // PDATA(pgm)->command_sequence = 1;
319
320 // /*
321 // * Now, have the JTAG ICE mkII backend allocate its own private
322 // * data. Store our own cookie in a safe place for the time being.
323 // */
324 // mycookie = pgm->cookie;
325 // jtagmkII_setup(pgm);
326 // theircookie = pgm->cookie;
327 // pgm->cookie = mycookie;
328 // PDATA(pgm)->chained_pdata = theircookie;
329}

Referenced by stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_isp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk500v2_jtagmkII_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_jtagmkII_teardown()

static void stk500v2_jtagmkII_teardown ( PROGRAMMER pgm)
static
360{
361 // void *mycookie;
362
363 // mycookie = pgm->cookie;
364 // pgm->cookie = PDATA(pgm)->chained_pdata;
365 // jtagmkII_teardown(pgm);
366
367 // free(mycookie);
368}

Referenced by stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_isp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk500v2_jtagmkII_initpgm().

+ Here is the caller graph for this function:

◆ stk500v2_loadaddr()

static int stk500v2_loadaddr ( PROGRAMMER pgm,
unsigned int  addr 
)
static
1779{
1780 unsigned char buf[16];
1781 int result;
1782
1783 DEBUG("STK500V2: stk500v2_loadaddr(%d)\n",addr);
1784
1785 buf[0] = CMD_LOAD_ADDRESS;
1786 buf[1] = (addr >> 24) & 0xff;
1787 buf[2] = (addr >> 16) & 0xff;
1788 buf[3] = (addr >> 8) & 0xff;
1789 buf[4] = addr & 0xff;
1790
1791 result = stk500v2_command(pgm, buf, 5, sizeof(buf));
1792
1793 if (result < 0) {
1794 avrdude_message(MSG_INFO, "%s: stk500v2_loadaddr(): failed to set load address\n",
1795 progname);
1796 return -1;
1797 }
1798
1799 return 0;
1800}
#define CMD_LOAD_ADDRESS
Definition stk500v2_private.h:24

References avrdude_message(), CMD_LOAD_ADDRESS, DEBUG, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk500hv_paged_load(), stk500hv_paged_write(), stk500hv_read_byte(), stk500hv_write_byte(), stk500v2_paged_load(), stk500v2_paged_write(), stk600_xprog_paged_load(), and stk600_xprog_paged_write().

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

◆ stk500v2_mode_for_pagesize()

static unsigned int stk500v2_mode_for_pagesize ( unsigned int  pagesize)
static
2905{
2906 switch (pagesize)
2907 {
2908 case 256: return 0u << 1;
2909 case 2: return 1u << 1;
2910 case 4: return 2u << 1;
2911 case 8: return 3u << 1;
2912 case 16: return 4u << 1;
2913 case 32: return 5u << 1;
2914 case 64: return 6u << 1;
2915 case 128: return 7u << 1;
2916 }
2917 avrdude_message(MSG_INFO, "%s: stk500v2_mode_for_pagesize(): invalid pagesize: %u\n",
2918 progname, pagesize);
2919 return 0;
2920}

References avrdude_message(), MSG_INFO, and progname.

Referenced by stk500hv_paged_write(), and stk500hv_write_byte().

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

◆ stk500v2_open()

static int stk500v2_open ( PROGRAMMER pgm,
char *  port 
)
static
1640{
1641 union pinfo pinfo = { .baud = 115200 };
1642
1643 DEBUG("STK500V2: stk500v2_open()\n");
1644
1645 if (pgm->baudrate)
1647
1648 PDATA(pgm)->pgmtype = PGMTYPE_UNKNOWN;
1649
1650 if(strcasecmp(port, "avrdoper") == 0){
1651#if defined(HAVE_LIBUSB) || (defined(WIN32NATIVE) && defined(HAVE_LIBHID))
1653 PDATA(pgm)->pgmtype = PGMTYPE_STK500;
1654#else
1655 avrdude_message(MSG_INFO, "avrdude was compiled without usb support.\n");
1656 return -1;
1657#endif
1658 }
1659
1660 /*
1661 * If the port name starts with "usb", divert the serial routines
1662 * to the USB ones. The serial_open() function for USB overrides
1663 * the meaning of the "baud" parameter to be the USB device ID to
1664 * search for.
1665 */
1666 if (strncmp(port, "usb", 3) == 0) {
1667#if defined(HAVE_LIBUSB)
1670 pinfo.usbinfo.flags = 0;
1672 PDATA(pgm)->pgmtype = PGMTYPE_AVRISP_MKII;
1674 pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
1677 pgm->fd.usb.eep = 0; /* no seperate EP for events */
1678#else
1679 avrdude_message(MSG_INFO, "avrdude was compiled without usb support.\n");
1680 return -1;
1681#endif
1682 }
1683
1684 strcpy(pgm->port, port);
1685 if (serial_open(port, pinfo, &pgm->fd)==-1) {
1686 return -1;
1687 }
1688
1689 /*
1690 * drain any extraneous input
1691 */
1692 stk500v2_drain(pgm, 0);
1693
1695
1696 stk500v2_drain(pgm, 0);
1697
1698 if (pgm->bitclock != 0.0) {
1699 if (pgm->set_sck_period(pgm, pgm->bitclock) != 0) {
1700 serial_close(&pgm->fd);
1701 return -1;
1702 }
1703 }
1704
1705 return 0;
1706}
struct serial_device avrdoper_serdev
struct serial_device * serdev
Definition ser_posix.c:562
#define serial_open
Definition libavrdude.h:574
struct filedescriptor::@12 usb
struct serial_device usb_serdev_frame
struct pinfo::@13 usbinfo
long baud
Definition libavrdude.h:537
Definition libavrdude.h:536
int stk500v2_drain(PROGRAMMER *pgm, int display)
Definition stk500v2.c:530
char port[PGM_PORTLEN]
Definition libavrdude.h:620
double bitclock
Definition libavrdude.h:635
int baudrate
Definition libavrdude.h:630
#define strcasecmp
Definition unistd.h:52
#define USB_VENDOR_ATMEL
Definition usbdevs.h:28
#define USBDEV_BULK_EP_WRITE_MKII
Definition usbdevs.h:60
#define USBDEV_MAX_XFER_MKII
Definition usbdevs.h:62
#define USB_DEVICE_AVRISPMKII
Definition usbdevs.h:30
#define USBDEV_BULK_EP_READ_MKII
Definition usbdevs.h:61

References avrdoper_serdev, avrdude_message(), pinfo::baud, programmer_t::baudrate, programmer_t::bitclock, DEBUG, programmer_t::fd, MSG_INFO, PDATA, pgm, programmer_t::port, serdev, serial_close, serial_open, programmer_t::set_sck_period, stk500v2_drain(), stk500v2_getsync(), stk500v2_set_sck_period_mk2(), strcasecmp, filedescriptor::usb, USB_DEVICE_AVRISPMKII, usb_serdev_frame, USB_VENDOR_ATMEL, USBDEV_BULK_EP_READ_MKII, USBDEV_BULK_EP_WRITE_MKII, USBDEV_MAX_XFER_MKII, and pinfo::usbinfo.

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), and stk500v2_initpgm().

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

◆ stk500v2_page_erase()

static int stk500v2_page_erase ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  addr 
)
static
2760{
2761 avrdude_message(MSG_INFO, "%s: stk500v2_page_erase(): this function must never be called\n",
2762 progname);
2763 return -1;
2764}

References avrdude_message(), MSG_INFO, and progname.

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500v2_paged_load()

static int stk500v2_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
2570{
2571 unsigned int block_size, hiaddr, addrshift, use_ext_addr;
2572 unsigned int maxaddr = addr + n_bytes;
2573 unsigned char commandbuf[4];
2574 unsigned char buf[275]; // max buffer size for stk500v2 at this point
2575 unsigned char cmds[4];
2576 int result;
2577 OPCODE * rop;
2578
2579 DEBUG("STK500V2: stk500v2_paged_load(..,%s,%u,%u,%u)\n",
2580 m->desc, page_size, addr, n_bytes);
2581
2582 page_size = m->readsize;
2583
2584 rop = m->op[AVR_OP_READ];
2585
2586 hiaddr = UINT_MAX;
2587 addrshift = 0;
2588 use_ext_addr = 0;
2589
2590 // determine which command is to be used
2591 if (strcmp(m->desc, "flash") == 0) {
2592 commandbuf[0] = CMD_READ_FLASH_ISP;
2593 rop = m->op[AVR_OP_READ_LO];
2594 addrshift = 1;
2595 /*
2596 * If bit 31 is set, this indicates that the following read/write
2597 * operation will be performed on a memory that is larger than
2598 * 64KBytes. This is an indication to STK500 that a load extended
2599 * address must be executed.
2600 */
2601 if (m->op[AVR_OP_LOAD_EXT_ADDR] != NULL) {
2602 use_ext_addr = (1U << 31);
2603 }
2604 }
2605 else if (strcmp(m->desc, "eeprom") == 0) {
2606 commandbuf[0] = CMD_READ_EEPROM_ISP;
2607 }
2608
2609 // the read command is common to both methods
2610 if (rop == NULL) {
2611 avrdude_message(MSG_INFO, "%s: stk500v2_paged_load: read instruction not defined for part \"%s\"\n",
2612 progname, p->desc);
2613 return -1;
2614 }
2615 avr_set_bits(rop, cmds);
2616 commandbuf[3] = cmds[0];
2617
2618 for (; addr < maxaddr; addr += page_size) {
2619 if ((maxaddr - addr) < page_size)
2620 block_size = maxaddr - addr;
2621 else
2622 block_size = page_size;
2623 DEBUG("block_size at addr %d is %d\n",addr,block_size);
2624
2625 memcpy(buf,commandbuf,sizeof(commandbuf));
2626
2627 buf[1] = block_size >> 8;
2628 buf[2] = block_size & 0xff;
2629
2630 // Ensure a new "load extended address" will be issued
2631 // when crossing a 64 KB boundary in flash.
2632 if (hiaddr != (addr & ~0xFFFF)) {
2633 hiaddr = addr & ~0xFFFF;
2634 if (stk500v2_loadaddr(pgm, use_ext_addr | (addr >> addrshift)) < 0)
2635 return -1;
2636 }
2637
2638 result = stk500v2_command(pgm,buf,4,sizeof(buf));
2639 if (result < 0) {
2640 avrdude_message(MSG_INFO, "%s: stk500v2_paged_load: read command failed\n",
2641 progname);
2642 return -1;
2643 }
2644#if 0
2645 for (i=0;i<page_size;i++) {
2646 avrdude_message(MSG_INFO, "%02X",buf[2+i]);
2647 if (i%16 == 15) avrdude_message(MSG_INFO, "\n");
2648 }
2649#endif
2650
2651 memcpy(&m->buf[addr], &buf[2], block_size);
2652 }
2653
2654 return n_bytes;
2655}
@ AVR_OP_READ_LO
Definition libavrdude.h:148
#define CMD_READ_EEPROM_ISP
Definition stk500v2_private.h:38
#define CMD_READ_FLASH_ISP
Definition stk500v2_private.h:36

References AVR_OP_LOAD_EXT_ADDR, AVR_OP_READ, AVR_OP_READ_LO, avr_set_bits(), avrdude_message(), avrmem::buf, CMD_READ_EEPROM_ISP, CMD_READ_FLASH_ISP, DEBUG, avrpart::desc, avrmem::desc, MSG_INFO, avrmem::op, pgm, progname, avrmem::readsize, stk500v2_command(), and stk500v2_loadaddr().

Referenced by stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500v2_paged_write()

static int stk500v2_paged_write ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
2301{
2302// static int page = 0;
2303 unsigned int block_size, last_addr, addrshift, use_ext_addr;
2304 unsigned int maxaddr = addr + n_bytes;
2305 unsigned char commandbuf[10];
2306 unsigned char buf[266];
2307 unsigned char cmds[4];
2308 int result;
2309 OPCODE * rop, * wop;
2310
2311 // Prusa3D workaround for a bug in the USB communication controller. The semicolon character is used as an initial character
2312 // for special command sequences for the USB communication chip. The early releases of the USB communication chip had
2313 // a bug, which produced a 0x0ff character after the semicolon. The patch is to program the semicolons by flashing
2314 // firmware blocks twice: First the low nibbles of semicolons, second the high nibbles of the semicolon characters.
2315 //
2316 // Inside the 2nd round of a firmware block flashing?
2317 bool prusa3d_semicolon_workaround_round2 = false;
2318 // Buffer containing the other nibbles of semicolons to be flashed in the 2nd round.
2319 unsigned char prusa3d_semicolon_workaround_round2_data[256];
2320
2321 DEBUG("STK500V2: stk500v2_paged_write(..,%s,%u,%u,%u)\n",
2322 m->desc, page_size, addr, n_bytes);
2323
2324 if (page_size == 0) page_size = 256;
2325 addrshift = 0;
2326 use_ext_addr = 0;
2327
2328 // determine which command is to be used
2329 if (strcmp(m->desc, "flash") == 0) {
2330 addrshift = 1;
2331 commandbuf[0] = CMD_PROGRAM_FLASH_ISP;
2332 /*
2333 * If bit 31 is set, this indicates that the following read/write
2334 * operation will be performed on a memory that is larger than
2335 * 64KBytes. This is an indication to STK500 that a load extended
2336 * address must be executed.
2337 */
2338 if (m->op[AVR_OP_LOAD_EXT_ADDR] != NULL) {
2339 use_ext_addr = (1U << 31);
2340 }
2341 } else if (strcmp(m->desc, "eeprom") == 0) {
2342 commandbuf[0] = CMD_PROGRAM_EEPROM_ISP;
2343 }
2344 commandbuf[4] = m->delay;
2345
2346 if (addrshift == 0) {
2347 wop = m->op[AVR_OP_WRITE];
2348 rop = m->op[AVR_OP_READ];
2349 }
2350 else {
2351 wop = m->op[AVR_OP_WRITE_LO];
2352 rop = m->op[AVR_OP_READ_LO];
2353 }
2354
2355 // if the memory is paged, load the appropriate commands into the buffer
2356 if (m->mode & 0x01) {
2357 commandbuf[3] = m->mode | 0x80; // yes, write the page to flash
2358
2359 if (m->op[AVR_OP_LOADPAGE_LO] == NULL) {
2360 avrdude_message(MSG_INFO, "%s: stk500v2_paged_write: loadpage instruction not defined for part \"%s\"\n",
2361 progname, p->desc);
2362 return -1;
2363 }
2365 commandbuf[5] = cmds[0];
2366
2367 if (m->op[AVR_OP_WRITEPAGE] == NULL) {
2368 avrdude_message(MSG_INFO, "%s: stk500v2_paged_write: write page instruction not defined for part \"%s\"\n",
2369 progname, p->desc);
2370 return -1;
2371 }
2372 avr_set_bits(m->op[AVR_OP_WRITEPAGE], cmds);
2373 commandbuf[6] = cmds[0];
2374
2375 // otherwise, we need to load different commands in
2376 }
2377 else {
2378 commandbuf[3] = m->mode | 0x80; // yes, write the words to flash
2379
2380 if (wop == NULL) {
2381 avrdude_message(MSG_INFO, "%s: stk500v2_paged_write: write instruction not defined for part \"%s\"\n",
2382 progname, p->desc);
2383 return -1;
2384 }
2385 avr_set_bits(wop, cmds);
2386 commandbuf[5] = cmds[0];
2387 commandbuf[6] = 0;
2388 }
2389
2390 // the read command is common to both methods
2391 if (rop == NULL) {
2392 avrdude_message(MSG_INFO, "%s: stk500v2_paged_write: read instruction not defined for part \"%s\"\n",
2393 progname, p->desc);
2394 return -1;
2395 }
2396 avr_set_bits(rop, cmds);
2397 commandbuf[7] = cmds[0];
2398
2399 commandbuf[8] = m->readback[0];
2400 commandbuf[9] = m->readback[1];
2401
2402 last_addr=UINT_MAX; /* impossible address */
2403
2404 for (; addr < maxaddr; addr += prusa3d_semicolon_workaround_round2 ? 0 : page_size) {
2405 if ((maxaddr - addr) < page_size)
2406 block_size = maxaddr - addr;
2407 else
2408 block_size = page_size;
2409
2410 DEBUG("block_size at addr %d is %d\n",addr,block_size);
2411
2412 memcpy(buf,commandbuf,sizeof(commandbuf));
2413
2414 buf[1] = block_size >> 8;
2415 buf[2] = block_size & 0xff;
2416
2417 if((last_addr==UINT_MAX)||(last_addr+block_size != addr)||prusa3d_semicolon_workaround_round2){
2418 if (stk500v2_loadaddr(pgm, use_ext_addr | (addr >> addrshift)) < 0)
2419 return -1;
2420 }
2421 last_addr=addr;
2422
2423 if (prusa3d_semicolon_workaround_round2) {
2424 // printf("Round 2: address %d\r\n", addr);
2425 memcpy(buf+10, prusa3d_semicolon_workaround_round2_data, block_size);
2426 prusa3d_semicolon_workaround_round2 = false;
2427 } else {
2428 for (size_t i = 0; i < block_size; ++ i) {
2429 unsigned char b = m->buf[addr+i];
2430 if (b == ';') {
2431 // printf("semicolon at %d %d\r\n", addr, i);
2432 prusa3d_semicolon_workaround_round2_data[i] = b | 0x0f0;
2433 b |= 0x0f;
2434 prusa3d_semicolon_workaround_round2 = true;
2435 } else
2436 prusa3d_semicolon_workaround_round2_data[i] = 0x0ff;
2437 buf[i+10] = b;
2438 }
2439 }
2440
2441 result = stk500v2_command(pgm,buf,block_size+10, sizeof(buf));
2442 if (result < 0) {
2443 avrdude_message(MSG_INFO, "%s: stk500v2_paged_write: write command failed\n",
2444 progname);
2445 return -1;
2446 }
2447 }
2448
2449 return n_bytes;
2450}
unsigned char readback[2]
Definition libavrdude.h:296
@ AVR_OP_WRITE_LO
Definition libavrdude.h:150
@ AVR_OP_WRITEPAGE
Definition libavrdude.h:155
@ AVR_OP_LOADPAGE_LO
Definition libavrdude.h:152
int mode
Definition libavrdude.h:298
#define CMD_PROGRAM_FLASH_ISP
Definition stk500v2_private.h:35
#define CMD_PROGRAM_EEPROM_ISP
Definition stk500v2_private.h:37

References AVR_OP_LOAD_EXT_ADDR, AVR_OP_LOADPAGE_LO, AVR_OP_READ, AVR_OP_READ_LO, AVR_OP_WRITE, AVR_OP_WRITE_LO, AVR_OP_WRITEPAGE, avr_set_bits(), avrdude_message(), avrmem::buf, CMD_PROGRAM_EEPROM_ISP, CMD_PROGRAM_FLASH_ISP, DEBUG, avrmem::delay, avrpart::desc, avrmem::desc, avrmem::mode, MSG_INFO, avrmem::op, pgm, progname, avrmem::readback, stk500v2_command(), and stk500v2_loadaddr().

Referenced by stk500isp_write_byte(), stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500v2_perform_osccal()

static int stk500v2_perform_osccal ( PROGRAMMER pgm)
static
3427{
3428 unsigned char buf[32];
3429 int rv;
3430
3431 buf[0] = CMD_OSCCAL;
3432
3433 rv = stk500v2_command(pgm, buf, 1, sizeof(buf));
3434 if (rv < 0) {
3435 avrdude_message(MSG_INFO, "%s: stk500v2_perform_osccal(): failed\n",
3436 progname);
3437 return -1;
3438 }
3439
3440 return 0;
3441}
#define CMD_OSCCAL
Definition stk500v2_private.h:23

References avrdude_message(), CMD_OSCCAL, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), and stk600_initpgm().

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

◆ stk500v2_print_parms()

static void stk500v2_print_parms ( PROGRAMMER pgm)
static
3422{
3424}

References pgm, and stk500v2_print_parms1().

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_isp_initpgm(), stk500v2_dragon_pp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

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

◆ stk500v2_print_parms1()

static void stk500v2_print_parms1 ( PROGRAMMER pgm,
const char *  p 
)
static
3304{
3305 unsigned char vtarget = 0;
3306 unsigned char vadjust = 0;
3307 unsigned char sck_duration = 0;
3308 unsigned char osc_pscale = 0;
3309 unsigned char osc_cmatch = 0;
3310 unsigned varef = 0;
3311 unsigned sck_stk600 = 0;
3312 unsigned clock_conf = 0;
3313 unsigned dac, oct;
3314 // unsigned char vtarget_jtag[4];
3315 int prescale;
3316 double f;
3317 const char *unit;
3318 // void *mycookie;
3319
3320 if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE_MKII) {
3321 return;
3322 // mycookie = pgm->cookie;
3323 // pgm->cookie = PDATA(pgm)->chained_pdata;
3324 // jtagmkII_getparm(pgm, PAR_OCD_VTARGET, vtarget_jtag);
3325 // pgm->cookie = mycookie;
3326 // avrdude_message(MSG_INFO, "%sVtarget : %.1f V\n", p,
3327 // b2_to_u16(vtarget_jtag) / 1000.0);
3328 } else if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE3) {
3329 return;
3330 // mycookie = pgm->cookie;
3331 // pgm->cookie = PDATA(pgm)->chained_pdata;
3332 // jtag3_getparm(pgm, SCOPE_GENERAL, 1, PARM3_VTARGET, vtarget_jtag, 2);
3333 // pgm->cookie = mycookie;
3334 // avrdude_message(MSG_INFO, "%sVtarget : %.1f V\n", p,
3335 // b2_to_u16(vtarget_jtag) / 1000.0);
3336
3337 } else {
3339 avrdude_message(MSG_INFO, "%sVtarget : %.1f V\n", p, vtarget / 10.0);
3340 }
3341
3342 switch (PDATA(pgm)->pgmtype) {
3343 case PGMTYPE_STK500:
3344 stk500v2_getparm(pgm, PARAM_SCK_DURATION, &sck_duration);
3346 stk500v2_getparm(pgm, PARAM_OSC_PSCALE, &osc_pscale);
3347 stk500v2_getparm(pgm, PARAM_OSC_CMATCH, &osc_cmatch);
3348 avrdude_message(MSG_INFO, "%sSCK period : %.1f us\n", p,
3349 stk500v2_sck_to_us(pgm, sck_duration));
3350 avrdude_message(MSG_INFO, "%sVaref : %.1f V\n", p, vadjust / 10.0);
3351 avrdude_message(MSG_INFO, "%sOscillator : ", p);
3352 if (osc_pscale == 0)
3353 avrdude_message(MSG_INFO, "Off\n");
3354 else {
3355 prescale = 1;
3356 f = STK500V2_XTAL / 2;
3357
3358 switch (osc_pscale) {
3359 case 2: prescale = 8; break;
3360 case 3: prescale = 32; break;
3361 case 4: prescale = 64; break;
3362 case 5: prescale = 128; break;
3363 case 6: prescale = 256; break;
3364 case 7: prescale = 1024; break;
3365 }
3366 f /= prescale;
3367 f /= (osc_cmatch + 1);
3368 f = f_to_kHz_MHz(f, &unit);
3369 avrdude_message(MSG_INFO, "%.3f %s\n", f, unit);
3370 }
3371 break;
3372
3373 case PGMTYPE_AVRISP_MKII:
3374 case PGMTYPE_JTAGICE_MKII:
3375 stk500v2_getparm(pgm, PARAM_SCK_DURATION, &sck_duration);
3376 avrdude_message(MSG_INFO, "%sSCK period : %.2f us\n", p,
3377 (float) 1000000 / avrispmkIIfreqs[sck_duration]);
3378 break;
3379
3380 case PGMTYPE_JTAGICE3:
3381 {
3382 unsigned char cmd[4];
3383
3384 cmd[0] = CMD_GET_SCK;
3385 if (stk500v2_jtag3_send(pgm, cmd, 1) >= 0 &&
3386 stk500v2_jtag3_recv(pgm, cmd, 4) >= 2) {
3387 unsigned int sck = cmd[1] | (cmd[2] << 8);
3388 avrdude_message(MSG_INFO, "%sSCK period : %.2f us\n", p,
3389 (float)(1E6 / (1000.0 * sck)));
3390 }
3391 }
3392 break;
3393
3394 case PGMTYPE_STK600:
3396 avrdude_message(MSG_INFO, "%sVaref 0 : %.2f V\n", p, varef / 100.0);
3398 avrdude_message(MSG_INFO, "%sVaref 1 : %.2f V\n", p, varef / 100.0);
3400 avrdude_message(MSG_INFO, "%sSCK period : %.2f us\n", p,
3401 (float) (sck_stk600 + 1) / 8.0);
3403 oct = (clock_conf & 0xf000) >> 12u;
3404 dac = (clock_conf & 0x0ffc) >> 2u;
3405 f = pow(2, (double)oct) * 2078.0 / (2 - (double)dac / 1024.0);
3406 f = f_to_kHz_MHz(f, &unit);
3407 avrdude_message(MSG_INFO, "%sOscillator : %.3f %s\n",
3408 p, f, unit);
3409 break;
3410
3411 default:
3412 avrdude_message(MSG_INFO, "%sSCK period : %.1f us\n", p,
3413 sck_duration * 8.0e6 / STK500V2_XTAL + 0.05);
3414 break;
3415 }
3416
3417 return;
3418}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
Definition Half.h:477
static double f_to_kHz_MHz(double f, const char **unit)
Definition stk500v2.c:3289
static double stk500v2_sck_to_us(PROGRAMMER *pgm, unsigned char dur)
Definition stk500v2.c:2956
static double avrispmkIIfreqs[]
Definition stk500v2.c:2863
#define STK500V2_XTAL
Definition stk500v2.c:76
#define PARAM_OSC_CMATCH
Definition stk500v2_private.h:182
#define CMD_GET_SCK
Definition stk500v2_private.h:47
#define PARAM2_AREF0
Definition stk500v2_private.h:213
#define PARAM_VADJUST
Definition stk500v2_private.h:180
#define PARAM_VTARGET
Definition stk500v2_private.h:179
#define PARAM2_SCK_DURATION
Definition stk500v2_private.h:211
#define PARAM_SCK_DURATION
Definition stk500v2_private.h:183
#define PARAM2_CLOCK_CONF
Definition stk500v2_private.h:212
#define PARAM_OSC_PSCALE
Definition stk500v2_private.h:181
#define PARAM2_AREF1
Definition stk500v2_private.h:214

References avrdude_message(), avrispmkIIfreqs, cmd, CMD_GET_SCK, f_to_kHz_MHz(), MSG_INFO, PARAM2_AREF0, PARAM2_AREF1, PARAM2_CLOCK_CONF, PARAM2_SCK_DURATION, PARAM_OSC_CMATCH, PARAM_OSC_PSCALE, PARAM_SCK_DURATION, PARAM_VADJUST, PARAM_VTARGET, PDATA, pgm, stk500v2_getparm(), stk500v2_getparm2(), stk500v2_jtag3_recv(), stk500v2_jtag3_send(), stk500v2_sck_to_us(), and STK500V2_XTAL.

Referenced by stk500v2_display(), and stk500v2_print_parms().

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

◆ stk500v2_program_enable()

static int stk500v2_program_enable ( PROGRAMMER pgm,
AVRPART p 
)
static
1128{
1129 unsigned char buf[16];
1130 char msg[100]; /* see remarks above about size needed */
1131 int rv;
1132 // int tries;
1133
1134 PDATA(pgm)->lastpart = p;
1135
1136 if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
1137 avrdude_message(MSG_INFO, "%s: stk500v2_program_enable(): program enable instruction not defined for part \"%s\"\n",
1138 progname, p->desc);
1139 return -1;
1140 }
1141
1142 if (PDATA(pgm)->pgmtype == PGMTYPE_STK500 ||
1143 PDATA(pgm)->pgmtype == PGMTYPE_STK600)
1144 /* Activate AVR-style (low active) RESET */
1146
1147 // tries = 0;
1148// retry:
1149 buf[0] = CMD_ENTER_PROGMODE_ISP;
1150 buf[1] = p->timeout;
1151 buf[2] = p->stabdelay;
1152 buf[3] = p->cmdexedelay;
1153 buf[4] = p->synchloops;
1154 buf[5] = p->bytedelay;
1155 buf[6] = p->pollvalue;
1156 buf[7] = p->pollindex;
1157 avr_set_bits(p->op[AVR_OP_PGM_ENABLE], buf+8);
1158 buf[10] = buf[11] = 0;
1159
1160 rv = stk500v2_command(pgm, buf, 12, sizeof(buf));
1161
1162 if (rv < 0) {
1163 switch (PDATA(pgm)->pgmtype)
1164 {
1165 case PGMTYPE_STK600:
1166 case PGMTYPE_AVRISP_MKII:
1167 if (stk500v2_getparm(pgm, PARAM_STATUS_TGT_CONN, &buf[0]) != 0) {
1168 avrdude_message(MSG_INFO, "%s: stk500v2_program_enable(): cannot get connection status\n",
1169 progname);
1170 } else {
1171 stk500v2_translate_conn_status(buf[0], msg);
1172 avrdude_message(MSG_INFO, "%s: stk500v2_program_enable():"
1173 " bad AVRISPmkII connection status: %s\n",
1174 progname, msg);
1175 }
1176 break;
1177
1178 case PGMTYPE_JTAGICE3:
1179 return -1;
1180 // if (buf[1] == STATUS_CMD_FAILED &&
1181 // (p->flags & AVRPART_HAS_DW) != 0) {
1182 // void *mycookie;
1183 // unsigned char cmd[4], *resp;
1184
1185 // /* Try debugWIRE, and MONCON_DISABLE */
1186 // avrdude_message(MSG_NOTICE2, "%s: No response in ISP mode, trying debugWIRE\n",
1187 // progname);
1188
1189 // mycookie = pgm->cookie;
1190 // pgm->cookie = PDATA(pgm)->chained_pdata;
1191
1192 // cmd[0] = PARM3_CONN_DW;
1193 // if (jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CONNECTION, cmd, 1) < 0) {
1194 // pgm->cookie = mycookie;
1195 // break;
1196 // }
1197
1198 // cmd[0] = SCOPE_AVR;
1199
1200 // cmd[1] = CMD3_SIGN_ON;
1201 // cmd[2] = cmd[3] = 0;
1202 // if (jtag3_command(pgm, cmd, 4, &resp, "AVR sign-on") >= 0) {
1203 // free(resp);
1204
1205 // cmd[1] = CMD3_START_DW_DEBUG;
1206 // if (jtag3_command(pgm, cmd, 4, &resp, "start DW debug") >= 0) {
1207 // free(resp);
1208
1209 // cmd[1] = CMD3_MONCON_DISABLE;
1210 // if (jtag3_command(pgm, cmd, 3, &resp, "MonCon disable") >= 0)
1211 // free(resp);
1212 // }
1213 // }
1214 // pgm->cookie = mycookie;
1215 // if (tries++ > 3) {
1216 // avrdude_message(MSG_INFO, "%s: Failed to return from debugWIRE to ISP.\n",
1217 // progname);
1218 // break;
1219 // }
1220 // avrdude_message(MSG_INFO, "%s: Target prepared for ISP, signed off.\n"
1221 // "%s: Now retrying without power-cycling the target.\n",
1222 // progname, progname);
1223 // goto retry;
1224 // }
1225 break;
1226
1227 default:
1228 /* cannot report anything for other pgmtypes */
1229 break;
1230 }
1231 }
1232
1233 return rv;
1234}
int synchloops
Definition libavrdude.h:235
int stabdelay
Definition libavrdude.h:233
@ AVR_OP_PGM_ENABLE
Definition libavrdude.h:157
int pollindex
Definition libavrdude.h:237
unsigned char pollvalue
Definition libavrdude.h:238
int cmdexedelay
Definition libavrdude.h:234
int bytedelay
Definition libavrdude.h:236
int timeout
Definition libavrdude.h:232
static int stk500v2_setparm_real(PROGRAMMER *pgm, unsigned char parm, unsigned char value)
Definition stk500v2.c:3128
static void stk500v2_translate_conn_status(unsigned char status, char *msg)
Definition stk500v2.c:1099
#define PARAM_STATUS_TGT_CONN
Definition stk500v2_private.h:191
#define CMD_ENTER_PROGMODE_ISP
Definition stk500v2_private.h:32
#define PARAM_RESET_POLARITY
Definition stk500v2_private.h:187

References AVR_OP_PGM_ENABLE, avr_set_bits(), avrdude_message(), avrpart::bytedelay, CMD_ENTER_PROGMODE_ISP, avrpart::cmdexedelay, avrpart::desc, MSG_INFO, avrpart::op, PARAM_RESET_POLARITY, PARAM_STATUS_TGT_CONN, PDATA, pgm, avrpart::pollindex, avrpart::pollvalue, progname, avrpart::stabdelay, stk500v2_command(), stk500v2_getparm(), stk500v2_setparm_real(), stk500v2_translate_conn_status(), avrpart::synchloops, and avrpart::timeout.

Referenced by stk500v2_dragon_isp_initpgm(), stk500v2_initpgm(), stk500v2_jtag3_initpgm(), stk500v2_jtagmkII_initpgm(), stk600_initpgm(), and stk600_setup_isp().

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

◆ stk500v2_recv()

static int stk500v2_recv ( PROGRAMMER pgm,
unsigned char *  msg,
size_t  maxsize 
)
static
628 {
629 enum states { sINIT, sSTART, sSEQNUM, sSIZE1, sSIZE2, sTOKEN, sDATA, sCSUM, sDONE } state = sSTART;
630 unsigned int msglen = 0;
631 unsigned int curlen = 0;
632 int timeout = 0;
633 unsigned char c, checksum = 0;
634
635 /*
636 * The entire timeout handling here is not very consistent, see
637 *
638 * https://savannah.nongnu.org/bugs/index.php?43626
639 */
640 long timeoutval = SERIAL_TIMEOUT; // seconds
641 struct timeval tv;
642 double tstart, tnow;
643
644 if (PDATA(pgm)->pgmtype == PGMTYPE_AVRISP_MKII ||
645 PDATA(pgm)->pgmtype == PGMTYPE_STK600)
646 return stk500v2_recv_mk2(pgm, msg, maxsize);
647 else if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE_MKII)
648 return stk500v2_jtagmkII_recv(pgm, msg, maxsize);
649 else if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE3)
650 return stk500v2_jtag3_recv(pgm, msg, maxsize);
651
652 DEBUG("STK500V2: stk500v2_recv(): ");
653
654 gettimeofday(&tv, NULL);
655 tstart = tv.tv_sec;
656
657 while ( (state != sDONE ) && (!timeout) ) {
659 if (serial_recv(&pgm->fd, &c, 1) < 0)
660 goto timedout;
661 DEBUG("0x%02x ",c);
662 checksum ^= c;
663
664 switch (state) {
665 case sSTART:
666 DEBUGRECV("hoping for start token...");
667 if (c == MESSAGE_START) {
668 DEBUGRECV("got it\n");
669 checksum = MESSAGE_START;
670 state = sSEQNUM;
671 } else
672 DEBUGRECV("sorry\n");
673 break;
674 case sSEQNUM:
675 DEBUGRECV("hoping for sequence...\n");
676 if (c == PDATA(pgm)->command_sequence) {
677 DEBUGRECV("got it, incrementing\n");
678 state = sSIZE1;
679 PDATA(pgm)->command_sequence++;
680 } else {
681 DEBUGRECV("sorry\n");
682 state = sSTART;
683 }
684 break;
685 case sSIZE1:
686 DEBUGRECV("hoping for size LSB\n");
687 msglen = (unsigned)c * 256;
688 state = sSIZE2;
689 break;
690 case sSIZE2:
691 DEBUGRECV("hoping for size MSB...");
692 msglen += (unsigned)c;
693 DEBUG(" msg is %u bytes\n",msglen);
694 state = sTOKEN;
695 break;
696 case sTOKEN:
697 if (c == TOKEN) state = sDATA;
698 else state = sSTART;
699 break;
700 case sDATA:
701 if (curlen < maxsize) {
702 msg[curlen] = c;
703 } else {
704 avrdude_message(MSG_INFO, "%s: stk500v2_recv(): buffer too small, received %d byte into %u byte buffer\n",
705 progname,curlen,(unsigned int)maxsize);
706 return -2;
707 }
708 if ((curlen == 0) && (msg[0] == ANSWER_CKSUM_ERROR)) {
709 avrdude_message(MSG_INFO, "%s: stk500v2_recv(): previous packet sent with wrong checksum\n",
710 progname);
711 return -3;
712 }
713 curlen++;
714 if (curlen == msglen) state = sCSUM;
715 break;
716 case sCSUM:
717 if (checksum == 0) {
718 state = sDONE;
719 } else {
720 state = sSTART;
721 avrdude_message(MSG_INFO, "%s: stk500v2_recv(): checksum error\n",
722 progname);
723 return -4;
724 }
725 break;
726 default:
727 avrdude_message(MSG_INFO, "%s: stk500v2_recv(): unknown state\n",
728 progname);
729 return -5;
730 } /* switch */
731
732 gettimeofday(&tv, NULL);
733 tnow = tv.tv_sec;
734 if (tnow-tstart > timeoutval) { // wuff - signed/unsigned/overflow
735 timedout:
736 avrdude_message(MSG_INFO, "%s: stk500v2_recv(): timeout\n",
737 progname);
738 return -1;
739 }
740
741 } /* while */
742 DEBUG("\n");
743
744 return (int)(msglen+6);
745}
Definition config.h:42
#define MESSAGE_START
Definition jtagmkII_private.h:61
#define serial_recv
Definition libavrdude.h:578
static int stk500v2_recv_mk2(PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
Definition stk500v2.c:535
static int stk500v2_jtagmkII_recv(PROGRAMMER *pgm, unsigned char *msg, size_t maxsize)
Definition stk500v2.c:549
#define SERIAL_TIMEOUT
Definition stk500v2.c:79
#define DEBUGRECV(...)
Definition stk500v2.c:93
#define ANSWER_CKSUM_ERROR
Definition stk500v2_private.h:284
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition unistd.cpp:21

References ANSWER_CKSUM_ERROR, avrdude_message(), DEBUG, DEBUGRECV, programmer_t::fd, gettimeofday(), MESSAGE_START, MSG_INFO, PDATA, pgm, progname, RETURN_IF_CANCEL, serial_recv, SERIAL_TIMEOUT, stk500v2_jtag3_recv(), stk500v2_jtagmkII_recv(), and stk500v2_recv_mk2().

Referenced by stk500v2_command(), and stk500v2_getsync().

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

◆ stk500v2_recv_mk2()

static int stk500v2_recv_mk2 ( PROGRAMMER pgm,
unsigned char *  msg,
size_t  maxsize 
)
static
537{
538 int rv;
539
540 rv = serial_recv(&pgm->fd, msg, maxsize);
541 if (rv < 0) {
542 avrdude_message(MSG_INFO, "%s: stk500v2_recv_mk2: error in USB receive\n", progname);
543 return -1;
544 }
545
546 return rv;
547}

References avrdude_message(), programmer_t::fd, MSG_INFO, pgm, progname, and serial_recv.

Referenced by stk500v2_recv().

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

◆ stk500v2_sck_to_us()

static double stk500v2_sck_to_us ( PROGRAMMER pgm,
unsigned char  dur 
)
static
2957{
2958 double x;
2959
2960 if (dur == 0)
2961 return 0.5425;
2962 if (dur == 1)
2963 return 2.17;
2964 if (dur == 2)
2965 return 8.68;
2966 if (dur == 3)
2967 return 17.36;
2968
2969 x = (double)dur + 10.0 / 12.0;
2970 x = 1.0 / x;
2971 x /= 24.0;
2972 x *= (double)STK500V2_XTAL;
2973 return 1E6 / x;
2974}
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297

References STK500V2_XTAL.

Referenced by stk500v2_print_parms1().

+ Here is the caller graph for this function:

◆ stk500v2_send()

static int stk500v2_send ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
static
493{
494 unsigned char buf[275 + 6]; // max MESSAGE_BODY of 275 bytes, 6 bytes overhead
495 int i;
496
497 if (PDATA(pgm)->pgmtype == PGMTYPE_AVRISP_MKII ||
498 PDATA(pgm)->pgmtype == PGMTYPE_STK600)
499 return stk500v2_send_mk2(pgm, data, len);
500 else if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE_MKII)
501 return stk500v2_jtagmkII_send(pgm, data, len);
502 else if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE3)
503 return stk500v2_jtag3_send(pgm, data, len);
504
505 buf[0] = MESSAGE_START;
506 buf[1] = PDATA(pgm)->command_sequence;
507 buf[2] = (char)(len / 256);
508 buf[3] = len % 256;
509 buf[4] = TOKEN;
510 memcpy(buf+5, data, len);
511
512 // calculate the XOR checksum
513 buf[5+len] = 0;
514 for (i=0;i<5+len;i++)
515 buf[5+len] ^= buf[i];
516
517 DEBUG("STK500V2: stk500v2_send(");
518 for (i=0;i<len+6;i++) DEBUG("0x%02x ",buf[i]);
519 DEBUG(", %d)\n",len+6);
520
521 if (serial_send(&pgm->fd, buf, len+6) != 0) {
522 avrdude_message(MSG_INFO, "%s: stk500v2_send(): failed to send command to serial port\n",progname);
523 return -1;
524 }
525
526 return 0;
527}
#define TOKEN
Definition jtag3_private.h:91
#define serial_send
Definition libavrdude.h:577
static int stk500v2_send_mk2(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition stk500v2.c:392
static int stk500v2_jtagmkII_send(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition stk500v2.c:419

References avrdude_message(), DEBUG, programmer_t::fd, MESSAGE_START, MSG_INFO, PDATA, pgm, progname, serial_send, stk500v2_jtag3_send(), stk500v2_jtagmkII_send(), stk500v2_send_mk2(), and TOKEN.

Referenced by stk500v2_command(), and stk500v2_getsync().

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

◆ stk500v2_send_mk2()

static int stk500v2_send_mk2 ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
static
393{
394 if (serial_send(&pgm->fd, data, len) != 0) {
395 avrdude_message(MSG_INFO, "%s: stk500_send_mk2(): failed to send command to serial port\n",progname);
396 return -1;
397 }
398
399 return 0;
400}

References avrdude_message(), programmer_t::fd, MSG_INFO, pgm, progname, and serial_send.

Referenced by stk500v2_send().

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

◆ stk500v2_set_fosc()

static int stk500v2_set_fosc ( PROGRAMMER pgm,
double  v 
)
static
2813{
2814 int fosc;
2815 unsigned char prescale, cmatch;
2816 static unsigned ps[] = {
2817 1, 8, 32, 64, 128, 256, 1024
2818 };
2819 int idx, rc;
2820
2821 prescale = cmatch = 0;
2822 if (v > 0.0) {
2823 if (v > STK500V2_XTAL / 2) {
2824 const char *unit;
2825 if (v > 1e6) {
2826 v /= 1e6;
2827 unit = "MHz";
2828 } else if (v > 1e3) {
2829 v /= 1e3;
2830 unit = "kHz";
2831 } else
2832 unit = "Hz";
2833 avrdude_message(MSG_INFO, "%s: stk500v2_set_fosc(): f = %.3f %s too high, using %.3f MHz\n",
2834 progname, v, unit, STK500V2_XTAL / 2e6);
2835 fosc = STK500V2_XTAL / 2;
2836 } else
2837 fosc = (int)v;
2838
2839 for (idx = 0; idx < sizeof(ps) / sizeof(ps[0]); idx++) {
2840 if (fosc >= (int)(STK500V2_XTAL / (256 * ps[idx] * 2))) {
2841 /* this prescaler value can handle our frequency */
2842 prescale = idx + 1;
2843 cmatch = (unsigned)(STK500V2_XTAL / (2 * fosc * ps[idx])) - 1;
2844 break;
2845 }
2846 }
2847 if (idx == sizeof(ps) / sizeof(ps[0])) {
2848 avrdude_message(MSG_INFO, "%s: stk500v2_set_fosc(): f = %u Hz too low, %u Hz min\n",
2849 progname, fosc, STK500V2_XTAL / (256 * 1024 * 2));
2850 return -1;
2851 }
2852 }
2853
2854 if ((rc = stk500v2_setparm(pgm, PARAM_OSC_PSCALE, prescale)) != 0
2855 || (rc = stk500v2_setparm(pgm, PARAM_OSC_CMATCH, cmatch)) != 0)
2856 return rc;
2857
2858 return 0;
2859}
static int stk500v2_setparm(PROGRAMMER *pgm, unsigned char parm, unsigned char value)
Definition stk500v2.c:3145

References avrdude_message(), MSG_INFO, PARAM_OSC_CMATCH, PARAM_OSC_PSCALE, pgm, progname, stk500v2_setparm(), and STK500V2_XTAL.

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk500v2_initpgm().

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

◆ stk500v2_set_sck_period()

static int stk500v2_set_sck_period ( PROGRAMMER pgm,
double  v 
)
static
2934{
2935 unsigned int d;
2936 unsigned char dur;
2937 double f = 1 / v;
2938
2939 if (f >= 1.8432E6)
2940 d = 0;
2941 else if (f > 460.8E3)
2942 d = 1;
2943 else if (f > 115.2E3)
2944 d = 2;
2945 else if (f > 57.6E3)
2946 d = 3;
2947 else
2948 d = (unsigned int)ceil(1 / (24 * f / (double)STK500V2_XTAL) - 10.0 / 12.0);
2949 if (d >= 255)
2950 d = 254;
2951 dur = d;
2952
2954}
EIGEN_DEVICE_FUNC const CeilReturnType ceil() const
Definition ArrayCwiseUnaryOps.h:402

References ceil(), PARAM_SCK_DURATION, pgm, stk500v2_setparm(), and STK500V2_XTAL.

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), and stk500v2_initpgm().

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

◆ stk500v2_set_sck_period_mk2()

static int stk500v2_set_sck_period_mk2 ( PROGRAMMER pgm,
double  v 
)
static
2886{
2887 int i;
2888
2889 for (i = 0; i < sizeof(avrispmkIIfreqs); i++) {
2890 if (1 / avrispmkIIfreqs[i] >= v)
2891 break;
2892 }
2893
2894 avrdude_message(MSG_NOTICE2, "Using p = %.2f us for SCK (param = %d)\n",
2895 1000000 / avrispmkIIfreqs[i], i);
2896
2898}

References avrdude_message(), avrispmkIIfreqs, MSG_NOTICE2, PARAM_SCK_DURATION, pgm, and stk500v2_setparm().

Referenced by stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_isp_initpgm(), stk500v2_dragon_pp_initpgm(), stk500v2_jtagmkII_initpgm(), and stk500v2_open().

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

◆ stk500v2_set_upload_size()

void stk500v2_set_upload_size ( PROGRAMMER pgm,
int  size 
)
4809{
4810 unsigned char buf[16];
4812 buf[1] = size & 0xff;
4813 buf[2] = size >> 8;
4814 buf[3] = size >> 16;
4815 stk500v2_command(pgm, buf, 4, sizeof(buf));
4816}
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183
#define CMD_SET_UPLOAD_SIZE_PRUSA3D
Definition stk500v2_private.h:95

References CMD_SET_UPLOAD_SIZE_PRUSA3D, pgm, and stk500v2_command().

Referenced by stk500v2_initpgm().

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

◆ stk500v2_set_varef()

static int stk500v2_set_varef ( PROGRAMMER pgm,
unsigned int  chan,
double  v 
)
static
2791{
2792 unsigned char uaref, utarg;
2793
2794 uaref = (unsigned)((v + 0.049) * 10);
2795
2796 if (stk500v2_getparm(pgm, PARAM_VTARGET, &utarg) != 0) {
2797 avrdude_message(MSG_INFO, "%s: stk500v2_set_varef(): cannot obtain V[target]\n",
2798 progname);
2799 return -1;
2800 }
2801
2802 if (uaref > utarg) {
2803 avrdude_message(MSG_INFO, "%s: stk500v2_set_varef(): V[aref] must not be greater than "
2804 "V[target] = %.1f\n",
2805 progname, utarg / 10.0);
2806 return -1;
2807 }
2808 return stk500v2_setparm(pgm, PARAM_VADJUST, uaref);
2809}

References avrdude_message(), MSG_INFO, PARAM_VADJUST, PARAM_VTARGET, pgm, progname, stk500v2_getparm(), and stk500v2_setparm().

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk500v2_initpgm().

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

◆ stk500v2_set_vtarget()

static int stk500v2_set_vtarget ( PROGRAMMER pgm,
double  v 
)
static
2767{
2768 unsigned char uaref, utarg;
2769
2770 utarg = (unsigned)((v + 0.049) * 10);
2771
2772 if (stk500v2_getparm(pgm, PARAM_VADJUST, &uaref) != 0) {
2773 avrdude_message(MSG_INFO, "%s: stk500v2_set_vtarget(): cannot obtain V[aref]\n",
2774 progname);
2775 return -1;
2776 }
2777
2778 if (uaref > utarg) {
2779 avrdude_message(MSG_INFO, "%s: stk500v2_set_vtarget(): reducing V[aref] from %.1f to %.1f\n",
2780 progname, uaref / 10.0, v);
2782 != 0)
2783 return -1;
2784 }
2785 return stk500v2_setparm(pgm, PARAM_VTARGET, utarg);
2786}

References avrdude_message(), MSG_INFO, PARAM_VADJUST, PARAM_VTARGET, pgm, progname, stk500v2_getparm(), and stk500v2_setparm().

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_dragon_hvsp_initpgm(), stk500v2_dragon_pp_initpgm(), and stk500v2_initpgm().

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

◆ stk500v2_setparm()

static int stk500v2_setparm ( PROGRAMMER pgm,
unsigned char  parm,
unsigned char  value 
)
static
3146{
3147 unsigned char current_value = 0;
3148 int res;
3149
3150 res = stk500v2_getparm(pgm, parm, &current_value);
3151 if (res < 0)
3152 avrdude_message(MSG_INFO, "%s: Unable to get parameter 0x%02x\n", progname, parm);
3153
3154 // don't issue a write if the correct value is already set.
3155 if (value == current_value) {
3156 avrdude_message(MSG_NOTICE2, "%s: Skipping parameter write; parameter value already set.\n", progname);
3157 return 0;
3158 }
3159
3160 return stk500v2_setparm_real(pgm, parm, value);
3161}

References avrdude_message(), MSG_INFO, MSG_NOTICE2, pgm, progname, stk500v2_getparm(), and stk500v2_setparm_real().

Referenced by stk500v2_set_fosc(), stk500v2_set_sck_period(), stk500v2_set_sck_period_mk2(), stk500v2_set_varef(), stk500v2_set_vtarget(), and stk600_set_vtarget().

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

◆ stk500v2_setparm2()

static int stk500v2_setparm2 ( PROGRAMMER pgm,
unsigned char  parm,
unsigned int  value 
)
static
3182{
3183 unsigned char buf[32];
3184
3185 buf[0] = CMD_SET_PARAMETER;
3186 buf[1] = parm;
3187 buf[2] = value >> 8;
3188 buf[3] = value;
3189
3190 if (stk500v2_command(pgm, buf, 4, sizeof(buf)) < 0) {
3191 avrdude_message(MSG_INFO, "\n%s: stk500v2_setparm2(): failed to set parameter 0x%02x\n",
3192 progname, parm);
3193 return -1;
3194 }
3195
3196 return 0;
3197}
#define CMD_SET_PARAMETER
Definition stk500v2_private.h:20

References avrdude_message(), CMD_SET_PARAMETER, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk600_set_fosc(), stk600_set_sck_period(), stk600_set_varef(), and stk600_set_vtarget().

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

◆ stk500v2_setparm_real()

static int stk500v2_setparm_real ( PROGRAMMER pgm,
unsigned char  parm,
unsigned char  value 
)
static
3129{
3130 unsigned char buf[32];
3131
3132 buf[0] = CMD_SET_PARAMETER;
3133 buf[1] = parm;
3134 buf[2] = value;
3135
3136 if (stk500v2_command(pgm, buf, 3, sizeof(buf)) < 0) {
3137 avrdude_message(MSG_INFO, "\n%s: stk500v2_setparm(): failed to set parameter 0x%02x\n",
3138 progname, parm);
3139 return -1;
3140 }
3141
3142 return 0;
3143}

References avrdude_message(), CMD_SET_PARAMETER, MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk500v2_program_enable(), stk500v2_setparm(), and stk600_xprog_program_enable().

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

◆ stk500v2_setup()

void stk500v2_setup ( PROGRAMMER pgm)
296{
297 if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
298 // avrdude_message(MSG_INFO, "%s: stk500v2_setup(): Out of memory allocating private data\n",
299 // progname);
300 // exit(1);
301 avrdude_oom("stk500v2_setup(): Out of memory allocating private data\n");
302 }
303 memset(pgm->cookie, 0, sizeof(struct pdata));
304 PDATA(pgm)->command_sequence = 1;
305 PDATA(pgm)->boot_start = ULONG_MAX;
306}
void avrdude_oom(const char *context)
Definition main.c:169
Definition avr910.c:50
void * cookie
Definition libavrdude.h:689

References avrdude_oom(), programmer_t::cookie, malloc(), PDATA, and pgm.

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_initpgm(), stk600_initpgm(), stk600hvsp_initpgm(), stk600pp_initpgm(), and wiring_setup().

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

◆ stk500v2_teardown()

void stk500v2_teardown ( PROGRAMMER pgm)
355{
356 free(pgm->cookie);
357}

References programmer_t::cookie, free(), and pgm.

Referenced by stk500hvsp_initpgm(), stk500pp_initpgm(), stk500v2_initpgm(), stk600_initpgm(), stk600hvsp_initpgm(), stk600pp_initpgm(), and wiring_teardown().

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

◆ stk500v2_translate_conn_status()

static void stk500v2_translate_conn_status ( unsigned char  status,
char *  msg 
)
static
1100{
1101 size_t i;
1102 int need_comma;
1103
1104 *msg = 0;
1105 need_comma = 0;
1106
1107 for (i = 0;
1108 i < sizeof connection_status / sizeof connection_status[0];
1109 i++)
1110 {
1111 if ((status & connection_status[i].state) != 0)
1112 {
1113 if (need_comma)
1114 strcat(msg, ", ");
1115 strcat(msg, connection_status[i].description);
1116 need_comma = 1;
1117 }
1118 }
1119 if (*msg == 0)
1120 sprintf(msg, "Unknown status 0x%02x", status);
1121}
static struct @18 connection_status[]

References connection_status.

Referenced by stk500v2_program_enable().

+ Here is the caller graph for this function:

◆ stk600_get_cardname()

static const char * stk600_get_cardname ( const struct carddata table,
size_t  nele,
int  id 
)
static
3201{
3202 const struct carddata *cdp;
3203
3204 if (id == 0xFF)
3205 /* 0xFF means this card is not present at all. */
3206 return "Not present";
3207
3208 for (cdp = table; nele > 0; cdp++, nele--)
3209 if (cdp->id == id)
3210 return cdp->name;
3211
3212 return "Unknown";
3213}
const char * name
Definition stk500v2.c:111
int id
Definition stk500v2.c:110
Definition stk500v2.c:109

References carddata::id, and carddata::name.

Referenced by stk500v2_display().

+ Here is the caller graph for this function:

◆ stk600_initpgm()

void stk600_initpgm ( PROGRAMMER pgm)
4668{
4669 strcpy(pgm->type, "STK600");
4670
4671 /*
4672 * mandatory functions
4673 */
4680 pgm->cmd = stk500v2_cmd;
4681 pgm->open = stk600_open;
4685
4686 /*
4687 * optional functions
4688 */
4700 pgm->page_size = 256;
4701}
static int stk600_set_fosc(PROGRAMMER *pgm, double v)
Definition stk500v2.c:3065
static int stk600_set_vtarget(PROGRAMMER *pgm, double v)
Definition stk500v2.c:2977
static int stk600_set_varef(PROGRAMMER *pgm, unsigned int chan, double v)
Definition stk500v2.c:3029
static int stk600_open(PROGRAMMER *pgm, char *port)
Definition stk500v2.c:1709
static int stk600_set_sck_period(PROGRAMMER *pgm, double v)
Definition stk500v2.c:3075

References programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_erase, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, programmer_t::perform_osccal, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_chip_erase(), stk500v2_close(), stk500v2_cmd(), stk500v2_disable(), stk500v2_display(), stk500v2_enable(), stk500v2_initialize(), stk500v2_page_erase(), stk500v2_paged_load(), stk500v2_paged_write(), stk500v2_perform_osccal(), stk500v2_print_parms(), stk500v2_program_enable(), stk500v2_setup(), stk500v2_teardown(), stk600_open(), stk600_set_fosc(), stk600_set_sck_period(), stk600_set_varef(), stk600_set_vtarget(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk600_open()

static int stk600_open ( PROGRAMMER pgm,
char *  port 
)
static
1710{
1711 union pinfo pinfo = { .baud = 115200 };
1712
1713 DEBUG("STK500V2: stk600_open()\n");
1714
1715 if (pgm->baudrate)
1717
1718 PDATA(pgm)->pgmtype = PGMTYPE_UNKNOWN;
1719
1720 /*
1721 * If the port name starts with "usb", divert the serial routines
1722 * to the USB ones. The serial_open() function for USB overrides
1723 * the meaning of the "baud" parameter to be the USB device ID to
1724 * search for.
1725 */
1726 if (strncmp(port, "usb", 3) == 0) {
1727#if defined(HAVE_LIBUSB)
1730 pinfo.usbinfo.flags = 0;
1732 PDATA(pgm)->pgmtype = PGMTYPE_STK600;
1734 pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
1737 pgm->fd.usb.eep = 0; /* no seperate EP for events */
1738#else
1739 avrdude_message(MSG_INFO, "avrdude was compiled without usb support.\n");
1740 return -1;
1741#endif
1742 }
1743
1744 strcpy(pgm->port, port);
1745 if (serial_open(port, pinfo, &pgm->fd)==-1) {
1746 return -1;
1747 }
1748
1749 /*
1750 * drain any extraneous input
1751 */
1752 stk500v2_drain(pgm, 0);
1753
1755
1756 stk500v2_drain(pgm, 0);
1757
1758 if (pgm->bitclock != 0.0) {
1759 if (pgm->set_sck_period(pgm, pgm->bitclock) != 0) {
1760 serial_close(&pgm->fd);
1761 return -1;
1762 }
1763 }
1764
1765 return 0;
1766}
#define USBDEV_BULK_EP_READ_STK600
Definition usbdevs.h:66
#define USB_DEVICE_STK600
Definition usbdevs.h:31
#define USBDEV_BULK_EP_WRITE_STK600
Definition usbdevs.h:65

References avrdude_message(), pinfo::baud, programmer_t::baudrate, programmer_t::bitclock, DEBUG, programmer_t::fd, MSG_INFO, PDATA, pgm, programmer_t::port, serdev, serial_close, serial_open, programmer_t::set_sck_period, stk500v2_drain(), stk500v2_getsync(), stk600_set_sck_period(), filedescriptor::usb, USB_DEVICE_STK600, usb_serdev_frame, USB_VENDOR_ATMEL, USBDEV_BULK_EP_READ_STK600, USBDEV_BULK_EP_WRITE_STK600, USBDEV_MAX_XFER_MKII, and pinfo::usbinfo.

Referenced by stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

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

◆ stk600_set_fosc()

static int stk600_set_fosc ( PROGRAMMER pgm,
double  v 
)
static
3066{
3067 unsigned int oct, dac;
3068
3069 oct = (unsigned)(1.443 * log(v / 1039.0));
3070 dac = (unsigned)(2048.0 - (2078.0 * pow(2, (double)(10 + oct))) / v);
3071
3072 return stk500v2_setparm2(pgm, PARAM2_CLOCK_CONF, (oct << 12) | (dac << 2));
3073}
EIGEN_DEVICE_FUNC const LogReturnType log() const
Definition ArrayCwiseUnaryOps.h:105
static int stk500v2_setparm2(PROGRAMMER *pgm, unsigned char parm, unsigned int value)
Definition stk500v2.c:3181

References log(), PARAM2_CLOCK_CONF, pgm, and stk500v2_setparm2().

Referenced by stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

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

◆ stk600_set_sck_period()

static int stk600_set_sck_period ( PROGRAMMER pgm,
double  v 
)
static
3076{
3077 unsigned int sck;
3078
3079 sck = (unsigned)ceil((16e6 / (2 * 1.0 / v)) - 1);
3080
3081 if (sck >= 4096)
3082 sck = 4095;
3083
3085}

References ceil(), PARAM2_SCK_DURATION, pgm, and stk500v2_setparm2().

Referenced by stk600_initpgm(), stk600_open(), stk600hvsp_initpgm(), and stk600pp_initpgm().

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

◆ stk600_set_varef()

static int stk600_set_varef ( PROGRAMMER pgm,
unsigned int  chan,
double  v 
)
static
3030{
3031 unsigned char utarg;
3032 unsigned int uaref;
3033
3034 uaref = (unsigned)((v + 0.0049) * 100);
3035
3036 if (stk500v2_getparm(pgm, PARAM_VTARGET, &utarg) != 0) {
3037 avrdude_message(MSG_INFO, "%s: stk500v2_set_varef(): cannot obtain V[target]\n",
3038 progname);
3039 return -1;
3040 }
3041
3042 if (uaref > (unsigned)utarg * 10) {
3043 avrdude_message(MSG_INFO, "%s: stk500v2_set_varef(): V[aref] must not be greater than "
3044 "V[target] = %.1f\n",
3045 progname, utarg / 10.0);
3046 return -1;
3047 }
3048
3049 switch (chan)
3050 {
3051 case 0:
3052 return stk500v2_setparm2(pgm, PARAM2_AREF0, uaref);
3053
3054 case 1:
3055 return stk500v2_setparm2(pgm, PARAM2_AREF1, uaref);
3056
3057 default:
3058 avrdude_message(MSG_INFO, "%s: stk500v2_set_varef(): invalid channel %d\n",
3059 progname, chan);
3060 return -1;
3061 }
3062}

References avrdude_message(), MSG_INFO, PARAM2_AREF0, PARAM2_AREF1, PARAM_VTARGET, pgm, progname, stk500v2_getparm(), and stk500v2_setparm2().

Referenced by stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

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

◆ stk600_set_vtarget()

static int stk600_set_vtarget ( PROGRAMMER pgm,
double  v 
)
static
2978{
2979 unsigned char utarg;
2980 unsigned int uaref;
2981 int rv;
2982
2983 utarg = (unsigned)((v + 0.049) * 10);
2984
2985 if (stk500v2_getparm2(pgm, PARAM2_AREF0, &uaref) != 0) {
2986 avrdude_message(MSG_INFO, "%s: stk500v2_set_vtarget(): cannot obtain V[aref][0]\n",
2987 progname);
2988 return -1;
2989 }
2990
2991 if (uaref > (unsigned)utarg * 10) {
2992 avrdude_message(MSG_INFO, "%s: stk500v2_set_vtarget(): reducing V[aref][0] from %.2f to %.1f\n",
2993 progname, uaref / 100.0, v);
2994 uaref = 10 * (unsigned)utarg;
2996 != 0)
2997 return -1;
2998 }
2999
3000 if (stk500v2_getparm2(pgm, PARAM2_AREF1, &uaref) != 0) {
3001 avrdude_message(MSG_INFO, "%s: stk500v2_set_vtarget(): cannot obtain V[aref][1]\n",
3002 progname);
3003 return -1;
3004 }
3005
3006 if (uaref > (unsigned)utarg * 10) {
3007 avrdude_message(MSG_INFO, "%s: stk500v2_set_vtarget(): reducing V[aref][1] from %.2f to %.1f\n",
3008 progname, uaref / 100.0, v);
3009 uaref = 10 * (unsigned)utarg;
3011 != 0)
3012 return -1;
3013 }
3014
3015 /*
3016 * Vtarget on the STK600 can only be adjusted while not being in
3017 * programming mode.
3018 */
3019 if (PDATA(pgm)->lastpart)
3020 pgm->disable(pgm);
3021 rv = stk500v2_setparm(pgm, PARAM_VTARGET, utarg);
3022 if (PDATA(pgm)->lastpart)
3023 pgm->program_enable(pgm, PDATA(pgm)->lastpart);
3024
3025 return rv;
3026}

References avrdude_message(), programmer_t::disable, MSG_INFO, PARAM2_AREF0, PARAM2_AREF1, PARAM_VTARGET, PDATA, pgm, progname, programmer_t::program_enable, stk500v2_getparm2(), stk500v2_setparm(), and stk500v2_setparm2().

Referenced by stk600_initpgm(), stk600hvsp_initpgm(), and stk600pp_initpgm().

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

◆ stk600_setup_isp()

static void stk600_setup_isp ( PROGRAMMER pgm)
static

References programmer_t::chip_erase, programmer_t::disable, programmer_t::page_erase, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::program_enable, programmer_t::read_byte, stk500isp_read_byte(), stk500isp_write_byte(), stk500v2_chip_erase(), stk500v2_disable(), stk500v2_page_erase(), stk500v2_paged_load(), stk500v2_paged_write(), stk500v2_program_enable(), and programmer_t::write_byte.

Referenced by stk500v2_initialize().

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

◆ stk600_setup_xprog()

static void stk600_setup_xprog ( PROGRAMMER pgm)
static
4389{
4398}
static int stk600_xprog_program_enable(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:3793
static int stk600_xprog_chip_erase(PROGRAMMER *pgm, AVRPART *p)
Definition stk500v2.c:4320
static int stk600_xprog_paged_write(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:4145
static int stk600_xprog_page_erase(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int addr)
Definition stk500v2.c:4349
static int stk600_xprog_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition stk500v2.c:3916
static int stk600_xprog_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition stk500v2.c:4045
static int stk600_xprog_read_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition stk500v2.c:3997
static void stk600_xprog_disable(PROGRAMMER *pgm)
Definition stk500v2.c:3905

References programmer_t::chip_erase, programmer_t::disable, programmer_t::page_erase, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::program_enable, programmer_t::read_byte, stk600_xprog_chip_erase(), stk600_xprog_disable(), stk600_xprog_page_erase(), stk600_xprog_paged_load(), stk600_xprog_paged_write(), stk600_xprog_program_enable(), stk600_xprog_read_byte(), stk600_xprog_write_byte(), and programmer_t::write_byte.

Referenced by stk500v2_initialize().

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

◆ stk600_xprog_chip_erase()

static int stk600_xprog_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
static
4321{
4322 unsigned char b[6];
4323 AVRMEM *mem;
4324 unsigned int addr = 0;
4325
4326 if (p->flags & AVRPART_HAS_TPI) {
4327 if ((mem = avr_locate_mem(p, "flash")) == NULL) {
4328 avrdude_message(MSG_INFO, "%s: stk600_xprog_chip_erase(): no FLASH definition found for TPI device\n",
4329 progname);
4330 return -1;
4331 }
4332 addr = mem->offset + 1;
4333 }
4334
4335 b[0] = XPRG_CMD_ERASE;
4336 b[1] = XPRG_ERASE_CHIP;
4337 b[2] = addr >> 24;
4338 b[3] = addr >> 16;
4339 b[4] = addr >> 8;
4340 b[5] = addr;
4341 if (stk600_xprog_command(pgm, b, 6, 2) < 0) {
4342 avrdude_message(MSG_INFO, "%s: stk600_xprog_chip_erase(): XPRG_CMD_ERASE(XPRG_ERASE_CHIP) failed\n",
4343 progname);
4344 return -1;
4345 }
4346 return 0;
4347}
static int stk600_xprog_command(PROGRAMMER *pgm, unsigned char *b, unsigned int cmdsize, unsigned int responsesize)
Definition stk500v2.c:3759
#define XPRG_ERASE_CHIP
Definition stk500v2_private.h:247
#define XPRG_CMD_ERASE
Definition stk500v2_private.h:231

References avr_locate_mem(), avrdude_message(), AVRPART_HAS_TPI, avrpart::flags, MSG_INFO, avrmem::offset, pgm, progname, stk600_xprog_command(), XPRG_CMD_ERASE, and XPRG_ERASE_CHIP.

Referenced by stk600_setup_xprog().

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

◆ stk600_xprog_command()

static int stk600_xprog_command ( PROGRAMMER pgm,
unsigned char *  b,
unsigned int  cmdsize,
unsigned int  responsesize 
)
static
3761{
3762 unsigned char *newb;
3763 unsigned int s;
3764 int rv;
3765
3766 if (cmdsize < responsesize)
3767 s = responsesize;
3768 else
3769 s = cmdsize;
3770
3771 if ((newb = malloc(s + 1)) == 0) {
3772 avrdude_message(MSG_INFO, "%s: stk600_xprog_cmd(): out of memory\n",
3773 progname);
3774 return -1;
3775 }
3776
3777 newb[0] = CMD_XPROG;
3778 memcpy(newb + 1, b, cmdsize);
3779 rv = stk500v2_command(pgm, newb, cmdsize + 1, responsesize + 1);
3780 if (rv == 0) {
3781 memcpy(b, newb + 1, responsesize);
3782 }
3783
3784 free(newb);
3785
3786 return rv;
3787}

References avrdude_message(), CMD_XPROG, free(), malloc(), MSG_INFO, pgm, progname, and stk500v2_command().

Referenced by stk600_xprog_chip_erase(), stk600_xprog_disable(), stk600_xprog_page_erase(), stk600_xprog_paged_load(), stk600_xprog_paged_write(), stk600_xprog_program_enable(), stk600_xprog_read_byte(), and stk600_xprog_write_byte().

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

◆ stk600_xprog_disable()

static void stk600_xprog_disable ( PROGRAMMER pgm)
static
3906{
3907 unsigned char buf[2];
3908
3909 buf[0] = XPRG_CMD_LEAVE_PROGMODE;
3910 if (stk600_xprog_command(pgm, buf, 1, 2) < 0) {
3911 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_disable(): XPRG_CMD_LEAVE_PROGMODE failed\n",
3912 progname);
3913 }
3914}
#define XPRG_CMD_LEAVE_PROGMODE
Definition stk500v2_private.h:230

References avrdude_message(), MSG_INFO, pgm, progname, stk600_xprog_command(), and XPRG_CMD_LEAVE_PROGMODE.

Referenced by stk600_setup_xprog().

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

◆ stk600_xprog_memtype()

static unsigned char stk600_xprog_memtype ( PROGRAMMER pgm,
unsigned long  addr 
)
static
3897{
3898 if (addr >= PDATA(pgm)->boot_start)
3899 return XPRG_MEM_TYPE_BOOT;
3900 else
3901 return XPRG_MEM_TYPE_APPL;
3902}
#define XPRG_MEM_TYPE_APPL
Definition stk500v2_private.h:238
#define XPRG_MEM_TYPE_BOOT
Definition stk500v2_private.h:239

References PDATA, pgm, XPRG_MEM_TYPE_APPL, and XPRG_MEM_TYPE_BOOT.

Referenced by stk600_xprog_page_erase(), stk600_xprog_paged_load(), stk600_xprog_paged_write(), stk600_xprog_read_byte(), and stk600_xprog_write_byte().

+ Here is the caller graph for this function:

◆ stk600_xprog_page_erase()

static int stk600_xprog_page_erase ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  addr 
)
static
4351{
4352 unsigned char b[6];
4353
4354 if (strcmp(m->desc, "flash") == 0) {
4357 } else if (strcmp(m->desc, "application") == 0 ||
4358 strcmp(m->desc, "apptable") == 0) {
4360 } else if (strcmp(m->desc, "boot") == 0) {
4362 } else if (strcmp(m->desc, "eeprom") == 0) {
4364 } else if (strcmp(m->desc, "usersig") == 0) {
4365 b[1] = XPRG_ERASE_USERSIG;
4366 } else {
4367 avrdude_message(MSG_INFO, "%s: stk600_xprog_page_erase(): unknown paged memory \"%s\"\n",
4368 progname, m->desc);
4369 return -1;
4370 }
4371 addr += m->offset;
4372 b[0] = XPRG_CMD_ERASE;
4373 b[2] = addr >> 24;
4374 b[3] = addr >> 16;
4375 b[4] = addr >> 8;
4376 b[5] = addr;
4377 if (stk600_xprog_command(pgm, b, 6, 2) < 0) {
4378 avrdude_message(MSG_INFO, "%s: stk600_xprog_page_erase(): XPRG_CMD_ERASE(%d) failed\n",
4379 progname, b[1]);
4380 return -1;
4381 }
4382 return 0;
4383}
static unsigned char stk600_xprog_memtype(PROGRAMMER *pgm, unsigned long addr)
Definition stk500v2.c:3896
#define XPRG_ERASE_BOOT_PAGE
Definition stk500v2_private.h:252
#define XPRG_ERASE_EEPROM_PAGE
Definition stk500v2_private.h:253
#define XPRG_ERASE_APP_PAGE
Definition stk500v2_private.h:251
#define XPRG_ERASE_USERSIG
Definition stk500v2_private.h:254

References avrdude_message(), avrmem::desc, MSG_INFO, avrmem::offset, pgm, progname, stk600_xprog_command(), stk600_xprog_memtype(), XPRG_CMD_ERASE, XPRG_ERASE_APP_PAGE, XPRG_ERASE_BOOT_PAGE, XPRG_ERASE_EEPROM_PAGE, XPRG_ERASE_USERSIG, and XPRG_MEM_TYPE_APPL.

Referenced by stk600_setup_xprog().

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

◆ stk600_xprog_paged_load()

static int stk600_xprog_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
4048{
4049 unsigned char *b;
4050 unsigned int offset;
4051 unsigned char memtype;
4052 int n_bytes_orig = n_bytes, dynamic_memtype = 0;
4053 unsigned long use_ext_addr = 0;
4054
4055 /*
4056 * The XPROG read command supports at most 256 bytes in one
4057 * transfer.
4058 */
4059 if (page_size > 256)
4060 page_size = 256; /* not really a page size anymore */
4061
4062 /*
4063 * Fancy offsets everywhere.
4064 * This is probably what AVR079 means when writing about the
4065 * "TIF address space".
4066 */
4067 if (strcmp(mem->desc, "flash") == 0) {
4068 memtype = 0;
4069 dynamic_memtype = 1;
4070 if (mem->size > 64 * 1024)
4071 use_ext_addr = (1UL << 31);
4072 } else if (strcmp(mem->desc, "application") == 0 ||
4073 strcmp(mem->desc, "apptable") == 0) {
4074 memtype = XPRG_MEM_TYPE_APPL;
4075 if (mem->size > 64 * 1024)
4076 use_ext_addr = (1UL << 31);
4077 } else if (strcmp(mem->desc, "boot") == 0) {
4078 memtype = XPRG_MEM_TYPE_BOOT;
4079 // Do we have to consider the total amount of flash
4080 // instead to decide whether to use extended addressing?
4081 if (mem->size > 64 * 1024)
4082 use_ext_addr = (1UL << 31);
4083 } else if (strcmp(mem->desc, "eeprom") == 0) {
4084 memtype = XPRG_MEM_TYPE_EEPROM;
4085 } else if (strcmp(mem->desc, "signature") == 0) {
4086 memtype = XPRG_MEM_TYPE_APPL;
4087 } else if (strncmp(mem->desc, "fuse", strlen("fuse")) == 0) {
4088 memtype = XPRG_MEM_TYPE_FUSE;
4089 } else if (strncmp(mem->desc, "lock", strlen("lock")) == 0) {
4090 memtype = XPRG_MEM_TYPE_LOCKBITS;
4091 } else if (strcmp(mem->desc, "calibration") == 0) {
4093 } else if (strcmp(mem->desc, "usersig") == 0) {
4094 memtype = XPRG_MEM_TYPE_USERSIG;
4095 } else {
4096 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_load(): unknown paged memory \"%s\"\n",
4097 progname, mem->desc);
4098 return -1;
4099 }
4100 offset = addr;
4101 addr += mem->offset;
4102
4103 if ((b = malloc(page_size + 2)) == NULL) {
4104 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_load(): out of memory\n",
4105 progname);
4106 return -1;
4107 }
4108
4109 if (stk500v2_loadaddr(pgm, use_ext_addr) < 0) {
4110 free(b);
4111 return -1;
4112 }
4113
4114 while (n_bytes != 0) {
4115 if (dynamic_memtype)
4116 memtype = stk600_xprog_memtype(pgm, addr - mem->offset);
4117
4118 b[0] = XPRG_CMD_READ_MEM;
4119 b[1] = memtype;
4120 b[2] = addr >> 24;
4121 b[3] = addr >> 16;
4122 b[4] = addr >> 8;
4123 b[5] = addr;
4124 b[6] = page_size >> 8;
4125 b[7] = page_size;
4126 if (stk600_xprog_command(pgm, b, 8, page_size + 2) < 0) {
4127 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_load(): XPRG_CMD_READ_MEM failed\n",
4128 progname);
4129 free(b);
4130 return -1;
4131 }
4132 memcpy(mem->buf + offset, b + 2, page_size);
4133 if (n_bytes < page_size) {
4134 n_bytes = page_size;
4135 }
4136 offset += page_size;
4137 addr += page_size;
4138 n_bytes -= page_size;
4139 }
4140 free(b);
4141
4142 return n_bytes_orig;
4143}
int size
Definition libavrdude.h:286
void offset(Slic3r::ExPolygon &sh, coord_t distance, const PolygonTag &)
Definition geometries.hpp:132
#define XPRG_MEM_TYPE_EEPROM
Definition stk500v2_private.h:240
#define XPRG_MEM_TYPE_USERSIG
Definition stk500v2_private.h:243
#define XPRG_MEM_TYPE_FUSE
Definition stk500v2_private.h:241
#define XPRG_MEM_TYPE_LOCKBITS
Definition stk500v2_private.h:242
#define XPRG_CMD_READ_MEM
Definition stk500v2_private.h:233
#define XPRG_MEM_TYPE_FACTORY_CALIBRATION
Definition stk500v2_private.h:244

References avrdude_message(), avrmem::buf, avrmem::desc, free(), malloc(), MSG_INFO, avrmem::offset, pgm, progname, avrmem::size, stk500v2_loadaddr(), stk600_xprog_command(), stk600_xprog_memtype(), XPRG_CMD_READ_MEM, XPRG_MEM_TYPE_APPL, XPRG_MEM_TYPE_BOOT, XPRG_MEM_TYPE_EEPROM, XPRG_MEM_TYPE_FACTORY_CALIBRATION, XPRG_MEM_TYPE_FUSE, XPRG_MEM_TYPE_LOCKBITS, and XPRG_MEM_TYPE_USERSIG.

Referenced by stk600_setup_xprog().

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

◆ stk600_xprog_paged_write()

static int stk600_xprog_paged_write ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
4148{
4149 unsigned char *b;
4150 unsigned int offset;
4151 unsigned char memtype;
4152 int n_bytes_orig = n_bytes, dynamic_memtype = 0;
4153 size_t writesize;
4154 unsigned long use_ext_addr = 0;
4155 unsigned char writemode;
4156
4157 /*
4158 * The XPROG read command supports at most 256 bytes in one
4159 * transfer.
4160 */
4161 if (page_size > 512) {
4162 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_write(): cannot handle page size > 512\n",
4163 progname);
4164 return -1;
4165 }
4166
4167 /*
4168 * Fancy offsets everywhere.
4169 * This is probably what AVR079 means when writing about the
4170 * "TIF address space".
4171 */
4172 if (strcmp(mem->desc, "flash") == 0) {
4173 memtype = 0;
4174 dynamic_memtype = 1;
4175 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4176 if (mem->size > 64 * 1024)
4177 use_ext_addr = (1UL << 31);
4178 } else if (strcmp(mem->desc, "application") == 0 ||
4179 strcmp(mem->desc, "apptable") == 0) {
4180 memtype = XPRG_MEM_TYPE_APPL;
4181 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4182 if (mem->size > 64 * 1024)
4183 use_ext_addr = (1UL << 31);
4184 } else if (strcmp(mem->desc, "boot") == 0) {
4185 memtype = XPRG_MEM_TYPE_BOOT;
4186 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4187 // Do we have to consider the total amount of flash
4188 // instead to decide whether to use extended addressing?
4189 if (mem->size > 64 * 1024)
4190 use_ext_addr = (1UL << 31);
4191 } else if (strcmp(mem->desc, "eeprom") == 0) {
4192 memtype = XPRG_MEM_TYPE_EEPROM;
4193 writemode = (1 << XPRG_MEM_WRITE_WRITE) | (1 << XPRG_MEM_WRITE_ERASE);
4194 } else if (strcmp(mem->desc, "signature") == 0) {
4195 memtype = XPRG_MEM_TYPE_APPL;
4196 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4197 } else if (strncmp(mem->desc, "fuse", strlen("fuse")) == 0) {
4198 memtype = XPRG_MEM_TYPE_FUSE;
4199 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4200 } else if (strncmp(mem->desc, "lock", strlen("lock")) == 0) {
4201 memtype = XPRG_MEM_TYPE_LOCKBITS;
4202 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4203 } else if (strcmp(mem->desc, "calibration") == 0) {
4205 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4206 } else if (strcmp(mem->desc, "usersig") == 0) {
4207 memtype = XPRG_MEM_TYPE_USERSIG;
4208 writemode = (1 << XPRG_MEM_WRITE_WRITE);
4209 } else {
4210 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_write(): unknown paged memory \"%s\"\n",
4211 progname, mem->desc);
4212 return -1;
4213 }
4214 offset = addr;
4215 addr += mem->offset;
4216
4217 if ((b = malloc(page_size + 9)) == NULL) {
4218 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_write(): out of memory\n",
4219 progname);
4220 return -1;
4221 }
4222
4223 if (stk500v2_loadaddr(pgm, use_ext_addr) < 0) {
4224 free(b);
4225 return -1;
4226 }
4227
4228 while (n_bytes != 0) {
4229
4230 if (dynamic_memtype)
4231 memtype = stk600_xprog_memtype(pgm, addr - mem->offset);
4232
4233 if (page_size > 256) {
4234 /*
4235 * AVR079 is not quite clear. While it suggests that
4236 * downloading up to 512 bytes (256 words) were OK, it
4237 * obviously isn't -- 512-byte pages on the ATxmega128A1
4238 * are getting corrupted when written as a single piece.
4239 * It writes random junk somewhere beyond byte 256.
4240 * Splitting it into 256 byte chunks, and only setting the
4241 * erase page / write page bits in the final chunk helps.
4242 */
4243 if (page_size % 256 != 0) {
4244 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_write(): page size not multiple of 256\n",
4245 progname);
4246 free(b);
4247 return -1;
4248 }
4249 unsigned int chunk;
4250 for (chunk = 0; chunk < page_size; chunk += 256) {
4251 if (n_bytes < 256) {
4252 memset(b + 9 + n_bytes, 0xff, 256 - n_bytes);
4253 writesize = n_bytes;
4254 } else {
4255 writesize = 256;
4256 }
4257 b[0] = XPRG_CMD_WRITE_MEM;
4258 b[1] = memtype;
4259 b[2] = writemode;
4260 b[3] = addr >> 24;
4261 b[4] = addr >> 16;
4262 b[5] = addr >> 8;
4263 b[6] = addr;
4264 b[7] = 1;
4265 b[8] = 0;
4266 memcpy(b + 9, mem->buf + offset, writesize);
4267 if (stk600_xprog_command(pgm, b, 256 + 9, 2) < 0) {
4268 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_write(): XPRG_CMD_WRITE_MEM failed\n",
4269 progname);
4270 free(b);
4271 return -1;
4272 }
4273 if (n_bytes < 256)
4274 n_bytes = 256;
4275
4276 offset += 256;
4277 addr += 256;
4278 n_bytes -= 256;
4279 }
4280 } else {
4281 if (n_bytes < page_size) {
4282 /*
4283 * This can easily happen if the input file was not a
4284 * multiple of the page size.
4285 */
4286 memset(b + 9 + n_bytes, 0xff, page_size - n_bytes);
4287 writesize = n_bytes;
4288 } else {
4289 writesize = page_size;
4290 }
4291 b[0] = XPRG_CMD_WRITE_MEM;
4292 b[1] = memtype;
4293 b[2] = writemode;
4294 b[3] = addr >> 24;
4295 b[4] = addr >> 16;
4296 b[5] = addr >> 8;
4297 b[6] = addr;
4298 b[7] = page_size >> 8;
4299 b[8] = page_size;
4300 memcpy(b + 9, mem->buf + offset, writesize);
4301 if (stk600_xprog_command(pgm, b, page_size + 9, 2) < 0) {
4302 avrdude_message(MSG_INFO, "%s: stk600_xprog_paged_write(): XPRG_CMD_WRITE_MEM failed\n",
4303 progname);
4304 free(b);
4305 return -1;
4306 }
4307 if (n_bytes < page_size)
4308 n_bytes = page_size;
4309
4310 offset += page_size;
4311 addr += page_size;
4312 n_bytes -= page_size;
4313 }
4314 }
4315 free(b);
4316
4317 return n_bytes_orig;
4318}
#define XPRG_MEM_WRITE_ERASE
Definition stk500v2_private.h:258
#define XPRG_CMD_WRITE_MEM
Definition stk500v2_private.h:232
#define XPRG_MEM_WRITE_WRITE
Definition stk500v2_private.h:259

References avrdude_message(), avrmem::buf, avrmem::desc, free(), malloc(), MSG_INFO, avrmem::offset, pgm, progname, avrmem::size, stk500v2_loadaddr(), stk600_xprog_command(), stk600_xprog_memtype(), XPRG_CMD_WRITE_MEM, XPRG_MEM_TYPE_APPL, XPRG_MEM_TYPE_BOOT, XPRG_MEM_TYPE_EEPROM, XPRG_MEM_TYPE_FACTORY_CALIBRATION, XPRG_MEM_TYPE_FUSE, XPRG_MEM_TYPE_LOCKBITS, XPRG_MEM_TYPE_USERSIG, XPRG_MEM_WRITE_ERASE, and XPRG_MEM_WRITE_WRITE.

Referenced by stk600_setup_xprog().

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

◆ stk600_xprog_program_enable()

static int stk600_xprog_program_enable ( PROGRAMMER pgm,
AVRPART p 
)
static
3794{
3795 unsigned char buf[16];
3796 unsigned int eepagesize = 42;
3797 unsigned int nvm_base;
3798 AVRMEM *mem = NULL;
3799 int use_tpi;
3800
3801 use_tpi = (p->flags & AVRPART_HAS_TPI) != 0;
3802
3803 if (!use_tpi) {
3804 if (p->nvm_base == 0) {
3805 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): no nvm_base parameter for PDI device\n",
3806 progname);
3807 return -1;
3808 }
3809 if ((mem = avr_locate_mem(p, "eeprom")) != NULL) {
3810 if (mem->page_size == 0) {
3811 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): no EEPROM page_size parameter for PDI device\n",
3812 progname);
3813 return -1;
3814 }
3815 eepagesize = mem->page_size;
3816 }
3817 }
3818
3819 buf[0] = CMD_XPROG_SETMODE;
3820 buf[1] = use_tpi? XPRG_MODE_TPI: XPRG_MODE_PDI;
3821 if (stk500v2_command(pgm, buf, 2, sizeof(buf)) < 0) {
3822 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): CMD_XPROG_SETMODE(XPRG_MODE_%s) failed\n",
3823 progname, use_tpi? "TPI": "PDI");
3824 return -1;
3825 }
3826
3827 buf[0] = XPRG_CMD_ENTER_PROGMODE;
3828 if (stk600_xprog_command(pgm, buf, 1, 2) < 0) {
3829 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): XPRG_CMD_ENTER_PROGMODE failed\n",
3830 progname);
3831 return -1;
3832 }
3833
3834 if (use_tpi) {
3835 /*
3836 * Whatever all that might mean, it matches what AVR Studio
3837 * does.
3838 */
3840 return -1;
3841
3842 buf[0] = XPRG_CMD_SET_PARAM;
3843 buf[1] = XPRG_PARAM_TPI_3;
3844 buf[2] = 51;
3845 if (stk600_xprog_command(pgm, buf, 3, 2) < 0) {
3846 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): XPRG_CMD_SET_PARAM(XPRG_PARAM_TPI_3) failed\n",
3847 progname);
3848 return -1;
3849 }
3850
3851 buf[0] = XPRG_CMD_SET_PARAM;
3852 buf[1] = XPRG_PARAM_TPI_4;
3853 buf[2] = 50;
3854 if (stk600_xprog_command(pgm, buf, 3, 2) < 0) {
3855 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): XPRG_CMD_SET_PARAM(XPRG_PARAM_TPI_4) failed\n",
3856 progname);
3857 return -1;
3858 }
3859 } else {
3860 buf[0] = XPRG_CMD_SET_PARAM;
3861 buf[1] = XPRG_PARAM_NVMBASE;
3862 nvm_base = p->nvm_base;
3863 /*
3864 * The 0x01000000 appears to be an indication to the programmer
3865 * that the respective address is located in IO (i.e., SRAM)
3866 * memory address space rather than flash. This is not documented
3867 * anywhere in AVR079 but matches what AVR Studio does.
3868 */
3869 nvm_base |= 0x01000000;
3870 buf[2] = nvm_base >> 24;
3871 buf[3] = nvm_base >> 16;
3872 buf[4] = nvm_base >> 8;
3873 buf[5] = nvm_base;
3874 if (stk600_xprog_command(pgm, buf, 6, 2) < 0) {
3875 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): XPRG_CMD_SET_PARAM(XPRG_PARAM_NVMBASE) failed\n",
3876 progname);
3877 return -1;
3878 }
3879
3880 if (mem != NULL) {
3881 buf[0] = XPRG_CMD_SET_PARAM;
3882 buf[1] = XPRG_PARAM_EEPPAGESIZE;
3883 buf[2] = eepagesize >> 8;
3884 buf[3] = eepagesize;
3885 if (stk600_xprog_command(pgm, buf, 4, 2) < 0) {
3886 avrdude_message(MSG_INFO, "%s: stk600_xprog_program_enable(): XPRG_CMD_SET_PARAM(XPRG_PARAM_EEPPAGESIZE) failed\n",
3887 progname);
3888 return -1;
3889 }
3890 }
3891 }
3892
3893 return 0;
3894}
unsigned int nvm_base
Definition libavrdude.h:272
#define XPRG_MODE_TPI
Definition stk500v2_private.h:226
#define XPRG_MODE_PDI
Definition stk500v2_private.h:224
#define XPRG_PARAM_TPI_3
Definition stk500v2_private.h:278
#define XPRG_PARAM_NVMBASE
Definition stk500v2_private.h:274
#define XPRG_CMD_SET_PARAM
Definition stk500v2_private.h:235
#define XPRG_PARAM_TPI_4
Definition stk500v2_private.h:280
#define PARAM_DISCHARGEDELAY
Definition stk500v2_private.h:192
#define XPRG_CMD_ENTER_PROGMODE
Definition stk500v2_private.h:229
#define XPRG_PARAM_EEPPAGESIZE
Definition stk500v2_private.h:276

References avr_locate_mem(), avrdude_message(), AVRPART_HAS_TPI, CMD_XPROG_SETMODE, avrpart::flags, MSG_INFO, avrpart::nvm_base, avrmem::page_size, PARAM_DISCHARGEDELAY, pgm, progname, stk500v2_command(), stk500v2_setparm_real(), stk600_xprog_command(), XPRG_CMD_ENTER_PROGMODE, XPRG_CMD_SET_PARAM, XPRG_MODE_PDI, XPRG_MODE_TPI, XPRG_PARAM_EEPPAGESIZE, XPRG_PARAM_NVMBASE, XPRG_PARAM_TPI_3, and XPRG_PARAM_TPI_4.

Referenced by stk600_setup_xprog().

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

◆ stk600_xprog_read_byte()

static int stk600_xprog_read_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
static
3999{
4000 unsigned char b[8];
4001
4002 if (strcmp(mem->desc, "flash") == 0) {
4003 b[1] = stk600_xprog_memtype(pgm, addr);
4004 } else if (strcmp(mem->desc, "application") == 0 ||
4005 strcmp(mem->desc, "apptable") == 0) {
4006 b[1] = XPRG_MEM_TYPE_APPL;
4007 } else if (strcmp(mem->desc, "boot") == 0) {
4008 b[1] = XPRG_MEM_TYPE_BOOT;
4009 } else if (strcmp(mem->desc, "eeprom") == 0) {
4011 } else if (strcmp(mem->desc, "signature") == 0) {
4012 b[1] = XPRG_MEM_TYPE_APPL;
4013 } else if (strncmp(mem->desc, "fuse", strlen("fuse")) == 0) {
4014 b[1] = XPRG_MEM_TYPE_FUSE;
4015 } else if (strncmp(mem->desc, "lock", strlen("lock")) == 0) {
4017 } else if (strcmp(mem->desc, "calibration") == 0) {
4019 } else if (strcmp(mem->desc, "usersig") == 0) {
4021 } else {
4022 avrdude_message(MSG_INFO, "%s: stk600_xprog_read_byte(): unknown memory \"%s\"\n",
4023 progname, mem->desc);
4024 return -1;
4025 }
4026 addr += mem->offset;
4027
4028 b[0] = XPRG_CMD_READ_MEM;
4029 b[2] = (char)(addr >> 24);
4030 b[3] = (char)(addr >> 16);
4031 b[4] = (char)(addr >> 8);
4032 b[5] = (char)addr;
4033 b[6] = 0;
4034 b[7] = 1;
4035 if (stk600_xprog_command(pgm, b, 8, 3) < 0) {
4036 avrdude_message(MSG_INFO, "%s: stk600_xprog_read_byte(): XPRG_CMD_READ_MEM failed\n",
4037 progname);
4038 return -1;
4039 }
4040 *value = b[2];
4041 return 0;
4042}

References avrdude_message(), avrmem::desc, MSG_INFO, avrmem::offset, pgm, progname, stk600_xprog_command(), stk600_xprog_memtype(), XPRG_CMD_READ_MEM, XPRG_MEM_TYPE_APPL, XPRG_MEM_TYPE_BOOT, XPRG_MEM_TYPE_EEPROM, XPRG_MEM_TYPE_FACTORY_CALIBRATION, XPRG_MEM_TYPE_FUSE, XPRG_MEM_TYPE_LOCKBITS, and XPRG_MEM_TYPE_USERSIG.

Referenced by stk600_setup_xprog().

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

◆ stk600_xprog_write_byte()

static int stk600_xprog_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
static
3918{
3919 unsigned char b[9 + 256];
3920 int need_erase = 0;
3921 unsigned char write_size = 1;
3922 unsigned char memcode;
3923
3924 memset(b, 0, sizeof(b));
3925
3926 if (strcmp(mem->desc, "flash") == 0) {
3927 memcode = stk600_xprog_memtype(pgm, addr);
3928 } else if (strcmp(mem->desc, "application") == 0 ||
3929 strcmp(mem->desc, "apptable") == 0) {
3930 memcode = XPRG_MEM_TYPE_APPL;
3931 } else if (strcmp(mem->desc, "boot") == 0) {
3932 memcode = XPRG_MEM_TYPE_BOOT;
3933 } else if (strcmp(mem->desc, "eeprom") == 0) {
3934 memcode = XPRG_MEM_TYPE_EEPROM;
3935 } else if (strncmp(mem->desc, "lock", strlen("lock")) == 0) {
3936 memcode = XPRG_MEM_TYPE_LOCKBITS;
3937 } else if (strncmp(mem->desc, "fuse", strlen("fuse")) == 0) {
3938 memcode = XPRG_MEM_TYPE_FUSE;
3939 if (p->flags & AVRPART_HAS_TPI)
3940 /*
3941 * TPI devices need a mystic erase prior to writing their
3942 * fuses.
3943 */
3944 need_erase = 1;
3945 } else if (strcmp(mem->desc, "usersig") == 0) {
3946 memcode = XPRG_MEM_TYPE_USERSIG;
3947 } else {
3948 avrdude_message(MSG_INFO, "%s: stk600_xprog_write_byte(): unknown memory \"%s\"\n",
3949 progname, mem->desc);
3950 return -1;
3951 }
3952 addr += mem->offset;
3953
3954 if (need_erase) {
3955 b[0] = XPRG_CMD_ERASE;
3956 b[1] = XPRG_ERASE_CONFIG;
3957 b[2] = mem->offset >> 24;
3958 b[3] = mem->offset >> 16;
3959 b[4] = mem->offset >> 8;
3960 b[5] = mem->offset + 1;
3961 if (stk600_xprog_command(pgm, b, 6, 2) < 0) {
3962 avrdude_message(MSG_INFO, "%s: stk600_xprog_chip_erase(): XPRG_CMD_ERASE(XPRG_ERASE_CONFIG) failed\n",
3963 progname);
3964 return -1;
3965 }
3966 }
3967
3968 if (p->flags & AVRPART_HAS_TPI) {
3969 /*
3970 * Some TPI memories (configuration aka. fuse) require a
3971 * larger write block size. We record that as a blocksize in
3972 * avrdude.conf.
3973 */
3974 if (mem->blocksize != 0)
3975 write_size = mem->blocksize;
3976 }
3977
3978 b[0] = XPRG_CMD_WRITE_MEM;
3979 b[1] = memcode;
3980 b[2] = 0; /* pagemode: non-paged write */
3981 b[3] = (char)(addr >> 24);
3982 b[4] = (char)(addr >> 16);
3983 b[5] = (char)(addr >> 8);
3984 b[6] = (char)addr;
3985 b[7] = 0;
3986 b[8] = write_size;
3987 b[9] = data;
3988 if (stk600_xprog_command(pgm, b, 9 + write_size, 2) < 0) {
3989 avrdude_message(MSG_INFO, "%s: stk600_xprog_write_byte(): XPRG_CMD_WRITE_MEM failed\n",
3990 progname);
3991 return -1;
3992 }
3993 return 0;
3994}
int blocksize
Definition libavrdude.h:300
#define XPRG_ERASE_CONFIG
Definition stk500v2_private.h:255

References avrdude_message(), AVRPART_HAS_TPI, avrmem::blocksize, avrmem::desc, avrpart::flags, MSG_INFO, avrmem::offset, pgm, progname, stk600_xprog_command(), stk600_xprog_memtype(), XPRG_CMD_ERASE, XPRG_CMD_WRITE_MEM, XPRG_ERASE_CONFIG, XPRG_MEM_TYPE_APPL, XPRG_MEM_TYPE_BOOT, XPRG_MEM_TYPE_EEPROM, XPRG_MEM_TYPE_FUSE, XPRG_MEM_TYPE_LOCKBITS, and XPRG_MEM_TYPE_USERSIG.

Referenced by stk600_setup_xprog().

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

◆ stk600hvsp_initpgm()

void stk600hvsp_initpgm ( PROGRAMMER pgm)

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500hvsp_chip_erase(), stk500hvsp_disable(), stk500hvsp_initialize(), stk500hvsp_paged_load(), stk500hvsp_paged_write(), stk500hvsp_program_enable(), stk500hvsp_read_byte(), stk500hvsp_write_byte(), stk500v2_close(), stk500v2_display(), stk500v2_enable(), stk500v2_print_parms(), stk500v2_setup(), stk500v2_teardown(), stk600_open(), stk600_set_fosc(), stk600_set_sck_period(), stk600_set_varef(), stk600_set_vtarget(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ stk600pp_initpgm()

void stk600pp_initpgm ( PROGRAMMER pgm)

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_fosc, programmer_t::set_sck_period, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, stk500pp_chip_erase(), stk500pp_disable(), stk500pp_initialize(), stk500pp_paged_load(), stk500pp_paged_write(), stk500pp_program_enable(), stk500pp_read_byte(), stk500pp_write_byte(), stk500v2_close(), stk500v2_display(), stk500v2_enable(), stk500v2_print_parms(), stk500v2_setup(), stk500v2_teardown(), stk600_open(), stk600_set_fosc(), stk600_set_sck_period(), stk600_set_varef(), stk600_set_vtarget(), programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

Variable Documentation

◆ avrispmkIIfreqs

double avrispmkIIfreqs[]
static
Initial value:
= {
8000000, 4000000, 2000000, 1000000, 500000, 250000, 125000,
96386, 89888, 84211, 79208, 74767, 70797, 67227, 64000,
61069, 58395, 55945, 51613, 49690, 47905, 46243, 43244,
41885, 39409, 38278, 36200, 34335, 32654, 31129, 29740,
28470, 27304, 25724, 24768, 23461, 22285, 21221, 20254,
19371, 18562, 17583, 16914, 16097, 15356, 14520, 13914,
13224, 12599, 12031, 11511, 10944, 10431, 9963, 9468,
9081, 8612, 8239, 7851, 7498, 7137, 6809, 6478, 6178,
5879, 5607, 5359, 5093, 4870, 4633, 4418, 4209, 4019,
3823, 3645, 3474, 3310, 3161, 3011, 2869, 2734, 2611,
2484, 2369, 2257, 2152, 2052, 1956, 1866, 1779, 1695,
1615, 1539, 1468, 1398, 1333, 1271, 1212, 1155, 1101,
1049, 1000, 953, 909, 866, 826, 787, 750, 715, 682,
650, 619, 590, 563, 536, 511, 487, 465, 443, 422,
402, 384, 366, 349, 332, 317, 302, 288, 274, 261,
249, 238, 226, 216, 206, 196, 187, 178, 170, 162,
154, 147, 140, 134, 128, 122, 116, 111, 105, 100,
95.4, 90.9, 86.6, 82.6, 78.7, 75.0, 71.5, 68.2,
65.0, 61.9, 59.0, 56.3, 53.6, 51.1
}

Referenced by stk500v2_print_parms1(), and stk500v2_set_sck_period_mk2().

◆ [struct]

struct { ... } connection_status[]
Initial value:
=
{
{ STATUS_CONN_FAIL_MOSI, "MOSI fail" },
{ STATUS_CONN_FAIL_RST, "RST fail" },
{ STATUS_CONN_FAIL_SCK, "SCK fail" },
{ STATUS_TGT_NOT_DETECTED, "Target not detected" },
{ STATUS_TGT_REVERSE_INSERTED, "Target reverse inserted" },
}
#define STATUS_CONN_FAIL_SCK
Definition stk500v2_private.h:149
#define STATUS_TGT_REVERSE_INSERTED
Definition stk500v2_private.h:151
#define STATUS_TGT_NOT_DETECTED
Definition stk500v2_private.h:150
#define STATUS_CONN_FAIL_RST
Definition stk500v2_private.h:148
#define STATUS_CONN_FAIL_MOSI
Definition stk500v2_private.h:147

Referenced by stk500v2_translate_conn_status().

◆ pgmname

const char* pgmname[]
static
Initial value:
=
{
"unknown",
"STK500",
"AVRISP",
"AVRISP mkII",
"JTAG ICE mkII",
"STK600",
"JTAGICE3",
}

Referenced by stk500v2_display(), and stk500v2_getsync().

◆ routing_cards

const struct carddata routing_cards[]
static

Referenced by stk500v2_display().

◆ socket_cards

const struct carddata socket_cards[]
static
Initial value:
=
{
{ 0x01, "STK600-TQFP48" },
{ 0x02, "STK600-TQFP32" },
{ 0x03, "STK600-TQFP100" },
{ 0x04, "STK600-SOIC" },
{ 0x06, "STK600-TQFP144" },
{ 0x09, "STK600-TinyX3U" },
{ 0x0C, "STK600-TSSOP44" },
{ 0x0D, "STK600-TQFP44" },
{ 0x0E, "STK600-TQFP64-2" },
{ 0x0F, "STK600-ATMEGA2560" },
{ 0x15, "STK600-MLF64" },
{ 0x16, "STK600-ATXMEGAT0" },
{ 0x18, "QT600-ATMEGA324-QM64" },
{ 0x19, "STK600-ATMEGA128RFA1" },
{ 0x1A, "QT600-ATTINY88-QT8" },
{ 0x1B, "QT600-ATXMEGA128A1-QT16" },
{ 0x1C, "QT600-AT32UC3L-QM64" },
{ 0x1D, "STK600-HVE2" },
{ 0x1E, "STK600-ATTINY10" },
{ 0x55, "STK600-TQFP64" },
{ 0x69, "STK600-uC3-144" },
{ 0xF0, "STK600-ATXMEGA1281A1" },
{ 0xF1, "STK600-DIP" },
}

Referenced by stk500v2_display().

◆ stk500hvsp_desc

const char stk500hvsp_desc[] = "Atmel STK500 V2 in high-voltage serial programming mode"

◆ stk500pp_desc

const char stk500pp_desc[] = "Atmel STK500 V2 in parallel programming mode"

◆ stk500v2_desc

const char stk500v2_desc[] = "Atmel STK500 Version 2.x firmware"

◆ stk500v2_dragon_hvsp_desc

const char stk500v2_dragon_hvsp_desc[] = "Atmel AVR Dragon in HVSP mode"

◆ stk500v2_dragon_isp_desc

const char stk500v2_dragon_isp_desc[] = "Atmel AVR Dragon in ISP mode"

◆ stk500v2_dragon_pp_desc

const char stk500v2_dragon_pp_desc[] = "Atmel AVR Dragon in PP mode"

◆ stk500v2_jtag3_desc

const char stk500v2_jtag3_desc[] = "Atmel JTAGICE3 in ISP mode"

◆ stk500v2_jtagmkII_desc

const char stk500v2_jtagmkII_desc[] = "Atmel JTAG ICE mkII in ISP mode"

◆ stk600_desc

const char stk600_desc[] = "Atmel STK600"

◆ stk600hvsp_desc

const char stk600hvsp_desc[] = "Atmel STK600 in high-voltage serial programming mode"

◆ stk600pp_desc

const char stk600pp_desc[] = "Atmel STK600 in parallel programming mode"