Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
avr.c File Reference
#include "ac_cfg.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "tpi.h"
+ Include dependency graph for avr.c:

Go to the source code of this file.

Macros

#define DEBUG   0
 

Functions

int avr_tpi_poll_nvmbsy (PROGRAMMER *pgm)
 
int avr_tpi_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
int avr_tpi_program_enable (PROGRAMMER *pgm, AVRPART *p, unsigned char guard_time)
 
static int avr_tpi_setup_rw (PROGRAMMER *pgm, AVRMEM *mem, unsigned long addr, unsigned char nvmcmd)
 
int avr_read_byte_default (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
 
int avr_mem_hiaddr (AVRMEM *mem)
 
int avr_read (PROGRAMMER *pgm, AVRPART *p, char *memtype, AVRPART *v)
 
int avr_write_page (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr)
 
int avr_write_byte_default (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
int avr_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
int avr_write (PROGRAMMER *pgm, AVRPART *p, char *memtype, int size, int auto_erase)
 
int avr_signature (PROGRAMMER *pgm, AVRPART *p)
 
int avr_verify (AVRPART *p, AVRPART *v, char *memtype, int size)
 
int avr_get_cycle_count (PROGRAMMER *pgm, AVRPART *p, int *cycles)
 
int avr_put_cycle_count (PROGRAMMER *pgm, AVRPART *p, int cycles)
 
int avr_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
void report_progress (int completed, int total, char *hdr)
 

Variables

FP_UpdateProgress update_progress
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG   0

Function Documentation

◆ avr_chip_erase()

int avr_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
1197{
1198 int rc;
1199
1200 rc = pgm->chip_erase(pgm, p);
1201
1202 return rc;
1203}
static PROGRAMMER * pgm
Definition main.c:192
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650

References programmer_t::chip_erase, and pgm.

Referenced by avrdude_main().

+ Here is the caller graph for this function:

◆ avr_get_cycle_count()

int avr_get_cycle_count ( PROGRAMMER pgm,
AVRPART p,
int *  cycles 
)
1131{
1132 AVRMEM * a;
1133 unsigned int cycle_count = 0;
1134 unsigned char v1;
1135 int rc;
1136 int i;
1137
1138 a = avr_locate_mem(p, "eeprom");
1139 if (a == NULL) {
1140 return -1;
1141 }
1142
1143 for (i=4; i>0; i--) {
1144 rc = pgm->read_byte(pgm, p, a, a->size-i, &v1);
1145 if (rc < 0) {
1146 avrdude_message(MSG_INFO, "%s: WARNING: can't read memory for cycle count, rc=%d\n",
1147 progname, rc);
1148 return -1;
1149 }
1150 cycle_count = (cycle_count << 8) | v1;
1151 }
1152
1153 /*
1154 * If the EEPROM is erased, the cycle count reads 0xffffffff.
1155 * In this case we return a cycle_count of zero.
1156 * So, the calling function don't have to care about whether or not
1157 * the cycle count was initialized.
1158 */
1159 if (cycle_count == 0xffffffff) {
1160 cycle_count = 0;
1161 }
1162
1163 *cycles = (int) cycle_count;
1164
1165 return 0;
1166}
#define MSG_INFO
Definition avrdude.h:51
char * progname
Definition main.c:61
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
AVRMEM * avr_locate_mem(AVRPART *p, char *desc)
Definition avrpart.c:354
Definition libavrdude.h:283
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670

References avr_locate_mem(), avrdude_message(), MSG_INFO, pgm, progname, and programmer_t::read_byte.

+ Here is the call graph for this function:

◆ avr_mem_hiaddr()

int avr_mem_hiaddr ( AVRMEM mem)
285{
286 int i, n;
287
288 /* return the highest non-0xff address regardless of how much
289 memory was read */
290 for (i=mem->size-1; i>0; i--) {
291 if (mem->buf[i] != 0xff) {
292 n = i+1;
293 if (n & 0x01)
294 return n+1;
295 else
296 return n;
297 }
298 }
299
300 return 0;
301}
int size
Definition libavrdude.h:286
unsigned char * buf
Definition libavrdude.h:304

References avrmem::buf, and avrmem::size.

Referenced by avr_read(), and fileio().

+ Here is the caller graph for this function:

◆ avr_put_cycle_count()

int avr_put_cycle_count ( PROGRAMMER pgm,
AVRPART p,
int  cycles 
)
1170{
1171 AVRMEM * a;
1172 unsigned char v1;
1173 int rc;
1174 int i;
1175
1176 a = avr_locate_mem(p, "eeprom");
1177 if (a == NULL) {
1178 return -1;
1179 }
1180
1181 for (i=1; i<=4; i++) {
1182 v1 = cycles & 0xff;
1183 cycles = cycles >> 8;
1184
1185 rc = avr_write_byte(pgm, p, a, a->size-i, v1);
1186 if (rc < 0) {
1187 avrdude_message(MSG_INFO, "%s: WARNING: can't write memory for cycle count, rc=%d\n",
1188 progname, rc);
1189 return -1;
1190 }
1191 }
1192
1193 return 0;
1194 }
int avr_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition avr.c:791

References avr_locate_mem(), avr_write_byte(), avrdude_message(), MSG_INFO, pgm, and progname.

+ Here is the call graph for this function:

◆ avr_read()

int avr_read ( PROGRAMMER pgm,
AVRPART p,
char *  memtype,
AVRPART v 
)
314{
315 unsigned long i, lastaddr;
316 unsigned char cmd[4];
317 AVRMEM * mem, * vmem = NULL;
318 int rc;
319
320 mem = avr_locate_mem(p, memtype);
321 if (v != NULL)
322 vmem = avr_locate_mem(v, memtype);
323 if (mem == NULL) {
324 avrdude_message(MSG_INFO, "No \"%s\" memory for part %s\n",
325 memtype, p->desc);
326 return -1;
327 }
328
329 /*
330 * start with all 0xff
331 */
332 memset(mem->buf, 0xff, mem->size);
333
334 /* supports "paged load" thru post-increment */
335 if ((p->flags & AVRPART_HAS_TPI) && mem->page_size != 0 &&
336 pgm->cmd_tpi != NULL) {
337
338 while (avr_tpi_poll_nvmbsy(pgm));
339
340 /* setup for read (NOOP) */
342
343 /* load bytes */
344 for (lastaddr = i = 0; i < (unsigned)mem->size; i++) {
346 if (vmem == NULL ||
347 (vmem->tags[i] & TAG_ALLOCATED) != 0)
348 {
349 if (lastaddr != i) {
350 /* need to setup new address */
352 lastaddr = i;
353 }
354 cmd[0] = TPI_CMD_SLD_PI;
355 rc = pgm->cmd_tpi(pgm, cmd, 1, mem->buf + i, 1);
356 lastaddr++;
357 if (rc == -1) {
358 avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i);
359 return -1;
360 }
361 }
362 report_progress(i, mem->size, NULL);
363 }
364 return avr_mem_hiaddr(mem);
365 }
366
367 if (pgm->paged_load != NULL && mem->page_size != 0) {
368 /*
369 * the programmer supports a paged mode read
370 */
371 int need_read, failure;
372 unsigned int pageaddr;
373 unsigned int npages, nread;
374
375 /* quickly scan number of pages to be written to first */
376 for (pageaddr = 0, npages = 0;
377 pageaddr < (unsigned)mem->size;
378 pageaddr += mem->page_size) {
379 /* check whether this page must be read */
380 for (i = pageaddr;
381 i < pageaddr + mem->page_size;
382 i++)
383 if (vmem == NULL /* no verify, read everything */ ||
384 (mem->tags[i] & TAG_ALLOCATED) != 0 /* verify, do only
385 read pages that
386 are needed in
387 input file */) {
388 npages++;
389 break;
390 }
391 }
392
393 for (pageaddr = 0, failure = 0, nread = 0;
394 !failure && pageaddr < (unsigned)mem->size;
395 pageaddr += mem->page_size) {
397 /* check whether this page must be read */
398 for (i = pageaddr, need_read = 0;
399 i < pageaddr + mem->page_size;
400 i++)
401 if (vmem == NULL /* no verify, read everything */ ||
402 (vmem->tags[i] & TAG_ALLOCATED) != 0 /* verify, do only
403 read pages that
404 are needed in
405 input file */) {
406 need_read = 1;
407 break;
408 }
409 if (need_read) {
410 rc = pgm->paged_load(pgm, p, mem, mem->page_size,
411 pageaddr, mem->page_size);
412 if (rc < 0)
413 /* paged load failed, fall back to byte-at-a-time read below */
414 failure = 1;
415 } else {
416 avrdude_message(MSG_DEBUG, "%s: avr_read(): skipping page %u: no interesting data\n",
417 progname, pageaddr / mem->page_size);
418 }
419 nread++;
420 report_progress(nread, npages, NULL);
421 }
422 if (!failure) {
423 if (strcasecmp(mem->desc, "flash") == 0 ||
424 strcasecmp(mem->desc, "application") == 0 ||
425 strcasecmp(mem->desc, "apptable") == 0 ||
426 strcasecmp(mem->desc, "boot") == 0)
427 return avr_mem_hiaddr(mem);
428 else
429 return mem->size;
430 }
431 /* else: fall back to byte-at-a-time write, for historical reasons */
432 }
433
434 if (strcmp(mem->desc, "signature") == 0) {
435 if (pgm->read_sig_bytes) {
436 return pgm->read_sig_bytes(pgm, p, mem);
437 }
438 }
439
440 for (i = 0; i < (unsigned)mem->size; i++) {
442 if (vmem == NULL ||
443 (vmem->tags[i] & TAG_ALLOCATED) != 0)
444 {
445 rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
446 if (rc != 0) {
447 avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i);
448 if (rc == -1)
449 avrdude_message(MSG_INFO, " read operation not supported for memory \"%s\"\n",
450 memtype);
451 return -2;
452 }
453 }
454 report_progress(i, mem->size, NULL);
455 }
456
457 if (strcasecmp(mem->desc, "flash") == 0 ||
458 strcasecmp(mem->desc, "application") == 0 ||
459 strcasecmp(mem->desc, "apptable") == 0 ||
460 strcasecmp(mem->desc, "boot") == 0)
461 return avr_mem_hiaddr(mem);
462 else
463 return i;
464}
int avr_mem_hiaddr(AVRMEM *mem)
Definition avr.c:284
void report_progress(int completed, int total, char *hdr)
Definition avr.c:1224
static int avr_tpi_setup_rw(PROGRAMMER *pgm, AVRMEM *mem, unsigned long addr, unsigned char nvmcmd)
Definition avr.c:154
int avr_tpi_poll_nvmbsy(PROGRAMMER *pgm)
Definition avr.c:44
#define MSG_DEBUG
Definition avrdude.h:54
#define TAG_ALLOCATED
Definition libavrdude.h:215
unsigned char * tags
Definition libavrdude.h:305
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
int page_size
Definition libavrdude.h:287
#define AVRPART_HAS_TPI
Definition libavrdude.h:206
#define RETURN_IF_CANCEL()
Definition libavrdude.h:733
unsigned flags
Definition libavrdude.h:230
char desc[AVR_MEMDESCLEN]
Definition libavrdude.h:284
int(* read_sig_bytes)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m)
Definition libavrdude.h:672
int(* paged_load)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:662
int(* cmd_tpi)(struct programmer_t *pgm, const unsigned char *cmd, int cmd_len, unsigned char res[], int res_len)
Definition libavrdude.h:653
struct command cmd[]
Definition term.c:94
#define TPI_CMD_SLD_PI
Definition tpi.h:42
#define TPI_NVMCMD_NO_OPERATION
Definition tpi.h:64
#define strcasecmp
Definition unistd.h:52

