diff loadtools/sercomm.c @ 7:aa1f6fe16fef

loadtools building blocks started
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 30 Apr 2013 07:19:48 +0000
parents
children fea204bc7674
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadtools/sercomm.c	Tue Apr 30 07:19:48 2013 +0000
@@ -0,0 +1,39 @@
+/*
+ * This module handles the establishment of serial communication
+ * with the target, i.e., the host-side termios stuff.
+ */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+char *target_ttydev;
+int target_fd;
+struct termios target_termios;
+
+open_target_serial()
+{
+	target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK);
+	if (target_fd < 0) {
+		perror(target_ttydev);
+		exit(1);
+	}
+	target_termios.c_iflag = IGNBRK;
+	target_termios.c_oflag = 0;
+	target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8;
+	target_termios.c_lflag = 0;
+	target_termios.c_cc[VMIN] = 1;
+	target_termios.c_cc[VTIME] = 0;
+	/* start at B19200, as that's what we'll need to use initially */
+	cfsetispeed(&target_termios, B19200);
+	cfsetospeed(&target_termios, B19200);
+	if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
+		perror("initial tcsetattr on target");
+		exit(1);
+	}
+	return 0;
+}