2005-09-18 20:12:23 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
|
|
|
* Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean <bsd@bsdhome.com>
|
2018-03-15 22:03:36 +00:00
|
|
|
* Copyright (C) 2005 Juliane Holzt <avrdude@juliane.holzt.de>
|
2011-08-24 07:40:48 +00:00
|
|
|
* Copyright (C) 2011 Darell Tan <darell.tan@gmail.com>
|
2005-09-18 20:12:23 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2012-11-20 14:03:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-09-18 20:12:23 +00:00
|
|
|
*/
|
2022-01-07 12:15:55 +00:00
|
|
|
/* $Id$ */
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/time.h>
|
2006-08-17 15:06:20 +00:00
|
|
|
#endif
|
|
|
|
|
2007-01-24 21:07:54 +00:00
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2005-09-18 20:12:23 +00:00
|
|
|
#include "par.h"
|
|
|
|
#include "serbb.h"
|
2011-08-23 21:03:36 +00:00
|
|
|
#include "tpi.h"
|
2014-05-16 15:52:25 +00:00
|
|
|
#include "bitbang.h"
|
2005-09-18 20:12:23 +00:00
|
|
|
|
2006-08-17 15:06:20 +00:00
|
|
|
static int delay_decrement;
|
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#if defined(WIN32)
|
2010-01-08 14:50:22 +00:00
|
|
|
static int has_perfcount;
|
2010-01-08 20:02:35 +00:00
|
|
|
static LARGE_INTEGER freq;
|
2010-01-08 14:50:22 +00:00
|
|
|
#else
|
2006-08-17 15:06:20 +00:00
|
|
|
static volatile int done;
|
|
|
|
|
|
|
|
typedef void (*mysighandler_t)(int);
|
|
|
|
static mysighandler_t saved_alarmhandler;
|
|
|
|
|
|
|
|
static void alarmhandler(int signo)
|
|
|
|
{
|
|
|
|
done = 1;
|
|
|
|
signal(SIGALRM, saved_alarmhandler);
|
|
|
|
}
|
2022-01-07 12:15:55 +00:00
|
|
|
#endif /* WIN32 */
|
2006-08-17 15:06:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calibrate the microsecond delay loop below.
|
|
|
|
*/
|
|
|
|
static void bitbang_calibrate_delay(void)
|
|
|
|
{
|
2022-01-07 12:15:55 +00:00
|
|
|
#if defined(WIN32)
|
2006-08-17 15:06:20 +00:00
|
|
|
/*
|
2010-01-08 14:50:22 +00:00
|
|
|
* If the hardware supports a high-resolution performance counter,
|
|
|
|
* we ultimately prefer that one, as it gives quite accurate delays
|
|
|
|
* on modern high-speed CPUs.
|
2006-08-17 15:06:20 +00:00
|
|
|
*/
|
2010-01-08 14:50:22 +00:00
|
|
|
if (QueryPerformanceFrequency(&freq))
|
|
|
|
{
|
|
|
|
has_perfcount = 1;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("using performance counter for bitbang delays\n");
|
2010-01-08 14:50:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If a high-resolution performance counter is not available, we
|
|
|
|
* don't have any Win32 implementation for setting up the
|
|
|
|
* per-microsecond delay count, so we can only run on a
|
|
|
|
* preconfigured delay stepping there. The figure below should at
|
|
|
|
* least be correct within an order of magnitude, judging from the
|
|
|
|
* auto-calibration figures seen on various Unix systems on
|
|
|
|
* comparable hardware.
|
|
|
|
*/
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("using guessed per-microsecond delay count for bitbang delays\n");
|
2010-01-08 14:50:22 +00:00
|
|
|
delay_decrement = 100;
|
|
|
|
}
|
2022-01-07 12:15:55 +00:00
|
|
|
#else /* !WIN32 */
|
2006-08-17 15:06:20 +00:00
|
|
|
struct itimerval itv;
|
|
|
|
volatile int i;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("calibrating delay loop ...");
|
2006-08-17 15:06:20 +00:00
|
|
|
i = 0;
|
|
|
|
done = 0;
|
|
|
|
saved_alarmhandler = signal(SIGALRM, alarmhandler);
|
|
|
|
/*
|
|
|
|
* Set ITIMER_REAL to 100 ms. All known systems have a timer
|
|
|
|
* granularity of 10 ms or better, so counting the delay cycles
|
|
|
|
* accumulating over 100 ms should give us a rather realistic
|
|
|
|
* picture, without annoying the user by a lengthy startup time (as
|
|
|
|
* an alarm(1) would do). Of course, if heavy system activity
|
|
|
|
* happens just during calibration but stops before the remaining
|
|
|
|
* part of AVRDUDE runs, this will yield wrong values. There's not
|
|
|
|
* much we can do about this.
|
|
|
|
*/
|
|
|
|
itv.it_value.tv_sec = 0;
|
|
|
|
itv.it_value.tv_usec = 100000;
|
|
|
|
itv.it_interval.tv_sec = itv.it_interval.tv_usec = 0;
|
|
|
|
setitimer(ITIMER_REAL, &itv, 0);
|
|
|
|
while (!done)
|
|
|
|
i--;
|
|
|
|
itv.it_value.tv_sec = itv.it_value.tv_usec = 0;
|
|
|
|
setitimer(ITIMER_REAL, &itv, 0);
|
|
|
|
/*
|
|
|
|
* Calculate back from 100 ms to 1 us.
|
|
|
|
*/
|
|
|
|
delay_decrement = -i / 100000;
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2(" calibrated to %d cycles per us\n",
|
2014-06-13 20:07:40 +00:00
|
|
|
delay_decrement);
|
2022-01-07 12:15:55 +00:00
|
|
|
#endif /* WIN32 */
|
2006-08-17 15:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delay for approximately the number of microseconds specified.
|
|
|
|
* usleep()'s granularity is usually like 1 ms or 10 ms, so it's not
|
|
|
|
* really suitable for short delays in bit-bang algorithms.
|
|
|
|
*/
|
2014-05-16 15:52:25 +00:00
|
|
|
void bitbang_delay(unsigned int us)
|
2006-08-17 15:06:20 +00:00
|
|
|
{
|
2022-01-07 12:15:55 +00:00
|
|
|
#if defined(WIN32)
|
2010-01-08 14:50:22 +00:00
|
|
|
LARGE_INTEGER countNow, countEnd;
|
|
|
|
|
|
|
|
if (has_perfcount)
|
|
|
|
{
|
|
|
|
QueryPerformanceCounter(&countNow);
|
|
|
|
countEnd.QuadPart = countNow.QuadPart + freq.QuadPart * us / 1000000ll;
|
|
|
|
|
|
|
|
while (countNow.QuadPart < countEnd.QuadPart)
|
|
|
|
QueryPerformanceCounter(&countNow);
|
|
|
|
}
|
|
|
|
else /* no performance counters -- run normal uncalibrated delay */
|
|
|
|
{
|
2022-01-07 12:15:55 +00:00
|
|
|
#endif /* WIN32 */
|
2014-05-16 15:52:25 +00:00
|
|
|
volatile unsigned int del = us * delay_decrement;
|
2006-08-17 15:06:20 +00:00
|
|
|
|
|
|
|
while (del > 0)
|
|
|
|
del--;
|
2022-01-07 12:15:55 +00:00
|
|
|
#if defined(WIN32)
|
2010-01-08 14:50:22 +00:00
|
|
|
}
|
2022-01-07 12:15:55 +00:00
|
|
|
#endif /* WIN32 */
|
2006-08-17 15:06:20 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 20:12:23 +00:00
|
|
|
/*
|
|
|
|
* transmit and receive a byte of data to/from the AVR device
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static unsigned char bitbang_txrx(const PROGRAMMER *pgm, unsigned char byte) {
|
2005-09-18 20:12:23 +00:00
|
|
|
int i;
|
|
|
|
unsigned char r, b, rbyte;
|
|
|
|
|
|
|
|
rbyte = 0;
|
|
|
|
for (i=7; i>=0; i--) {
|
|
|
|
/*
|
|
|
|
* Write and read one bit on SPI.
|
|
|
|
* Some notes on timing: Let T be the time it takes to do
|
2005-11-01 23:02:06 +00:00
|
|
|
* one pgm->setpin()-call resp. par clrpin()-call, then
|
2005-09-18 20:12:23 +00:00
|
|
|
* - SCK is high for 2T
|
|
|
|
* - SCK is low for 2T
|
2022-11-22 17:04:05 +00:00
|
|
|
* - SDO setuptime is 1T
|
|
|
|
* - SDO holdtime is 3T
|
|
|
|
* - SCK low to SDI read is 2T to 3T
|
2005-09-18 20:12:23 +00:00
|
|
|
* So we are within programming specs (expect for AT90S1200),
|
|
|
|
* if and only if T>t_CLCL (t_CLCL=clock period of target system).
|
|
|
|
*
|
|
|
|
* Due to the delay introduced by "IN" and "OUT"-commands,
|
|
|
|
* T is greater than 1us (more like 2us) on x86-architectures.
|
|
|
|
* So programming works safely down to 1MHz target clock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
b = (byte >> i) & 0x01;
|
|
|
|
|
|
|
|
/* set the data input line as desired */
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, b);
|
2005-09-18 20:12:23 +00:00
|
|
|
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SCK, 1);
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* read the result bit (it is either valid from a previous falling
|
|
|
|
* edge or it is ignored in the current context)
|
|
|
|
*/
|
2022-11-22 17:04:05 +00:00
|
|
|
r = pgm->getpin(pgm, PIN_AVR_SDI);
|
2005-09-18 20:12:23 +00:00
|
|
|
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SCK, 0);
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
rbyte |= r << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rbyte;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int bitbang_tpi_clk(const PROGRAMMER *pgm) {
|
2011-08-23 21:03:36 +00:00
|
|
|
unsigned char r = 0;
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SCK, 1);
|
2011-08-23 21:03:36 +00:00
|
|
|
|
2022-11-22 17:04:05 +00:00
|
|
|
r = pgm->getpin(pgm, PIN_AVR_SDI);
|
2011-08-23 21:03:36 +00:00
|
|
|
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SCK, 0);
|
2011-08-23 21:03:36 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
void bitbang_tpi_tx(const PROGRAMMER *pgm, unsigned char byte) {
|
2011-08-23 21:03:36 +00:00
|
|
|
int i;
|
|
|
|
unsigned char b, parity;
|
|
|
|
|
|
|
|
/* start bit */
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, 0);
|
2011-08-23 21:03:36 +00:00
|
|
|
bitbang_tpi_clk(pgm);
|
|
|
|
|
|
|
|
parity = 0;
|
|
|
|
for (i = 0; i <= 7; i++) {
|
|
|
|
b = (byte >> i) & 0x01;
|
|
|
|
parity ^= b;
|
|
|
|
|
|
|
|
/* set the data input line as desired */
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, b);
|
2011-08-23 21:03:36 +00:00
|
|
|
bitbang_tpi_clk(pgm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parity bit */
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, parity);
|
2011-08-23 21:03:36 +00:00
|
|
|
bitbang_tpi_clk(pgm);
|
|
|
|
|
|
|
|
/* 2 stop bits */
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, 1);
|
2011-08-23 21:03:36 +00:00
|
|
|
bitbang_tpi_clk(pgm);
|
|
|
|
bitbang_tpi_clk(pgm);
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_tpi_rx(const PROGRAMMER *pgm) {
|
2011-08-23 21:03:36 +00:00
|
|
|
int i;
|
|
|
|
unsigned char b, rbyte, parity;
|
|
|
|
|
|
|
|
/* make sure pin is on for "pullup" */
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, 1);
|
2011-08-23 21:03:36 +00:00
|
|
|
|
|
|
|
/* wait for start bit (up to 10 bits) */
|
|
|
|
b = 1;
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
b = bitbang_tpi_clk(pgm);
|
|
|
|
if (b == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (b != 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("start bit not received correctly\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rbyte = 0;
|
|
|
|
parity = 0;
|
|
|
|
for (i=0; i<=7; i++) {
|
|
|
|
b = bitbang_tpi_clk(pgm);
|
|
|
|
parity ^= b;
|
|
|
|
|
|
|
|
rbyte |= b << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parity bit */
|
|
|
|
if (bitbang_tpi_clk(pgm) != parity) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("parity bit is wrong\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2 stop bits */
|
|
|
|
b = 1;
|
|
|
|
b &= bitbang_tpi_clk(pgm);
|
|
|
|
b &= bitbang_tpi_clk(pgm);
|
|
|
|
if (b != 1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("stop bits not received correctly\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rbyte;
|
|
|
|
}
|
2005-09-18 20:12:23 +00:00
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_rdy_led(const PROGRAMMER *pgm, int value) {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_LED_RDY, !value);
|
2005-09-18 20:12:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_err_led(const PROGRAMMER *pgm, int value) {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_LED_ERR, !value);
|
2005-09-18 20:12:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_pgm_led(const PROGRAMMER *pgm, int value) {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_LED_PGM, !value);
|
2005-09-18 20:12:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_vfy_led(const PROGRAMMER *pgm, int value) {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_LED_VFY, !value);
|
2005-09-18 20:12:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* transmit an AVR device command and return the results; 'cmd' and
|
|
|
|
* 'res' must point to at least a 4 byte data buffer
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
|
2013-09-02 20:22:53 +00:00
|
|
|
unsigned char *res)
|
2005-09-18 20:12:23 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
res[i] = bitbang_txrx(pgm, cmd[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(verbose >= 2)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("bitbang_cmd(): [ ");
|
2005-09-18 20:12:23 +00:00
|
|
|
for(i = 0; i < 4; i++)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", cmd[i]);
|
|
|
|
msg_notice2("] [ ");
|
2005-09-18 20:12:23 +00:00
|
|
|
for(i = 0; i < 4; i++)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", res[i]);
|
2005-09-18 20:12:23 +00:00
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("]\n");
|
2005-09-18 20:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_cmd_tpi(const PROGRAMMER *pgm, const unsigned char *cmd,
|
2013-09-02 20:22:53 +00:00
|
|
|
int cmd_len, unsigned char *res, int res_len)
|
2011-08-23 21:03:36 +00:00
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
|
|
|
|
for (i=0; i<cmd_len; i++) {
|
|
|
|
bitbang_tpi_tx(pgm, cmd[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = 0;
|
|
|
|
for (i=0; i<res_len; i++) {
|
|
|
|
r = bitbang_tpi_rx(pgm);
|
|
|
|
if (r == -1)
|
|
|
|
break;
|
|
|
|
res[i] = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(verbose >= 2)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("bitbang_cmd_tpi(): [ ");
|
2011-08-23 21:03:36 +00:00
|
|
|
for(i = 0; i < cmd_len; i++)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", cmd[i]);
|
|
|
|
msg_notice2("] [ ");
|
2011-08-23 21:03:36 +00:00
|
|
|
for(i = 0; i < res_len; i++)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", res[i]);
|
2011-08-23 21:03:36 +00:00
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("]\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
if (r == -1)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-17 15:31:27 +00:00
|
|
|
/*
|
|
|
|
* transmit bytes via SPI and return the results; 'cmd' and
|
|
|
|
* 'res' must point to data buffers
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_spi(const PROGRAMMER *pgm, const unsigned char *cmd,
|
2013-09-02 20:22:53 +00:00
|
|
|
unsigned char *res, int count)
|
2009-02-17 15:31:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_LED_PGM, 0);
|
2009-02-17 15:31:27 +00:00
|
|
|
|
|
|
|
for (i=0; i<count; i++) {
|
|
|
|
res[i] = bitbang_txrx(pgm, cmd[i]);
|
|
|
|
}
|
|
|
|
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_LED_PGM, 1);
|
2009-02-17 15:31:27 +00:00
|
|
|
|
|
|
|
if(verbose >= 2)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("bitbang_cmd(): [ ");
|
2009-02-17 15:31:27 +00:00
|
|
|
for(i = 0; i < count; i++)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", cmd[i]);
|
|
|
|
msg_notice2("] [ ");
|
2009-02-17 15:31:27 +00:00
|
|
|
for(i = 0; i < count; i++)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", res[i]);
|
2009-02-17 15:31:27 +00:00
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("]\n");
|
2009-02-17 15:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* issue the 'chip erase' command to the AVR device
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2005-09-18 20:12:23 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
2011-08-23 21:03:36 +00:00
|
|
|
AVRMEM *mem;
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2011-08-23 21:03:36 +00:00
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
/* NVMCMD <- CHIP_ERASE */
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SOUT | TPI_SIO_ADDR(TPI_IOREG_NVMCMD));
|
|
|
|
bitbang_tpi_tx(pgm, TPI_NVMCMD_CHIP_ERASE); /* CHIP_ERASE */
|
|
|
|
|
|
|
|
/* Set Pointer Register */
|
|
|
|
mem = avr_locate_mem(p, "flash");
|
|
|
|
if (mem == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("no flash memory to erase for part %s\n", p->desc);
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SSTPR | 0);
|
|
|
|
bitbang_tpi_tx(pgm, (mem->offset & 0xFF) | 1); /* high byte */
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SSTPR | 1);
|
|
|
|
bitbang_tpi_tx(pgm, (mem->offset >> 8) & 0xFF);
|
|
|
|
|
|
|
|
/* write dummy value to start erase */
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SST);
|
|
|
|
bitbang_tpi_tx(pgm, 0xFF);
|
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
|
2005-09-18 20:12:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
|
|
|
|
memset(cmd, 0, sizeof(cmd));
|
|
|
|
|
|
|
|
avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd);
|
|
|
|
pgm->cmd(pgm, cmd, res);
|
|
|
|
usleep(p->chip_erase_delay);
|
|
|
|
pgm->initialize(pgm, p);
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* issue the 'program enable' command to the AVR device
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
2005-09-18 20:12:23 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
2011-08-23 21:03:36 +00:00
|
|
|
int i;
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2011-08-23 21:03:36 +00:00
|
|
|
/* enable NVM programming */
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SKEY);
|
|
|
|
for (i = sizeof(tpi_skey) - 1; i >= 0; i--)
|
|
|
|
bitbang_tpi_tx(pgm, tpi_skey[i]);
|
|
|
|
|
|
|
|
/* check NVMEN bit */
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SLDCS | TPI_REG_TPISR);
|
|
|
|
i = bitbang_tpi_rx(pgm);
|
|
|
|
return (i != -1 && (i & TPI_REG_TPISR_NVMEN)) ? 0 : -2;
|
|
|
|
}
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("program enable instruction not defined for part %s\n", p->desc);
|
2005-09-18 20:12:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(cmd, 0, sizeof(cmd));
|
|
|
|
avr_set_bits(p->op[AVR_OP_PGM_ENABLE], cmd);
|
|
|
|
pgm->cmd(pgm, cmd, res);
|
|
|
|
|
|
|
|
if (res[2] != cmd[1])
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the AVR device and prepare it to accept commands
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
|
2005-09-18 20:12:23 +00:00
|
|
|
int rc;
|
|
|
|
int tries;
|
2011-08-23 21:03:36 +00:00
|
|
|
int i;
|
2005-09-18 20:12:23 +00:00
|
|
|
|
2006-08-17 15:06:20 +00:00
|
|
|
bitbang_calibrate_delay();
|
|
|
|
|
2005-09-18 20:12:23 +00:00
|
|
|
pgm->powerup(pgm);
|
|
|
|
usleep(20000);
|
|
|
|
|
2022-11-22 17:04:05 +00:00
|
|
|
/* TPIDATA is a single line, so SDI & SDO should be connected */
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2011-08-23 21:03:36 +00:00
|
|
|
/* make sure cmd_tpi() is defined */
|
|
|
|
if (pgm->cmd_tpi == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("%s programmer does not support TPI\n", pgm->type);
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bring RESET high first */
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_RESET, 1);
|
2021-11-14 13:17:44 +00:00
|
|
|
usleep(128000); /* wait t_TOUT (32-128ms) */
|
|
|
|
|
|
|
|
/* RESET must be LOW in case the existing code is driving the TPI pins: */
|
|
|
|
pgm->setpin(pgm, PIN_AVR_RESET, 0);
|
2011-08-23 21:03:36 +00:00
|
|
|
|
2022-11-22 17:04:05 +00:00
|
|
|
msg_notice2("doing SDO-SDI link check\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, 0);
|
|
|
|
if (pgm->getpin(pgm, PIN_AVR_SDI) != 0) {
|
|
|
|
pmsg_error("SDO->SDI 0 failed\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, 1);
|
|
|
|
if (pgm->getpin(pgm, PIN_AVR_SDI) != 1) {
|
|
|
|
pmsg_error("SDO->SDI 1 failed\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-11-22 17:04:05 +00:00
|
|
|
msg_notice2("SDO-SDI link present\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
}
|
|
|
|
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SCK, 0);
|
|
|
|
pgm->setpin(pgm, PIN_AVR_RESET, 0);
|
2005-09-18 20:12:23 +00:00
|
|
|
usleep(20000);
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2011-08-23 21:03:36 +00:00
|
|
|
/* keep TPIDATA high for 16 clock cycles */
|
2022-11-22 17:04:05 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_SDO, 1);
|
2011-08-23 21:03:36 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->highpulsepin(pgm, PIN_AVR_SCK);
|
2011-08-23 21:03:36 +00:00
|
|
|
|
|
|
|
/* remove extra guard timing bits */
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SSTCS | TPI_REG_TPIPCR);
|
|
|
|
bitbang_tpi_tx(pgm, 0x7);
|
|
|
|
|
|
|
|
/* read TPI ident reg */
|
|
|
|
bitbang_tpi_tx(pgm, TPI_CMD_SLDCS | TPI_REG_TPIIR);
|
|
|
|
rc = bitbang_tpi_rx(pgm);
|
|
|
|
if (rc != 0x80) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("TPIIR not correct\n");
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->highpulsepin(pgm, PIN_AVR_RESET);
|
2011-08-23 21:03:36 +00:00
|
|
|
}
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
usleep(20000); /* 20 ms XXX should be a per-chip parameter */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable programming mode. If we are programming an AT90S1200, we
|
|
|
|
* can only issue the command and hope it worked. If we are using
|
|
|
|
* one of the other chips, the chip will echo 0x53 when issuing the
|
|
|
|
* third byte of the command. In this case, try up to 32 times in
|
|
|
|
* order to possibly get back into sync with the chip if we are out
|
|
|
|
* of sync.
|
|
|
|
*/
|
2011-08-29 09:25:04 +00:00
|
|
|
if (p->flags & AVRPART_IS_AT90S1200) {
|
2005-09-18 20:12:23 +00:00
|
|
|
pgm->program_enable(pgm, p);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tries = 0;
|
|
|
|
do {
|
|
|
|
rc = pgm->program_enable(pgm, p);
|
|
|
|
if ((rc == 0)||(rc == -1))
|
|
|
|
break;
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
pgm->highpulsepin(pgm, p->retry_pulse/*PIN_AVR_SCK*/);
|
2005-09-18 20:12:23 +00:00
|
|
|
tries++;
|
|
|
|
} while (tries < 65);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* can't sync with the device, maybe it's not attached?
|
|
|
|
*/
|
|
|
|
if (rc) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("AVR device not responding\n");
|
2005-09-18 20:12:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int verify_pin_assigned(const PROGRAMMER *pgm, int pin, char *desc) {
|
2006-08-23 21:06:28 +00:00
|
|
|
if (pgm->pinno[pin] == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("no pin has been assigned for %s\n", desc);
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2006-08-23 21:06:28 +00:00
|
|
|
}
|
2014-05-16 15:52:25 +00:00
|
|
|
return 0;
|
2006-08-23 21:06:28 +00:00
|
|
|
}
|
2005-09-18 20:12:23 +00:00
|
|
|
|
2006-08-23 21:06:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify all prerequisites for a bit-bang programmer are present.
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int bitbang_check_prerequisites(const PROGRAMMER *pgm) {
|
2006-08-23 21:06:28 +00:00
|
|
|
|
2014-05-16 15:52:25 +00:00
|
|
|
if (verify_pin_assigned(pgm, PIN_AVR_RESET, "AVR RESET") < 0)
|
|
|
|
return -1;
|
|
|
|
if (verify_pin_assigned(pgm, PIN_AVR_SCK, "AVR SCK") < 0)
|
|
|
|
return -1;
|
2022-11-22 17:04:05 +00:00
|
|
|
if (verify_pin_assigned(pgm, PIN_AVR_SDI, "AVR SDI") < 0)
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2022-11-22 17:04:05 +00:00
|
|
|
if (verify_pin_assigned(pgm, PIN_AVR_SDO, "AVR SDO") < 0)
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2006-11-20 15:04:09 +00:00
|
|
|
|
|
|
|
if (pgm->cmd == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("no cmd() method defined for bitbang programmer\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2006-11-20 15:04:09 +00:00
|
|
|
}
|
2014-05-16 15:52:25 +00:00
|
|
|
return 0;
|
2006-08-23 21:06:28 +00:00
|
|
|
}
|