References avr_locate_mem(), avr_mem_hiaddr(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avrdude_message(), AVRPART_HAS_TPI, avrmem::buf, cmd, programmer_t::cmd_tpi, avrpart::desc, avrmem::desc, avrpart::flags, MSG_DEBUG, MSG_INFO, avrmem::page_size, programmer_t::paged_load, pgm, progname, programmer_t::read_byte, programmer_t::read_sig_bytes, report_progress(), RETURN_IF_CANCEL, avrmem::size, strcasecmp, TAG_ALLOCATED, avrmem::tags, TPI_CMD_SLD_PI, and TPI_NVMCMD_NO_OPERATION.

Referenced by avr_signature(), and do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_read_byte_default()

int avr_read_byte_default ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
185{
186 unsigned char cmd[4];
187 unsigned char res[4];
188 unsigned char data;
189 int r;
190 OPCODE * readop, * lext;
191
192 if (pgm->cmd == NULL) {
193 avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_read_byte_default() but does not\n"
194 "provide a cmd() method.\n",
195 progname, pgm->type);
196 return -1;
197 }
198
199 pgm->pgm_led(pgm, ON);
200 pgm->err_led(pgm, OFF);
201
202 if (p->flags & AVRPART_HAS_TPI) {
203 if (pgm->cmd_tpi == NULL) {
204 avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
205 progname, pgm->type);
206 return -1;
207 }
208
209 while (avr_tpi_poll_nvmbsy(pgm));
210
211 /* setup for read */
213
214 /* load byte */
215 cmd[0] = TPI_CMD_SLD;
216 r = pgm->cmd_tpi(pgm, cmd, 1, value, 1);
217 if (r == -1)
218 return -1;
219
220 return 0;
221 }
222
223 /*
224 * figure out what opcode to use
225 */
226 if (mem->op[AVR_OP_READ_LO]) {
227 if (addr & 0x00000001)
228 readop = mem->op[AVR_OP_READ_HI];
229 else
230 readop = mem->op[AVR_OP_READ_LO];
231 addr = addr / 2;
232 }
233 else {
234 readop = mem->op[AVR_OP_READ];
235 }
236
237 if (readop == NULL) {
238#if DEBUG
239 avrdude_message(MSG_INFO, "avr_read_byte(): operation not supported on memory type \"%s\"\n",
240 mem->desc);
241#endif
242 return -1;
243 }
244
245 /*
246 * If this device has a "load extended address" command, issue it.
247 */
248 lext = mem->op[AVR_OP_LOAD_EXT_ADDR];
249 if (lext != NULL) {
250 memset(cmd, 0, sizeof(cmd));
251
252 avr_set_bits(lext, cmd);
253 avr_set_addr(lext, cmd, addr);
254 r = pgm->cmd(pgm, cmd, res);
255 if (r < 0)
256 return r;
257 }
258
259 memset(cmd, 0, sizeof(cmd));
260
261 avr_set_bits(readop, cmd);
262 avr_set_addr(readop, cmd, addr);
263 r = pgm->cmd(pgm, cmd, res);
264 if (r < 0)
265 return r;
266 data = 0;
267 avr_get_output(readop, res, &data);
268
269 pgm->pgm_led(pgm, OFF);
270
271 *value = data;
272
273 return 0;
274}
int avr_get_output(OPCODE *op, unsigned char *res, unsigned char *data)
Definition avrpart.c:165
int avr_set_addr(OPCODE *op, unsigned char *cmd, unsigned long addr)
Definition avrpart.c:107
int avr_set_bits(OPCODE *op, unsigned char *cmd)
Definition avrpart.c:80
#define OFF
Definition libavrdude.h:585
@ AVR_OP_READ
Definition libavrdude.h:146
@ AVR_OP_READ_LO
Definition libavrdude.h:148
@ AVR_OP_LOAD_EXT_ADDR
Definition libavrdude.h:154
@ AVR_OP_READ_HI
Definition libavrdude.h:149
#define ON
Definition libavrdude.h:584
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:306
Definition libavrdude.h:190
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651
int(* pgm_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:641
int(* err_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:640
char type[PGM_TYPELEN]
Definition libavrdude.h:619
#define TPI_CMD_SLD
Definition tpi.h:41

References avr_get_output(), AVR_OP_LOAD_EXT_ADDR, AVR_OP_READ, AVR_OP_READ_HI, AVR_OP_READ_LO, avr_set_addr(), avr_set_bits(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avrdude_message(), AVRPART_HAS_TPI, programmer_t::cmd, cmd, programmer_t::cmd_tpi, avrmem::desc, programmer_t::err_led, avrpart::flags, MSG_INFO, OFF, ON, avrmem::op, pgm, programmer_t::pgm_led, progname, TPI_CMD_SLD, TPI_NVMCMD_NO_OPERATION, and programmer_t::type.

Referenced by avr910_read_byte(), buspirate_bb_initpgm(), buspirate_initpgm(), serbb_initpgm(), and stk500_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_signature()

int avr_signature ( PROGRAMMER pgm,
AVRPART p 
)
1056{
1057 int rc;
1058
1059 report_progress(0,1,"Reading");
1060 rc = avr_read(pgm, p, "signature", 0);
1061 if (rc < 0) {
1062 avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n",
1063 progname, p->desc, rc);
1064 return -1;
1065 }
1066 report_progress(1,1,NULL);
1067
1068 return 0;
1069}
int avr_read(PROGRAMMER *pgm, AVRPART *p, char *memtype, AVRPART *v)
Definition avr.c:312

References avr_read(), avrdude_message(), avrpart::desc, MSG_INFO, pgm, progname, and report_progress().

Referenced by avrdude_main(), and cmd_sig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_tpi_chip_erase()

int avr_tpi_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
56{
57 int err;
58 AVRMEM *mem;
59
60 if (p->flags & AVRPART_HAS_TPI) {
61 pgm->pgm_led(pgm, ON);
62
63 /* Set Pointer Register */
64 mem = avr_locate_mem(p, "flash");
65 if (mem == NULL) {
66 avrdude_message(MSG_INFO, "No flash memory to erase for part %s\n",
67 p->desc);
68 return -1;
69 }
70
71 unsigned char cmd[] = {
72 /* write pointer register high byte */
73 (TPI_CMD_SSTPR | 0),
74 ((mem->offset & 0xFF) | 1),
75 /* and low byte */
76 (TPI_CMD_SSTPR | 1),
77 ((mem->offset >> 8) & 0xFF),
78 /* write CHIP_ERASE command to NVMCMD register */
81 /* write dummy value to start erase */
83 0xFF
84 };
85
86 while (avr_tpi_poll_nvmbsy(pgm));
87
88 err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
89 if(err)
90 return err;
91
92 while (avr_tpi_poll_nvmbsy(pgm));
93
94 pgm->pgm_led(pgm, OFF);
95
96 return 0;
97 } else {
98 avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
99 return -1;
100 }
101}
unsigned int offset
Definition libavrdude.h:289
#define TPI_CMD_SSTPR
Definition tpi.h:50
#define TPI_SIO_ADDR(x)
Definition tpi.h:54
#define TPI_IOREG_NVMCMD
Definition tpi.h:58
#define TPI_CMD_SST
Definition tpi.h:46
#define TPI_CMD_SOUT
Definition tpi.h:44
#define TPI_NVMCMD_CHIP_ERASE
Definition tpi.h:65
#define __func__
Definition unistd.h:26

References __func__, avr_locate_mem(), avr_tpi_poll_nvmbsy(), avrdude_message(), AVRPART_HAS_TPI, cmd, programmer_t::cmd_tpi, avrpart::desc, avrpart::flags, MSG_INFO, OFF, avrmem::offset, ON, pgm, programmer_t::pgm_led, TPI_CMD_SOUT, TPI_CMD_SST, TPI_CMD_SSTPR, TPI_IOREG_NVMCMD, TPI_NVMCMD_CHIP_ERASE, and TPI_SIO_ADDR.

+ Here is the call graph for this function:

◆ avr_tpi_poll_nvmbsy()

int avr_tpi_poll_nvmbsy ( PROGRAMMER pgm)
45{
46 unsigned char cmd;
47 unsigned char res;
48
50 (void)pgm->cmd_tpi(pgm, &cmd, 1, &res, 1);
51 return (res & TPI_IOREG_NVMCSR_NVMBSY);
52}
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
#define TPI_CMD_SIN
Definition tpi.h:43
#define TPI_IOREG_NVMCSR
Definition tpi.h:57
#define TPI_IOREG_NVMCSR_NVMBSY
Definition tpi.h:61

References cmd, programmer_t::cmd_tpi, pgm, TPI_CMD_SIN, TPI_IOREG_NVMCSR, TPI_IOREG_NVMCSR_NVMBSY, TPI_SIO_ADDR, and void().

Referenced by avr_read(), avr_read_byte_default(), avr_tpi_chip_erase(), avr_write(), avr_write_byte_default(), and bitbang_chip_erase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_tpi_program_enable()

int avr_tpi_program_enable ( PROGRAMMER pgm,
AVRPART p,
unsigned char  guard_time 
)
105{
106 int err, retry;
107 unsigned char cmd[2];
108 unsigned char response;
109
110 if(p->flags & AVRPART_HAS_TPI) {
111 /* set guard time */
113 cmd[1] = guard_time;
114
115 err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
116 if(err)
117 return err;
118
119 /* read TPI ident reg */
121 err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
122 if (err || response != TPI_IDENT_CODE) {
123 avrdude_message(MSG_INFO, "TPIIR not correct\n");
124 return -1;
125 }
126
127 /* send SKEY command + SKEY */
128 err = pgm->cmd_tpi(pgm, tpi_skey_cmd, sizeof(tpi_skey_cmd), NULL, 0);
129 if(err)
130 return err;
131
132 /* check if device is ready */
133 for(retry = 0; retry < 10; retry++)
134 {
136 err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
137 if(err || !(response & TPI_REG_TPISR_NVMEN))
138 continue;
139
140 return 0;
141 }
142
143 avrdude_message(MSG_INFO, "Error enabling TPI external programming mode:");
144 avrdude_message(MSG_INFO, "Target does not reply\n");
145 return -1;
146
147 } else {
148 avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
149 return -1;
150 }
151}
#define TPI_REG_TPIPCR
Definition tpi.h:35
#define TPI_CMD_SLDCS
Definition tpi.h:49
#define TPI_REG_TPIIR
Definition tpi.h:31
#define TPI_IDENT_CODE
Definition tpi.h:33
static const unsigned char tpi_skey_cmd[]
Definition tpi.h:69
#define TPI_REG_TPISR_NVMEN
Definition tpi.h:38
#define TPI_REG_TPISR
Definition tpi.h:36
#define TPI_CMD_SSTCS
Definition tpi.h:45

References __func__, avrdude_message(), AVRPART_HAS_TPI, cmd, programmer_t::cmd_tpi, avrpart::flags, MSG_INFO, pgm, TPI_CMD_SLDCS, TPI_CMD_SSTCS, TPI_IDENT_CODE, TPI_REG_TPIIR, TPI_REG_TPIPCR, TPI_REG_TPISR, TPI_REG_TPISR_NVMEN, and tpi_skey_cmd.

+ Here is the call graph for this function:

◆ avr_tpi_setup_rw()

static int avr_tpi_setup_rw ( PROGRAMMER pgm,
AVRMEM mem,
unsigned long  addr,
unsigned char  nvmcmd 
)
static
156{
157 unsigned char cmd[4];
158 int rc;
159
160 /* set NVMCMD register */
162 cmd[1] = nvmcmd;
163 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
164 if (rc == -1)
165 return -1;
166
167 /* set Pointer Register (PR) */
168 cmd[0] = TPI_CMD_SSTPR | 0;
169 cmd[1] = (mem->offset + addr) & 0xFF;
170 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
171 if (rc == -1)
172 return -1;
173
174 cmd[0] = TPI_CMD_SSTPR | 1;
175 cmd[1] = ((mem->offset + addr) >> 8) & 0xFF;
176 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
177 if (rc == -1)
178 return -1;
179
180 return 0;
181}

References cmd, programmer_t::cmd_tpi, avrmem::offset, pgm, TPI_CMD_SOUT, TPI_CMD_SSTPR, TPI_IOREG_NVMCMD, and TPI_SIO_ADDR.

Referenced by avr_read(), avr_read_byte_default(), avr_write(), and avr_write_byte_default().

+ Here is the caller graph for this function:

◆ avr_verify()

int avr_verify ( AVRPART p,
AVRPART v,
char *  memtype,
int  size 
)
1080{
1081 int i;
1082 unsigned char * buf1, * buf2;
1083 int vsize;
1084 AVRMEM * a, * b;
1085
1086 a = avr_locate_mem(p, memtype);
1087 if (a == NULL) {
1088 avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
1089 memtype, p->desc);
1090 return -1;
1091 }
1092
1093 b = avr_locate_mem(v, memtype);
1094 if (b == NULL) {
1095 avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
1096 memtype, v->desc);
1097 return -1;
1098 }
1099
1100 buf1 = a->buf;
1101 buf2 = b->buf;
1102 vsize = a->size;
1103
1104 if (vsize < size) {
1105 avrdude_message(MSG_INFO, "%s: WARNING: requested verification for %d bytes\n"
1106 "%s%s memory region only contains %d bytes\n"
1107 "%sOnly %d bytes will be verified.\n",
1108 progname, size,
1109 progbuf, memtype, vsize,
1110 progbuf, vsize);
1111 size = vsize;
1112 }
1113
1114 for (i=0; i<size; i++) {
1116 if ((b->tags[i] & TAG_ALLOCATED) != 0 &&
1117 buf1[i] != buf2[i]) {
1118 avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n"
1119 "%s0x%02x != 0x%02x\n",
1120 progname, i,
1121 progbuf, buf1[i], buf2[i]);
1122 return -1;
1123 }
1124 }
1125
1126 return size;
1127}
char progbuf[]
Definition main.c:62
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183

