Skip to content

Commit

Permalink
Sort all memories of all parts in canonical order
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanrueger committed Nov 17, 2023
1 parent 1b9d087 commit a3a1871
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
2 changes: 2 additions & 0 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a3a1871

Please sign in to comment.