From a8ee4d010fa32ac2324935a37c94e2ad366d23be Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sun, 18 Aug 2024 01:54:36 +0100 Subject: [PATCH] Reformat spacing/comments in src/wiring.c --- src/wiring.c | 55 +++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/wiring.c b/src/wiring.c index 76a2a53b..c5b76d33 100644 --- a/src/wiring.c +++ b/src/wiring.c @@ -49,17 +49,14 @@ #include "stk500v2.h" #include "wiring.h" -/* - * Private data for this programmer. - */ struct wiringpdata { int snoozetime, delay; bool noautoreset; }; +// wiringpdata is our private data -/* wiringpdata is our private data */ -/* pdata is stk500v2's private data (inherited) */ +// pdata is stk500v2's private data (inherited) #define WIRINGPDATA(pgm) ((struct wiringpdata *)(((struct pdata *)(pgm->cookie)) -> chained_pdata)) @@ -68,12 +65,12 @@ static void wiring_setup(PROGRAMMER *pgm) { stk500v2_setup(pgm); // Then prepare our data and store in a safe place for the time being - ((struct pdata *)(pgm->cookie))->chained_pdata = mmt_malloc(sizeof(struct wiringpdata)); + ((struct pdata *) (pgm->cookie))->chained_pdata = mmt_malloc(sizeof(struct wiringpdata)); } static void wiring_teardown(PROGRAMMER *pgm) { if(pgm->cookie) - mmt_free(((struct pdata *)(pgm->cookie))->chained_pdata); + mmt_free(((struct pdata *) (pgm->cookie))->chained_pdata); stk500v2_teardown(pgm); pgm->cookie = NULL; } @@ -83,11 +80,12 @@ static int wiring_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 (str_starts(extended_param, "snooze=")) { - int val = str_int(extended_param+7, STR_INT32, &errstr); + if(str_starts(extended_param, "snooze=")) { + int val = str_int(extended_param + 7, STR_INT32, &errstr); + if(errstr || val < 0) { pmsg_error("-x %s: %s\n", extended_param, errstr? errstr: "snooze time cannot be negative"); rv = -1; @@ -98,8 +96,9 @@ static int wiring_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { continue; } - if (str_starts(extended_param, "delay=")) { - int val = str_int(extended_param+6, STR_INT32, &errstr); + if(str_starts(extended_param, "delay=")) { + int val = str_int(extended_param + 6, STR_INT32, &errstr); + if(errstr) { pmsg_error("-x %s: %s\n", extended_param, errstr); rv = -1; @@ -115,12 +114,12 @@ static int wiring_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) { 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; } @@ -140,19 +139,19 @@ static int wiring_open(PROGRAMMER *pgm, const char *port) { union pinfo pinfo; pgm->port = port; - pinfo.serialinfo.baud = pgm->baudrate ? pgm->baudrate: 115200; + pinfo.serialinfo.baud = pgm->baudrate? pgm->baudrate: 115200; pinfo.serialinfo.cflags = SERIAL_8N1; serial_open(port, pinfo, &pgm->fd); // If we have a snoozetime, then we wait and do NOT toggle DTR/RTS - if (WIRINGPDATA(pgm)->snoozetime > 0) { + if(WIRINGPDATA(pgm)->snoozetime > 0) { timetosnooze = WIRINGPDATA(pgm)->snoozetime; pmsg_notice2("%s(): snoozing for %d ms\n", __func__, timetosnooze); - while (timetosnooze--) + while(timetosnooze--) usleep(1000); pmsg_notice2("%s(): done snoozing\n", __func__); - } else if (WIRINGPDATA(pgm)->noautoreset == false) { + } else if(WIRINGPDATA(pgm)->noautoreset == false) { // This code assumes a negative-logic USB to TTL serial adapter // Set RTS/DTR high to discharge the series-capacitor, if present pmsg_notice2("%s(): releasing DTR/RTS\n", __func__); @@ -169,14 +168,14 @@ static int wiring_open(PROGRAMMER *pgm, const char *port) { serial_set_dtr_rts(&pgm->fd, 0); int delay = WIRINGPDATA(pgm)->delay; - if((100+delay) > 0) - usleep((100+delay)*1000); // Wait until board comes out of reset - } + if((100 + delay) > 0) + usleep((100 + delay)*1000); // Wait until board comes out of reset + } // Drain any extraneous input stk500v2_drain(pgm, 0); - if (stk500v2_getsync(pgm) < 0) { + if(stk500v2_getsync(pgm) < 0) { pmsg_error("stk500v2_getsync() failed; try -x delay=n with some n in [-80, 100]\n"); return -1; } @@ -192,16 +191,14 @@ static void wiring_close(PROGRAMMER *pgm) { const char wiring_desc[] = "Bootloader using STK500v2 protocol, see http://wiring.org.co"; void wiring_initpgm(PROGRAMMER *pgm) { - /* The Wiring bootloader uses a near-complete STK500v2 protocol. */ - + // The Wiring bootloader uses a near-complete STK500v2 protocol stk500v2_initpgm(pgm); strcpy(pgm->type, "Wiring"); - pgm->open = wiring_open; - pgm->close = wiring_close; - pgm->setup = wiring_setup; - pgm->teardown = wiring_teardown; + pgm->open = wiring_open; + pgm->close = wiring_close; + pgm->setup = wiring_setup; + pgm->teardown = wiring_teardown; pgm->parseextparams = wiring_parseextparms; } -