References avr_locate_mem(), avrdude_message(), avrpart::desc, MSG_INFO, progbuf, progname, RETURN_IF_CANCEL, and TAG_ALLOCATED.

Referenced by do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write()

int avr_write ( PROGRAMMER pgm,
AVRPART p,
char *  memtype,
int  size,
int  auto_erase 
)
833{
834 int rc;
835 int newpage, page_tainted, flush_page, do_write;
836 int wsize;
837 unsigned int i, lastaddr;
838 unsigned char data;
839 int werror;
840 unsigned char cmd[4];
841 AVRMEM * m;
842
843 m = avr_locate_mem(p, memtype);
844 if (m == NULL) {
845 avrdude_message(MSG_INFO, "No \"%s\" memory for part %s\n",
846 memtype, p->desc);
847 return -1;
848 }
849
850 pgm->err_led(pgm, OFF);
851
852 werror = 0;
853
854 wsize = m->size;
855 if (size < wsize) {
856 wsize = size;
857 }
858 else if (size > wsize) {
859 avrdude_message(MSG_INFO, "%s: WARNING: %d bytes requested, but memory region is only %d"
860 "bytes\n"
861 "%sOnly %d bytes will actually be written\n",
862 progname, size, wsize,
863 progbuf, wsize);
864 }
865
866
867 if ((p->flags & AVRPART_HAS_TPI) && m->page_size != 0 &&
868 pgm->cmd_tpi != NULL) {
869
870 while (avr_tpi_poll_nvmbsy(pgm));
871
872 /* setup for WORD_WRITE */
874
875 /* make sure it's aligned to a word boundary */
876 if (wsize & 0x1) {
877 wsize++;
878 }
879
880 /* write words, low byte first */
881 for (lastaddr = i = 0; i < (unsigned)wsize; i += 2) {
883 if ((m->tags[i] & TAG_ALLOCATED) != 0 ||
884 (m->tags[i + 1] & TAG_ALLOCATED) != 0) {
885
886 if (lastaddr != i) {
887 /* need to setup new address */
889 lastaddr = i;
890 }
891
892 cmd[0] = TPI_CMD_SST_PI;
893 cmd[1] = m->buf[i];
894 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
895
896 cmd[1] = m->buf[i + 1];
897 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
898
899 lastaddr += 2;
900
901 while (avr_tpi_poll_nvmbsy(pgm));
902 }
903 report_progress(i, wsize, NULL);
904 }
905 return i;
906 }
907
908 if (pgm->paged_write != NULL && m->page_size != 0) {
909 /*
910 * the programmer supports a paged mode write
911 */
912 int need_write, failure;
913 unsigned int pageaddr;
914 unsigned int npages, nwritten;
915
916 /* quickly scan number of pages to be written to first */
917 for (pageaddr = 0, npages = 0;
918 pageaddr < (unsigned)wsize;
919 pageaddr += m->page_size) {
920 /* check whether this page must be written to */
921 for (i = pageaddr;
922 i < pageaddr + m->page_size;
923 i++)
924 if ((m->tags[i] & TAG_ALLOCATED) != 0) {
925 npages++;
926 break;
927 }
928 }
929
930 for (pageaddr = 0, failure = 0, nwritten = 0;
931 !failure && pageaddr < (unsigned)wsize;
932 pageaddr += m->page_size) {
934 /* check whether this page must be written to */
935 for (i = pageaddr, need_write = 0;
936 i < pageaddr + m->page_size;
937 i++)
938 if ((m->tags[i] & TAG_ALLOCATED) != 0) {
939 need_write = 1;
940 break;
941 }
942 if (need_write) {
943 rc = 0;
944 if (auto_erase)
945 rc = pgm->page_erase(pgm, p, m, pageaddr);
946 if (rc >= 0)
947 rc = pgm->paged_write(pgm, p, m, m->page_size, pageaddr, m->page_size);
948 if (rc < 0)
949 /* paged write failed, fall back to byte-at-a-time write below */
950 failure = 1;
951 } else {
952 avrdude_message(MSG_DEBUG, "%s: avr_write(): skipping page %u: no interesting data\n",
953 progname, pageaddr / m->page_size);
954 }
955 nwritten++;
956 report_progress(nwritten, npages, NULL);
957 }
958 if (!failure)
959 return wsize;
960 /* else: fall back to byte-at-a-time write, for historical reasons */
961 }
962
963 if (pgm->write_setup) {
964 pgm->write_setup(pgm, p, m);
965 }
966
967 newpage = 1;
968 page_tainted = 0;
969 flush_page = 0;
970
971 for (i = 0; i < (unsigned)wsize; i++) {
973 data = m->buf[i];
974 report_progress(i, wsize, NULL);
975
976 /*
977 * Find out whether the write action must be invoked for this
978 * byte.
979 *
980 * For non-paged memory, this only happens if TAG_ALLOCATED is
981 * set for the byte.
982 *
983 * For paged memory, TAG_ALLOCATED also invokes the write
984 * operation, which is actually a page buffer fill only. This
985 * "taints" the page, and upon encountering the last byte of each
986 * tainted page, the write operation must also be invoked in order
987 * to actually write the page buffer to memory.
988 */
989 do_write = (m->tags[i] & TAG_ALLOCATED) != 0;
990 if (m->paged) {
991 if (newpage) {
992 page_tainted = do_write;
993 } else {
994 page_tainted |= do_write;
995 }
996 if (i % m->page_size == m->page_size - 1 ||
997 i == wsize - 1) {
998 /* last byte this page */
999 flush_page = page_tainted;
1000 newpage = 1;
1001 } else {
1002 flush_page = newpage = 0;
1003 }
1004 }
1005
1006 if (!do_write && !flush_page) {
1007 continue;
1008 }
1009
1010 if (do_write) {
1011 rc = avr_write_byte(pgm, p, m, i, data);
1012 if (rc) {
1013 avrdude_message(MSG_INFO, " ***failed; ");
1015 pgm->err_led(pgm, ON);
1016 werror = 1;
1017 }
1018 }
1019
1020 /*
1021 * check to see if it is time to flush the page with a page
1022 * write
1023 */
1024 if (flush_page) {
1025 rc = avr_write_page(pgm, p, m, i);
1026 if (rc) {
1027 avrdude_message(MSG_INFO, " *** page %d (addresses 0x%04x - 0x%04x) failed "
1028 "to write\n",
1029 i % m->page_size,
1030 i - m->page_size + 1, i);
1032 pgm->err_led(pgm, ON);
1033 werror = 1;
1034 }
1035 }
1036
1037 if (werror) {
1038 /*
1039 * make sure the error led stay on if there was a previous write
1040 * error, otherwise it gets cleared in avr_write_byte()
1041 */
1042 pgm->err_led(pgm, ON);
1043 return -1;
1044 }
1045 }
1046
1047 return i;
1048}
int avr_write_page(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr)
Definition avr.c:470
int paged
Definition libavrdude.h:285
int(* paged_write)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:659
void(* write_setup)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m)
Definition libavrdude.h:667
int(* page_erase)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int baseaddr)
Definition libavrdude.h:665
#define TPI_NVMCMD_WORD_WRITE
Definition tpi.h:67
#define TPI_CMD_SST_PI
Definition tpi.h:47

