diff loadtools/sercomm.c @ 49:54392d1ea474

loadtools: first beginnings for the baud rate switching logic
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Jun 2013 02:53:16 +0000
parents fea204bc7674
children f1df95eed62c
line wrap: on
line diff
--- a/loadtools/sercomm.c	Sun Jun 23 01:13:03 2013 +0000
+++ b/loadtools/sercomm.c	Sun Jun 23 02:53:16 2013 +0000
@@ -10,11 +10,27 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include "baudrate.h"
 
 char *target_ttydev;
 int target_fd;
 struct termios target_termios;
 
+struct baudrate baud_rate_table[] = {
+	/* the first listed rate will be our default */
+	{"115200",	B115200,	0},
+	{"57600",	B57600,		1},
+	{"38400",	B38400,		2},
+	{"19200",	B19200,		4},
+	/* non-standard high baud rates "remapped" by CP2102 usb2serial IC */
+	{"812500",	B921600,	-1},
+	{"406250",	B460800,	-1},
+	{"203125",	B230400,	-1},
+	/* table search terminator */
+	{NULL,		B0,		-1},
+};
+struct baudrate *current_baud_rate;
+
 open_target_serial()
 {
 	target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK);
@@ -38,12 +54,14 @@
 	return 0;
 }
 
-switch_baud_rate(code)
+switch_baud_rate(br)
+	struct baudrate *br;
 {
-	cfsetispeed(&target_termios, code);
-	cfsetospeed(&target_termios, code);
+	cfsetispeed(&target_termios, br->termios_code);
+	cfsetospeed(&target_termios, br->termios_code);
 	if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
 		perror("tcsetattr to switch baud rate");
 		exit(1);
 	}
+	current_baud_rate = br;
 }