Utilise magic memory tree interface for avr910.c

This commit is contained in:
Stefan Rueger
2024-04-18 21:03:30 +01:00
parent 7e3854ff2f
commit 68d8023b6c
2 changed files with 12 additions and 16 deletions

View File

@@ -76,19 +76,13 @@ struct pdata
} while(0)
static void avr910_setup(PROGRAMMER * pgm)
{
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
pmsg_error("out of memory allocating private data\n");
exit(1);
}
memset(pgm->cookie, 0, sizeof(struct pdata));
static void avr910_setup(PROGRAMMER * pgm) {
pgm->cookie = mmt_malloc(sizeof(struct pdata));
PDATA(pgm)->test_blockmode = 1;
}
static void avr910_teardown(PROGRAMMER * pgm)
{
free(pgm->cookie);
static void avr910_teardown(PROGRAMMER * pgm) {
mmt_free(pgm->cookie);
}
@@ -596,9 +590,8 @@ static int avr910_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR
avr910_set_addr(pgm, isee? addr: addr>>1);
cmd = malloc(4 + blocksize);
if (!cmd) return -1;
cmd = mmt_malloc(4 + blocksize);
cmd[0] = 'B';
cmd[3] = isee? 'E': 'F';
@@ -610,13 +603,15 @@ static int avr910_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR
cmd[1] = (blocksize >> 8) & 0xff;
cmd[2] = blocksize & 0xff;
EI(avr910_send(pgm, cmd, 4 + blocksize));
if(avr910_vfy_cmd_sent(pgm, "write block") < 0)
if(avr910_send(pgm, cmd, 4 + blocksize) < 0 ||
avr910_vfy_cmd_sent(pgm, "write block") < 0) {
mmt_free(cmd);
return -1;
}
addr += blocksize;
}
free(cmd);
mmt_free(cmd);
}
return n_bytes;

View File

@@ -44,6 +44,7 @@ extern const char *pgmid; // Programmer -c string
#define mmt_strdup(s) cfg_strdup(__func__, s)
#define mmt_malloc(n) cfg_malloc(__func__, n)
#define mmt_realloc(p, n) cfg_realloc(__func__, p, n)
#define mmt_free(p) free(p)
int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int msgmode, int msglvl, const char *format, ...);