References avr_locate_mem(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avr_write_byte(), avr_write_page(), avrdude_message(), AVRPART_HAS_TPI, avrmem::buf, cmd, programmer_t::cmd_tpi, avrpart::desc, programmer_t::err_led, avrpart::flags, MSG_DEBUG, MSG_INFO, OFF, ON, programmer_t::page_erase, avrmem::page_size, avrmem::paged, programmer_t::paged_write, pgm, progbuf, progname, report_progress(), RETURN_IF_CANCEL, avrmem::size, TAG_ALLOCATED, avrmem::tags, TPI_CMD_SST_PI, TPI_NVMCMD_WORD_WRITE, and programmer_t::write_setup.

Referenced by do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write_byte()

int avr_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
793{
794
795 unsigned char safemode_lfuse;
796 unsigned char safemode_hfuse;
797 unsigned char safemode_efuse;
798 unsigned char safemode_fuse;
799
800 /* If we write the fuses, then we need to tell safemode that they *should* change */
801 safemode_memfuses(0, &safemode_lfuse, &safemode_hfuse, &safemode_efuse, &safemode_fuse);
802
803 if (strcmp(mem->desc, "fuse")==0) {
804 safemode_fuse = data;
805 }
806 if (strcmp(mem->desc, "lfuse")==0) {
807 safemode_lfuse = data;
808 }
809 if (strcmp(mem->desc, "hfuse")==0) {
810 safemode_hfuse = data;
811 }
812 if (strcmp(mem->desc, "efuse")==0) {
813 safemode_efuse = data;
814 }
815
816 safemode_memfuses(1, &safemode_lfuse, &safemode_hfuse, &safemode_efuse, &safemode_fuse);
817
818 return pgm->write_byte(pgm, p, mem, addr, data);
819}
int safemode_memfuses(int save, unsigned char *lfuse, unsigned char *hfuse, unsigned char *efuse, unsigned char *fuse)
Definition safemode.c:290
int(* write_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition libavrdude.h:668

References avrmem::desc, pgm, safemode_memfuses(), and programmer_t::write_byte.

Referenced by avr_put_cycle_count(), avr_write(), cmd_write(), and safemode_writefuse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write_byte_default()

int avr_write_byte_default ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
532{
533 unsigned char cmd[4];
534 unsigned char res[4];
535 unsigned char r;
536 int ready;
537 int tries;
538 unsigned long start_time;
539 unsigned long prog_time;
540 unsigned char b;
541 unsigned short caddr;
542 OPCODE * writeop;
543 int rc;
544 int readok=0;
545 struct timeval tv;
546
547 if (pgm->cmd == NULL) {
548 avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_byte_default() but does not\n"
549 "provide a cmd() method.\n",
550 progname, pgm->type);
551 return -1;
552 }
553
554 if (p->flags & AVRPART_HAS_TPI) {
555 if (pgm->cmd_tpi == NULL) {
556 avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
557 progname, pgm->type);
558 return -1;
559 }
560
561 if (strcmp(mem->desc, "flash") == 0) {
562 avrdude_message(MSG_INFO, "Writing a byte to flash is not supported for %s\n", p->desc);
563 return -1;
564 } else if ((mem->offset + addr) & 1) {
565 avrdude_message(MSG_INFO, "Writing a byte to an odd location is not supported for %s\n", p->desc);
566 return -1;
567 }
568
569 while (avr_tpi_poll_nvmbsy(pgm));
570
571 /* must erase fuse first */
572 if (strcmp(mem->desc, "fuse") == 0) {
573 /* setup for SECTION_ERASE (high byte) */
575
576 /* write dummy byte */
577 cmd[0] = TPI_CMD_SST;
578 cmd[1] = 0xFF;
579 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
580
581 while (avr_tpi_poll_nvmbsy(pgm));
582 }
583
584 /* setup for WORD_WRITE */
586
587 cmd[0] = TPI_CMD_SST_PI;
588 cmd[1] = data;
589 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
590 /* dummy high byte to start WORD_WRITE */
591 cmd[0] = TPI_CMD_SST_PI;
592 cmd[1] = data;
593 rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
594
595 while (avr_tpi_poll_nvmbsy(pgm));
596
597 return 0;
598 }
599
600 if (!mem->paged &&
601 (p->flags & AVRPART_IS_AT90S1200) == 0) {
602 /*
603 * check to see if the write is necessary by reading the existing
604 * value and only write if we are changing the value; we can't
605 * use this optimization for paged addressing.
606 *
607 * For mysterious reasons, on the AT90S1200, this read operation
608 * sometimes causes the high byte of the same word to be
609 * programmed to the value of the low byte that has just been
610 * programmed before. Avoid that optimization on this device.
611 */
612 rc = pgm->read_byte(pgm, p, mem, addr, &b);
613 if (rc != 0) {
614 if (rc != -1) {
615 return -2;
616 }
617 /*
618 * the read operation is not support on this memory type
619 */
620 }
621 else {
622 readok = 1;
623 if (b == data) {
624 return 0;
625 }
626 }
627 }
628
629 /*
630 * determine which memory opcode to use
631 */
632 if (mem->op[AVR_OP_WRITE_LO]) {
633 if (addr & 0x01)
634 writeop = mem->op[AVR_OP_WRITE_HI];
635 else
636 writeop = mem->op[AVR_OP_WRITE_LO];
637 caddr = (unsigned short)(addr / 2);
638 }
639 else if (mem->paged && mem->op[AVR_OP_LOADPAGE_LO]) {
640 if (addr & 0x01)
641 writeop = mem->op[AVR_OP_LOADPAGE_HI];
642 else
643 writeop = mem->op[AVR_OP_LOADPAGE_LO];
644 caddr = (unsigned short)(addr / 2);
645 }
646 else {
647 writeop = mem->op[AVR_OP_WRITE];
648 caddr = (unsigned short)addr;
649 }
650
651 if (writeop == NULL) {
652#if DEBUG
653 avrdude_message(MSG_INFO, "avr_write_byte(): write not supported for memory type \"%s\"\n",
654 mem->desc);
655#endif
656 return -1;
657 }
658
659
660 pgm->pgm_led(pgm, ON);
661 pgm->err_led(pgm, OFF);
662
663 memset(cmd, 0, sizeof(cmd));
664
665 avr_set_bits(writeop, cmd);
666 avr_set_addr(writeop, cmd, caddr);
667 avr_set_input(writeop, cmd, data);
668 pgm->cmd(pgm, cmd, res);
669
670 if (mem->paged) {
671 /*
672 * in paged addressing, single bytes to be written to the memory
673 * page complete immediately, we only need to delay when we commit
674 * the whole page via the avr_write_page() routine.
675 */
676 pgm->pgm_led(pgm, OFF);
677 return 0;
678 }
679
680 if (readok == 0) {
681 /*
682 * read operation not supported for this memory type, just wait
683 * the max programming time and then return
684 */
685 usleep(mem->max_write_delay); /* maximum write delay */
686 pgm->pgm_led(pgm, OFF);
687 return 0;
688 }
689
690 tries = 0;
691 ready = 0;
692 while (!ready) {
693
694 if ((data == mem->readback[0]) ||
695 (data == mem->readback[1])) {
696 /*
697 * use an extra long delay when we happen to be writing values
698 * used for polled data read-back. In this case, polling
699 * doesn't work, and we need to delay the worst case write time
700 * specified for the chip.
701 */
703 rc = pgm->read_byte(pgm, p, mem, addr, &r);
704 if (rc != 0) {
705 pgm->pgm_led(pgm, OFF);
706 pgm->err_led(pgm, OFF);
707 return -5;
708 }
709 }
710 else {
711 gettimeofday (&tv, NULL);
712 start_time = (tv.tv_sec * 1000000) + tv.tv_usec;
713 do {
714 /*
715 * Do polling, but timeout after max_write_delay.
716 */
717 rc = pgm->read_byte(pgm, p, mem, addr, &r);
718 if (rc != 0) {
719 pgm->pgm_led(pgm, OFF);
720 pgm->err_led(pgm, ON);
721 return -4;
722 }
723 gettimeofday (&tv, NULL);
724 prog_time = (tv.tv_sec * 1000000) + tv.tv_usec;
725 } while ((r != data) &&
726 ((prog_time - start_time) < (unsigned long)mem->max_write_delay));
727 }
728
729 /*
730 * At this point we either have a valid readback or the
731 * max_write_delay is expired.
732 */
733
734 if (r == data) {
735 ready = 1;
736 }
737 else if (mem->pwroff_after_write) {
738 /*
739 * The device has been flagged as power-off after write to this
740 * memory type. The reason we don't just blindly follow the
741 * flag is that the power-off advice may only apply to some
742 * memory bits but not all. We only actually power-off the
743 * device if the data read back does not match what we wrote.
744 */
745 pgm->pgm_led(pgm, OFF);
746 avrdude_message(MSG_INFO, "%s: this device must be powered off and back on to continue\n",
747 progname);
748 if (pgm->pinno[PPI_AVR_VCC]) {
749 avrdude_message(MSG_INFO, "%s: attempting to do this now ...\n", progname);
750 pgm->powerdown(pgm);
751 usleep(250000);
752 rc = pgm->initialize(pgm, p);
753 if (rc < 0) {
754 avrdude_message(MSG_INFO, "%s: initialization failed, rc=%d\n", progname, rc);
755 avrdude_message(MSG_INFO, "%s: can't re-initialize device after programming the "
756 "%s bits\n", progname, mem->desc);
757 avrdude_message(MSG_INFO, "%s: you must manually power-down the device and restart\n"
758 "%s: %s to continue.\n",
760 return -3;
761 }
762
763 avrdude_message(MSG_INFO, "%s: device was successfully re-initialized\n",
764 progname);
765 return 0;
766 }
767 }
768
769 tries++;
770 if (!ready && tries > 5) {
771 /*
772 * we wrote the data, but after waiting for what should have
773 * been plenty of time, the memory cell still doesn't match what
774 * we wrote. Indicate a write error.
775 */
776 pgm->pgm_led(pgm, OFF);
777 pgm->err_led(pgm, ON);
778
779 return -6;
780 }
781 }
782
783 pgm->pgm_led(pgm, OFF);
784 return 0;
785}
int avr_set_input(OPCODE *op, unsigned char *cmd, unsigned char data)
Definition avrpart.c:136
#define AVRPART_IS_AT90S1200
Definition libavrdude.h:207
unsigned char readback[2]
Definition libavrdude.h:296
int max_write_delay
Definition libavrdude.h:291
@ AVR_OP_WRITE_LO
Definition libavrdude.h:150
@ AVR_OP_LOADPAGE_LO
Definition libavrdude.h:152
@ AVR_OP_WRITE_HI
Definition libavrdude.h:151
@ AVR_OP_LOADPAGE_HI
Definition libavrdude.h:153
@ AVR_OP_WRITE
Definition libavrdude.h:147
@ PPI_AVR_VCC
Definition libavrdude.h:353
int pwroff_after_write
Definition libavrdude.h:292
unsigned int pinno[N_PINS]
Definition libavrdude.h:622
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
void(* powerdown)(struct programmer_t *pgm)
Definition libavrdude.h:648
#define TPI_NVMCMD_SECTION_ERASE
Definition tpi.h:66
int usleep(unsigned usec)
Definition unistd.cpp:13
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition unistd.cpp:21

References AVR_OP_LOADPAGE_HI, AVR_OP_LOADPAGE_LO, AVR_OP_WRITE, AVR_OP_WRITE_HI, AVR_OP_WRITE_LO, avr_set_addr(), avr_set_bits(), avr_set_input(), avr_tpi_poll_nvmbsy(), avr_tpi_setup_rw(), avrdude_message(), AVRPART_HAS_TPI, AVRPART_IS_AT90S1200, programmer_t::cmd, cmd, programmer_t::cmd_tpi, avrpart::desc, avrmem::desc, programmer_t::err_led, avrpart::flags, gettimeofday(), programmer_t::initialize, avrmem::max_write_delay, MSG_INFO, OFF, avrmem::offset, ON, avrmem::op, avrmem::paged, pgm, programmer_t::pgm_led, programmer_t::pinno, programmer_t::powerdown, PPI_AVR_VCC, progname, avrmem::pwroff_after_write, programmer_t::read_byte, avrmem::readback, TPI_CMD_SST, TPI_CMD_SST_PI, TPI_NVMCMD_SECTION_ERASE, TPI_NVMCMD_WORD_WRITE, programmer_t::type, and usleep().

Referenced by avr910_write_byte(), buspirate_bb_initpgm(), buspirate_initpgm(), serbb_initpgm(), and stk500_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr_write_page()

int avr_write_page ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr 
)
472{
473 unsigned char cmd[4];
474 unsigned char res[4];
475 OPCODE * wp, * lext;
476
477 if (pgm->cmd == NULL) {
478 avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_page() but does not\n"
479 "provide a cmd() method.\n",
480 progname, pgm->type);
481 return -1;
482 }
483
484 wp = mem->op[AVR_OP_WRITEPAGE];
485 if (wp == NULL) {
486 avrdude_message(MSG_INFO, "avr_write_page(): memory \"%s\" not configured for page writes\n",
487 mem->desc);
488 return -1;
489 }
490
491 /*
492 * if this memory is word-addressable, adjust the address
493 * accordingly
494 */
495 if ((mem->op[AVR_OP_LOADPAGE_LO]) || (mem->op[AVR_OP_READ_LO]))
496 addr = addr / 2;
497
498 pgm->pgm_led(pgm, ON);
499 pgm->err_led(pgm, OFF);
500
501 /*
502 * If this device has a "load extended address" command, issue it.
503 */
504 lext = mem->op[AVR_OP_LOAD_EXT_ADDR];
505 if (lext != NULL) {
506 memset(cmd, 0, sizeof(cmd));
507
508 avr_set_bits(lext, cmd);
509 avr_set_addr(lext, cmd, addr);
510 pgm->cmd(pgm, cmd, res);
511 }
512
513 memset(cmd, 0, sizeof(cmd));
514
515 avr_set_bits(wp, cmd);
516 avr_set_addr(wp, cmd, addr);
517 pgm->cmd(pgm, cmd, res);
518
519 /*
520 * since we don't know what voltage the target AVR is powered by, be
521 * conservative and delay the max amount the spec says to wait
522 */
524
525 pgm->pgm_led(pgm, OFF);
526 return 0;
527}
@ AVR_OP_WRITEPAGE
Definition libavrdude.h:155

