Add ability to read classic sernum mem to avr_read_byte_default()

This commit is contained in:
Stefan Rueger
2024-07-12 18:41:37 +01:00
parent be63435aa2
commit 8a4c00fc21
2 changed files with 18 additions and 1 deletions

View File

@@ -181,6 +181,22 @@ static int avr_tpi_setup_rw(const PROGRAMMER *pgm, const AVRMEM *mem,
return 0;
}
// If mem is a sub-memory of sigrow return its offset within sigrow, 0 otherwise
int avr_sigrow_offset(const AVRPART *p, const AVRMEM *mem, int addr) {
int offset = 0;
if(mem_is_in_sigrow(mem)) {
AVRMEM *m = avr_locate_sigrow(p);
if(m) {
int off = mem->offset - m->offset;
if(off >= 0 && off + addr < m->size)
offset = off;
}
}
return offset;
}
int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char * value)
{
@@ -258,7 +274,7 @@ int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
memset(cmd, 0, sizeof(cmd));
avr_set_bits(readop, cmd);
avr_set_addr(readop, cmd, addr);
avr_set_addr(readop, cmd, addr + avr_sigrow_offset(p, mem, addr));
rc = pgm->cmd(pgm, cmd, res);
if(rc < 0)
goto rcerror;

View File

@@ -1102,6 +1102,7 @@ extern "C" {
int avr_tpi_poll_nvmbsy(const PROGRAMMER *pgm);
int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p);
int avr_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p, unsigned char guard_time);
int avr_sigrow_offset(const AVRPART *p, const AVRMEM *mem, int addr);
int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char * value);