diff -ur a/bootloader.c b/bootloader.c --- a/bootloader.c 2010-11-28 13:18:36.000000000 +0100 +++ b/bootloader.c 2011-08-23 18:28:11.911355006 +0200 @@ -628,6 +628,7 @@ printf("-b Baudrate\n"); printf("-t TxD Blocksize\n"); printf("-v Verify\n"); + printf("-r Automatically reset device (toggle DTR)\n"); printf("-p Program\n"); printf("-P Password\n"); printf("-T enter terminal mode\n"); @@ -866,6 +867,15 @@ }//int read_info() +/** + * Resets the connected device to put it into bootloader mode + */ +void prog_reset(int fd){ + com_set_dtr(fd, 0); + usleep(10000); + com_set_dtr(fd, 1); +} + int prog_verify (int fd, int mode, @@ -983,7 +993,8 @@ * ****************************************************************************/ static int handle_keyboard (FILE *input, - int output) + int output, + int autoreset) { static char fname[1024+1] = ""; int char_in = EOF; @@ -1023,7 +1034,12 @@ case CTRLP: tcsetattr (desc_in, TCSAFLUSH, &old_term); - printf("\n== PROGRAM: Reset Target Device ==============\n"); + if (autoreset){ + printf("\n== PROGRAM: Reseting Target Device ==============\n"); + prog_reset(output); + } else { + printf("\n== PROGRAM: Manually Reset Target Device ==============\n"); + } prog_verify (output, AVR_PROGRAM, baud, bsize, password, device, fname); tcsetattr (desc_in, TCSAFLUSH, &curr_term); @@ -1031,7 +1047,13 @@ case CTRLV: tcsetattr (desc_in, TCSAFLUSH, &old_term); - printf("\n== VERIFY: Reset Target Device ==============\n"); + if (autoreset){ + printf("\n== VERIFY: Reseting Target Device ==============\n"); + prog_reset(output); + } else { + printf("\n== VERIFY: Reset Target Device ==============\n"); + } + prog_reset(output); prog_verify (output, AVR_VERIFY, baud, bsize, password, device, fname); tcsetattr (desc_in, TCSAFLUSH, &curr_term); @@ -1101,7 +1123,7 @@ * Program loop * ****************************************************************************/ -static void do_v24 (int iFd) +static void do_v24 (int iFd, int autoreset) { int old_timeout; int stdio; @@ -1174,7 +1196,7 @@ if (FD_ISSET (stdio, &fdset)) { /* stdin: someone hacked the keyboard */ - ok = handle_keyboard (fp_stdio, iFd); + ok = handle_keyboard (fp_stdio, iFd, autoreset); } /* -- we got something from serial line -- */ @@ -1222,6 +1244,8 @@ // default values int baudid = -1; + + int autoreset = 0; struct tms timestruct; struct sigaction sa; @@ -1262,6 +1286,10 @@ if (i < argc) baud = atoi(argv[i]); } + else if (strcmp (argv[i], "-r") == 0) + { + autoreset = 1; + } else if (strcmp (argv[i], "-v") == 0) { mode |= AVR_VERIFY; @@ -1335,10 +1363,11 @@ } if (mode & (AVR_PROGRAM | AVR_VERIFY)) + if (autoreset) prog_reset(fd); prog_verify (fd, mode, baud, bsize, password, device, hexfile); if (mode & AVR_TERMINAL) - do_v24 (fd); + do_v24 (fd, autoreset); com_close(fd); //close open com port return 0; diff -ur a/com.c b/com.c --- a/com.c 2010-11-28 13:13:25.000000000 +0100 +++ b/com.c 2011-08-23 18:10:02.102411885 +0200 @@ -13,6 +13,7 @@ #include #include #include +#include #include "com.h" #include "protocol.h" @@ -187,6 +188,22 @@ com_putc_fast (fd, c); } +/** + * Sets the DTR (Data Terminal Ready) on the com port + */ +void com_set_dtr(int fd, unsigned char on) +{ + int flags; + + ioctl(fd, TIOCMGET, &flags); + if (on){ + flags |= TIOCM_DTR; + } else { + flags &= ~TIOCM_DTR; + } + ioctl(fd, TIOCMSET, &flags); +} + /** * Sending a command diff -ur a/com.h b/com.h --- a/com.h 2010-11-28 13:13:25.000000000 +0100 +++ b/com.h 2011-08-23 18:10:18.648823446 +0200 @@ -42,6 +42,11 @@ void com_putc(int fd, unsigned char c); /** + * Sets the DTR (Data Terminal Ready) on the com port + */ +void com_set_dtr(int fd, unsigned char on); + +/** * Receives one char or -1 if timeout */ int com_getc(int fd, int timeout);