Enable interactive adjustment of the various

clock frequencies (JTAG Xmega, JTAG megaAVR, PDI Xmega)
through the set_sck_period() callback.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1121 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
joerg_wunsch 2012-12-03 16:52:23 +00:00
parent 707ddd2de9
commit 3024312901
2 changed files with 50 additions and 31 deletions

View File

@ -1,3 +1,9 @@
2012-12-03 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* jtag3.c: Enable interactive adjustment of the various
clock frequencies (JTAG Xmega, JTAG megaAVR, PDI Xmega)
through the set_sck_period() callback.
2012-12-03 Joerg Wunsch <j.gnu@uriah.heep.sax.de> 2012-12-03 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* jtag3.c: Remove unused code that was left over from * jtag3.c: Remove unused code that was left over from

75
jtag3.c
View File

@ -70,6 +70,9 @@ struct pdata
/* Start address of Xmega boot area */ /* Start address of Xmega boot area */
unsigned long boot_start; unsigned long boot_start;
/* Function to set the appropriate clock parameter */
int (*set_sck)(PROGRAMMER *, unsigned char *);
}; };
#define PDATA(pgm) ((struct pdata *)(pgm->cookie)) #define PDATA(pgm) ((struct pdata *)(pgm->cookie))
@ -674,6 +677,22 @@ static int jtag3_program_disable(PROGRAMMER * pgm)
return 0; return 0;
} }
static int jtag3_set_sck_xmega_pdi(PROGRAMMER *pgm, unsigned char *clk)
{
return jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_PDI, clk, 2);
}
static int jtag3_set_sck_xmega_jtag(PROGRAMMER *pgm, unsigned char *clk)
{
return jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_JTAG, clk, 2);
}
static int jtag3_set_sck_mega_jtag(PROGRAMMER *pgm, unsigned char *clk)
{
return jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_PROG, clk, 2);
}
/* /*
* initialize the AVR device and prepare it to accept commands * initialize the AVR device and prepare it to accept commands
*/ */
@ -722,7 +741,15 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
if (jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CONNECTION, parm, 1) < 0) if (jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CONNECTION, parm, 1) < 0)
return -1; return -1;
if (conn == PARM3_CONN_JTAG && pgm->bitclock != 0.0) if (conn == PARM3_CONN_PDI)
PDATA(pgm)->set_sck = jtag3_set_sck_xmega_pdi;
else if (conn == PARM3_CONN_JTAG) {
if (p->flags & AVRPART_HAS_PDI)
PDATA(pgm)->set_sck = jtag3_set_sck_xmega_jtag;
else
PDATA(pgm)->set_sck = jtag3_set_sck_mega_jtag;
}
if (pgm->bitclock != 0.0 && PDATA(pgm)->set_sck != NULL)
{ {
unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */ unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */
if (verbose >= 2) if (verbose >= 2)
@ -731,23 +758,10 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
progname, clock); progname, clock);
parm[0] = clock & 0xff; parm[0] = clock & 0xff;
parm[1] = (clock >> 8) & 0xff; parm[1] = (clock >> 8) & 0xff;
if (jtag3_setparm(pgm, SCOPE_AVR, 1, if (PDATA(pgm)->set_sck(pgm, parm) < 0)
((p->flags & AVRPART_HAS_PDI)? PARM3_CLK_XMEGA_JTAG: PARM3_CLK_MEGA_PROG),
parm, 2) < 0)
return -1;
}
if (conn == PARM3_CONN_PDI && pgm->bitclock != 0.0)
{
unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */
if (verbose >= 2)
fprintf(stderr, "%s: jtag3_initialize(): "
"trying to set PDI clock to %u kHz\n",
progname, clock);
parm[0] = clock & 0xff;
parm[1] = (clock >> 8) & 0xff;
if (jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_PDI, parm, 2) < 0)
return -1; return -1;
} }
if (conn == PARM3_CONN_JTAG) if (conn == PARM3_CONN_JTAG)
{ {
if (verbose >= 2) if (verbose >= 2)
@ -1609,22 +1623,19 @@ static int jtag3_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
*/ */
static int jtag3_set_sck_period(PROGRAMMER * pgm, double v) static int jtag3_set_sck_period(PROGRAMMER * pgm, double v)
{ {
#if 0 unsigned char parm[2];
unsigned char dur; unsigned int clock = 1E-3 / v; /* kHz */
v = 1 / v; /* convert to frequency */ parm[0] = clock & 0xff;
if (v >= 6.4e6) parm[1] = (clock >> 8) & 0xff;
dur = 0;
else if (v >= 2.8e6)
dur = 1;
else if (v >= 20.9e3)
dur = (unsigned char)(5.35e6 / v);
else
dur = 255;
return jtag3_setparm(pgm, PAR_OCD_JTAG_CLK, &dur); if (PDATA(pgm)->set_sck == NULL) {
#endif fprintf(stderr, "%s: No backend to set the SCK period for\n",
return 0; progname);
return -1;
}
return (PDATA(pgm)->set_sck(pgm, parm) < 0)? -1: 0;
} }
@ -1707,7 +1718,8 @@ int jtag3_setparm(PROGRAMMER * pgm, unsigned char scope,
status = jtag3_command(pgm, buf, length + 6, &resp, descr); status = jtag3_command(pgm, buf, length + 6, &resp, descr);
free(buf); free(buf);
free(resp); if (status > 0)
free(resp);
return status; return status;
} }
@ -1921,6 +1933,7 @@ void jtag3_pdi_initpgm(PROGRAMMER * pgm)
pgm->paged_load = jtag3_paged_load; pgm->paged_load = jtag3_paged_load;
pgm->page_erase = jtag3_page_erase; pgm->page_erase = jtag3_page_erase;
pgm->print_parms = jtag3_print_parms; pgm->print_parms = jtag3_print_parms;
pgm->set_sck_period = jtag3_set_sck_period;
pgm->setup = jtag3_setup; pgm->setup = jtag3_setup;
pgm->teardown = jtag3_teardown; pgm->teardown = jtag3_teardown;
pgm->page_size = 256; pgm->page_size = 256;