References AVR_OP_LOAD_EXT_ADDR, AVR_OP_LOADPAGE_LO, AVR_OP_READ_LO, AVR_OP_WRITEPAGE, avr_set_addr(), avr_set_bits(), avrdude_message(), programmer_t::cmd, cmd, avrmem::desc, programmer_t::err_led, avrmem::max_write_delay, MSG_INFO, OFF, ON, avrmem::op, pgm, programmer_t::pgm_led, progname, programmer_t::type, and usleep().

Referenced by avr_write(), and buspirate_paged_write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ report_progress()

void report_progress ( int  completed,
int  total,
char *  hdr 
)
1225{
1226 static int last = 0;
1227 static double start_time;
1228 int percent = (total > 0) ? ((completed * 100) / total) : 100;
1229 struct timeval tv;
1230 double t;
1231
1232 if (update_progress == NULL)
1233 return;
1234
1235 gettimeofday(&tv, NULL);
1236 t = tv.tv_sec + ((double)tv.tv_usec)/1000000;
1237
1238 if (hdr) {
1239 last = 0;
1240 start_time = t;
1241 update_progress (percent, t - start_time, hdr);
1242 }
1243
1244 if (percent > 100)
1245 percent = 100;
1246
1247 if (percent > last) {
1248 last = percent;
1249 update_progress (percent, t - start_time, hdr);
1250 }
1251
1252 if (percent == 100)
1253 last = 0; /* Get ready for next time. */
1254}
FP_UpdateProgress update_progress
Definition avr.c:39

References gettimeofday(), and update_progress.

Referenced by avr_read(), avr_signature(), avr_write(), and do_op().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ update_progress

FP_UpdateProgress update_progress

Referenced by avrdude_main(), and report_progress().