From: Bernhard Tittelbach Date: Thu, 12 Aug 2010 11:35:18 +0000 (+0000) Subject: autocompile reset_tty fix X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=8682625b18daa7a9f6ae5d3fff47e9e3158d19ef;p=svn42.git autocompile reset_tty fix --- diff --git a/firmware/Makefile b/firmware/Makefile index 411fb4b..b3e15dd 100755 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -14,6 +14,8 @@ F_CPU = 16000000L ############################################################################ # Below here nothing should be changed... +RESET_TTY_DIR=../reset_tty/ +RESET_TTY=$(RESET_TTY_DIR)reset_tty ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino AVR_TOOLS_PATH = /usr/bin SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ @@ -116,9 +118,12 @@ lss: applet/$(TARGET).lss sym: applet/$(TARGET).sym # Program the device. -upload: applet/$(TARGET).hex +upload: applet/$(TARGET).hex $(RESET_TTY) + $(RESET_TTY) $(PORT) $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) +$(RESET_TTY): + make -C $(RESET_TTY_DIR) # Display size of file. HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex diff --git a/reset_tty/Makefile b/reset_tty/Makefile new file mode 100644 index 0000000..d076402 --- /dev/null +++ b/reset_tty/Makefile @@ -0,0 +1,9 @@ + +TARGET=reset_tty + +all: reset_tty + +.PHONY: clean + +clean: + rm -f $(TARGET) diff --git a/reset_tty/reset_tty.c b/reset_tty/reset_tty.c new file mode 100644 index 0000000..bf1c0a0 --- /dev/null +++ b/reset_tty/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; +} + diff --git a/rf433ctl/Makefile b/rf433ctl/Makefile index c5dc50e..30a0031 100755 --- a/rf433ctl/Makefile +++ b/rf433ctl/Makefile @@ -12,6 +12,8 @@ F_CPU = 16000000 ############################################################################ # Below here nothing should be changed... +RESET_TTY_DIR=../reset_tty/ +RESET_TTY=$(RESET_TTY_DIR)reset_tty ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino AVR_TOOLS_PATH = /usr/bin SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ @@ -114,8 +116,8 @@ lss: applet/$(TARGET).lss sym: applet/$(TARGET).sym # Program the device. -upload: applet/$(TARGET).hex reset_tty - ./reset_tty +upload: applet/$(TARGET).hex $(RESET_TTY) + $(RESET_TTY) $(PORT) $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) @@ -208,7 +210,7 @@ depend: >> $(MAKEFILE); \ $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) -reset_tty: reset_tty.c - $(CC) -L /usr/lib/ -L /lib -I /usr/include/ -o reset_tty reset_tty.c +$(RESET_TTY): + make -C $(RESET_TTY_DIR) .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 deleted file mode 100644 index bf1c0a0..0000000 --- a/rf433ctl/reset_tty.c +++ /dev/null @@ -1,42 +0,0 @@ -#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; -} -