From fa186e26a33929e49017e3a7ba1d12ce1708b5b0 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 7 May 2024 21:11:39 +0100 Subject: [PATCH] Put static variables of avrpart.c into context structure --- src/avr.c | 25 +++++++++++++++++++++---- src/avrpart.c | 34 ---------------------------------- src/libavrdude.h | 5 ++--- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/avr.c b/src/avr.c index 564c1d3d..61c8872e 100644 --- a/src/avr.c +++ b/src/avr.c @@ -1442,8 +1442,13 @@ int avr_put_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int cycles) { } -// Returns a string in closed-circuit space with list of programming modes -char *avr_prog_modes(int pm) { +/* + * Returns a string in closed-circuit space with a comma-separated list of + * programming modes; variant creates the list in subtly different way + * - 0: PM_SPM prints bootloader, pm == 0 prints "?" + * - 1: PM_SPM prints SPM, pm == 0 prints "0" + */ +static char *prog_modes_string(int pm, int variant) { // Return string is overwritten after a few calls if(!cx->avr_s) cx->avr_s = cx->avr_space; @@ -1452,8 +1457,8 @@ char *avr_prog_modes(int pm) { if((size_t) (type - cx->avr_space) > sizeof cx->avr_space - 128) type = cx->avr_space; - strcpy(type, "?"); - if(pm & PM_SPM) + strcpy(type, variant? "0": "?"); + if(variant == 0 && (pm & PM_SPM)) strcat(type, ", bootloader"); if(pm & PM_TPI) strcat(type, ", TPI"); @@ -1479,11 +1484,23 @@ char *avr_prog_modes(int pm) { strcat(type, ", AVR32JTAG"); if(pm & PM_aWire) strcat(type, ", aWire"); + if(variant == 1 && (pm & PM_SPM)) + strcat(type, ", SPM"); cx->avr_s = type + (type[1] == 0? 0: 3); return cx->avr_s; } +// Returns a string in closed-circuit space with list of programming modes or "0" +char *avr_prog_modes_str(int pm) { + return prog_modes_string(pm, 1); +} + +// Returns a string in closed-circuit space with list of programming modes or "?" +char *avr_prog_modes(int pm) { + return prog_modes_string(pm, 0); +} + // Typical order in which memories show in avrdude.conf, runtime adds unknown ones (if any) memtable_t avr_mem_order[100] = { diff --git a/src/avrpart.c b/src/avrpart.c index 86235fce..c4023843 100644 --- a/src/avrpart.c +++ b/src/avrpart.c @@ -1083,40 +1083,6 @@ void sort_avrparts(LISTID avrparts) lsort(avrparts,(int (*)(void*, void*)) sort_avrparts_compare); } -const char *avr_prog_modes_str(int pm) { - static char type[1024]; - - strcpy(type, "0"); - if(pm & PM_TPI) - strcat(type, ", TPI"); - if(pm & PM_ISP) - strcat(type, ", ISP"); - if(pm & PM_PDI) - strcat(type, ", PDI"); - if(pm & PM_UPDI) - strcat(type, ", UPDI"); - if(pm & PM_HVSP) - strcat(type, ", HVSP"); - if(pm & PM_HVPP) - strcat(type, ", HVPP"); - if(pm & PM_debugWIRE) - strcat(type, ", debugWIRE"); - if(pm & PM_JTAG) - strcat(type, ", JTAG"); - if(pm & PM_JTAGmkI) - strcat(type, ", JTAGmkI"); - if(pm & PM_XMEGAJTAG) - strcat(type, ", XMEGAJTAG"); - if(pm & PM_AVR32JTAG) - strcat(type, ", AVR32JTAG"); - if(pm & PM_aWire) - strcat(type, ", aWire"); - if(pm & PM_SPM) - strcat(type, ", SPM"); - - return type + (type[1] == 0? 0: 3); -} - void avr_display(FILE *f, const AVRPART *p, const char *prefix, int verbose) { fprintf(f, "%sAVR Part : %s\n", prefix, p->desc); diff --git a/src/libavrdude.h b/src/libavrdude.h index 4e5c2e3c..a5f5f0da 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -573,7 +573,8 @@ AVRPART * locate_part(const LISTID parts, const char *partdesc); AVRPART * locate_part_by_avr910_devcode(const LISTID parts, int devcode); AVRPART * locate_part_by_signature(const LISTID parts, unsigned char *sig, int sigsize); AVRPART * locate_part_by_signature_pm(const LISTID parts, unsigned char *sig, int sigsize, int prog_modes); -const char *avr_prog_modes_str(int pm); +char *avr_prog_modes(int pm); +char *avr_prog_modes_str(int pm); void avr_display(FILE *f, const AVRPART *p, const char *prefix, int verbose); int avr_variants_display(FILE *f, const AVRPART *p, const char *prefix); @@ -1155,8 +1156,6 @@ int avr_get_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int *cycles); int avr_put_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int cycles); -char *avr_prog_modes(int pm); - int avr_get_mem_type(const char *str); int avr_mem_is_flash_type(const AVRMEM *mem);