summaryrefslogtreecommitdiffstats
path: root/sw/programmer/linux/src/serial.c
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2017-08-07 19:27:05 +0200
committerNao Pross <naopross@thearcway.org>2017-08-07 19:27:05 +0200
commitd0801b36b47d8f3da610597160fde92059fd7e62 (patch)
treef9f0e348145c3548433e60adbf459e784b909f96 /sw/programmer/linux/src/serial.c
parentfilesystem structure intro and docs (diff)
downloadz80uPC-d0801b36b47d8f3da610597160fde92059fd7e62.tar.gz
z80uPC-d0801b36b47d8f3da610597160fde92059fd7e62.zip
implementation for avr programmer
the programmer will receive the binary in blocks of defined size by a program under sw/programmer/linux (moved from sw/linux).
Diffstat (limited to 'sw/programmer/linux/src/serial.c')
-rw-r--r--sw/programmer/linux/src/serial.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/sw/programmer/linux/src/serial.c b/sw/programmer/linux/src/serial.c
new file mode 100644
index 0000000..564676b
--- /dev/null
+++ b/sw/programmer/linux/src/serial.c
@@ -0,0 +1,42 @@
+#include "serial.h"
+
+int serial_connect(const char *devpath, long baudrate)
+{
+ int fd;
+ struct termios tty;
+ // struct termios tty_old;
+
+ // open device
+ if ((fd = open(devpath, O_RDWR | O_NOCTTY)) < 0) {
+ return -1;
+ }
+
+ // set parameters
+ if (tcgetattr(fd, &tty) != 0) {
+ return -1;
+ }
+
+ // TODO: update UI or add support for custom baudrate
+ // cfsetospeed(&tty,
+ // cfsetispeed(&tty,
+
+ tty.c_cflag &= ~PARENB; // no parity
+ tty.c_cflag &= ~CSTOPB; // no stop bit
+ tty.c_cflag |= CS8; // 8 bit data
+ tty.c_cflag &= ~CRTSCTS; // no flow control
+
+ tty.c_lflag = 0; // no signaling chars, no echo, no canonical processing
+ tty.c_oflag = 0; // no remapping, no delays
+ tty.c_cc[VMIN] = 0; // no block read
+ tty.c_cc[VTIME] = .5; // .5 seconds read timeout
+
+ tty.c_cflag |= CREAD | CLOCAL; // turn on read and ignore ctrl lines
+ tty.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl
+ tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw
+ tty.c_oflag &= ~OPOST; // make raw
+
+ tcflush(fd , TCIFLUSH);
+ // if (tcsetaddr(
+
+ return fd;
+}