Sort all memories of all parts in canonical order

This commit is contained in:
stefanrueger
2023-11-17 14:28:51 +13:00
parent 1b9d087004
commit a3a1871d9b
3 changed files with 40 additions and 0 deletions

View File

@@ -1559,6 +1559,39 @@ int avr_mem_is_usersig_type(const AVRMEM *mem) {
return mem_is_user_type(mem);
}
static int mem_group(AVRMEM *mem) {
return
!mem? -1:
mem_is_eeprom(mem)? 0:
mem_is_in_flash(mem)? 1:
mem_is_in_fuses(mem)? 2:
mem_is_lock(mem)? 3:
mem_is_in_sigrow(mem)? 4:
mem_is_user_type(mem)? 5:
mem_is_io(mem)? 6:
mem_is_sram(mem)? 7:
mem_is_sib(mem)? 8: 9;
}
// Return sort order of memories
int avr_mem_cmp(void *mem1, void *mem2) {
AVRMEM *m1 = mem1, *m2 = mem2;
int diff = mem_group(m1) - mem_group(m2); // First sort by group
if(diff)
return diff;
if(!m1) // Sanity, if called with NULL pointers
return 0;
diff = m1->offset - m2->offset; // Sort by offset within each group
if(diff)
return diff;
diff = m2->size - m1->size; // Sic: larger size is listed first, eg, fuses before fuse0
if(diff)
return diff;
return strcmp(m1->desc, m2->desc);
}
int avr_mem_is_known(const char *str) {
if(str && *str)
for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++)

View File

@@ -1132,6 +1132,8 @@ int avr_mem_is_eeprom_type(const AVRMEM *mem);
int avr_mem_is_usersig_type(const AVRMEM *mem);
int avr_mem_cmp(void *mem1, void *mem2);
int avr_mem_is_known(const char *str);
int avr_mem_might_be_known(const char *str);

View File

@@ -1033,6 +1033,11 @@ int main(int argc, char * argv [])
}
}
// Sort memories of all parts in canonical order
for(LNODEID ln1 = lfirst(part_list); ln1; ln1 = lnext(ln1))
if((p = ldata(ln1))->mem)
lsort(p->mem, avr_mem_cmp);
// set bitclock from configuration files unless changed by command line
if (default_bitclock > 0 && bitclock == 0.0) {
bitclock = default_bitclock;