2005-09-18 20:12:23 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
|
|
|
* Copyright (C) 2003, 2004 Martin J. Thomas <mthomas@rhrk.uni-kl.de>
|
2018-03-15 22:03:36 +00:00
|
|
|
* Copyright (C) 2005 Juliane Holzt <avrdude@juliane.holzt.de>
|
2006-08-30 14:09:58 +00:00
|
|
|
* Copyright (C) 2005, 2006 Joerg Wunsch <j@uriah.heep.sax.de>
|
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
|
|
|
*/
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Win32 serial bitbanging interface for avrdude.
|
|
|
|
*/
|
|
|
|
|
2009-02-23 22:04:57 +00:00
|
|
|
#include "avrdude.h"
|
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#if defined(WIN32)
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2005-09-18 20:12:23 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "avrdude.h"
|
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2005-09-18 20:12:23 +00:00
|
|
|
#include "bitbang.h"
|
2012-01-31 17:03:43 +00:00
|
|
|
#include "serbb.h"
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
/* cached status lines */
|
|
|
|
static int dtr, rts, txd;
|
|
|
|
|
|
|
|
#define W32SERBUFSIZE 1024
|
|
|
|
|
|
|
|
/*
|
|
|
|
serial port/pin mapping
|
|
|
|
|
|
|
|
1 cd <-
|
2006-08-30 14:09:58 +00:00
|
|
|
2 (rxd) <-
|
2005-09-18 20:12:23 +00:00
|
|
|
3 txd ->
|
|
|
|
4 dtr ->
|
2006-08-30 14:09:58 +00:00
|
|
|
5 GND
|
|
|
|
6 dsr <-
|
|
|
|
7 rts ->
|
|
|
|
8 cts <-
|
|
|
|
9 ri <-
|
2005-09-18 20:12:23 +00:00
|
|
|
*/
|
|
|
|
|
2006-08-30 14:09:58 +00:00
|
|
|
#define DB9PINS 9
|
|
|
|
|
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 serbb_setpin(const PROGRAMMER *pgm, int pinfunc, 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
|
|
|
int pin = pgm->pinno[pinfunc];
|
2006-12-11 12:47:35 +00:00
|
|
|
HANDLE hComPort = (HANDLE)pgm->fd.pfd;
|
2005-09-18 20:12:23 +00:00
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
DWORD dwFunc;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (pin & PIN_INVERSE)
|
|
|
|
{
|
|
|
|
value = !value;
|
|
|
|
pin &= PIN_MASK;
|
|
|
|
}
|
|
|
|
|
2006-08-30 14:09:58 +00:00
|
|
|
if (pin < 1 || pin > DB9PINS)
|
2005-11-01 23:02:06 +00:00
|
|
|
return -1;
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
switch (pin)
|
|
|
|
{
|
2006-08-30 14:09:58 +00:00
|
|
|
case 3: /* txd */
|
2005-09-18 20:12:23 +00:00
|
|
|
dwFunc = value? SETBREAK: CLRBREAK;
|
|
|
|
name = value? "SETBREAK": "CLRBREAK";
|
|
|
|
txd = value;
|
|
|
|
break;
|
|
|
|
|
2006-08-30 14:09:58 +00:00
|
|
|
case 4: /* dtr */
|
2005-09-18 20:12:23 +00:00
|
|
|
dwFunc = value? SETDTR: CLRDTR;
|
|
|
|
name = value? "SETDTR": "CLRDTR";
|
|
|
|
dtr = value;
|
|
|
|
break;
|
|
|
|
|
2006-08-30 14:09:58 +00:00
|
|
|
case 7: /* rts */
|
2005-09-18 20:12:23 +00:00
|
|
|
dwFunc = value? SETRTS: CLRRTS;
|
|
|
|
name = value? "SETRTS": "CLRRTS";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE, "%s: serbb_setpin(): unknown pin %d\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, pin + 1);
|
2005-11-01 23:02:06 +00:00
|
|
|
return -1;
|
2005-09-18 20:12:23 +00:00
|
|
|
}
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE2, "%s: serbb_setpin(): EscapeCommFunction(%s)\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, name);
|
2005-09-18 20:12:23 +00:00
|
|
|
if (!EscapeCommFunction(hComPort, dwFunc))
|
|
|
|
{
|
|
|
|
FormatMessage(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
|
|
(LPTSTR) &lpMsgBuf,
|
|
|
|
0,
|
|
|
|
NULL);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: serbb_setpin(): SetCommState() failed: %s\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, (char *)lpMsgBuf);
|
2005-09-18 20:12:23 +00:00
|
|
|
CloseHandle(hComPort);
|
|
|
|
LocalFree(lpMsgBuf);
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2005-09-18 20:12:23 +00:00
|
|
|
}
|
2010-01-15 16:40:17 +00:00
|
|
|
|
|
|
|
if (pgm->ispdelay > 1)
|
|
|
|
bitbang_delay(pgm->ispdelay);
|
|
|
|
|
2005-11-01 23:02:06 +00:00
|
|
|
return 0;
|
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
|
|
|
static int serbb_getpin(const PROGRAMMER *pgm, int pinfunc) {
|
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
|
|
|
int pin = pgm->pinno[pinfunc];
|
2006-12-11 12:47:35 +00:00
|
|
|
HANDLE hComPort = (HANDLE)pgm->fd.pfd;
|
2005-09-18 20:12:23 +00:00
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
int invert, rv;
|
|
|
|
const char *name;
|
|
|
|
DWORD modemstate;
|
|
|
|
|
|
|
|
if (pin & PIN_INVERSE)
|
|
|
|
{
|
|
|
|
invert = 1;
|
|
|
|
pin &= PIN_MASK;
|
|
|
|
} else
|
|
|
|
invert = 0;
|
|
|
|
|
2006-08-30 14:09:58 +00:00
|
|
|
if (pin < 1 || pin > DB9PINS)
|
2005-09-18 20:12:23 +00:00
|
|
|
return -1;
|
|
|
|
|
2006-08-30 14:09:58 +00:00
|
|
|
if (pin == 1 /* cd */ || pin == 6 /* dsr */ || pin == 8 /* cts */)
|
2005-09-18 20:12:23 +00:00
|
|
|
{
|
|
|
|
if (!GetCommModemStatus(hComPort, &modemstate))
|
|
|
|
{
|
|
|
|
FormatMessage(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
|
|
(LPTSTR) &lpMsgBuf,
|
|
|
|
0,
|
|
|
|
NULL);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: serbb_setpin(): GetCommModemStatus() failed: %s\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, (char *)lpMsgBuf);
|
2005-09-18 20:12:23 +00:00
|
|
|
CloseHandle(hComPort);
|
|
|
|
LocalFree(lpMsgBuf);
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2005-09-18 20:12:23 +00:00
|
|
|
}
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE2, "%s: serbb_getpin(): GetCommState() => 0x%lx\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, modemstate);
|
2005-09-18 20:12:23 +00:00
|
|
|
switch (pin)
|
|
|
|
{
|
2006-08-30 14:09:58 +00:00
|
|
|
case 1:
|
2005-09-18 20:12:23 +00:00
|
|
|
modemstate &= MS_RLSD_ON;
|
|
|
|
break;
|
2006-08-30 14:09:58 +00:00
|
|
|
case 6:
|
2005-09-18 20:12:23 +00:00
|
|
|
modemstate &= MS_DSR_ON;
|
|
|
|
break;
|
2006-08-30 14:09:58 +00:00
|
|
|
case 8:
|
2005-09-18 20:12:23 +00:00
|
|
|
modemstate &= MS_CTS_ON;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = modemstate != 0;
|
|
|
|
if (invert)
|
|
|
|
rv = !rv;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pin)
|
|
|
|
{
|
2006-08-30 14:09:58 +00:00
|
|
|
case 3: /* txd */
|
2005-09-18 20:12:23 +00:00
|
|
|
rv = txd;
|
|
|
|
name = "TXD";
|
|
|
|
break;
|
2006-08-30 14:09:58 +00:00
|
|
|
case 4: /* dtr */
|
2005-09-18 20:12:23 +00:00
|
|
|
rv = dtr;
|
|
|
|
name = "DTR";
|
|
|
|
break;
|
2006-08-30 14:09:58 +00:00
|
|
|
case 7: /* rts */
|
2005-09-18 20:12:23 +00:00
|
|
|
rv = rts;
|
|
|
|
name = "RTS";
|
|
|
|
break;
|
|
|
|
default:
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE, "%s: serbb_getpin(): unknown pin %d\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, pin + 1);
|
2005-09-18 20:12:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE2, "%s: serbb_getpin(): return cached state for %s\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, name);
|
2005-09-18 20:12:23 +00:00
|
|
|
if (invert)
|
|
|
|
rv = !rv;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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 serbb_highpulsepin(const PROGRAMMER *pgm, int pinfunc) {
|
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
|
|
|
int pin = pgm->pinno[pinfunc];
|
2010-01-08 16:31:54 +00:00
|
|
|
if ( (pin & PIN_MASK) < 1 || (pin & PIN_MASK) > DB9PINS )
|
|
|
|
return -1;
|
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
|
|
|
serbb_setpin(pgm, pinfunc, 1);
|
|
|
|
serbb_setpin(pgm, pinfunc, 0);
|
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
|
|
|
static void serbb_display(const PROGRAMMER *pgm, const char *p) {
|
2005-09-18 20:12:23 +00:00
|
|
|
/* MAYBE */
|
|
|
|
}
|
|
|
|
|
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 void serbb_enable(PROGRAMMER *pgm, const AVRPART *p) {
|
2005-09-18 20:12:23 +00:00
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
|
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 void serbb_disable(const PROGRAMMER *pgm) {
|
2005-09-18 20:12:23 +00:00
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
|
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 void serbb_powerup(const PROGRAMMER *pgm) {
|
2005-09-18 20:12:23 +00:00
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
|
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 void serbb_powerdown(const PROGRAMMER *pgm) {
|
2005-09-18 20:12:23 +00:00
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
|
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 serbb_open(PROGRAMMER *pgm, const char *port) {
|
2005-09-18 20:12:23 +00:00
|
|
|
DCB dcb;
|
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
HANDLE hComPort = INVALID_HANDLE_VALUE;
|
|
|
|
|
2014-05-16 16:01:08 +00:00
|
|
|
if (bitbang_check_prerequisites(pgm) < 0)
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2006-08-23 21:06:28 +00:00
|
|
|
|
2005-09-18 20:12:23 +00:00
|
|
|
hComPort = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (hComPort == INVALID_HANDLE_VALUE) {
|
|
|
|
FormatMessage(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
|
|
(LPTSTR) &lpMsgBuf,
|
|
|
|
0,
|
|
|
|
NULL);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_open(): can't open device \"%s\": %s\n",
|
2005-09-18 20:12:23 +00:00
|
|
|
progname, port, (char*)lpMsgBuf);
|
|
|
|
LocalFree(lpMsgBuf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
|
|
|
|
{
|
|
|
|
CloseHandle(hComPort);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_open(): can't set buffers for \"%s\"\n",
|
2005-09-18 20:12:23 +00:00
|
|
|
progname, port);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZeroMemory(&dcb, sizeof(DCB));
|
|
|
|
dcb.DCBlength = sizeof(DCB);
|
|
|
|
dcb.BaudRate = CBR_9600;
|
|
|
|
dcb.fBinary = 1;
|
|
|
|
dcb.fDtrControl = DTR_CONTROL_DISABLE;
|
|
|
|
dcb.fRtsControl = RTS_CONTROL_DISABLE;
|
|
|
|
dcb.ByteSize = 8;
|
|
|
|
dcb.Parity = NOPARITY;
|
|
|
|
dcb.StopBits = ONESTOPBIT;
|
|
|
|
|
|
|
|
if (!SetCommState(hComPort, &dcb))
|
|
|
|
{
|
|
|
|
CloseHandle(hComPort);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_open(): can't set com-state for \"%s\"\n",
|
2005-09-18 20:12:23 +00:00
|
|
|
progname, port);
|
|
|
|
return -1;
|
|
|
|
}
|
2021-12-28 10:26:09 +00:00
|
|
|
avrdude_message(MSG_DEBUG, "%s: ser_open(): opened comm port \"%s\", handle 0x%zx\n",
|
|
|
|
progname, port, (INT_PTR)hComPort);
|
2005-09-18 20:12:23 +00:00
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
pgm->fd.pfd = (void *)hComPort;
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
dtr = rts = txd = 0;
|
|
|
|
|
|
|
|
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 void serbb_close(PROGRAMMER *pgm) {
|
2006-12-11 12:47:35 +00:00
|
|
|
HANDLE hComPort=(HANDLE)pgm->fd.pfd;
|
2005-09-18 20:12:23 +00:00
|
|
|
if (hComPort != INVALID_HANDLE_VALUE)
|
2006-08-31 10:55:20 +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_RESET, 1);
|
2005-09-18 20:12:23 +00:00
|
|
|
CloseHandle (hComPort);
|
2006-08-31 10:55:20 +00:00
|
|
|
}
|
2021-12-28 10:26:09 +00:00
|
|
|
avrdude_message(MSG_DEBUG, "%s: ser_close(): closed comm port handle 0x%zx\n",
|
|
|
|
progname, (INT_PTR)hComPort);
|
2005-09-18 20:12:23 +00:00
|
|
|
|
|
|
|
hComPort = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:03:43 +00:00
|
|
|
const char serbb_desc[] = "Serial port bitbanging";
|
|
|
|
|
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 serbb_initpgm(PROGRAMMER *pgm) {
|
2005-09-18 20:12:23 +00:00
|
|
|
strcpy(pgm->type, "SERBB");
|
|
|
|
|
2013-05-03 22:35:00 +00:00
|
|
|
pgm_fill_old_pins(pgm); // TODO to be removed if old pin data no longer needed
|
|
|
|
|
2005-09-18 20:12:23 +00:00
|
|
|
pgm->rdy_led = bitbang_rdy_led;
|
|
|
|
pgm->err_led = bitbang_err_led;
|
|
|
|
pgm->pgm_led = bitbang_pgm_led;
|
|
|
|
pgm->vfy_led = bitbang_vfy_led;
|
|
|
|
pgm->initialize = bitbang_initialize;
|
|
|
|
pgm->display = serbb_display;
|
|
|
|
pgm->enable = serbb_enable;
|
|
|
|
pgm->disable = serbb_disable;
|
|
|
|
pgm->powerup = serbb_powerup;
|
|
|
|
pgm->powerdown = serbb_powerdown;
|
|
|
|
pgm->program_enable = bitbang_program_enable;
|
|
|
|
pgm->chip_erase = bitbang_chip_erase;
|
|
|
|
pgm->cmd = bitbang_cmd;
|
2011-08-23 21:03:36 +00:00
|
|
|
pgm->cmd_tpi = bitbang_cmd_tpi;
|
2005-09-18 20:12:23 +00:00
|
|
|
pgm->open = serbb_open;
|
|
|
|
pgm->close = serbb_close;
|
2005-11-01 23:02:06 +00:00
|
|
|
pgm->setpin = serbb_setpin;
|
|
|
|
pgm->getpin = serbb_getpin;
|
|
|
|
pgm->highpulsepin = serbb_highpulsepin;
|
2006-11-20 15:08:13 +00:00
|
|
|
pgm->read_byte = avr_read_byte_default;
|
|
|
|
pgm->write_byte = avr_write_byte_default;
|
2005-09-18 20:12:23 +00:00
|
|
|
}
|
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#endif /* WIN32 */
|