From 00422f3f293a0fa49cdee83123c2f17498f7586c Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sun, 18 Aug 2024 16:25:34 +0100 Subject: [PATCH] Change xxx->prog_modes & PM_ABCD to is_abcd(xxx) --- src/avr.c | 24 ++++++++++++------------ src/avr_opcodes.c | 4 ++-- src/avrcache.c | 16 ++++++++-------- src/avrftdi.c | 4 ++-- src/bitbang.c | 8 ++++---- src/config.c | 2 +- src/developer_opts.c | 4 ++-- src/dryrun.c | 36 ++++++++++++++++++------------------ src/fileio.c | 22 +++++++++++----------- src/flip1.c | 2 +- src/flip2.c | 2 +- src/ft245r.c | 6 +++--- src/jtag3.c | 44 ++++++++++++++++++++++---------------------- src/jtagmkI.c | 2 +- src/jtagmkII.c | 22 +++++++++++----------- src/linuxspi.c | 2 +- src/main.c | 8 ++++---- src/serprog.c | 2 +- src/stk500.c | 10 +++++----- src/stk500v2.c | 18 +++++++++--------- src/term.c | 4 ++-- src/update.c | 6 +++--- src/urclock.c | 10 +++++----- src/usbasp.c | 2 +- src/usbtiny.c | 8 ++++---- 25 files changed, 134 insertions(+), 134 deletions(-) diff --git a/src/avr.c b/src/avr.c index 279e75e0d..b6337c760 100644 --- a/src/avr.c +++ b/src/avr.c @@ -52,7 +52,7 @@ int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { int err; AVRMEM *mem; - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { led_clr(pgm, LED_ERR); led_set(pgm, LED_PGM); @@ -107,7 +107,7 @@ int avr_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p, unsigned cha unsigned char cmd[2]; unsigned char response; - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { // Set guard time cmd[0] = (TPI_CMD_SSTCS | TPI_REG_TPIPCR); cmd[1] = guard_time; @@ -230,7 +230,7 @@ int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM led_clr(pgm, LED_ERR); led_set(pgm, LED_PGM); - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { if(pgm->cmd_tpi == NULL) { pmsg_error("%s programmer does not support TPI\n", pgm->type); goto error; @@ -377,7 +377,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con memset(mem->buf, 0xff, mem->size); // Supports paged load thru post-increment - if((p->prog_modes & PM_TPI) && mem->page_size > 1 && mem->size%mem->page_size == 0 && pgm->cmd_tpi != NULL) { + if(is_tpi(p) && mem->page_size > 1 && mem->size%mem->page_size == 0 && pgm->cmd_tpi != NULL) { while(avr_tpi_poll_nvmbsy(pgm)) continue; @@ -412,7 +412,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con } // HW programmers need a page size > 1, bootloader typ only offer paged r/w if((pgm->paged_load && mem->page_size > 1 && mem->size%mem->page_size == 0) || - ((pgm->prog_modes & PM_SPM) && avr_has_paged_access(pgm, p, mem))) { + (is_spm(pgm) && avr_has_paged_access(pgm, p, mem))) { // The programmer supports a paged mode read int need_read, failure; unsigned int pageaddr; @@ -664,7 +664,7 @@ int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM data = avr_bitmask_data(pgm, p, mem, addr, data); - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { if(pgm->cmd_tpi == NULL) { pmsg_error("%s programmer does not support TPI\n", pgm->type); goto error; @@ -939,7 +939,7 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int return wsize; } - if((p->prog_modes & PM_TPI) && m->page_size > 1 && pgm->cmd_tpi) { + if(is_tpi(p) && m->page_size > 1 && pgm->cmd_tpi) { unsigned int chunk; // Number of words for each write command unsigned int j, writeable_chunk; @@ -1013,7 +1013,7 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int } // HW programmers need a page size > 1, bootloader typ only offer paged r/w if((pgm->paged_load && m->page_size > 1 && m->size%m->page_size == 0) || - ((pgm->prog_modes & PM_SPM) && avr_has_paged_access(pgm, p, m))) { + (is_spm(pgm) && avr_has_paged_access(pgm, p, m))) { // The programmer supports a paged mode write int need_write, failure, nset; @@ -1039,7 +1039,7 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int AVRMEM *cm = avr_dup_mem(m); // Establish and sanity check effective page size - int pgsize = (pgm->prog_modes & PM_SPM) && p->n_page_erase > 0? p->n_page_erase*cm->page_size: cm->page_size; + int pgsize = is_spm(pgm) && p->n_page_erase > 0? p->n_page_erase*cm->page_size: cm->page_size; if((pgsize & (pgsize - 1)) || pgsize < 1) { pmsg_error("effective page size %d implausible\n", pgsize); @@ -1216,7 +1216,7 @@ int avr_mem_bitmask(const AVRPART *p, const AVRMEM *mem, int addr) { int bitmask = mem->bitmask; // Collective memory fuses will have a different bitmask for each address (ie, fuse) - if(mem_is_fuses(mem) && addr >= 0 && addr < 16) { // Get right fuse in fuses memory + if(mem_is_fuses(mem) && addr >= 0 && addr < 16) { // Get right fuse in fuses memory AVRMEM *dfuse = avr_locate_fuse_by_offset(p, addr); if(dfuse) { @@ -1306,7 +1306,7 @@ int avr_verify_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRPART *v, co for(i = 0; i < size; i++) { if((b->tags[i] & TAG_ALLOCATED) != 0 && buf1[i] != buf2[i]) { - uint8_t bitmask = p->prog_modes & PM_ISP? get_fuse_bitmask(a): avr_mem_bitmask(p, a, i); + uint8_t bitmask = is_isp(p)? get_fuse_bitmask(a): avr_mem_bitmask(p, a, i); if(ro || (pgm->readonly && pgm->readonly(pgm, p, a, i))) { if(quell_progress < 2) { @@ -1555,7 +1555,7 @@ Memtable avr_mem_order[100] = { // Whether a memory is an exception that shouldn't be there for this particular i/face int avr_mem_exclude(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m) { - return is_type(pgm, dryrun)? 0: // Never exclude dryrun memories + return is_type(pgm, dryrun)? 0: // Never exclude dryrun memories // debugWIRE only allows eeprom/flash/signature (both_debugwire(pgm, p) && !(mem_is_in_flash(m) || mem_is_eeprom(m) || mem_is_signature(m))) || // urclock type only allows eeprom/flash/signature diff --git a/src/avr_opcodes.c b/src/avr_opcodes.c index f25b6a881..bf11d9446 100644 --- a/src/avr_opcodes.c +++ b/src/avr_opcodes.c @@ -667,7 +667,7 @@ int op16_is_benign(int op16, int avrlevel) { // Benign means no I/O or SRAM i // Opcodes in avr_opcodes[] that a part ought to be able to run int avr_get_archlevel(const AVRPART *p) { int ret = - p->prog_modes & PM_UPDI? PART_AVR_XT: p->prog_modes & PM_PDI? PART_AVR_XM: p->prog_modes & PM_TPI? PART_AVR_RC: 0; + is_updi(p)? PART_AVR_XT: is_pdi(p)? PART_AVR_XM: is_tpi(p)? PART_AVR_RC: 0; if(!ret) { // Non-TPI classic part switch(p->archnum) { @@ -717,7 +717,7 @@ int avr_get_archlevel(const AVRPART *p) { // Index in the avr_opcodes[].clock[] array for timings of an opcode AVR_cycle_index avr_get_cycle_index(const AVRPART *p) { - return p->prog_modes & PM_UPDI? OP_AVRxt: p->prog_modes & PM_PDI? OP_AVRxm: p->prog_modes & PM_TPI? OP_AVRrc: OP_AVRe; + return is_updi(p)? OP_AVRxt: is_pdi(p)? OP_AVRxm: is_tpi(p)? OP_AVRrc: OP_AVRe; } // Return the mnemonic string of an opcode diff --git a/src/avrcache.c b/src/avrcache.c index f34b18dd4..960933de0 100644 --- a/src/avrcache.c +++ b/src/avrcache.c @@ -76,7 +76,7 @@ * avr_chip_erase_cached() erases the chip and discards pending writes() to * flash or EEPROM. It presets the flash cache to all 0xff alleviating the * need to read from the device flash. However, if the programmer serves - * bootloaders (pgm->prog_modes & PM_SPM) then the flash cache is reset + * bootloaders is_spm(pgm) then the flash cache is reset * instead, necessitating flash memory be fetched from the device on first * read; the reason for this is that bootloaders emulate chip erase and they * won't overwrite themselves (some bootloaders, eg, optiboot ignore chip @@ -269,7 +269,7 @@ static int initCache(AVR_Cache *cp, const PROGRAMMER *pgm, const AVRPART *p) { cp->copy = mmt_malloc(cp->size); cp->iscached = mmt_malloc(cp->size/cp->page_size); - if((pgm->prog_modes & PM_SPM) && mem_is_in_flash(basemem)) { // Could be vector bootloader + if(is_spm(pgm) && 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; @@ -329,7 +329,7 @@ static int guessBootStart(const PROGRAMMER *pgm, const AVRPART *p) { int bootstart = 0; const AVR_Cache *cp = pgm->cp_flash; - if(p->prog_modes & PM_UPDI) // Modern AVRs put the bootloader at 0 + if(is_updi(p)) // Modern AVRs put the bootloader at 0 return 0; if(p->n_boot_sections > 0 && p->boot_section_size > 0) @@ -512,8 +512,8 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) { continue; if(mems[i].isflash) { - memset(cp->copy, 0xff, cp->size); // Record device memory as erased - if(pgm->prog_modes & PM_SPM) { // Bootloaders will not overwrite themselves + memset(cp->copy, 0xff, cp->size); // Record device memory as erased + if(is_spm(pgm)) { // Bootloaders will not overwrite themselves // Read back generously estimated bootloader section to avoid verification errors int bootstart = guessBootStart(pgm, p); int nbo = (cp->size - bootstart)/cp->page_size; @@ -532,7 +532,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) { } else if(mems[i].iseeprom) { // Don't know whether chip erase has zapped EEPROM for(int n = 0; n < cp->size; n += cp->page_size) { - if(!is_memset(cp->copy + n, 0xff, cp->page_size)) { // First page that had EEPROM data + if(!is_memset(cp->copy + n, 0xff, cp->page_size)) { // First page that had EEPROM data if(avr_read_page_default(pgm, p, mem, n, cp->copy + n) < 0) { report_progress(1, -1, NULL); if(quell_progress) @@ -714,7 +714,7 @@ int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p) { return LIBAVRDUDE_GENERAL_FAILURE; if(mems[i].isflash) { - if(pgm->prog_modes & PM_SPM) { // Reset cache to unknown + if(is_spm(pgm)) { // Reset cache to unknown memset(cp->iscached, 0, cp->size/cp->page_size); } else { // Preset all pages as erased memset(cp->copy, 0xff, cp->size); @@ -726,7 +726,7 @@ int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p) { for(int pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size) { if(cp->iscached[pgno]) { - if(!is_memset(cp->copy + n, 0xff, cp->page_size)) { // Page has data? + if(!is_memset(cp->copy + n, 0xff, cp->page_size)) { // Page has data? if(avr_read_page_default(pgm, p, mem, n, cp->copy + n) < 0) return LIBAVRDUDE_GENERAL_FAILURE; erased = is_memset(cp->copy + n, 0xff, cp->page_size); diff --git a/src/avrftdi.c b/src/avrftdi.c index 72da168f2..4a1062600 100644 --- a/src/avrftdi.c +++ b/src/avrftdi.c @@ -232,7 +232,7 @@ static void avrftdi_enable(PROGRAMMER *pgm, const AVRPART *p) { set_pin(pgm, PPI_AVR_BUFF, ON); // Switch to TPI initialisation in avrftdi_tpi.c - if(p->prog_modes & PM_TPI) + if(is_tpi(p)) avrftdi_tpi_initpgm(pgm); } @@ -784,7 +784,7 @@ static void avrftdi_close(PROGRAMMER *pgm) { static int avrftdi_initialize(const PROGRAMMER *pgm, const AVRPART *p) { avrftdi_powerup(pgm); - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { // See avrftdi_tpi.c avrftdi_tpi_initialize(pgm, p); } else { diff --git a/src/bitbang.c b/src/bitbang.c index 50622cde7..76f245a43 100644 --- a/src/bitbang.c +++ b/src/bitbang.c @@ -372,7 +372,7 @@ int bitbang_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { unsigned char res[4]; AVRMEM *mem; - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { while(avr_tpi_poll_nvmbsy(pgm)); @@ -421,7 +421,7 @@ int bitbang_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { unsigned char res[4]; int i; - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { // Enable NVM programming bitbang_tpi_tx(pgm, TPI_CMD_SKEY); for(i = sizeof(tpi_skey) - 1; i >= 0; i--) @@ -460,7 +460,7 @@ int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) { usleep(20000); // TPIDATA is a single line, so SDI & SDO should be connected - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { // Make sure cmd_tpi() is defined if(pgm->cmd_tpi == NULL) { pmsg_error("%s programmer does not support TPI\n", pgm->type); @@ -494,7 +494,7 @@ int bitbang_initialize(const PROGRAMMER *pgm, const AVRPART *p) { pgm->setpin(pgm, PIN_AVR_RESET, 0); usleep(20000); - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { // Keep TPIDATA high for 16 clock cycles pgm->setpin(pgm, PIN_AVR_SDO, 1); for(i = 0; i < 16; i++) diff --git a/src/config.c b/src/config.c index 8774c956a..6d04fdf4b 100644 --- a/src/config.c +++ b/src/config.c @@ -1033,7 +1033,7 @@ void cfg_update_mcuid(AVRPART *part) { return; // Don't assign an mcuid for 32-bit AVR parts - if(part->prog_modes & PM_aWire) + if(is_awire(part)) return; // Find an entry that shares the same name, overwrite mcuid with known, existing mcuid diff --git a/src/developer_opts.c b/src/developer_opts.c index 4f2c8e5e2..4f8ea8ffa 100644 --- a/src/developer_opts.c +++ b/src/developer_opts.c @@ -1201,7 +1201,7 @@ void dev_output_part_defs(char *partdesc) { } // Print wait delays for AVR family parts if(waits) { - if(p->prog_modes & PM_ISP) + if(is_isp(p)) dev_info(".wd_chip_erase %.3f ms %s\n", p->chip_erase_delay/1000.0, p->desc); if(p->mem) { for(LNODEID lnm = lfirst(p->mem); lnm; lnm = lnext(lnm)) { @@ -1209,7 +1209,7 @@ void dev_output_part_defs(char *partdesc) { // Write delays not needed for read-only calibration and signature memories if(!mem_is_readonly(m)) { - if(p->prog_modes & PM_ISP) { + if(is_isp(p)) { if(m->min_write_delay == m->max_write_delay) dev_info(".wd_%s %.3f ms %s\n", m->desc, m->min_write_delay/1000.0, p->desc); else { diff --git a/src/dryrun.c b/src/dryrun.c index 8e842729c..744572237 100644 --- a/src/dryrun.c +++ b/src/dryrun.c @@ -107,7 +107,7 @@ static int dryrun_chip_erase(const PROGRAMMER *pgm, const AVRPART *punused) { verbose = -123; if((mem = avr_locate_eeprom(dry.dp))) // Check whether EEPROM needs erasing - if(avr_get_config_value(pgm, dry.dp, "eesave", &eesave) == 0 && eesave == !(dry.dp->prog_modes & PM_UPDI)) + if(avr_get_config_value(pgm, dry.dp, "eesave", &eesave) == 0 && eesave == !is_updi(dry.dp)) if(mem->size > 0) memset(mem->buf, 0xff, mem->size); verbose = bakverb; @@ -174,7 +174,7 @@ static int dryrun_program_enable(const PROGRAMMER *pgm, const AVRPART *p_unused) static void randflashconfig(const PROGRAMMER *pgm, const AVRPART *p, const Avrintel *up, const Configitem *cp, int nc) { - if(up && p->prog_modes & PM_UPDI) { + if(up && is_updi(p)) { int sectorsize = up->bootsize > 0? up->bootsize: 256; int nsectors = up->flashsize/sectorsize; int bootsize = random()%(nsectors > 4? nsectors/4: nsectors); @@ -197,7 +197,7 @@ static int flashlayout(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *fl AVRMEM *m; - if(p->prog_modes & PM_UPDI) { + if(is_updi(p)) { int nbootsec = 0, ncodesec = 0; int size = !!avr_locate_config(cp, nc, "bootsize", str_eq); @@ -221,10 +221,10 @@ static int flashlayout(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *fl avr_get_config_value(pgm, p, "bootrst", &bootrst); if(bootrst == 0) { // Jump to bootloader on reset - if((p->prog_modes & PM_PDI) && (m = avr_locate_boot(p)) && m->size > 0) { + if(is_pdi(p) && (m = avr_locate_boot(p)) && m->size > 0) { dry.bootstart = m->offset - flm->offset; dry.bootsize = m->size; - } else if(p->prog_modes & PM_Classic) { + } else if(is_classic(p)) { if(up->nboots == 4) { int bootsz = 0; @@ -237,7 +237,7 @@ static int flashlayout(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *fl } } dry.datastart = 0, dry.datasize = 0; - if((p->prog_modes & PM_PDI) && (m = avr_locate_apptable(p)) && m->size > 0) { + if(is_pdi(p) && (m = avr_locate_apptable(p)) && m->size > 0) { dry.datastart = m->offset - flm->offset; dry.datasize = up->flashsize - dry.datastart - dry.bootsize; } @@ -270,7 +270,7 @@ static int flashlayout(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *fl if(!dry.appsize) Retwarning("no application section"); - if(p->prog_modes & PM_UPDI) { + if(is_updi(p)) { if(dry.bootsize && dry.appstart != dry.bootsize) Retwarning("application section %s does not touch boot section %s", str_ccinterval(dry.appstart, dry.appstart + dry.appsize - 1), @@ -561,9 +561,9 @@ static void dryrun_enable(PROGRAMMER *pgm, const AVRPART *p) { prodsigm = m; memset(m->buf, 0xff, m->size); // Classic parts: signature at even addresses - int n = q->prog_modes & PM_TPI? 1: 2; // ... unless it's the TPI parts t102/t104 + int n = is_tpi(q)? 1: 2; // ... unless it's the TPI parts t102/t104 - if(q->prog_modes & PM_Classic) + if(is_classic(q)) for(int i = 0; i < 3; i++) m->buf[n*i] = q->signature[i]; } else if(mem_is_io(m)) { // Initialise reset values (if known) @@ -593,16 +593,16 @@ static void dryrun_enable(PROGRAMMER *pgm, const AVRPART *p) { memcpy(prodsigm->buf + off, m->buf, cpy); } } - if((q->prog_modes & PM_Classic) && (calm = avr_locate_calibration(q))) { + if(is_classic(q) && (calm = avr_locate_calibration(q))) { // Calibration bytes of classic parts are interspersed with signature - int n, tpi = !!(q->prog_modes & PM_TPI); // ... unless it's the TPI parts t102/t104 + int n, tpi = is_tpi(q); // ... unless it's the TPI parts t102/t104 for(int i = 0; i < calm->size; i++) { if((n = tpi? 3 + i: 2*i + 1) < prodsigm->size) prodsigm->buf[n] = 'U'; } } - if((q->prog_modes & PM_Classic) && (m = avr_locate_sernum(q))) { // m324pb/m328pb, t102/t104 + if(is_classic(q) && (m = avr_locate_sernum(q))) { // m324pb/m328pb, t102/t104 int off = m->offset - prodsigm->offset; int cpy = m->size; @@ -617,11 +617,11 @@ static void dryrun_enable(PROGRAMMER *pgm, const AVRPART *p) { } // Is the programmer a bootloader? - if((m = avr_locate_flash(q)) && m->size >= 1024 && (pgm->prog_modes & PM_SPM)) - dry.bl = (q->prog_modes & PM_UPDI)? DRY_BOTTOM: DRY_TOP; + if((m = avr_locate_flash(q)) && m->size >= 1024 && is_spm(pgm)) + dry.bl = is_updi(q)? DRY_BOTTOM: DRY_TOP; // So that dryrun can emulate AVRDUDE page erase - if(!(pgm->prog_modes & PM_SPM) && (q->prog_modes & (PM_PDI | PM_UPDI))) + if(!is_spm(pgm) && (q->prog_modes & (PM_PDI | PM_UPDI))) pgm->page_erase = dryrun_page_erase; if(!dry.random && !dry.init) // OK, no further initialisation needed @@ -656,7 +656,7 @@ static void dryrun_enable(PROGRAMMER *pgm, const AVRPART *p) { int vtb = putvectortable(q, flm, dry.appstart, dry.init), urbtsz = 0; int urboot = random()%3 && dry.bootsize <= 512 && flm->size >= 1024 && - flm->size >= 4*dry.bootsize && (q->prog_modes & PM_Classic) && (q->prog_modes & PM_SPM); + flm->size >= 4*dry.bootsize && is_classic(q) && is_spm(q); if(urboot) { // Give some classic parts a small bootloader int ps = flm->page_size; @@ -905,7 +905,7 @@ int dryrun_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, Return("cannot read byte %s %s as address 0x%04lx outside range [0, 0x%04x]", dry.dp->desc, dmem->desc, addr, dmem->size - 1); - if(!dry.bl && (mem_is_io(dmem) || mem_is_sram(dmem)) && (p->prog_modes & PM_Classic)) + if(!dry.bl && (mem_is_io(dmem) || mem_is_sram(dmem)) && is_classic(p)) Return("classic part io/sram memories cannot be read externally"); *value = dmem->buf[addr]; @@ -956,7 +956,7 @@ static int dryrun_readonly(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM if(!dry.bl) { // io and sram may not be accessible by external programming if(mem_is_io(mem) || mem_is_sram(mem)) - return !(p->prog_modes & PM_UPDI); // Can not even read these externally in classic parts + return !is_updi(p); // Can not even read these externally in classic parts return 0; } diff --git a/src/fileio.c b/src/fileio.c index 685b3e6d2..f5c2af9b0 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -219,13 +219,13 @@ unsigned fileio_mem_offset(const AVRPART *p, const AVRMEM *mem) { mem_is_eeprom(mem)? MBASE(EEPROM): mem_is_in_fuses(mem)? MBASE(FUSES) + mem_fuse_offset(mem): mem_is_lock(mem)? MBASE(LOCK): // Classic parts intersperse signature and calibration bytes, this code places them together - (p->prog_modes & PM_Classic) && mem_is_signature(mem)? MBASE(SIGROW): - (p->prog_modes & PM_Classic) && mem_is_calibration(mem)? MBASE(SIGROW) + 3: - (p->prog_modes & PM_Classic) && mem_is_in_sigrow(mem)? MBASE(SIGROW) + 0x10 + mem->offset - boffset(p, sigrow): + is_classic(p) && mem_is_signature(mem)? MBASE(SIGROW): + is_classic(p) && mem_is_calibration(mem)? MBASE(SIGROW) + 3: + is_classic(p) && mem_is_in_sigrow(mem)? MBASE(SIGROW) + 0x10 + mem->offset - boffset(p, sigrow): // XMEGA parts have signature separate from prodsig, place prodsig at +0x10 as above - (p->prog_modes & PM_PDI) && mem_is_signature(mem)? MBASE(SIGROW): - (p->prog_modes & PM_PDI) && mem_is_in_sigrow(mem)? MBASE(SIGROW) + 0x10 + mem->offset - boffset(p, sigrow): - (p->prog_modes & PM_UPDI) && mem_is_in_sigrow(mem)? MBASE(SIGROW) + mem->offset - boffset(p, sigrow): + is_pdi(p) && mem_is_signature(mem)? MBASE(SIGROW): + is_pdi(p) && mem_is_in_sigrow(mem)? MBASE(SIGROW) + 0x10 + mem->offset - boffset(p, sigrow): + is_updi(p) && mem_is_in_sigrow(mem)? MBASE(SIGROW) + mem->offset - boffset(p, sigrow): mem_is_sib(mem)? MBASE(SIGROW) + 0x1000: // Arbitrary 0x1000 offset in signature section for sib mem_is_userrow(mem)? MBASE(USERROW): mem_is_bootrow(mem)? MBASE(BOOTROW): ~0U; @@ -986,7 +986,7 @@ static int elf_mem_limits(const AVRMEM *mem, const AVRPART *p, unsigned int *lowbound, unsigned int *highbound, unsigned int *fileoff) { int rv = 0; - if(p->prog_modes & PM_aWire) { // AVR32 + if(is_awire(p)) { // AVR32 if(mem_is_flash(mem)) { *lowbound = 0x80000000; *highbound = 0xffffffff; @@ -1054,7 +1054,7 @@ static int elf2b(const char *infile, FILE *inf, const AVRMEM *mem, * allows to select only the appropriate sections out of an ELF file that * contains section data for more than one sub-segment. */ - if((p->prog_modes & PM_PDI) && mem_is_in_flash(mem) && !mem_is_flash(mem)) { + if(is_pdi(p) && mem_is_in_flash(mem) && !mem_is_flash(mem)) { AVRMEM *flashmem = avr_locate_flash(p); if(flashmem == NULL) { @@ -1090,7 +1090,7 @@ static int elf2b(const char *infile, FILE *inf, const AVRMEM *mem, const char *endianname; unsigned char endianness; - if(p->prog_modes & PM_aWire) { // AVR32 + if(is_awire(p)) { // AVR32 endianness = ELFDATA2MSB; endianname = "little"; } else { @@ -1117,7 +1117,7 @@ static int elf2b(const char *infile, FILE *inf, const AVRMEM *mem, const char *mname; uint16_t machine; - if(p->prog_modes & PM_aWire) { + if(is_awire(p)) { machine = EM_AVR32; mname = "AVR32"; } else { @@ -1525,7 +1525,7 @@ static int fileio_setparms(int op, struct fioparms *fp, const AVRPART *p, const * AVR32 devices maintain their load offset within the file itself, but * AVRDUDE maintains all memory images 0-based. */ - fp->fileoffset = p->prog_modes & PM_aWire? m->offset: 0; + fp->fileoffset = is_awire(p)? m->offset: 0; return 0; } diff --git a/src/flip1.c b/src/flip1.c index 67d0b946e..39ab9e562 100644 --- a/src/flip1.c +++ b/src/flip1.c @@ -218,7 +218,7 @@ static int flip1_initialize(const PROGRAMMER *pgm, const AVRPART *part) { } else { pid = part->usbpid; } - if(!ovsigck && (part->prog_modes & PM_PDI)) { + if(!ovsigck && is_pdi(part)) { pmsg_error("flip1 (FLIP protocol version 1) is for AT90USB* and ATmega*U* devices\n"); imsg_error("for Xmega devices, use flip2 or use -F to bypass this check\n"); return -1; diff --git a/src/flip2.c b/src/flip2.c index c3bf692ac..63ffbe1fb 100644 --- a/src/flip2.c +++ b/src/flip2.c @@ -217,7 +217,7 @@ static int flip2_initialize(const PROGRAMMER *pgm, const AVRPART *part) { pid = part->usbpid; } - if(!ovsigck && !(part->prog_modes & PM_PDI)) { + if(!ovsigck && !is_pdi(part)) { pmsg_error("flip2 (FLIP protocol version 2) is for Xmega devices;\n"); imsg_error("for AT90USB* or ATmega*U* devices use flip1 or use -F to bypass this check\n"); return -1; diff --git a/src/ft245r.c b/src/ft245r.c index 99151fc7a..d7e320778 100644 --- a/src/ft245r.c +++ b/src/ft245r.c @@ -340,7 +340,7 @@ static int ft245r_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { unsigned char cmd[4] = { 0, 0, 0, 0 }; unsigned char res[4]; - if(p->prog_modes & PM_TPI) + if(is_tpi(p)) return avr_tpi_chip_erase(pgm, p); if(p->op[AVR_OP_CHIP_ERASE] == NULL) { @@ -481,7 +481,7 @@ static int ft245r_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { unsigned char res[4]; int i; - if(p->prog_modes & PM_TPI) + if(is_tpi(p)) return avr_tpi_program_enable(pgm, p, TPIPCR_GT_0b); if(p->op[AVR_OP_PGM_ENABLE] == NULL) { @@ -540,7 +540,7 @@ static int ft245r_initialize(const PROGRAMMER *pgm, const AVRPART *p) { */ ft245r_usleep(pgm, 20000); // 20ms - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { bool io_link_ok = true; uint8_t byte; int i; diff --git a/src/jtag3.c b/src/jtag3.c index a3be21f8f..bda8bd8e1 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1019,15 +1019,15 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { if(pgm->flag & PGM_FL_IS_DW) { ifname = "debugWire"; - if(p->prog_modes & PM_debugWIRE) + if(is_debugwire(p)) conn = PARM3_CONN_DW; } else if(pgm->flag & PGM_FL_IS_PDI) { ifname = "PDI"; - if(p->prog_modes & PM_PDI) + if(is_pdi(p)) conn = PARM3_CONN_PDI; } else if(pgm->flag & PGM_FL_IS_UPDI) { ifname = "UPDI"; - if(p->prog_modes & PM_UPDI) + if(is_updi(p)) conn = PARM3_CONN_UPDI; } else { ifname = "JTAG"; @@ -1040,11 +1040,11 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { return -1; } - if(p->prog_modes & PM_PDI) + if(is_pdi(p)) parm[0] = PARM3_ARCH_XMEGA; - else if(p->prog_modes & PM_UPDI) + else if(is_updi(p)) parm[0] = PARM3_ARCH_UPDI; - else if(p->prog_modes & PM_debugWIRE) + else if(is_debugwire(p)) parm[0] = PARM3_ARCH_TINY; else parm[0] = PARM3_ARCH_MEGA; @@ -1062,7 +1062,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { if(conn == PARM3_CONN_PDI || conn == PARM3_CONN_UPDI) my.set_sck = jtag3_set_sck_xmega_pdi; else if(conn == PARM3_CONN_JTAG) { - if(p->prog_modes & PM_PDI) + if(is_pdi(p)) my.set_sck = jtag3_set_sck_xmega_jtag; else my.set_sck = jtag3_set_sck_mega_jtag; @@ -1154,7 +1154,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { } // Set device descriptor data - if((p->prog_modes & PM_PDI)) { + if(is_pdi(p)) { struct xmega_device_desc xd; LNODEID ln; AVRMEM *m; @@ -1196,7 +1196,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { if(jtag3_setparm(pgm, SCOPE_AVR, 2, PARM3_DEVICEDESC, (unsigned char *) &xd, sizeof xd) < 0) return -1; - } else if((p->prog_modes & PM_UPDI)) { + } else if(is_updi(p)) { struct updi_device_desc xd; LNODEID ln; AVRMEM *m; @@ -1324,7 +1324,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { int ocdrev; // Lacking a proper definition, guess the OCD revision - if(p->prog_modes & PM_debugWIRE) + if(is_debugwire(p)) ocdrev = 1; // Exception: ATtiny13, 2313, 4313 else if(flashsize > 128*1024) ocdrev = 4; @@ -1383,7 +1383,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { * is just RSP_OK. */ if(resp[1] == RSP3_DATA && status >= 7) { - if(p->prog_modes & PM_UPDI) { + if(is_updi(p)) { // Partial Family_ID has been returned pmsg_notice("partial Family_ID returned: \"%c%c%c%c\"\n", resp[3], resp[4], resp[5], resp[6]); } else @@ -1407,7 +1407,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { } my.boot_start = ULONG_MAX; - if(p->prog_modes & PM_PDI) { + if(is_pdi(p)) { // Find the border between application and boot area AVRMEM *bootmem = avr_locate_boot(p); AVRMEM *flashmem = avr_locate_flash(p); @@ -1443,7 +1443,7 @@ static void jtag3_disable(const PROGRAMMER *pgm) { static void jtag3_enable(PROGRAMMER *pgm, const AVRPART *p) { // Page erase only useful for classic parts with usersig mem or AVR8X/XMEGAs - if(p->prog_modes & PM_Classic) + if(is_classic(p)) if(!avr_locate_usersig(p)) pgm->page_erase = NULL; } @@ -1869,7 +1869,7 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME pmsg_notice2("jtag3_page_erase(.., %s, 0x%x)\n", m->desc, addr); - if((p->prog_modes & PM_Classic) && !mem_is_userrow(m)) { + if(is_classic(p) && !mem_is_userrow(m)) { pmsg_error("page erase only available for AVR8X/XMEGAs or classic-part usersig mem\n"); return -1; } @@ -1935,7 +1935,7 @@ static int jtag3_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRM if(mem_is_flash(m)) { my.flash_pageaddr = ~0UL; cmd[3] = jtag3_mtype(pgm, p, m, addr); - if(p->prog_modes & PM_PDI) + if(is_pdi(p)) // Dynamically decide between flash/boot mtype dynamic_mtype = 1; } else if(mem_is_eeprom(m)) { @@ -2032,7 +2032,7 @@ static int jtag3_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRME if(mem_is_flash(m)) { cmd[3] = jtag3_mtype(pgm, p, m, addr); - if(p->prog_modes & PM_PDI) + if(is_pdi(p)) // Dynamically decide between flash/boot mtype dynamic_mtype = 1; } else if(mem_is_eeprom(m)) { @@ -2045,9 +2045,9 @@ static int jtag3_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRME cmd[3] = MTYPE_USERSIG; } else if(mem_is_boot(m)) { cmd[3] = MTYPE_BOOT_FLASH; - } else if(p->prog_modes & PM_PDI) { + } else if(is_pdi(p)) { cmd[3] = MTYPE_FLASH; - } else if(p->prog_modes & PM_UPDI) { + } else if(is_updi(p)) { cmd[3] = MTYPE_SRAM; } else { cmd[3] = MTYPE_SPM; @@ -2142,7 +2142,7 @@ static int jtag3_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM cache_ptr = my.eeprom_pagecache; } else if(mem_is_a_fuse(mem) || mem_is_fuses(mem)) { cmd[3] = MTYPE_FUSE_BITS; - if(!(p->prog_modes & PM_UPDI) && mem_is_a_fuse(mem)) + if(!is_updi(p) && mem_is_a_fuse(mem)) addr = mem_fuse_offset(mem); if(pgm->flag & PGM_FL_IS_DW) unsupp = 1; @@ -2161,7 +2161,7 @@ static int jtag3_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM if(pgm->flag & PGM_FL_IS_DW) unsupp = 1; } - } else if((p->prog_modes & PM_Classic) && mem_is_calibration(mem)) { // Classic part calibration + } else if(is_classic(p) && mem_is_calibration(mem)) { // Classic part calibration cmd[3] = MTYPE_OSCCAL_BYTE; if(pgm->flag & PGM_FL_IS_DW) unsupp = 1; @@ -2315,7 +2315,7 @@ static int jtag3_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRME my.eeprom_pageaddr = ~0UL; } else if(mem_is_a_fuse(mem) || mem_is_fuses(mem)) { cmd[3] = MTYPE_FUSE_BITS; - if(!(p->prog_modes & PM_UPDI) && mem_is_a_fuse(mem)) + if(!is_updi(p) && mem_is_a_fuse(mem)) addr = mem_fuse_offset(mem); if(pgm->flag & PGM_FL_IS_DW) unsupp = 1; @@ -2544,7 +2544,7 @@ int jtag3_read_chip_rev(const PROGRAMMER *pgm, const AVRPART *p, unsigned char * return -1; } int status = pgm->read_byte(pgm, p, m, - p->prog_modes & PM_PDI? p->mcu_base + 3: p->syscfg_base + 1, chip_rev); + is_pdi(p)? p->mcu_base + 3: p->syscfg_base + 1, chip_rev); if(status < 0) return status; diff --git a/src/jtagmkI.c b/src/jtagmkI.c index 3c732af6b..9bd3f10ec 100644 --- a/src/jtagmkI.c +++ b/src/jtagmkI.c @@ -435,7 +435,7 @@ static int jtagmkI_initialize(const PROGRAMMER *pgm, const AVRPART *p) { pmsg_error("part %s has no JTAG interface\n", p->desc); return -1; } - if(!(p->prog_modes & PM_JTAGmkI)) + if(!is_jtagmki(p)) pmsg_warning("part %s has JTAG interface, but may be too new\n", p->desc); jtagmkI_drain(pgm, 0); diff --git a/src/jtagmkII.c b/src/jtagmkII.c index 353fa7471..2b0eb7ea8 100644 --- a/src/jtagmkII.c +++ b/src/jtagmkII.c @@ -827,7 +827,7 @@ static int jtagmkII_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { return -1; } - if(p->prog_modes & PM_Classic) + if(is_classic(p)) pgm->initialize(pgm, p); my.recently_written = 1; @@ -876,7 +876,7 @@ static void jtagmkII_set_devdescr(const PROGRAMMER *pgm, const AVRPART *p) { u32_to_b4(sendbuf.dd.ulFlashSize, m->size); u16_to_b2(sendbuf.dd.uiFlashPageSize, m->page_size); u16_to_b2(sendbuf.dd.uiFlashpages, m->size/m->page_size); - if(p->prog_modes & PM_debugWIRE) { + if(is_debugwire(p)) { memcpy(sendbuf.dd.ucFlashInst, p->flash_instr, FLASH_INSTR_SIZE); memcpy(sendbuf.dd.ucEepromInst, p->eeprom_instr, EEPROM_INSTR_SIZE); } @@ -1162,8 +1162,8 @@ static int jtagmkII_initialize(const PROGRAMMER *pgm, const AVRPART *p) { } // Abort and print error if programmer does not support the target microcontroller - if((str_starts(pgm->type, "JTAGMKII_UPDI") && !(p->prog_modes & PM_UPDI)) || - (str_starts(pgmid, "jtagmkII") && (p->prog_modes & PM_UPDI))) { + if((str_starts(pgm->type, "JTAGMKII_UPDI") && !is_updi(p)) || + (str_starts(pgmid, "jtagmkII") && is_updi(p))) { msg_error("programmer %s does not support target %s\n\n", pgmid, p->desc); return -1; } @@ -1171,7 +1171,7 @@ static int jtagmkII_initialize(const PROGRAMMER *pgm, const AVRPART *p) { ok = 0; if(pgm->flag & PGM_FL_IS_DW) { ifname = "debugWire"; - if(p->prog_modes & PM_debugWIRE) + if(is_debugwire(p)) ok = 1; } else if(pgm->flag & PGM_FL_IS_PDI) { ifname = "PDI"; @@ -1268,7 +1268,7 @@ static int jtagmkII_initialize(const PROGRAMMER *pgm, const AVRPART *p) { return -1; } - if((pgm->flag & PGM_FL_IS_JTAG) && (p->prog_modes & PM_Classic)) { + if((pgm->flag & PGM_FL_IS_JTAG) && is_classic(p)) { int ocden = 0; if(avr_get_config_value(pgm, p, "ocden", &ocden) == 0 && ocden) // ocden == 1 means disabled @@ -1300,7 +1300,7 @@ static void jtagmkII_disable(const PROGRAMMER *pgm) { static void jtagmkII_enable(PROGRAMMER *pgm, const AVRPART *p) { // Page erase only useful for classic parts with usersig mem or AVR8X/XMEGAs - if(p->prog_modes & PM_Classic) + if(is_classic(p)) if(!avr_locate_usersig(p)) pgm->page_erase = NULL; @@ -1757,7 +1757,7 @@ static int jtagmkII_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AV pmsg_notice2("jtagmkII_page_erase(.., %s, 0x%x)\n", m->desc, addr); - if((p->prog_modes & PM_Classic) && !mem_is_userrow(m)) { + if(is_classic(p) && !mem_is_userrow(m)) { pmsg_error("page erase only available for AVR8X/XMEGAs or classic-part usersig mem\n"); return -1; } @@ -2046,7 +2046,7 @@ static int jtagmkII_read_chip_rev(const PROGRAMMER *pgm, const AVRPART *p, unsig return -1; } int status = pgm->read_byte(pgm, p, m, - p->prog_modes & PM_PDI? p->mcu_base + 3: p->syscfg_base + 1, chip_rev); + is_pdi(p)? p->mcu_base + 3: p->syscfg_base + 1, chip_rev); if(status < 0) return status; @@ -2095,7 +2095,7 @@ static int jtagmkII_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR } } else if(mem_is_a_fuse(mem) || mem_is_fuses(mem)) { cmd[1] = MTYPE_FUSE_BITS; - if((p->prog_modes & PM_Classic) && mem_is_a_fuse(mem)) + if(is_classic(p) && mem_is_a_fuse(mem)) addr = mem_fuse_offset(mem); if(pgm->flag & PGM_FL_IS_DW) unsupp = 1; @@ -2268,7 +2268,7 @@ static int jtagmkII_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AV my.eeprom_pageaddr = ~0UL; } else if(mem_is_a_fuse(mem) || mem_is_fuses(mem)) { cmd[1] = MTYPE_FUSE_BITS; - if((p->prog_modes & PM_Classic) && mem_is_a_fuse(mem)) + if(is_classic(p) && mem_is_a_fuse(mem)) addr = mem_fuse_offset(mem); if(pgm->flag & PGM_FL_IS_DW) unsupp = 1; diff --git a/src/linuxspi.c b/src/linuxspi.c index 153b546b4..485736793 100644 --- a/src/linuxspi.c +++ b/src/linuxspi.c @@ -299,7 +299,7 @@ static void linuxspi_display(const PROGRAMMER *pgm, const char *p) { static int linuxspi_initialize(const PROGRAMMER *pgm, const AVRPART *p) { int tries, ret; - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { // We do not support TPI; this is a dedicated SPI thing pmsg_error("programmer " LINUXSPI " does not support TPI\n"); return -1; diff --git a/src/main.c b/src/main.c index 1e871ab89..ba0ca0a52 100644 --- a/src/main.c +++ b/src/main.c @@ -1483,7 +1483,7 @@ int main(int argc, char *argv[]) { for(ln = lfirst(updates); ln; ln = lnext(ln)) { upd = ldata(ln); if(upd->memstr == NULL && upd->cmdline == NULL) { - const char *mtype = p->prog_modes & PM_PDI? "application": "flash"; + const char *mtype = is_pdi(p)? "application": "flash"; pmsg_notice2("defaulting memstr in -U %c:%s option to \"%s\"\n", (upd->op == DEVICE_READ)? 'r': (upd->op == DEVICE_WRITE)? 'w': 'v', upd->filename, mtype); @@ -1570,7 +1570,7 @@ int main(int argc, char *argv[]) { * the other end that is responding correctly. A check against * 0xffffff/0x000000 should ensure that the signature bytes are valid. */ - if(!(p->prog_modes & PM_aWire)) { // Not AVR32 + if(!is_awire(p)) { // Not AVR32 int attempt = 0; int waittime = 10000; // 10 ms @@ -1583,7 +1583,7 @@ int main(int argc, char *argv[]) { goto main_exit; } if(rc != LIBAVRDUDE_SUCCESS) { - if(rc == LIBAVRDUDE_SOFTFAIL && (p->prog_modes & PM_UPDI) && attempt < 1) { + if(rc == LIBAVRDUDE_SOFTFAIL && is_updi(p) && attempt < 1) { attempt++; if(pgm->read_sib) { // Read SIB and compare FamilyID @@ -1631,7 +1631,7 @@ int main(int argc, char *argv[]) { const char *mculist = str_ccmcunames_signature(sig->buf, pgm->prog_modes); if(!*mculist) { // No matching signatures? - if(p->prog_modes & PM_UPDI) { // UPDI parts have different(!) offsets for signature + if(is_updi(p)) { // UPDI parts have different(!) offsets for signature int k, n = 0; // Gather list of known different signature offsets unsigned myoff = sig->offset, offlist[10]; diff --git a/src/serprog.c b/src/serprog.c index aa0324455..c6622254e 100644 --- a/src/serprog.c +++ b/src/serprog.c @@ -281,7 +281,7 @@ static int serprog_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned } static int serprog_initialize(const PROGRAMMER *pgm, const AVRPART *part) { - if(part->prog_modes & PM_TPI) { + if(is_tpi(part)) { // We do not support TPI; this is a dedicated SPI thing pmsg_error("the %s programmer does not support TPI\n", pgmid); return -1; diff --git a/src/stk500.c b/src/stk500.c index 654514865..9fc0a674e 100644 --- a/src/stk500.c +++ b/src/stk500.c @@ -832,7 +832,7 @@ static void stk500_disable(const PROGRAMMER *pgm) { static void stk500_enable(PROGRAMMER *pgm, const AVRPART *p) { AVRMEM *mem; - if(pgm->prog_modes & PM_SPM) // For bootloaders (eg, arduino) + if(is_spm(pgm)) // For bootloaders (eg, arduino) if((mem = avr_locate_eeprom(p))) if(mem->page_size == 1) // Change EEPROM page size from 1 to 16 to force paged r/w mem->page_size = 16; @@ -890,7 +890,7 @@ static int stk500_loadaddr(const PROGRAMMER *pgm, const AVRMEM *mem, unsigned in // Support large flash by sending the correct extended address byte when needed - if(pgm->prog_modes & PM_SPM) { // Bootloaders, eg, optiboot, optiboot_dx, optiboot_x + if(is_spm(pgm)) { // Bootloaders, eg, optiboot, optiboot_dx, optiboot_x if(mem->size/a_div > 64*1024) { // Extended addressing needed ext_byte = (addr >> 16) & 0xff; if(ext_byte != my.ext_addr_byte) { // First addr load or a different 64k section @@ -967,7 +967,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(mem_is_in_flash(m)) { *memchrp = 'F'; - if(!(pgm->prog_modes & PM_SPM)) // Programmer *not* for bootloaders: original stk500v1 protocol + if(!is_spm(pgm)) // Programmer *not* for bootloaders: original stk500v1 protocol *a_divp = m->op[AVR_OP_LOADPAGE_LO] || m->op[AVR_OP_READ_LO]? 2: 1; else if(!(p->prog_modes & (PM_UPDI | PM_PDI | PM_aWire))) *a_divp = 2; // Bootloader where part is a "classic" part (eg, optiboot) @@ -979,8 +979,8 @@ static int set_memchr_a_div(const PROGRAMMER *pgm, const AVRPART *p, const AVRME 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")) - && (p->prog_modes & PM_Classic)? 2: 1; + *a_divp = (is_spm(pgm) || str_caseeq(pgmid, "arduino_as_isp")) + && is_classic(p)? 2: 1; return 0; } diff --git a/src/stk500v2.c b/src/stk500v2.c index 1fdcf8a9d..b0f891b8d 100644 --- a/src/stk500v2.c +++ b/src/stk500v2.c @@ -1063,7 +1063,7 @@ static int stk500v2_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { break; case PGMTYPE_JTAGICE3: - if(buf[1] == STATUS_CMD_FAILED && (p->prog_modes & PM_debugWIRE)) { + if(buf[1] == STATUS_CMD_FAILED && is_debugwire(p)) { unsigned char cmd[4], *resp; // Try debugWIRE, and MONCON_DISABLE @@ -1161,7 +1161,7 @@ static int stk500v2_initialize(const PROGRAMMER *pgm, const AVRPART *p) { my.pgmtype == PGMTYPE_AVRISP_MKII || my.pgmtype == PGMTYPE_JTAGICE_MKII) != 0 && (p->prog_modes & (PM_PDI | PM_TPI)) != 0) { // This is an ATxmega device, must use XPROG protocol for the remaining actions - if(p->prog_modes & PM_PDI) { + if(is_pdi(p)) { // Find the border between application and boot area AVRMEM *bootmem = avr_locate_boot(p); AVRMEM *flashmem = avr_locate_flash(p); @@ -1304,7 +1304,7 @@ static int stk500v2_jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { pgmcp->cookie = my.chained_pdata; - if(p->prog_modes & PM_debugWIRE) + if(is_debugwire(p)) parm[0] = PARM3_ARCH_TINY; else parm[0] = PARM3_ARCH_MEGA; @@ -2808,7 +2808,7 @@ static int stk500v2_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const A // Do not send request to write empty flash pages except for bootloaders (fixes Issue #425) unsigned char *p = m->buf + addr; - result = (pgm->prog_modes & PM_SPM) || !addrshift || *p != 0xff || memcmp(p, p + 1, block_size - 1)? + result = is_spm(pgm) || !addrshift || *p != 0xff || memcmp(p, p + 1, block_size - 1)? stk500v2_command(pgm, buf, block_size + 10, sizeof buf): 0; if(result < 0) { @@ -4175,7 +4175,7 @@ static int stk600_xprog_program_enable(const PROGRAMMER *pgm, const AVRPART *p) AVRMEM *mem = NULL; int use_tpi; - use_tpi = (p->prog_modes & PM_TPI) != 0; + use_tpi = is_tpi(p) != 0; if(!use_tpi) { if(p->nvm_base == 0) { @@ -4257,7 +4257,7 @@ static int stk600_xprog_program_enable(const PROGRAMMER *pgm, const AVRPART *p) } // Read XMEGA chip silicon revision - if(p->prog_modes & PM_PDI) { + if(is_pdi(p)) { AVRMEM *m = avr_locate_io(p); unsigned char chip_rev[AVR_CHIP_REVLEN]; @@ -4310,7 +4310,7 @@ static int stk600_xprog_write_byte(const PROGRAMMER *pgm, const AVRPART *p, cons memcode = XPRG_MEM_TYPE_LOCKBITS; } else if(mem_is_a_fuse(mem) || mem_is_fuses(mem)) { memcode = XPRG_MEM_TYPE_FUSE; - if(p->prog_modes & PM_TPI) + if(is_tpi(p)) need_erase = 1; } else if(mem_is_userrow(mem)) { memcode = XPRG_MEM_TYPE_USERSIG; @@ -4341,7 +4341,7 @@ static int stk600_xprog_write_byte(const PROGRAMMER *pgm, const AVRPART *p, cons } } - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { /* * Some TPI memories (configuration aka. fuse) require a larger write block * size. We record that as a blocksize in avrdude.conf. @@ -4659,7 +4659,7 @@ static int stk600_xprog_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { AVRMEM *mem; unsigned int addr = 0; - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { if((mem = avr_locate_flash(p)) == NULL) { pmsg_error("no FLASH definition found for TPI device\n"); return -1; diff --git a/src/term.c b/src/term.c index 181a4dac1..eb32a2254 100644 --- a/src/term.c +++ b/src/term.c @@ -1262,7 +1262,7 @@ static int cmd_erase(const PROGRAMMER *pgm, const AVRPART *p, int argc, const ch } term_out("%s chip erase; discarded pending writes to flash%s\n", - (pgm->prog_modes & PM_SPM)? "asking bootloader to perform": "performing", + is_spm(pgm)? "asking bootloader to perform": "performing", avr_locate_bootrow(p)? ", EEPROM and bootrow": avr_locate_eeprom(p)? " and EEPROM": ""); // Erase chip and clear cache @@ -2029,7 +2029,7 @@ static int cmd_factory(const PROGRAMMER *pgm, const AVRPART *p, int argc, const return -1; } - if(pgm->prog_modes & PM_SPM) { // Bootloader + if(is_spm(pgm)) { // Bootloader pmsg_warning("-c %s is for bootloaders, which cannot set fuses;\n", pgmid); imsg_warning("only erasing flash and other writable memories as far as possible\n"); if((m = avr_locate_flash(p))) { // First erase flash diff --git a/src/update.c b/src/update.c index 312a43768..c33a823cc 100644 --- a/src/update.c +++ b/src/update.c @@ -493,7 +493,7 @@ static int update_avr_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRME if(memstats_mem(p, mem, size, &fs_patched) < 0) return -1; if(memcmp(&fs_patched, &fs, sizeof fs)) { - pmsg_notice("preparing flash input for device%s\n", pgm->prog_modes & PM_SPM? " bootloader": ""); + pmsg_notice("preparing flash input for device%s\n", is_spm(pgm)? " bootloader": ""); imsg_notice("%d byte%s in %d section%s %s%s", fs_patched.nbytes, str_plural(fs_patched.nbytes), fs_patched.nsections, str_plural(fs_patched.nsections), @@ -594,7 +594,7 @@ static int update_mem_from_all(const UPDATE *upd, const AVRPART *p, const AVRMEM if(allsize - off < size) // Clip to available data in input size = allsize > off? allsize - off: 0; - if(is_memset(all->tags + off, 0, size)) // Nothing set? This memory was not present + if(is_memset(all->tags + off, 0, size)) // Nothing set? This memory was not present size = 0; if(size == 0) pmsg_warning("%s has no data for %s, skipping ...\n", str_infilename(upd->filename), m_name); @@ -775,7 +775,7 @@ int do_op(const PROGRAMMER *pgm, const AVRPART *p, const UPDATE *upd, enum updat for(int i = 0; i < ns; i++) { m = umemlist[i]; // Silently skip readonly memories and fuses/lock in bootloaders - if(mem_is_readonly(m) || ((pgm->prog_modes & PM_SPM) && (mem_is_in_fuses(m) || mem_is_lock(m)))) + if(mem_is_readonly(m) || (is_spm(pgm) && (mem_is_in_fuses(m) || mem_is_lock(m)))) continue; int ret, size = update_mem_from_all(upd, p, m, mem, allsize); diff --git a/src/urclock.c b/src/urclock.c index 678c9990a..424d425d3 100644 --- a/src/urclock.c +++ b/src/urclock.c @@ -1025,9 +1025,9 @@ static void set_uP(const PROGRAMMER *pgm, const AVRPART *p, int mcuid, int mcuid ur.uP.name = p->desc; ur.uP.mcuid = p->mcuid; ur.uP.avrarch = - p->prog_modes & PM_UPDI? F_AVR8X: - p->prog_modes & PM_PDI? F_XMEGA: - p->prog_modes & PM_TPI? F_AVR8L: + is_updi(p)? F_AVR8X: + is_pdi(p)? F_XMEGA: + is_tpi(p)? F_AVR8L: p->prog_modes & (PM_ISP | PM_HVPP | PM_HVSP)? F_AVR8: 0; memcpy(ur.uP.sigs, p->signature, sizeof ur.uP.sigs); if((mem = avr_locate_flash(p))) { @@ -1289,11 +1289,11 @@ static int ur_initstruct(const PROGRAMMER *pgm, const AVRPART *p) { ur.bleepromrw = 0; // No urboot bootloaders on AVR32 parts, neither on really small devices - if((p->prog_modes & PM_aWire) || flm->size < 512) + if(is_awire(p) || flm->size < 512) goto alldone; // UPDI parts have bootloader in low flash - ur.boothigh = !(p->prog_modes & PM_UPDI); + ur.boothigh = !is_updi(p); // Manual provision of above bootloader parameters if(ur.xbootsize) { diff --git a/src/usbasp.c b/src/usbasp.c index 2fb717c51..86a20a4df 100644 --- a/src/usbasp.c +++ b/src/usbasp.c @@ -719,7 +719,7 @@ static int usbasp_initialize(const PROGRAMMER *pgm, const AVRPART *p) { pdata->capabilities = usbasp_transmit(pgm, 1, USBASP_FUNC_GETCAPABILITIES, temp, res, sizeof(res)) == 4? res[0] | ((unsigned int) res[1] << 8) | ((unsigned int) res[2] << 16) | ((unsigned int) res[3] << 24): 0; - pdata->use_tpi = (pdata->capabilities & USBASP_CAP_TPI) && (p->prog_modes & PM_TPI); + pdata->use_tpi = (pdata->capabilities & USBASP_CAP_TPI) && is_tpi(p); // Query support for 3 MHz SCK in UsbAsp-flash firmware https://github.com/nofeletru/UsbAsp-flash pdata->sck_3mhz = ((pdata->capabilities & USBASP_CAP_3MHZ) != 0)? 1: 0; diff --git a/src/usbtiny.c b/src/usbtiny.c index 4266e4291..8c9df8e1c 100644 --- a/src/usbtiny.c +++ b/src/usbtiny.c @@ -416,7 +416,7 @@ static int usbtiny_initialize(const PROGRAMMER *pgm, const AVRPART *p) { // Let the device wake up. usleep(50000); - if(p->prog_modes & PM_TPI) { + if(is_tpi(p)) { /* * Since there is a single TPIDATA line, SDO and SDI must be linked * together through a 1kOhm resistor. Verify that everything we send on @@ -556,7 +556,7 @@ static int usbtiny_spi(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned static int usbtiny_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { unsigned char res[4]; - if(p->prog_modes & PM_TPI) + if(is_tpi(p)) return avr_tpi_chip_erase(pgm, p); if(p->op[AVR_OP_CHIP_ERASE] == NULL) { @@ -568,7 +568,7 @@ static int usbtiny_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) { if(usbtiny_avr_op(pgm, p, AVR_OP_CHIP_ERASE, res) < 0) return -1; - if(pgm->prog_modes & PM_SPM) { // Talking to bootloader directly + if(is_spm(pgm)) { // Talking to bootloader directly AVRMEM *fl = avr_locate_flash(p); // Estimated time it takes to erase all pages in bootloader @@ -719,7 +719,7 @@ static int usbtiny_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AV static int usbtiny_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { unsigned char buf[4]; - if(p->prog_modes & PM_TPI) + if(is_tpi(p)) return avr_tpi_program_enable(pgm, p, TPIPCR_GT_0b); else return usbtiny_avr_op(pgm, p, AVR_OP_PGM_ENABLE, buf);