2001-01-19 02:46:50 +00:00
|
|
|
/*
|
2003-02-08 04:17:25 +00:00
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
2004-12-22 01:52:45 +00:00
|
|
|
* Copyright (C) 2000-2004 Brian S. Dean <bsd@bsdhome.com>
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +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.
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* 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.
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* 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/>.
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2005-11-25 14:46:43 +00:00
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#if !defined(WIN32)
|
2005-11-25 14:46:43 +00:00
|
|
|
|
2003-02-14 20:34:03 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
2005-11-03 22:37:37 +00:00
|
|
|
#if HAVE_PARPORT
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
#include <stdio.h>
|
2003-02-11 21:58:07 +00:00
|
|
|
#include <stdlib.h>
|
2002-11-30 14:09:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
2001-01-19 02:46:50 +00:00
|
|
|
#include <unistd.h>
|
2002-11-30 14:09:12 +00:00
|
|
|
#include <errno.h>
|
2003-02-11 23:50:31 +00:00
|
|
|
|
2010-01-17 16:58:06 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2005-11-03 22:37:37 +00:00
|
|
|
# include "freebsd_ppi.h"
|
2003-02-11 23:50:31 +00:00
|
|
|
#elif defined(__linux__)
|
2005-11-03 22:37:37 +00:00
|
|
|
# include "linux_ppdev.h"
|
2009-02-23 22:04:57 +00:00
|
|
|
#elif defined(__sun__) || defined(__sun) /* Solaris */
|
2005-11-03 22:37:37 +00:00
|
|
|
# include "solaris_ecpp.h"
|
2003-02-11 23:50:31 +00:00
|
|
|
#endif
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2007-01-24 21:07:54 +00:00
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
#include "ppi.h"
|
|
|
|
|
2003-11-22 03:31:27 +00:00
|
|
|
enum {
|
|
|
|
PPI_READ,
|
|
|
|
PPI_WRITE,
|
|
|
|
PPI_SHADOWREAD
|
|
|
|
};
|
|
|
|
|
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 ppi_shadow_access(const union filedescriptor *fdp, int reg,
|
2007-01-24 22:43:46 +00:00
|
|
|
unsigned char *v, unsigned char action)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
2003-11-22 03:31:27 +00:00
|
|
|
static unsigned char shadow[3];
|
|
|
|
int shadow_num;
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
switch (reg) {
|
|
|
|
case PPIDATA:
|
2003-11-22 03:31:27 +00:00
|
|
|
shadow_num = 0;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
case PPICTRL:
|
2003-11-22 03:31:27 +00:00
|
|
|
shadow_num = 1;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
case PPISTATUS:
|
2003-11-22 03:31:27 +00:00
|
|
|
shadow_num = 2;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: avr_set(): invalid register=%d\n",
|
2001-10-13 03:13:13 +00:00
|
|
|
progname, reg);
|
2001-01-19 02:46:50 +00:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-11-22 03:31:27 +00:00
|
|
|
switch (action) {
|
|
|
|
case PPI_SHADOWREAD:
|
|
|
|
*v = shadow[shadow_num];
|
|
|
|
break;
|
|
|
|
case PPI_READ:
|
2006-12-11 12:47:35 +00:00
|
|
|
DO_PPI_READ(fdp->ifd, reg, v);
|
2003-11-22 03:31:27 +00:00
|
|
|
shadow[shadow_num]=*v;
|
|
|
|
break;
|
|
|
|
case PPI_WRITE:
|
|
|
|
shadow[shadow_num]=*v;
|
2006-12-11 12:47:35 +00:00
|
|
|
DO_PPI_WRITE(fdp->ifd, reg, v);
|
2003-11-22 03:31:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set the indicated bit of the specified register.
|
|
|
|
*/
|
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 ppi_set(const union filedescriptor *fdp, int reg, int bit) {
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char v;
|
|
|
|
int rc;
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = ppi_shadow_access(fdp, reg, &v, PPI_SHADOWREAD);
|
2003-11-22 03:31:27 +00:00
|
|
|
v |= bit;
|
2006-12-11 12:47:35 +00:00
|
|
|
rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
2003-11-22 03:31:27 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clear the indicated bit of the specified register.
|
|
|
|
*/
|
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 ppi_clr(const union filedescriptor *fdp, int reg, int bit) {
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char v;
|
|
|
|
int rc;
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = ppi_shadow_access(fdp, reg, &v, PPI_SHADOWREAD);
|
2003-11-22 03:31:27 +00:00
|
|
|
v &= ~bit;
|
2006-12-11 12:47:35 +00:00
|
|
|
rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
2003-11-22 03:31:27 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the indicated bit of the specified register.
|
|
|
|
*/
|
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 ppi_get(const union filedescriptor *fdp, int reg, int bit) {
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char v;
|
|
|
|
int rc;
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = ppi_shadow_access(fdp, reg, &v, PPI_READ);
|
2003-11-22 03:31:27 +00:00
|
|
|
v &= bit;
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc)
|
|
|
|
return -1;
|
|
|
|
|
2001-01-24 18:45:58 +00:00
|
|
|
return v; /* v == bit */
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* toggle the indicated bit of the specified register.
|
|
|
|
*/
|
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 ppi_toggle(const union filedescriptor *fdp, int reg, int bit) {
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char v;
|
|
|
|
int rc;
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = ppi_shadow_access(fdp, reg, &v, PPI_SHADOWREAD);
|
2003-11-22 03:31:27 +00:00
|
|
|
v ^= bit;
|
2006-12-11 12:47:35 +00:00
|
|
|
rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
2003-11-22 03:31:27 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get all bits of the specified register.
|
|
|
|
*/
|
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 ppi_getall(const union filedescriptor *fdp, int reg) {
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char v;
|
|
|
|
int rc;
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = ppi_shadow_access(fdp, reg, &v, PPI_READ);
|
2003-11-22 03:31:27 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc)
|
|
|
|
return -1;
|
|
|
|
|
2003-11-22 03:31:27 +00:00
|
|
|
return v; /* v == bit */
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set all bits of the specified register to val.
|
|
|
|
*/
|
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 ppi_setall(const union filedescriptor *fdp, int reg, int val) {
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char v;
|
|
|
|
int rc;
|
|
|
|
|
2003-11-22 03:31:27 +00:00
|
|
|
v = val;
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
2003-11-22 03:31:27 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc)
|
|
|
|
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
|
|
|
void ppi_open(const char *port, union filedescriptor *fdp) {
|
2003-02-13 19:27:50 +00:00
|
|
|
int fd;
|
2003-11-22 03:31:27 +00:00
|
|
|
unsigned char v;
|
2001-01-24 18:45:58 +00:00
|
|
|
|
2003-02-13 19:27:50 +00:00
|
|
|
fd = open(port, O_RDWR);
|
|
|
|
if (fd < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: can't open device \"%s\": %s\n",
|
2003-02-13 19:27:50 +00:00
|
|
|
progname, port, strerror(errno));
|
2006-12-11 12:47:35 +00:00
|
|
|
fdp->ifd = -1;
|
|
|
|
return;
|
2002-11-30 14:09:12 +00:00
|
|
|
}
|
|
|
|
|
2005-11-29 20:20:22 +00:00
|
|
|
ppi_claim (fd);
|
|
|
|
|
2003-11-22 03:31:27 +00:00
|
|
|
/*
|
|
|
|
* Initialize shadow registers
|
|
|
|
*/
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
ppi_shadow_access (fdp, PPIDATA, &v, PPI_READ);
|
|
|
|
ppi_shadow_access (fdp, PPICTRL, &v, PPI_READ);
|
|
|
|
ppi_shadow_access (fdp, PPISTATUS, &v, PPI_READ);
|
2003-11-22 03:31:27 +00:00
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
fdp->ifd = fd;
|
2002-11-30 14:09:12 +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
|
|
|
void ppi_close(const union filedescriptor *fdp) {
|
2006-12-11 12:47:35 +00:00
|
|
|
ppi_release (fdp->ifd);
|
|
|
|
close(fdp->ifd);
|
2002-11-30 14:09:12 +00:00
|
|
|
}
|
|
|
|
|
2005-11-03 22:37:37 +00:00
|
|
|
#endif /* HAVE_PARPORT */
|
2004-05-19 21:02:25 +00:00
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#endif /* !WIN32 */
|