From 7bdd61016f86748722e8d5665a95d9a704f1610f Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Wed, 25 Oct 2023 13:33:01 +0100 Subject: [PATCH] Replace avr_mem_is_...() functions with macros --- src/avr.c | 6 +++--- src/avrcache.c | 21 +++++++++------------ src/avrpart.c | 2 +- src/ch341a.c | 8 ++++---- src/dryrun.c | 12 ++++++------ src/jtag3.c | 6 +++--- src/jtagmkII.c | 4 ++-- src/stk500.c | 4 ++-- src/urclock.c | 16 ++++++++-------- 9 files changed, 38 insertions(+), 41 deletions(-) diff --git a/src/avr.c b/src/avr.c index f3715f60..50a33f9e 100644 --- a/src/avr.c +++ b/src/avr.c @@ -302,7 +302,7 @@ int avr_mem_hiaddr(const AVRMEM * mem) return mem->size; /* if the memory is not a flash-type memory do not remove trailing 0xff */ - if(!avr_mem_is_flash_type(mem)) + if(!mem_is_in_flash(mem)) return mem->size; /* return the highest non-0xff address regardless of how much @@ -1154,7 +1154,7 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int int page_tainted = 0; int flush_page = 0; - int paged = avr_mem_is_flash_type(m) && m->paged; + int paged = mem_is_in_flash(m) && m->paged; if(paged) wsize = (wsize+1)/2*2; // Round up write size for word boundary @@ -1319,7 +1319,7 @@ int avr_verify(const PROGRAMMER *pgm, const AVRPART *p, const AVRPART *v, const if(vroerror < 10) { if(!(verror + vroerror)) pmsg_warning("verification mismatch%s\n", - avr_mem_is_flash_type(a)? " in r/o areas, expected for vectors and/or bootloader": ""); + mem_is_in_flash(a)? " in r/o areas, expected for vectors and/or bootloader": ""); imsg_warning("device 0x%02x != input 0x%02x at addr 0x%04x (read only location)\n", buf1[i], buf2[i], i); } else if(vroerror == 10) diff --git a/src/avrcache.c b/src/avrcache.c index 4a75efe3..6848a80e 100644 --- a/src/avrcache.c +++ b/src/avrcache.c @@ -130,7 +130,7 @@ int avr_has_paged_access(const PROGRAMMER *pgm, const AVRMEM *mem) { return pgm->paged_load && pgm->paged_write && mem->page_size > 0 && (mem->page_size & (mem->page_size-1)) == 0 && mem->size > 0 && mem->size % mem->page_size == 0 && - (avr_mem_is_flash_type(mem) || avr_mem_is_eeprom_type(mem) || avr_mem_is_usersig_type(mem)); + mem_is_paged_type(mem); } @@ -276,7 +276,7 @@ static int initCache(AVR_Cache *cp, const PROGRAMMER *pgm, const AVRPART *p) { cp->copy = cfg_malloc("initCache()", cp->size); cp->iscached = cfg_malloc("initCache()", cp->size/cp->page_size); - if((pgm->prog_modes & PM_SPM) && avr_mem_is_flash_type(basemem)) { // Could be vector bootloader + if((pgm->prog_modes & PM_SPM) && mem_is_in_flash(basemem)) { // Could be vector bootloader // Caching the vector page hands over to the progammer that then can patch the reset vector if(loadCachePage(cp, pgm, p, basemem, 0, 0, 0) < 0) return LIBAVRDUDE_GENERAL_FAILURE; @@ -449,7 +449,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) { } } - if(!avr_mem_is_usersig_type(mems[i].mem)) // Only force CE if unable to write to flash/EEPROM + if(!mem_is_user_type(mems[i].mem)) // Only force CE if unable to write to flash/EEPROM chiperase = 1; } @@ -471,7 +471,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) { AVR_Cache *cp = mems[i].cp; if(!mem) continue; - if(avr_mem_is_usersig_type(mem)) // CE does not affect bootrow/usersig + if(mem_is_user_type(mem)) // CE does not affect bootrow/userrow continue; for(int pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size) @@ -487,7 +487,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) { AVR_Cache *cp = mems[i].cp; if(!mem) continue; - if(avr_mem_is_usersig_type(mem)) // CE does not affect bootrow/usersig + if(mem_is_user_type(mem)) // CE does not affect bootrow/userrow continue; for(int ird = 0, pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size) { @@ -516,7 +516,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) { AVR_Cache *cp = mems[i].cp; if(!mem) continue; - if(avr_mem_is_usersig_type(mem)) // CE does not affect bootrow/usersig + if(mem_is_user_type(mem)) // CE does not affect bootrow/userrow continue; if(mems[i].isflash) { @@ -628,8 +628,7 @@ int avr_read_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM * return LIBAVRDUDE_SUCCESS; } - AVR_Cache *cp = avr_mem_is_eeprom_type(mem)? pgm->cp_eeprom: - avr_mem_is_flash_type(mem)? pgm->cp_flash: + AVR_Cache *cp = mem_is_eeprom(mem)? pgm->cp_eeprom: mem_is_in_flash(mem)? pgm->cp_flash: str_eq(mem->desc, "bootrow")? pgm->cp_bootrow: pgm->cp_usersig; if(!cp->cont) // Init cache if needed @@ -669,8 +668,7 @@ int avr_write_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM if(addr >= (unsigned long) mem->size) return avr_flush_cache(pgm, p); - AVR_Cache *cp = avr_mem_is_eeprom_type(mem)? pgm->cp_eeprom: - avr_mem_is_flash_type(mem)? pgm->cp_flash: + AVR_Cache *cp = mem_is_eeprom(mem)? pgm->cp_eeprom: mem_is_in_flash(mem)? pgm->cp_flash: str_eq(mem->desc, "bootrow")? pgm->cp_bootrow: pgm->cp_usersig; if(!cp->cont) // Init cache if needed @@ -773,8 +771,7 @@ int avr_page_erase_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM return LIBAVRDUDE_GENERAL_FAILURE; } - AVR_Cache *cp = avr_mem_is_eeprom_type(mem)? pgm->cp_eeprom: - avr_mem_is_flash_type(mem)? pgm->cp_flash: + AVR_Cache *cp = mem_is_eeprom(mem)? pgm->cp_eeprom: mem_is_in_flash(mem)? pgm->cp_flash: str_eq(mem->desc, "bootrow")? pgm->cp_bootrow: pgm->cp_usersig; if(!cp->cont) // Init cache if needed diff --git a/src/avrpart.c b/src/avrpart.c index 3037f81b..fcd22f25 100644 --- a/src/avrpart.c +++ b/src/avrpart.c @@ -137,7 +137,7 @@ int avr_set_addr_mem(const AVRMEM *mem, int opnum, unsigned char *cmd, unsigned if(!(op = mem->op[opnum])) return -1; - isflash = avr_mem_is_flash_type(mem); + isflash = mem_is_in_flash(mem); memsize = mem->size >> isflash; // word addresses for flash pagesize = mem->page_size >> isflash; diff --git a/src/ch341a.c b/src/ch341a.c index 4c36473c..6bfbc77f 100644 --- a/src/ch341a.c +++ b/src/ch341a.c @@ -354,10 +354,10 @@ static int ch341a_spi_chip_erase(const struct programmer_t *pgm, const AVRPART * static int ch341a_spi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes) { - int isflash = avr_mem_is_flash_type(m); + int isflash = mem_is_in_flash(m); if(n_bytes) { - if(!isflash && !avr_mem_is_eeprom_type(m)) + if(!isflash && !mem_is_eeprom(m)) return -2; // Always called with addr at page boundary and n_bytes == m->page_size @@ -376,10 +376,10 @@ static int ch341a_spi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const static int ch341a_spi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes) { - int isflash = avr_mem_is_flash_type(m); + int isflash = mem_is_in_flash(m); if(n_bytes) { - if(!isflash && !avr_mem_is_eeprom_type(m)) + if(!isflash && !mem_is_eeprom(m)) return -2; // Always called with addr at page boundary and n_bytes == m->page_size diff --git a/src/dryrun.c b/src/dryrun.c index 56f25102..42c2ced5 100644 --- a/src/dryrun.c +++ b/src/dryrun.c @@ -122,7 +122,7 @@ static void dryrun_enable(PROGRAMMER *pgm, const AVRPART *p) { // Initialise the device with fuse factory setting and erase flash/EEPROM to 0xff for (LNODEID ln=lfirst(dry.dp->mem); ln; ln=lnext(ln)) { AVRMEM *m = ldata(ln); - if(avr_mem_is_flash_type(m) || avr_mem_is_eeprom_type(m)) { + if(mem_is_in_flash(m) || mem_is_eeprom(m)) { memset(m->buf, 0xff, m->size); } else if(str_eq(m->desc, "fuses")) { fusesm = m; @@ -264,8 +264,8 @@ static int dryrun_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR unsigned int end; // Paged writes only valid for flash and eeprom - mchr = avr_mem_is_flash_type(m)? 'F': 'E'; - if(mchr == 'E' && !avr_mem_is_eeprom_type(m)) + mchr = mem_is_in_flash(m)? 'F': 'E'; + if(mchr == 'E' && !mem_is_eeprom(m)) return -2; if(!(dmem = avr_locate_mem(dry.dp, m->desc))) @@ -290,7 +290,7 @@ static int dryrun_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVR if(str_eq(dmem->desc, "flash")) { for(LNODEID ln=lfirst(dry.dp->mem); ln; ln=lnext(ln)) { dm2 = ldata(ln); - if(avr_mem_is_flash_type(dm2) && !str_eq(dm2->desc, "flash")) { // Overlapping region? + if(mem_is_in_flash(dm2) && !str_eq(dm2->desc, "flash")) { // Overlapping region? unsigned int cpaddr = addr + dmem->offset - dm2->offset; if(cpaddr < (unsigned int) dm2->size && cpaddr + chunk <= (unsigned int) dm2->size) memcpy(dm2->buf+cpaddr, dmem->buf+addr, chunk); @@ -322,8 +322,8 @@ static int dryrun_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRM unsigned int end; // Paged load only valid for flash and eeprom - mchr = avr_mem_is_flash_type(m)? 'F': 'E'; - if(mchr == 'E' && !avr_mem_is_eeprom_type(m)) + mchr = mem_is_in_flash(m)? 'F': 'E'; + if(mchr == 'E' && !mem_is_eeprom(m)) return -2; if(!(dmem = avr_locate_mem(dry.dp, m->desc))) diff --git a/src/jtag3.c b/src/jtag3.c index 02c77c60..03849383 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1861,7 +1861,7 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME cmd[1] = CMD3_ERASE_MEMORY; cmd[2] = 0; - if (avr_mem_is_flash_type(m)) { + if (mem_is_in_flash(m)) { if (p->prog_modes & PM_UPDI || jtag3_mtype(pgm, p, addr) == MTYPE_FLASH) cmd[3] = XMEGA_ERASE_APP_PAGE; else @@ -2119,13 +2119,13 @@ static int jtag3_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM cmd[2] = 0; cmd[3] = p->prog_modes & (PM_PDI | PM_UPDI)? MTYPE_FLASH: MTYPE_FLASH_PAGE; - if (avr_mem_is_flash_type(mem)) { + if (mem_is_in_flash(mem)) { addr += mem->offset & (512 * 1024 - 1); /* max 512 KiB flash */ pagesize = PDATA(pgm)->flash_pagesize; paddr = addr & ~(pagesize - 1); paddr_ptr = &PDATA(pgm)->flash_pageaddr; cache_ptr = PDATA(pgm)->flash_pagecache; - } else if (avr_mem_is_eeprom_type(mem)) { + } else if (mem_is_eeprom(mem)) { if ( (pgm->flag & PGM_FL_IS_DW) || (p->prog_modes & PM_PDI) || (p->prog_modes & PM_UPDI) ) { cmd[3] = MTYPE_EEPROM; } else { diff --git a/src/jtagmkII.c b/src/jtagmkII.c index 69a8c163..53744735 100644 --- a/src/jtagmkII.c +++ b/src/jtagmkII.c @@ -2168,12 +2168,12 @@ static int jtagmkII_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR addr += mem->offset; cmd[1] = p->prog_modes & (PM_PDI | PM_UPDI)? MTYPE_FLASH: MTYPE_FLASH_PAGE; - if (avr_mem_is_flash_type(mem)) { + if (mem_is_in_flash(mem)) { pagesize = PDATA(pgm)->flash_pagesize; paddr = addr & ~(pagesize - 1); paddr_ptr = &PDATA(pgm)->flash_pageaddr; cache_ptr = PDATA(pgm)->flash_pagecache; - } else if (avr_mem_is_eeprom_type(mem)) { + } else if (mem_is_eeprom(mem)) { if ( (pgm->flag & PGM_FL_IS_DW) || (p->prog_modes & (PM_PDI | PM_UPDI)) ) { /* debugWire cannot use page access for EEPROM */ cmd[1] = MTYPE_EEPROM; diff --git a/src/stk500.c b/src/stk500.c index c97e44bc..929b8e8a 100644 --- a/src/stk500.c +++ b/src/stk500.c @@ -950,7 +950,7 @@ static int stk500_loadaddr(const PROGRAMMER *pgm, const AVRMEM *mem, unsigned in static int set_memchr_a_div(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int *memchrp, int *a_divp) { - if(avr_mem_is_flash_type(m)) { + if(mem_is_in_flash(m)) { *memchrp = 'F'; if(!(pgm->prog_modes & PM_SPM)) // Programmer *not* for bootloaders: original stk500v1 protocol *a_divp = m->op[AVR_OP_LOADPAGE_LO] || m->op[AVR_OP_READ_LO]? 2: 1; @@ -961,7 +961,7 @@ static int set_memchr_a_div(const PROGRAMMER *pgm, const AVRPART *p, const AVRME return 0; } - if(avr_mem_is_eeprom_type(m)) { + if(mem_is_eeprom(m)) { *memchrp = 'E'; // Word addr for bootloaders or Arduino as ISP if part is a "classic" part, byte addr otherwise *a_divp = ((pgm->prog_modes & PM_SPM) || str_caseeq(pgmid, "arduino_as_isp")) \ diff --git a/src/urclock.c b/src/urclock.c index b66b8332..c8dd6fb8 100644 --- a/src/urclock.c +++ b/src/urclock.c @@ -2269,8 +2269,8 @@ static int urclock_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AV if(n_bytes) { // Paged writes only valid for flash and eeprom - mchr = avr_mem_is_flash_type(m)? 'F': 'E'; - if(mchr == 'E' && !avr_mem_is_eeprom_type(m)) + mchr = mem_is_in_flash(m)? 'F': 'E'; + if(mchr == 'E' && !mem_is_eeprom(m)) return -2; if(mchr == 'E' && !ur.bleepromrw && !ur.xeepromrw) @@ -2301,8 +2301,8 @@ static int urclock_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVR if(n_bytes) { // Paged reads only valid for flash and eeprom - mchr = avr_mem_is_flash_type(m)? 'F': 'E'; - if(mchr == 'E' && !avr_mem_is_eeprom_type(m)) + mchr = mem_is_in_flash(m)? 'F': 'E'; + if(mchr == 'E' && !mem_is_eeprom(m)) return -2; if(mchr == 'F' && ur.urprotocol && !(ur.urfeatures & UB_READ_FLASH)) @@ -2356,8 +2356,8 @@ int urclock_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem unsigned long addr, unsigned char *value) { // Bytewise read only valid for flash and eeprom - int mchr = avr_mem_is_flash_type(mem)? 'F': 'E'; - if(mchr == 'E' && !avr_mem_is_eeprom_type(mem)) { + int mchr = mem_is_in_flash(mem)? 'F': 'E'; + if(mchr == 'E' && !mem_is_eeprom(mem)) { if(str_eq(mem->desc, "signature") && pgm->read_sig_bytes) { if((int) addr < 0 || (int) addr >= mem->size) { return -1; @@ -2405,7 +2405,7 @@ static void urclock_display(const PROGRAMMER *pgm, const char *p_unused) { static int urclock_readonly(const struct programmer_t *pgm, const AVRPART *p_unused, const AVRMEM *mem, unsigned int addr) { - if(avr_mem_is_flash_type(mem)) { + if(mem_is_in_flash(mem)) { if(addr > (unsigned int) ur.pfend) return 1; if(addr < (unsigned int) ur.pfstart) @@ -2420,7 +2420,7 @@ static int urclock_readonly(const struct programmer_t *pgm, const AVRPART *p_unu return 1; } } - } else if(!avr_mem_is_eeprom_type(mem)) + } else if(!mem_is_eeprom(mem)) return 1; return 0;