summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2012-05-20 16:15:45 +0000
committerChristian Pointner <equinox@spreadspace.org>2012-05-20 16:15:45 +0000
commit31442f0ec4e63a5421e17324d877bfb91233ea47 (patch)
tree25fd343eb304d984dcc0e4a79e2068f75f882f39
parentadded reset program for arduino 10000 and newer (diff)
added arduino reset func
git-svn-id: https://svn.spreadspace.org/avr/trunk@22 aa12f405-d877-488e-9caf-2d797e2a1cc7
-rw-r--r--include.mk18
-rw-r--r--tools/reset_arduino.c8
2 files changed, 19 insertions, 7 deletions
diff --git a/include.mk b/include.mk
index 5e5aa89..93c9a67 100644
--- a/include.mk
+++ b/include.mk
@@ -52,6 +52,8 @@ ifeq ($(BOARD_TYPE),arduinoUno)
UPLOAD_RATE := 57600
PROG_TYPE := stk500v1
AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
endif
ifeq ($(BOARD_TYPE),arduino2009v2)
MCU := atmega328p
@@ -60,6 +62,8 @@ ifeq ($(BOARD_TYPE),arduino2009v2)
UPLOAD_RATE := 57600
PROG_TYPE := stk500v1
AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
endif
ifeq ($(BOARD_TYPE),arduino2009)
MCU := atmega168
@@ -68,6 +72,8 @@ ifeq ($(BOARD_TYPE),arduino2009)
UPLOAD_RATE := 19200
PROG_TYPE := stk500v1
AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
endif
ifeq ($(BOARD_TYPE),arduino10000)
MCU := atmega168
@@ -76,6 +82,8 @@ ifeq ($(BOARD_TYPE),arduino10000)
UPLOAD_RATE := 19200
PROG_TYPE := stk500v1
AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
endif
ifeq ($(BOARD_TYPE),arduinoNG)
MCU := atmega8
@@ -198,10 +206,10 @@ run:
$(call $(PROG)/$@,)
reset:
- @if [ -n "$(RESET_FUNC)" ]; then \
- if [ -x "$(RESET_FUNC)" ]; then \
- "$(RESET_FUNC)"; \
- else \
+ @if [ -n "$(RESET_FUNC)" ]; then \
+ if [ -x "$(RESET_FUNC)" ]; then \
+ $(RESET_FUNC) $(RESET_PARAM); \
+ else \
echo "WARNING: ignoring non-existing or non-executable reset script"; \
- fi \
+ fi \
fi
diff --git a/tools/reset_arduino.c b/tools/reset_arduino.c
index 99ace88..53dbbf5 100644
--- a/tools/reset_arduino.c
+++ b/tools/reset_arduino.c
@@ -27,6 +27,8 @@
#include <time.h>
#include <stdio.h>
#include <sys/select.h>
+#include <errno.h>
+#include <string.h>
#define STATE_OFF 0
#define STATE_ON 1
@@ -44,10 +46,12 @@ 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);
+ if (fd < 0) {
+ fprintf(stderr, "Could not open %s (%s)\n", device, strerror(errno));
return EXIT_FAILURE;
}
+
+ printf("reseting arduino at %s\n", device);
setDTRState(fd, STATE_ON);
struct timeval sleeptime = {0, 100000}; // 100ms