Put static variables of avrpart.c into context structure

This commit is contained in:
Stefan Rueger
2024-05-07 21:11:39 +01:00
parent 9f69a6e09a
commit fa186e26a3
3 changed files with 23 additions and 41 deletions

View File

@@ -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] = {

View File

@@ -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);

View File

@@ -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);