From: Bernhard Tittelbach Date: Mon, 26 Jul 2010 20:24:12 +0000 (+0000) Subject: Autoreset on upload X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=fcdc69a2cf4e6751fd75f6ed7504d1de114c0eb5;p=svn42.git Autoreset on upload --- diff --git a/rf433ctl/Makefile b/rf433ctl/Makefile index 916e3fe..2b06faf 100755 --- a/rf433ctl/Makefile +++ b/rf433ctl/Makefile @@ -114,7 +114,8 @@ lss: applet/$(TARGET).lss sym: applet/$(TARGET).sym # Program the device. -upload: applet/$(TARGET).hex +upload: applet/$(TARGET).hex reset_tty + ./reset_tty $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) @@ -207,4 +208,7 @@ depend: >> $(MAKEFILE); \ $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) +reset_tty: reset_tty.c + $(CC) -o reset_tty reset_tty.c + .PHONY: all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter diff --git a/rf433ctl/reset_tty.c b/rf433ctl/reset_tty.c new file mode 100644 index 0000000..bf1c0a0 --- /dev/null +++ b/rf433ctl/reset_tty.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include + +#define STATE_OFF 0 +#define STATE_ON 1 + +void setDTRState (int fd, int state) { + int flags; + + ioctl(fd, TIOCMGET, &flags); + flags = (state == STATE_ON ? flags | TIOCM_DTR : flags & ~TIOCM_DTR); + ioctl(fd, TIOCMSET, &flags); +} + +int +main(int argc, char* argv[]) +{ + char* device = argc < 2 ? "/dev/ttyUSB0" : argv[1]; + int fd = open(device, O_RDWR); + if (fd == 0) { + fprintf(stderr, "Could not open %s\n", device); + return EXIT_FAILURE; + } + + setDTRState(fd, STATE_ON); + struct timeval sleeptime = {0, 100000}; // 100ms + select(0, NULL, NULL, NULL, &sleeptime); + setDTRState(fd, STATE_OFF); + sleeptime.tv_sec = 0; + sleeptime.tv_usec = 100000; + select(0, NULL, NULL, NULL, &sleeptime); + setDTRState(fd, STATE_ON); + close(fd); + + return EXIT_SUCCESS; +} +