2002-11-30 14:09:12 +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) 2002-2004 Brian S. Dean <bsd@bsdhome.com>
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
* Copyright 2007 Joerg Wunsch <j@uriah.heep.sax.de>
|
2002-11-30 14:09:12 +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.
|
2002-11-30 14:09:12 +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.
|
2002-11-30 14:09:12 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-11-30 14:09:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2003-02-14 20:34:03 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
#include <stdio.h>
|
2003-02-11 21:58:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-11-30 14:09:12 +00:00
|
|
|
|
2007-01-24 21:07:54 +00:00
|
|
|
#include "avrdude.h"
|
2002-11-30 14:09:12 +00:00
|
|
|
#include "pgm.h"
|
|
|
|
|
2004-01-29 13:23:59 +00:00
|
|
|
static int pgm_default_2 (struct programmer_t *, AVRPART *);
|
2006-11-20 15:04:09 +00:00
|
|
|
static int pgm_default_3 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem,
|
|
|
|
unsigned long addr, unsigned char * value);
|
2004-01-29 13:23:59 +00:00
|
|
|
static void pgm_default_4 (struct programmer_t *);
|
2006-11-20 15:04:09 +00:00
|
|
|
static int pgm_default_5 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem,
|
|
|
|
unsigned long addr, unsigned char data);
|
2007-01-30 13:41:54 +00:00
|
|
|
static void pgm_default_6 (struct programmer_t *, const char *);
|
2004-01-29 13:23:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int pgm_default_open (struct programmer_t *pgm, char * name)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "\n%s: Fatal error: Programmer does not support open()",
|
|
|
|
progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pgm_default_led (struct programmer_t * pgm, int value)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If programmer has no LEDs, just do nothing.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pgm_default_powerup_powerdown (struct programmer_t * pgm)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If programmer does not support powerup/down, just do nothing.
|
|
|
|
*/
|
|
|
|
}
|
2002-11-30 14:09:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
PROGRAMMER * pgm_new(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
PROGRAMMER * pgm;
|
|
|
|
|
|
|
|
pgm = (PROGRAMMER *)malloc(sizeof(*pgm));
|
|
|
|
if (pgm == NULL) {
|
|
|
|
fprintf(stderr, "%s: out of memory allocating programmer structure\n",
|
|
|
|
progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(pgm, 0, sizeof(*pgm));
|
|
|
|
|
|
|
|
pgm->id = lcreat(NULL, 0);
|
|
|
|
pgm->desc[0] = 0;
|
|
|
|
pgm->type[0] = 0;
|
2003-02-22 16:45:13 +00:00
|
|
|
pgm->config_file[0] = 0;
|
|
|
|
pgm->lineno = 0;
|
2004-01-03 18:36:44 +00:00
|
|
|
pgm->baudrate = 0;
|
2002-11-30 14:09:12 +00:00
|
|
|
|
|
|
|
for (i=0; i<N_PINS; i++)
|
|
|
|
pgm->pinno[i] = 0;
|
|
|
|
|
2002-12-01 06:35:18 +00:00
|
|
|
/*
|
|
|
|
* mandatory functions - these are called without checking to see
|
|
|
|
* whether they are assigned or not
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->initialize = pgm_default_2;
|
|
|
|
pgm->display = pgm_default_6;
|
|
|
|
pgm->enable = pgm_default_4;
|
|
|
|
pgm->disable = pgm_default_4;
|
2004-01-29 13:23:59 +00:00
|
|
|
pgm->powerup = pgm_default_powerup_powerdown;
|
|
|
|
pgm->powerdown = pgm_default_powerup_powerdown;
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->program_enable = pgm_default_2;
|
|
|
|
pgm->chip_erase = pgm_default_2;
|
2004-01-29 13:23:59 +00:00
|
|
|
pgm->open = pgm_default_open;
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->close = pgm_default_4;
|
2006-11-20 15:04:09 +00:00
|
|
|
pgm->read_byte = pgm_default_3;
|
|
|
|
pgm->write_byte = pgm_default_5;
|
2002-11-30 14:09:12 +00:00
|
|
|
|
2004-01-29 13:23:59 +00:00
|
|
|
/*
|
|
|
|
* predefined functions - these functions have a valid default
|
|
|
|
* implementation. Hence, they don't need to be defined in
|
|
|
|
* the programmer.
|
|
|
|
*/
|
|
|
|
pgm->rdy_led = pgm_default_led;
|
|
|
|
pgm->err_led = pgm_default_led;
|
|
|
|
pgm->pgm_led = pgm_default_led;
|
|
|
|
pgm->vfy_led = pgm_default_led;
|
|
|
|
|
2002-12-01 06:35:18 +00:00
|
|
|
/*
|
|
|
|
* optional functions - these are checked to make sure they are
|
|
|
|
* assigned before they are called
|
|
|
|
*/
|
2006-11-20 15:04:09 +00:00
|
|
|
pgm->cmd = NULL;
|
2011-08-23 21:03:36 +00:00
|
|
|
pgm->cmd_tpi = NULL;
|
2009-02-17 15:31:27 +00:00
|
|
|
pgm->spi = NULL;
|
2002-12-01 06:35:18 +00:00
|
|
|
pgm->paged_write = NULL;
|
|
|
|
pgm->paged_load = NULL;
|
2003-03-24 07:09:16 +00:00
|
|
|
pgm->write_setup = NULL;
|
2003-03-17 06:20:02 +00:00
|
|
|
pgm->read_sig_bytes = NULL;
|
2003-07-24 21:26:28 +00:00
|
|
|
pgm->set_vtarget = NULL;
|
|
|
|
pgm->set_varef = NULL;
|
|
|
|
pgm->set_fosc = NULL;
|
2006-10-09 14:34:24 +00:00
|
|
|
pgm->perform_osccal = NULL;
|
2007-11-06 19:42:16 +00:00
|
|
|
pgm->parseextparams = NULL;
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
pgm->setup = NULL;
|
|
|
|
pgm->teardown = NULL;
|
2002-12-01 06:35:18 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
return pgm;
|
|
|
|
}
|
|
|
|
|
2012-01-17 20:56:37 +00:00
|
|
|
void pgm_free(PROGRAMMER * const p)
|
|
|
|
{
|
|
|
|
ldestroy_cb(p->id,free);
|
|
|
|
p->id = NULL;
|
|
|
|
/* this is done by pgm_teardown, but usually cookie is not set to NULL */
|
|
|
|
/* if (p->cookie !=NULL) {
|
|
|
|
free(p->cookie);
|
|
|
|
p->cookie = NULL;
|
|
|
|
}*/
|
|
|
|
free(p);
|
|
|
|
}
|
2002-11-30 14:09:12 +00:00
|
|
|
|
2004-01-29 13:23:59 +00:00
|
|
|
static void pgm_default(void)
|
2002-11-30 14:09:12 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: programmer operation not supported\n", progname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-29 13:23:59 +00:00
|
|
|
static int pgm_default_2 (struct programmer_t * pgm, AVRPART * p)
|
2002-11-30 14:09:12 +00:00
|
|
|
{
|
|
|
|
pgm_default();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-11-20 15:04:09 +00:00
|
|
|
static int pgm_default_3 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem,
|
|
|
|
unsigned long addr, unsigned char * value)
|
|
|
|
{
|
|
|
|
pgm_default();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-29 13:23:59 +00:00
|
|
|
static void pgm_default_4 (struct programmer_t * pgm)
|
2002-11-30 14:09:12 +00:00
|
|
|
{
|
|
|
|
pgm_default();
|
|
|
|
}
|
|
|
|
|
2006-11-20 15:04:09 +00:00
|
|
|
static int pgm_default_5 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem,
|
|
|
|
unsigned long addr, unsigned char data)
|
2002-11-30 14:09:12 +00:00
|
|
|
{
|
|
|
|
pgm_default();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-01-30 13:41:54 +00:00
|
|
|
static void pgm_default_6 (struct programmer_t * pgm, const char * p)
|
2002-11-30 14:09:12 +00:00
|
|
|
{
|
|
|
|
pgm_default();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-30 13:41:54 +00:00
|
|
|
void programmer_display(PROGRAMMER * pgm, const char * p)
|
2007-01-24 22:43:46 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "%sProgrammer Type : %s\n", p, pgm->type);
|
|
|
|
fprintf(stderr, "%sDescription : %s\n", p, pgm->desc);
|
|
|
|
|
|
|
|
pgm->display(pgm, p);
|
|
|
|
}
|
|
|
|
|
2007-01-30 13:41:54 +00:00
|
|
|
PROGRAMMER * locate_programmer(LISTID programmers, const char * configid)
|
2007-01-24 22:43:46 +00:00
|
|
|
{
|
|
|
|
LNODEID ln1, ln2;
|
|
|
|
PROGRAMMER * p = NULL;
|
2007-01-30 13:41:54 +00:00
|
|
|
const char * id;
|
2007-01-24 22:43:46 +00:00
|
|
|
int found;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
|
|
|
|
for (ln1=lfirst(programmers); ln1 && !found; ln1=lnext(ln1)) {
|
|
|
|
p = ldata(ln1);
|
|
|
|
for (ln2=lfirst(p->id); ln2 && !found; ln2=lnext(ln2)) {
|
|
|
|
id = ldata(ln2);
|
|
|
|
if (strcasecmp(configid, id) == 0)
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return p;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-29 20:41:47 +00:00
|
|
|
/*
|
|
|
|
* Iterate over the list of programmers given as "programmers", and
|
|
|
|
* call the callback function cb for each entry found. cb is being
|
|
|
|
* passed the following arguments:
|
|
|
|
* . the name of the programmer (for -c)
|
|
|
|
* . the descriptive text given in the config file
|
|
|
|
* . the name of the config file this programmer has been defined in
|
|
|
|
* . the line number of the config file this programmer has been defined at
|
|
|
|
* . the "cookie" passed into walk_programmers() (opaque client data)
|
|
|
|
*/
|
|
|
|
void walk_programmers(LISTID programmers, walk_programmers_cb cb, void *cookie)
|
2007-01-24 22:43:46 +00:00
|
|
|
{
|
|
|
|
LNODEID ln1;
|
2011-12-16 20:44:07 +00:00
|
|
|
LNODEID ln2;
|
2007-01-24 22:43:46 +00:00
|
|
|
PROGRAMMER * p;
|
|
|
|
|
2007-01-29 20:41:47 +00:00
|
|
|
for (ln1 = lfirst(programmers); ln1; ln1 = lnext(ln1)) {
|
2007-01-24 22:43:46 +00:00
|
|
|
p = ldata(ln1);
|
2011-12-16 20:44:07 +00:00
|
|
|
for (ln2=lfirst(p->id); ln2; ln2=lnext(ln2)) {
|
|
|
|
cb(ldata(ln2), p->desc, p->config_file, p->lineno, cookie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare function to sort the list of programmers
|
|
|
|
*/
|
|
|
|
static int sort_programmer_compare(PROGRAMMER * p1,PROGRAMMER * p2)
|
|
|
|
{
|
|
|
|
char* id1;
|
|
|
|
char* id2;
|
|
|
|
if(p1 == NULL || p2 == NULL) {
|
|
|
|
return 0;
|
2007-01-24 22:43:46 +00:00
|
|
|
}
|
2011-12-16 20:44:07 +00:00
|
|
|
id1 = ldata(lfirst(p1->id));
|
|
|
|
id2 = ldata(lfirst(p2->id));
|
|
|
|
return strncasecmp(id1,id2,AVR_IDLEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort the list of programmers given as "programmers"
|
|
|
|
*/
|
|
|
|
void sort_programmers(LISTID programmers)
|
|
|
|
{
|
|
|
|
lsort(programmers,(int (*)(void*, void*)) sort_programmer_compare);
|
2007-01-24 22:43:46 +00:00
|
|
|
}
|
2007-01-29 20:41:47 +00:00
|
|
|
|