Skip to content

Commit

Permalink
Merge pull request #1893 from stefanrueger/space-the-final-frontier
Browse files Browse the repository at this point in the history
Space: the final frontier

Reformatting most of the source: The created avrdude executable stays invariant except for the source line numbers that errors and warnings emit with -vv. To prove this check out git main, replace all occurrences of __LINE__ in avrdude.h and jtagmkII.c with 07654321. Compile the executable avrdude and disassemble using objdump -d $(which avrdude) >ad.S. Then do the same with this PR and convince yourself that the ensuing .S files are identical. OK, I only checked under Linux but have every reason to believe that the semi-automated method of this PR will also leave the fraction of the code invariant that isn't seen by a Linux compilation.

Tools used:

$ indent -as -nsaf -nsai -nsaw -nut -bap -bacc -bad -bbb -brs -nbc -br -brf -nbs -c33 -cd33 -cp33 -ncdb -cdw -ce -ci2 -cli0 -d0 -di1 -neei -nfc1 -i2 -il-2 -ppi0 -nip -l130 -lc130 -nlp -npcs -npsl -nsc -sob -nlps -nprs -par

Then polish with a set of sed scripts to ensure the correct spacing of
  - switch(i)
  - a? b: c
  - type *p
  - single-line comments just so // Note the space and capital letter at the start and
  - Multi-line comments such as
    /*
     * Multi-line comments which
     *  - Tend to be about larger code regions
     *  - Contain vital algorithmic information
     *  - Deserve visual attention and prominence
     *  - Help users utilise functions and code thereafter
     */

Also 
  - Change PDATA(pgm)-> to my.
  - Change xxx->prog_modes & PM_ABCD to is_abcd(xxx)
  • Loading branch information
stefanrueger authored Aug 19, 2024
2 parents de2b5bb + 00422f3 commit 81d15b5
Show file tree
Hide file tree
Showing 138 changed files with 24,023 additions and 25,859 deletions.
6 changes: 3 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -1520,11 +1520,11 @@ Version 5.7:

- ATXMEGA64A1
- ATXMEGA192A1
- ATXMEGA256A1
- ATXMEGA256A1
- ATXMEGA64A3
- ATXMEGA128A3
- ATXMEGA192A3
- ATXMEGA256A3
- ATXMEGA256A3
- ATXMEGA256A3B
- ATXMEGA16A4
- ATXMEGA32A4
Expand Down Expand Up @@ -1794,7 +1794,7 @@ Version 4.1.0
* Add support for avr910 type programmers (mcu00100, pavr avr910, etc).

* Support new devices: ATmega8535, ATtiny26


Version 4.0.0

Expand Down
52 changes: 26 additions & 26 deletions src/arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ static int arduino_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
int rv = 0;
bool help = 0;

for (LNODEID ln = lfirst(extparms); ln; ln = lnext(ln)) {
for(LNODEID ln = lfirst(extparms); ln; ln = lnext(ln)) {
const char *extended_param = ldata(ln);

if (sscanf(extended_param, "attempts=%i", &attempts) == 1) {
PDATA(pgm)->retry_attempts = attempts;
if(sscanf(extended_param, "attempts=%i", &attempts) == 1) {
my.retry_attempts = attempts;
pmsg_info("setting number of retry attempts to %d\n", attempts);
continue;
}

if(str_eq(extended_param, "noautoreset")) {
PDATA(pgm)->autoreset = false;
my.autoreset = false;
continue;
}

if (str_eq(extended_param, "help")) {
if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
}

if (!help) {
if(!help) {
pmsg_error("invalid extended parameter -x %s\n", extended_param);
rv = -1;
}
Expand All @@ -72,13 +72,13 @@ static int arduino_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
return rv;
}

/* read signature bytes - arduino version */
// Read signature bytes - arduino version
static int arduino_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m) {
unsigned char buf[32];

/* Signature byte reads are always 3 bytes. */
// Signature byte reads are always 3 bytes

if (m->size < 3) {
if(m->size < 3) {
pmsg_error("memsize too small for sig byte read");
return -1;
}
Expand All @@ -88,17 +88,17 @@ static int arduino_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const

serial_send(&pgm->fd, buf, 2);

if (serial_recv(&pgm->fd, buf, 5) < 0)
if(serial_recv(&pgm->fd, buf, 5) < 0)
return -1;
if (buf[0] == Resp_STK_NOSYNC) {
if(buf[0] == Resp_STK_NOSYNC) {
pmsg_error("programmer is out of sync\n");
return -1;
} else if (buf[0] != Resp_STK_INSYNC) {
return -1;
} else if(buf[0] != Resp_STK_INSYNC) {
msg_error("\n");
pmsg_error("protocol expects sync byte 0x%02x but got 0x%02x\n", Resp_STK_INSYNC, buf[0]);
return -2;
}
if (buf[4] != Resp_STK_OK) {
if(buf[4] != Resp_STK_OK) {
msg_error("\n");
pmsg_error("protocol expects OK byte 0x%02x but got 0x%02x\n", Resp_STK_OK, buf[4]);
return -3;
Expand All @@ -113,38 +113,38 @@ static int arduino_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const

static int arduino_open(PROGRAMMER *pgm, const char *port) {
union pinfo pinfo;

pgm->port = port;
pinfo.serialinfo.baud = pgm->baudrate? pgm->baudrate: 115200;
pinfo.serialinfo.cflags = SERIAL_8N1;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
if(serial_open(port, pinfo, &pgm->fd) == -1) {
return -1;
}

if(PDATA(pgm)->autoreset) {
if(my.autoreset) {
// This code assumes a negative-logic USB to TTL serial adapter
// Set RTS/DTR high to discharge the series-capacitor, if present
serial_set_dtr_rts(&pgm->fd, 0);
/*
* Long wait needed for optiboot: otherwise the second of two bootloader
* calls in quick succession fails:
*
* avrdude -c arduino -qqp m328p -U x.hex; avrdude -c arduino -qqp m328p -U x.hex
*/
usleep(250 * 1000);
* Long wait needed for optiboot: otherwise the second of two bootloader
* calls in quick succession fails:
*
* avrdude -c arduino -qqp m328p -U x.hex; avrdude -c arduino -qqp m328p -U x.hex
*/
usleep(250*1000);
// Pull the RTS/DTR line low to reset AVR
serial_set_dtr_rts(&pgm->fd, 1);
// Max 100 us: charging a cap longer creates a high reset spike above Vcc
usleep(100);
// Set the RTS/DTR line back to high, so direct connection to reset works
serial_set_dtr_rts(&pgm->fd, 0);

usleep(100 * 1000);
usleep(100*1000);
}

// Drain any extraneous input
stk500_drain(pgm, 0);

if (stk500_getsync(pgm) < 0)
if(stk500_getsync(pgm) < 0)
return -1;

return 0;
Expand All @@ -159,7 +159,7 @@ const char arduino_desc[] = "Arduino programmer";

void arduino_initpgm(PROGRAMMER *pgm) {
/* This is mostly a STK500; just the signature is read
differently than on real STK500v1
differently than on real STK500v1
and the DTR signal is set when opening the serial port
for the Auto-Reset feature */
stk500_initpgm(pgm);
Expand Down
3 changes: 0 additions & 3 deletions src/arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@

extern const char arduino_desc[];
void arduino_initpgm(PROGRAMMER *pgm);

#endif


Loading

0 comments on commit 81d15b5

Please sign in to comment.