Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
term.c File Reference
#include "ac_cfg.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "avrdude.h"
#include "term.h"
+ Include dependency graph for term.c:

Go to the source code of this file.

Classes

struct  command
 

Macros

#define NCMDS   (sizeof(cmd)/sizeof(struct command))
 

Functions

static int cmd_dump (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_write (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_erase (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_sig (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_part (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_help (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_quit (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_send (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_parms (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_vtarg (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_varef (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_fosc (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_sck (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_spi (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_pgm (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int cmd_verbose (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
static int nexttok (char *buf, char **tok, char **next)
 
static int hexdump_line (char *buffer, unsigned char *p, int n, int pad)
 
static int chardump_line (char *buffer, unsigned char *p, int n, int pad)
 
static int hexdump_buf (FILE *f, int startaddr, unsigned char *buf, int len)
 
static int tokenize (char *s, char ***argv)
 
static int do_cmd (PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
 
char * terminal_get_input (const char *prompt)
 
int terminal_mode (PROGRAMMER *pgm, struct avrpart *p)
 

Variables

struct command cmd []
 
static int spi_mode = 0
 

Macro Definition Documentation

◆ NCMDS

#define NCMDS   (sizeof(cmd)/sizeof(struct command))

Function Documentation

◆ chardump_line()

static int chardump_line ( char *  buffer,
unsigned char *  p,
int  n,
int  pad 
)
static
183{
184 int i;
185 char b [ 128 ];
186
187 for (i=0; i<n; i++) {
188 memcpy(b, p, n);
189 buffer[i] = '.';
190 if (isalpha((int)(b[i])) || isdigit((int)(b[i])) || ispunct((int)(b[i])))
191 buffer[i] = b[i];
192 else if (isspace((int)(b[i])))
193 buffer[i] = ' ';
194 }
195
196 for (i=n; i<pad; i++)
197 buffer[i] = ' ';
198
199 buffer[i] = 0;
200
201 return 0;
202}

Referenced by hexdump_buf().

+ Here is the caller graph for this function:

◆ cmd_dump()

static int cmd_dump ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
233{
234 static char prevmem[128] = {0};
235 char * e;
236 unsigned char * buf;
237 int maxsize;
238 unsigned long i;
239 static unsigned long addr=0;
240 static int len=64;
241 AVRMEM * mem;
242 char * memtype = NULL;
243 int rc;
244
245 if (!((argc == 2) || (argc == 4))) {
246 avrdude_message(MSG_INFO, "Usage: dump <memtype> [<addr> <len>]\n");
247 return -1;
248 }
249
250 memtype = argv[1];
251
252 if (strncmp(prevmem, memtype, strlen(memtype)) != 0) {
253 addr = 0;
254 len = 64;
255 strncpy(prevmem, memtype, sizeof(prevmem)-1);
256 prevmem[sizeof(prevmem)-1] = 0;
257 }
258
259 mem = avr_locate_mem(p, memtype);
260 if (mem == NULL) {
261 avrdude_message(MSG_INFO, "\"%s\" memory type not defined for part \"%s\"\n",
262 memtype, p->desc);
263 return -1;
264 }
265
266 if (argc == 4) {
267 addr = strtoul(argv[2], &e, 0);
268 if (*e || (e == argv[2])) {
269 avrdude_message(MSG_INFO, "%s (dump): can't parse address \"%s\"\n",
270 progname, argv[2]);
271 return -1;
272 }
273
274 len = strtol(argv[3], &e, 0);
275 if (*e || (e == argv[3])) {
276 avrdude_message(MSG_INFO, "%s (dump): can't parse length \"%s\"\n",
277 progname, argv[3]);
278 return -1;
279 }
280 }
281
282 maxsize = mem->size;
283
284 if (addr >= (unsigned long)maxsize) {
285 if (argc == 2) {
286 /* wrap around */
287 addr = 0;
288 }
289 else {
290 avrdude_message(MSG_INFO, "%s (dump): address 0x%05lx is out of range for %s memory\n",
291 progname, addr, mem->desc);
292 return -1;
293 }
294 }
295
296 /* trim len if nessary to not read past the end of memory */
297 if ((addr + len) > (unsigned long)maxsize)
298 len = maxsize - addr;
299
300 buf = malloc(len);
301 if (buf == NULL) {
302 avrdude_message(MSG_INFO, "%s (dump): out of memory\n", progname);
303 return -1;
304 }
305
306 for (i = 0; i < (unsigned long)len; i++) {
307 rc = pgm->read_byte(pgm, p, mem, addr+i, &buf[i]);
308 if (rc != 0) {
309 avrdude_message(MSG_INFO, "error reading %s address 0x%05lx of part %s\n",
310 mem->desc, addr+i, p->desc);
311 if (rc == -1)
312 avrdude_message(MSG_INFO, "read operation not supported on memory type \"%s\"\n",
313 mem->desc);
314 return -1;
315 }
316 }
317
318 hexdump_buf(stdout, addr, buf, len);
319
320 fprintf(stdout, "\n");
321
322 free(buf);
323
324 addr = addr + len;
325
326 return 0;
327}
#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
void * malloc(YYSIZE_T)
void free(void *)
int size
Definition libavrdude.h:286
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
char desc[AVR_MEMDESCLEN]
Definition libavrdude.h:284
Definition libavrdude.h:283
static PROGRAMMER * pgm
Definition main.c:192
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670
static int hexdump_buf(FILE *f, int startaddr, unsigned char *buf, int len)
Definition term.c:205
wchar_t const wchar_t unsigned long
Definition windows.hpp:29

References avr_locate_mem(), avrdude_message(), avrpart::desc, avrmem::desc, free(), hexdump_buf(), long, malloc(), MSG_INFO, pgm, progname, programmer_t::read_byte, and avrmem::size.

+ Here is the call graph for this function:

◆ cmd_erase()

static int cmd_erase ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
496{
497 avrdude_message(MSG_INFO, "%s: erasing chip\n", progname);
498 pgm->chip_erase(pgm, p);
499 return 0;
500}
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650

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

+ Here is the call graph for this function:

◆ cmd_fosc()

static int cmd_fosc ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
598{
599 int rc;
600 double v;
601 char *endp;
602
603 if (argc != 2) {
604 avrdude_message(MSG_INFO, "Usage: fosc <value>[M|k] | off\n");
605 return -1;
606 }
607 v = strtod(argv[1], &endp);
608 if (endp == argv[1]) {
609 if (strcmp(argv[1], "off") == 0)
610 v = 0.0;
611 else {
612 avrdude_message(MSG_INFO, "%s (fosc): can't parse frequency \"%s\"\n",
613 progname, argv[1]);
614 return -1;
615 }
616 }
617 if (*endp == 'm' || *endp == 'M')
618 v *= 1e6;
619 else if (*endp == 'k' || *endp == 'K')
620 v *= 1e3;
621 if (pgm->set_fosc == NULL) {
622 avrdude_message(MSG_INFO, "%s (fosc): the %s programmer cannot set oscillator frequency\n",
623 progname, pgm->type);
624 return -2;
625 }
626 if ((rc = pgm->set_fosc(pgm, v)) != 0) {
627 avrdude_message(MSG_INFO, "%s (fosc): failed to set oscillator_frequency (rc = %d)\n",
628 progname, rc);
629 return -3;
630 }
631 return 0;
632}
int(* set_fosc)(struct programmer_t *pgm, double v)
Definition libavrdude.h:676
char type[PGM_TYPELEN]
Definition libavrdude.h:619

References avrdude_message(), MSG_INFO, pgm, progname, programmer_t::set_fosc, and programmer_t::type.

+ Here is the call graph for this function:

◆ cmd_help()

static int cmd_help ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
717{
718 int i;
719
720 fprintf(stdout, "Valid commands:\n\n");
721 for (i=0; i<NCMDS; i++) {
722 fprintf(stdout, " %-6s : ", cmd[i].name);
723 fprintf(stdout, cmd[i].desc, cmd[i].name);
724 fprintf(stdout, "\n");
725 }
726 fprintf(stdout,
727 "\nUse the 'part' command to display valid memory types for use with the\n"
728 "'dump' and 'write' commands.\n\n");
729
730 return 0;
731}
#define NCMDS
Definition term.c:115
struct command cmd[]
Definition term.c:94

References cmd, command::desc, command::name, and NCMDS.

◆ cmd_parms()

static int cmd_parms ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
552{
553 if (pgm->print_parms == NULL) {
554 avrdude_message(MSG_INFO, "%s (parms): the %s programmer does not support "
555 "adjustable parameters\n",
556 progname, pgm->type);
557 return -1;
558 }
560
561 return 0;
562}
void(* print_parms)(struct programmer_t *pgm)
Definition libavrdude.h:673

References avrdude_message(), MSG_INFO, pgm, programmer_t::print_parms, progname, and programmer_t::type.

+ Here is the call graph for this function:

◆ cmd_part()

static int cmd_part ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
505{
506 fprintf(stdout, "\n");
507 avr_display(stdout, p, "", 0);
508 fprintf(stdout, "\n");
509
510 return 0;
511}
void avr_display(FILE *f, AVRPART *p, const char *prefix, int verbose)
Definition avrpart.c:621

References avr_display().

+ Here is the call graph for this function:

◆ cmd_pgm()

static int cmd_pgm ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
743{
745 spi_mode = 0;
746 pgm->initialize(pgm, p);
747 return 0;
748}
@ PIN_AVR_RESET
Definition libavrdude.h:355
int(* setpin)(struct programmer_t *pgm, int pinfunc, int value)
Definition libavrdude.h:678
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
static int spi_mode
Definition term.c:119

References programmer_t::initialize, pgm, PIN_AVR_RESET, programmer_t::setpin, and spi_mode.

◆ cmd_quit()

static int cmd_quit ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
545{
546 return 1;
547}

◆ cmd_sck()

static int cmd_sck ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
637{
638 int rc;
639 double v;
640 char *endp;
641
642 if (argc != 2) {
643 avrdude_message(MSG_INFO, "Usage: sck <value>\n");
644 return -1;
645 }
646 v = strtod(argv[1], &endp);
647 if (endp == argv[1]) {
648 avrdude_message(MSG_INFO, "%s (sck): can't parse period \"%s\"\n",
649 progname, argv[1]);
650 return -1;
651 }
652 v *= 1e-6; /* Convert from microseconds to seconds. */
653 if (pgm->set_sck_period == NULL) {
654 avrdude_message(MSG_INFO, "%s (sck): the %s programmer cannot set SCK period\n",
655 progname, pgm->type);
656 return -2;
657 }
658 if ((rc = pgm->set_sck_period(pgm, v)) != 0) {
659 avrdude_message(MSG_INFO, "%s (sck): failed to set SCK period (rc = %d)\n",
660 progname, rc);
661 return -3;
662 }
663 return 0;
664}
int(* set_sck_period)(struct programmer_t *pgm, double v)
Definition libavrdude.h:677

References avrdude_message(), MSG_INFO, pgm, progname, programmer_t::set_sck_period, and programmer_t::type.

+ Here is the call graph for this function:

◆ cmd_send()

static int cmd_send ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
434{
435 unsigned char cmd[4], res[4];
436 char * e;
437 int i;
438 int len;
439
440 if (pgm->cmd == NULL) {
441 avrdude_message(MSG_INFO, "The %s programmer does not support direct ISP commands.\n",
442 pgm->type);
443 return -1;
444 }
445
446 if (spi_mode && (pgm->spi == NULL)) {
447 avrdude_message(MSG_INFO, "The %s programmer does not support direct SPI transfers.\n",
448 pgm->type);
449 return -1;
450 }
451
452
453 if ((argc > 5) || ((argc < 5) && (!spi_mode))) {
455 "Usage: send <byte1> [<byte2> [<byte3> [<byte4>]]]\n":
456 "Usage: send <byte1> <byte2> <byte3> <byte4>\n");
457 return -1;
458 }
459
460 /* number of bytes to write at the specified address */
461 len = argc - 1;
462
463 /* load command bytes */
464 for (i=1; i<argc; i++) {
465 cmd[i-1] = (char)strtoul(argv[i], &e, 0);
466 if (*e || (e == argv[i])) {
467 avrdude_message(MSG_INFO, "%s (send): can't parse byte \"%s\"\n",
468 progname, argv[i]);
469 return -1;
470 }
471 }
472
473 pgm->err_led(pgm, OFF);
474
475 if (spi_mode)
476 pgm->spi(pgm, cmd, res, argc-1);
477 else
478 pgm->cmd(pgm, cmd, res);
479
480 /*
481 * display results
482 */
483 avrdude_message(MSG_INFO, "results:");
484 for (i=0; i<len; i++)
485 avrdude_message(MSG_INFO, " %02x", res[i]);
487
488 fprintf(stdout, "\n");
489
490 return 0;
491}
#define OFF
Definition libavrdude.h:585
int(* spi)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res, int count)
Definition libavrdude.h:655
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651
int(* err_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:640

References avrdude_message(), programmer_t::cmd, cmd, programmer_t::err_led, MSG_INFO, OFF, pgm, progname, programmer_t::spi, spi_mode, and programmer_t::type.

+ Here is the call graph for this function:

◆ cmd_sig()

static int cmd_sig ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
516{
517 int i;
518 int rc;
519 AVRMEM * m;
520
521 rc = avr_signature(pgm, p);
522 if (rc != 0) {
523 avrdude_message(MSG_INFO, "error reading signature data, rc=%d\n",
524 rc);
525 }
526
527 m = avr_locate_mem(p, "signature");
528 if (m == NULL) {
529 avrdude_message(MSG_INFO, "signature data not defined for device \"%s\"\n",
530 p->desc);
531 }
532 else {
533 fprintf(stdout, "Device signature = 0x");
534 for (i=0; i<m->size; i++)
535 fprintf(stdout, "%02x", m->buf[i]);
536 fprintf(stdout, "\n\n");
537 }
538
539 return 0;
540}
int avr_signature(PROGRAMMER *pgm, AVRPART *p)
Definition avr.c:1055
unsigned char * buf
Definition libavrdude.h:304

References avr_locate_mem(), avr_signature(), avrdude_message(), avrmem::buf, avrpart::desc, MSG_INFO, pgm, and avrmem::size.

+ Here is the call graph for this function:

◆ cmd_spi()

static int cmd_spi ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
735{
737 spi_mode = 1;
738 return 0;
739}

References pgm, PIN_AVR_RESET, programmer_t::setpin, and spi_mode.

◆ cmd_varef()

static int cmd_varef ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
669{
670 int rc;
671 unsigned int chan;
672 double v;
673 char *endp;
674
675 if (argc != 2 && argc != 3) {
676 avrdude_message(MSG_INFO, "Usage: varef [channel] <value>\n");
677 return -1;
678 }
679 if (argc == 2) {
680 chan = 0;
681 v = strtod(argv[1], &endp);
682 if (endp == argv[1]) {
683 avrdude_message(MSG_INFO, "%s (varef): can't parse voltage \"%s\"\n",
684 progname, argv[1]);
685 return -1;
686 }
687 } else {
688 chan = strtoul(argv[1], &endp, 10);
689 if (endp == argv[1]) {
690 avrdude_message(MSG_INFO, "%s (varef): can't parse channel \"%s\"\n",
691 progname, argv[1]);
692 return -1;
693 }
694 v = strtod(argv[2], &endp);
695 if (endp == argv[2]) {
696 avrdude_message(MSG_INFO, "%s (varef): can't parse voltage \"%s\"\n",
697 progname, argv[2]);
698 return -1;
699 }
700 }
701 if (pgm->set_varef == NULL) {
702 avrdude_message(MSG_INFO, "%s (varef): the %s programmer cannot set V[aref]\n",
703 progname, pgm->type);
704 return -2;
705 }
706 if ((rc = pgm->set_varef(pgm, chan, v)) != 0) {
707 avrdude_message(MSG_INFO, "%s (varef): failed to set V[aref] (rc = %d)\n",
708 progname, rc);
709 return -3;
710 }
711 return 0;
712}
int(* set_varef)(struct programmer_t *pgm, unsigned int chan, double v)
Definition libavrdude.h:675

References avrdude_message(), MSG_INFO, pgm, progname, programmer_t::set_varef, and programmer_t::type.

+ Here is the call graph for this function:

◆ cmd_verbose()

static int cmd_verbose ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
752{
753 int nverb;
754 char *endp;
755
756 if (argc != 1 && argc != 2) {
757 avrdude_message(MSG_INFO, "Usage: verbose [<value>]\n");
758 return -1;
759 }
760 if (argc == 1) {
761 avrdude_message(MSG_INFO, "Verbosity level: %d\n", verbose);
762 return 0;
763 }
764 nverb = strtol(argv[1], &endp, 0);
765 if (endp == argv[2]) {
766 avrdude_message(MSG_INFO, "%s: can't parse verbosity level \"%s\"\n",
767 progname, argv[2]);
768 return -1;
769 }
770 if (nverb < 0) {
771 avrdude_message(MSG_INFO, "%s: verbosity level must be positive: %d\n",
772 progname, nverb);
773 return -1;
774 }
775 verbose = nverb;
776 avrdude_message(MSG_INFO, "New verbosity level: %d\n", verbose);
777
778 return 0;
779}
int verbose
Definition main.c:198

References avrdude_message(), MSG_INFO, progname, and verbose.

+ Here is the call graph for this function:

◆ cmd_vtarg()

static int cmd_vtarg ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
567{
568 int rc;
569 double v;
570 char *endp;
571
572 if (argc != 2) {
573 avrdude_message(MSG_INFO, "Usage: vtarg <value>\n");
574 return -1;
575 }
576 v = strtod(argv[1], &endp);
577 if (endp == argv[1]) {
578 avrdude_message(MSG_INFO, "%s (vtarg): can't parse voltage \"%s\"\n",
579 progname, argv[1]);
580 return -1;
581 }
582 if (pgm->set_vtarget == NULL) {
583 avrdude_message(MSG_INFO, "%s (vtarg): the %s programmer cannot set V[target]\n",
584 progname, pgm->type);
585 return -2;
586 }
587 if ((rc = pgm->set_vtarget(pgm, v)) != 0) {
588 avrdude_message(MSG_INFO, "%s (vtarg): failed to set V[target] (rc = %d)\n",
589 progname, rc);
590 return -3;
591 }
592 return 0;
593}
int(* set_vtarget)(struct programmer_t *pgm, double v)
Definition libavrdude.h:674

References avrdude_message(), MSG_INFO, pgm, progname, programmer_t::set_vtarget, and programmer_t::type.

+ Here is the call graph for this function:

◆ cmd_write()

static int cmd_write ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
332{
333 char * e;
334 int len, maxsize;
335 char * memtype;
336 unsigned long addr, i;
337 unsigned char * buf;
338 unsigned char b;
339 int rc;
340 int werror;
341 AVRMEM * mem;
342
343 if (argc < 4) {
344 avrdude_message(MSG_INFO, "Usage: write <memtype> <addr> <byte1> "
345 "<byte2> ... byteN>\n");
346 return -1;
347 }
348
349 memtype = argv[1];
350
351 mem = avr_locate_mem(p, memtype);
352 if (mem == NULL) {
353 avrdude_message(MSG_INFO, "\"%s\" memory type not defined for part \"%s\"\n",
354 memtype, p->desc);
355 return -1;
356 }
357
358 maxsize = mem->size;
359
360 addr = strtoul(argv[2], &e, 0);
361 if (*e || (e == argv[2])) {
362 avrdude_message(MSG_INFO, "%s (write): can't parse address \"%s\"\n",
363 progname, argv[2]);
364 return -1;
365 }
366
367 if (addr > (unsigned long)maxsize) {
368 avrdude_message(MSG_INFO, "%s (write): address 0x%05lx is out of range for %s memory\n",
369 progname, addr, memtype);
370 return -1;
371 }
372
373 /* number of bytes to write at the specified address */
374 len = argc - 3;
375
376 if ((addr + len) > (unsigned long)maxsize) {
377 avrdude_message(MSG_INFO, "%s (write): selected address and # bytes exceed "
378 "range for %s memory\n",
379 progname, memtype);
380 return -1;
381 }
382
383 buf = malloc(len);
384 if (buf == NULL) {
385 avrdude_message(MSG_INFO, "%s (write): out of memory\n", progname);
386 return -1;
387 }
388
389 for (i = 3; i < (unsigned long)argc; i++) {
390 buf[i-3] = (char)strtoul(argv[i], &e, 0);
391 if (*e || (e == argv[i])) {
392 avrdude_message(MSG_INFO, "%s (write): can't parse byte \"%s\"\n",
393 progname, argv[i]);
394 free(buf);
395 return -1;
396 }
397 }
398
399 pgm->err_led(pgm, OFF);
400 for (werror = 0, i = 0; i < (unsigned long)len; i++) {
401
402 rc = avr_write_byte(pgm, p, mem, addr+i, buf[i]);
403 if (rc) {
404 avrdude_message(MSG_INFO, "%s (write): error writing 0x%02x at 0x%05lx, rc=%d\n",
405 progname, buf[i], addr+i, rc);
406 if (rc == -1)
407 avrdude_message(MSG_INFO, "write operation not supported on memory type \"%s\"\n",
408 mem->desc);
409 werror = 1;
410 }
411
412 rc = pgm->read_byte(pgm, p, mem, addr+i, &b);
413 if (b != buf[i]) {
414 avrdude_message(MSG_INFO, "%s (write): error writing 0x%02x at 0x%05lx cell=0x%02x\n",
415 progname, buf[i], addr+i, b);
416 werror = 1;
417 }
418
419 if (werror) {
420 pgm->err_led(pgm, ON);
421 }
422 }
423
424 free(buf);
425
426 fprintf(stdout, "\n");
427
428 return 0;
429}
int avr_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition avr.c:791
#define ON
Definition libavrdude.h:584

References avr_locate_mem(), avr_write_byte(), avrdude_message(), avrpart::desc, avrmem::desc, programmer_t::err_led, free(), long, malloc(), MSG_INFO, OFF, ON, pgm, progname, programmer_t::read_byte, and avrmem::size.

Referenced by ImDrawListSplitter::Merge().

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

◆ do_cmd()

static int do_cmd ( PROGRAMMER pgm,
struct avrpart p,
int  argc,
char *  argv[] 
)
static
860{
861 int i;
862 int hold;
863 int len;
864
865 len = (int)strlen(argv[0]);
866 hold = -1;
867 for (i=0; i<NCMDS; i++) {
868 if (strcasecmp(argv[0], cmd[i].name) == 0) {
869 return cmd[i].func(pgm, p, argc, argv);
870 }
871 else if (strncasecmp(argv[0], cmd[i].name, len)==0) {
872 if (hold != -1) {
873 avrdude_message(MSG_INFO, "%s: command \"%s\" is ambiguous\n",
874 progname, argv[0]);
875 return -1;
876 }
877 hold = i;
878 }
879 }
880
881 if (hold != -1)
882 return cmd[hold].func(pgm, p, argc, argv);
883
884 avrdude_message(MSG_INFO, "%s: invalid command \"%s\"\n",
885 progname, argv[0]);
886
887 return -1;
888}
int(* func)(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:41
#define strncasecmp
Definition unistd.h:51
#define strcasecmp
Definition unistd.h:52

References avrdude_message(), cmd, command::func, MSG_INFO, command::name, NCMDS, pgm, progname, strcasecmp, and strncasecmp.

Referenced by terminal_mode().

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

◆ hexdump_buf()

static int hexdump_buf ( FILE *  f,
int  startaddr,
unsigned char *  buf,
int  len 
)
static
206{
207 int addr;
208 int n;
209 unsigned char * p;
210 char dst1[80];
211 char dst2[80];
212
213 addr = startaddr;
214 p = (unsigned char *)buf;
215 while (len) {
216 n = 16;
217 if (n > len)
218 n = len;
219 hexdump_line(dst1, p, n, 48);
220 chardump_line(dst2, p, n, 16);
221 fprintf(stdout, "%04x %s |%s|\n", addr, dst1, dst2);
222 len -= n;
223 addr += n;
224 p += n;
225 }
226
227 return 0;
228}
static int hexdump_line(char *buffer, unsigned char *p, int n, int pad)
Definition term.c:150
static int chardump_line(char *buffer, unsigned char *p, int n, int pad)
Definition term.c:182

References chardump_line(), and hexdump_line().

Referenced by cmd_dump().

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

◆ hexdump_line()

static int hexdump_line ( char *  buffer,
unsigned char *  p,
int  n,
int  pad 
)
static
151{
152 char * hexdata = "0123456789abcdef";
153 char * b;
154 int i, j;
155
156 b = buffer;
157
158 j = 0;
159 for (i=0; i<n; i++) {
160 if (i && ((i % 8) == 0))
161 b[j++] = ' ';
162 b[j++] = hexdata[(p[i] & 0xf0) >> 4];
163 b[j++] = hexdata[(p[i] & 0x0f)];
164 if (i < 15)
165 b[j++] = ' ';
166 }
167
168 for (i=j; i<pad; i++)
169 b[i] = ' ';
170
171 b[i] = 0;
172
173 for (i=0; i<pad; i++) {
174 if (!((b[i] == '0') || (b[i] == ' ')))
175 return 0;
176 }
177
178 return 1;
179}

Referenced by hexdump_buf().

+ Here is the caller graph for this function:

◆ nexttok()

static int nexttok ( char *  buf,
char **  tok,
char **  next 
)
static
122{
123 char * q, * n;
124
125 q = buf;
126 while (isspace((int)*q))
127 q++;
128
129 /* isolate first token */
130 n = q+1;
131 while (*n && !isspace((int)*n))
132 n++;
133
134 if (*n) {
135 *n = 0;
136 n++;
137 }
138
139 /* find start of next token */
140 while (isspace((int)*n))
141 n++;
142
143 *tok = q;
144 *next = n;
145
146 return 0;
147}

Referenced by tokenize().

+ Here is the caller graph for this function:

◆ terminal_get_input()

char * terminal_get_input ( const char *  prompt)
892{
893#if defined(HAVE_LIBREADLINE) && !defined(WIN32NATIVE)
894 char *input;
895 input = readline(prompt);
896 if ((input != NULL) && (strlen(input) >= 1))
897 add_history(input);
898
899 return input;
900#else
901 char input[256];
902 printf("%s", prompt);
903 if (fgets(input, sizeof(input), stdin))
904 {
905 /* FIXME: readline strips the '\n', should this too? */
906 return strdup(input);
907 }
908 else
909 return NULL;
910#endif
911}
static int input(void)

References input().

Referenced by avrdude_main(), and terminal_mode().

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

◆ terminal_mode()

int terminal_mode ( PROGRAMMER pgm,
struct avrpart p 
)
915{
916 char * cmdbuf;
917 int i;
918 char * q;
919 int rc;
920 int argc;
921 char ** argv;
922
923 rc = 0;
924 while ((cmdbuf = terminal_get_input("avrdude> ")) != NULL) {
925 /*
926 * find the start of the command, skipping any white space
927 */
928 q = cmdbuf;
929 while (*q && isspace((int)*q))
930 q++;
931
932 /* skip blank lines and comments */
933 if (!*q || (*q == '#'))
934 continue;
935
936 /* tokenize command line */
937 argc = tokenize(q, &argv);
938
939 fprintf(stdout, ">>> ");
940 for (i=0; i<argc; i++)
941 fprintf(stdout, "%s ", argv[i]);
942 fprintf(stdout, "\n");
943
944 /* run the command */
945 rc = do_cmd(pgm, p, argc, argv);
946 free(argv);
947 if (rc > 0) {
948 rc = 0;
949 break;
950 }
951 free(cmdbuf);
952 }
953
954 return rc;
955}
char * terminal_get_input(const char *prompt)
Definition term.c:891
static int tokenize(char *s, char ***argv)
Definition term.c:781
static int do_cmd(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:858

References do_cmd(), free(), pgm, terminal_get_input(), and tokenize().

Referenced by avrdude_main().

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

◆ tokenize()

static int tokenize ( char *  s,
char ***  argv 
)
static
782{
783 int i, n, l, nargs, offset;
784 int len, slen;
785 char * buf;
786 int bufsize;
787 char ** bufv;
788 char * q, * r;
789 char * nbuf;
790 char ** av;
791
792 slen = (int)strlen(s);
793
794 /*
795 * initialize allow for 20 arguments, use realloc to grow this if
796 * necessary
797 */
798 nargs = 20;
799 bufsize = slen + 20;
800 buf = malloc(bufsize);
801 bufv = (char **) malloc(nargs*sizeof(char *));
802 for (i=0; i<nargs; i++) {
803 bufv[i] = NULL;
804 }
805 buf[0] = 0;
806
807 n = 0;
808 l = 0;
809 nbuf = buf;
810 r = s;
811 while (*r) {
812 nexttok(r, &q, &r);
813 strcpy(nbuf, q);
814 bufv[n] = nbuf;
815 len = (int)strlen(q);
816 l += len + 1;
817 nbuf += len + 1;
818 nbuf[0] = 0;
819 n++;
820 if ((n % 20) == 0) {
821 /* realloc space for another 20 args */
822 bufsize += 20;
823 nargs += 20;
824 buf = realloc(buf, bufsize);
825 bufv = realloc(bufv, nargs*sizeof(char *));
826 nbuf = &buf[l];
827 for (i=n; i<nargs; i++)
828 bufv[i] = NULL;
829 }
830 }
831
832 /*
833 * We have parsed all the args, n == argc, bufv contains an array of
834 * pointers to each arg, and buf points to one memory block that
835 * contains all the args, back to back, seperated by a nul
836 * terminator. Consilidate bufv and buf into one big memory block
837 * so that the code that calls us, will have an easy job of freeing
838 * this memory.
839 */
840 av = (char **) malloc(slen + n + (n+1)*sizeof(char *));
841 q = (char *)&av[n+1];
842 memcpy(q, buf, l);
843 for (i=0; i<n; i++) {
844 offset = (int)(bufv[i] - buf);
845 av[i] = q + offset;
846 }
847 av[i] = NULL;
848
849 free(buf);
850 free(bufv);
851
852 *argv = av;
853
854 return n;
855}
void offset(Slic3r::ExPolygon &sh, coord_t distance, const PolygonTag &)
Definition geometries.hpp:132
static int nexttok(char *buf, char **tok, char **next)
Definition term.c:121

References free(), malloc(), and nexttok().

Referenced by terminal_mode().

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

Variable Documentation

◆ cmd

struct command cmd[]
Initial value:
= {
{ "dump", cmd_dump, "dump memory : %s <memtype> <addr> <N-Bytes>" },
{ "read", cmd_dump, "alias for dump" },
{ "write", cmd_write, "write memory : %s <memtype> <addr> <b1> <b2> ... <bN>" },
{ "erase", cmd_erase, "perform a chip erase" },
{ "sig", cmd_sig, "display device signature bytes" },
{ "part", cmd_part, "display the current part information" },
{ "send", cmd_send, "send a raw command : %s <b1> <b2> <b3> <b4>" },
{ "parms", cmd_parms, "display adjustable parameters (STK500 only)" },
{ "vtarg", cmd_vtarg, "set <V[target]> (STK500 only)" },
{ "varef", cmd_varef, "set <V[aref]> (STK500 only)" },
{ "fosc", cmd_fosc, "set <oscillator frequency> (STK500 only)" },
{ "sck", cmd_sck, "set <SCK period> (STK500 only)" },
{ "spi", cmd_spi, "enter direct SPI mode" },
{ "pgm", cmd_pgm, "return to programming mode" },
{ "verbose", cmd_verbose, "change verbosity" },
{ "help", cmd_help, "help" },
{ "?", cmd_help, "help" },
{ "quit", cmd_quit, "quit" }
}
static int cmd_verbose(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:750
static int cmd_pgm(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:741
static int cmd_sig(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:514
static int cmd_send(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:432
static int cmd_varef(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:667
static int cmd_fosc(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:596
static int cmd_parms(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:550
static int cmd_erase(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:494
static int cmd_help(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:715
static int cmd_sck(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:635
static int cmd_part(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:503
static int cmd_dump(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:231
static int cmd_quit(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:543
static int cmd_write(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:330
static int cmd_spi(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:733
static int cmd_vtarg(PROGRAMMER *pgm, struct avrpart *p, int argc, char *argv[])
Definition term.c:565

Referenced by agg::rasterizer_scanline_aa< Clip >::add_path(), agg::rasterizer_scanline_aa_nogamma< Clip >::add_path(), agg::vertex_block_storage< T, BlockShift, BlockPool >::add_vertex(), agg::vertex_stl_storage< Container >::add_vertex(), agg::rasterizer_scanline_aa< Clip >::add_vertex(), agg::rasterizer_scanline_aa_nogamma< Clip >::add_vertex(), agg::path_base< VertexContainer >::arrange_polygon_orientation(), avr910_cmd(), avr910_paged_load(), avr910_paged_write(), avr910_paged_write_eeprom(), avr910_paged_write_flash(), avr910_set_addr(), avr910_write_byte(), avr_read(), avr_read_byte_default(), avr_set_addr(), avr_set_bits(), avr_set_input(), avr_tpi_chip_erase(), avr_tpi_poll_nvmbsy(), avr_tpi_program_enable(), avr_tpi_setup_rw(), avr_write(), avr_write_byte_default(), avr_write_page(), bitbang_chip_erase(), bitbang_cmd(), bitbang_cmd_tpi(), bitbang_program_enable(), bitbang_spi(), buspirate_chip_erase(), buspirate_cmd(), buspirate_cmd_ascii(), buspirate_cmd_bin(), buspirate_program_enable(), buspirate_start_spi_mode_ascii(), butterfly_paged_load(), butterfly_paged_write(), butterfly_read_byte(), butterfly_set_addr(), butterfly_set_extaddr(), butterfly_write_byte(), cmd_help(), cmd_send(), agg::path_base< VertexContainer >::concat_path(), agg::path_base< VertexContainer >::curve3(), agg::path_base< VertexContainer >::curve4(), do_cmd(), Slic3r::Utils::TCPConsole::enqueue_cmd(), agg::path_base< VertexContainer >::flip_x(), agg::path_base< VertexContainer >::flip_y(), agg::path_base< VertexContainer >::join_path(), jtag3_command(), jtag3_display(), jtag3_initialize(), jtag3_page_erase(), jtag3_paged_load(), jtag3_paged_write(), jtag3_read_byte(), jtag3_write_byte(), jtagmkI_initialize(), jtagmkI_paged_load(), jtagmkI_paged_write(), jtagmkI_read_byte(), jtagmkI_set_devdescr(), jtagmkI_write_byte(), jtagmkII_flash_clear_pagebuffer32(), jtagmkII_flash_erase32(), jtagmkII_flash_lock32(), jtagmkII_flash_write_page32(), jtagmkII_page_erase(), jtagmkII_paged_load(), jtagmkII_paged_load32(), jtagmkII_paged_write(), jtagmkII_paged_write32(), jtagmkII_read_byte(), jtagmkII_set_devdescr(), jtagmkII_set_xmega_params(), jtagmkII_write_byte(), mib510_isp(), agg::vertex_block_storage< T, BlockShift, BlockPool >::modify_command(), agg::path_base< VertexContainer >::modify_command(), agg::vertex_stl_storage< Container >::modify_command(), agg::vertex_block_storage< T, BlockShift, BlockPool >::modify_vertex(), agg::path_base< VertexContainer >::modify_vertex(), agg::vertex_stl_storage< Container >::modify_vertex(), agg::vertex_block_storage< T, BlockShift, BlockPool >::operator=(), Slic3r::GCodeReader::parse_line(), Slic3r::GCodeProcessor::post_process(), Slic3r::GCodeProcessor::process_G28(), Slic3r::GCodeProcessor::process_gcode_line(), Slic3r::GCodeProcessor::process_M108(), Slic3r::GCodeProcessor::process_M135(), ImDrawData::ScaleClipRects(), stk500_chip_erase(), stk500_cmd(), stk500_set_extended_parms(), stk500v2_cmd(), stk500v2_print_parms1(), agg::vertex_block_storage< T, BlockShift, BlockPool >::swap_vertices(), agg::path_base< VertexContainer >::transform(), agg::path_base< VertexContainer >::translate(), Slic3r::Utils::TCPConsole::transmit_next_command(), and agg::conv_transform< VertexSource, Transformer >::vertex().

◆ spi_mode

int spi_mode = 0
static

Referenced by cmd_pgm(), cmd_send(), and cmd_spi().