Consolidate functions returning a prog_modes string

This commit is contained in:
Stefan Rueger
2024-05-08 22:10:06 +01:00
parent d425e737a4
commit 161f763507
5 changed files with 51 additions and 83 deletions

View File

@@ -1443,10 +1443,12 @@ int avr_put_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int cycles) {
/*
* 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"
* Returns a string in closed-circuit space with a list of programming
* modes encoded in pm; variant creates the list in subtly different ways:
* - variants == 0: PM_SPM prints bootloader
* - variants == 1: PM_SPM prints SPM
* - variants == 2: rather than a comma-separated list it's | PM_... separated
* If pm is 0 (no programming modes) returns "0"
*/
static char *prog_modes_string(int pm, int variant) {
// Return string is overwritten after a few calls
@@ -1457,48 +1459,52 @@ static char *prog_modes_string(int pm, int variant) {
if((size_t) (type - cx->avr_space) > sizeof cx->avr_space - 128)
type = cx->avr_space;
strcpy(type, variant? "0": "?");
if(variant == 0 && (pm & PM_SPM))
strcat(type, ", bootloader");
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(variant == 1 && (pm & PM_SPM))
strcat(type, ", SPM");
const char *spm = variant? "SPM": "bootloader";
const char *sep = variant == 2? " | PM_": ", ";
int skip = 3 + (variant == 2);
cx->avr_s = type + (type[1] == 0? 0: 3);
strcpy(type, "0");
if(pm & PM_SPM)
strcat(strcat(type, sep), spm);
if(pm & PM_TPI)
strcat(strcat(type, sep), "TPI");
if(pm & PM_ISP)
strcat(strcat(type, sep), "ISP");
if(pm & PM_PDI)
strcat(strcat(type, sep), "PDI");
if(pm & PM_UPDI)
strcat(strcat(type, sep), "UPDI");
if(pm & PM_HVSP)
strcat(strcat(type, sep), "HVSP");
if(pm & PM_HVPP)
strcat(strcat(type, sep), "HVPP");
if(pm & PM_debugWIRE)
strcat(strcat(type, sep), "debugWIRE");
if(pm & PM_JTAG)
strcat(strcat(type, sep), "JTAG");
if(pm & PM_JTAGmkI)
strcat(strcat(type, sep), "JTAGmkI");
if(pm & PM_XMEGAJTAG)
strcat(strcat(type, sep), "XMEGAJTAG");
if(pm & PM_AVR32JTAG)
strcat(strcat(type, sep), "AVR32JTAG");
if(pm & PM_aWire)
strcat(strcat(type, sep), "aWire");
cx->avr_s = type + (type[1] == 0? 0: skip);
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) {
char *avr_prog_modes(int pm) { // PM_SPM prints bootloader
return prog_modes_string(pm, 0);
}
char *str_prog_modes(int pm) { // PM_SPM prints SPM
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);
char *dev_prog_modes(int pm) { // Symbolic C code of prog_modes
return prog_modes_string(pm, 2);
}

View File

@@ -1086,7 +1086,7 @@ void sort_avrparts(LISTID avrparts)
void avr_display(FILE *f, const AVRPART *p, const char *prefix, int verbose) {
fprintf(f, "%sAVR Part : %s\n", prefix, p->desc);
fprintf(f, "%sProgramming modes : %s\n", prefix, avr_prog_modes_str(p->prog_modes));
fprintf(f, "%sProgramming modes : %s\n", prefix, str_prog_modes(p->prog_modes));
if(verbose > 1) {
avr_mem_display(f, p, prefix);

View File

@@ -133,43 +133,6 @@ static void printallopcodes(const AVRPART *p, const char *d, OPCODE * const *opa
}
// Programming modes
static char *prog_modes_str(int pm) {
static char type[1024];
strcpy(type, "0");
if(pm & PM_SPM)
strcat(type, " | PM_SPM");
if(pm & PM_TPI)
strcat(type, " | PM_TPI");
if(pm & PM_ISP)
strcat(type, " | PM_ISP");
if(pm & PM_PDI)
strcat(type, " | PM_PDI");
if(pm & PM_UPDI)
strcat(type, " | PM_UPDI");
if(pm & PM_HVSP)
strcat(type, " | PM_HVSP");
if(pm & PM_HVPP)
strcat(type, " | PM_HVPP");
if(pm & PM_debugWIRE)
strcat(type, " | PM_debugWIRE");
if(pm & PM_JTAG)
strcat(type, " | PM_JTAG");
if(pm & PM_JTAGmkI)
strcat(type, " | PM_JTAGmkI");
if(pm & PM_XMEGAJTAG)
strcat(type, " | PM_XMEGAJTAG");
if(pm & PM_AVR32JTAG)
strcat(type, " | PM_AVR32JTAG");
if(pm & PM_aWire)
strcat(type, " | PM_aWire");
return type + (type[1] == 0? 0: 4);
}
static char *extra_features_str(int m) {
static char mode[1024];
@@ -620,7 +583,7 @@ static void dev_part_strct(const AVRPART *p, bool tsv, const AVRPART *base, bool
}
_if_partout_str(strcmp, cfg_escape(p->family_id), family_id);
_if_partout_str(intcmp, mmt_strdup(prog_modes_str(p->prog_modes)), prog_modes);
_if_partout_str(intcmp, mmt_strdup(dev_prog_modes(p->prog_modes)), prog_modes);
if(p->mcuid == 21) {
_if_partout_str(intcmp, mmt_strdup("XVII + IV"), mcuid);
} else {
@@ -1124,7 +1087,7 @@ void dev_output_part_defs(char *partdesc) {
nfuses,
ok,
p->flags,
prog_modes_str(p->prog_modes),
dev_prog_modes(p->prog_modes),
p->config_file, p->lineno
);
}
@@ -1318,7 +1281,7 @@ static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *bas
_if_pgmout_str(strcmp, cfg_escape(pgm->desc), desc);
if(!base || base->initpgm != pgm->initpgm)
_pgmout_fmt("type", "\"%s\"", locate_programmer_type_id(pgm->initpgm));
_if_pgmout_str(intcmp, mmt_strdup(prog_modes_str(pgm->prog_modes)), prog_modes);
_if_pgmout_str(intcmp, mmt_strdup(dev_prog_modes(pgm->prog_modes)), prog_modes);
_if_pgmout_str(boolcmp, mmt_strdup(pgm->is_serialadapter? "yes": "no"), is_serialadapter);
_if_pgmout_str(intcmp, mmt_strdup(extra_features_str(pgm->extra_features)), extra_features);
if(!base || base->conntype != pgm->conntype)

View File

@@ -573,8 +573,7 @@ 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);
char *avr_prog_modes(int pm);
char *avr_prog_modes_str(int pm);
char *avr_prog_modes(int pm), *str_prog_modes(int pm), *dev_prog_modes(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);

View File

@@ -1890,7 +1890,7 @@ static int cmd_part(const PROGRAMMER *pgm, const AVRPART *p, int argc, const cha
else if(onlyvariants)
avr_variants_display(stdout, p, "");
else {
term_out("%s with programming modes %s\n", p->desc, avr_prog_modes_str(p->prog_modes));
term_out("%s with programming modes %s\n", p->desc, str_prog_modes(p->prog_modes));
avr_mem_display(stdout, p, "");
avr_variants_display(stdout, p, "");
}