X-Git-Url: http://git.techno-innov.fr/?a=blobdiff_plain;f=host%2Fexanh_datalog%2Fserial_utils.c;fp=host%2Fexanh_datalog%2Fserial_utils.c;h=700c11b013de48961bbfbb8cfc10ac8c3f68b314;hb=bdbab0310828ef5453ef5592309f2ba6b2bd2716;hp=0000000000000000000000000000000000000000;hpb=82be76c1ee7156036b72211214ffd25196823346;p=soft%2Flpc82x%2Fexanh diff --git a/host/exanh_datalog/serial_utils.c b/host/exanh_datalog/serial_utils.c new file mode 100644 index 0000000..700c11b --- /dev/null +++ b/host/exanh_datalog/serial_utils.c @@ -0,0 +1,59 @@ +/********************************************************************* + * + * Serial utility functions + * + * + * Copyright 2012-2014 Nathael Pajani + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define SERIAL_BAUD B115200 + + +int serial_setup(char* name) +{ + struct termios tio; + int fd = -1; + + /* Open serial port */ + fd = open(name, O_RDWR | O_NONBLOCK); + if (fd < 0) { + perror("Unable to open communication with companion chip"); + return -1; + } + /* Setup serial port */ + memset(&tio, 0, sizeof(tio)); + tio.c_cflag = CS8 | CREAD | CLOCAL; /* 8n1, see termios.h for more information */ + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 5; + cfsetospeed(&tio, SERIAL_BAUD); + cfsetispeed(&tio, SERIAL_BAUD); + tcsetattr(fd, TCSANOW, &tio); + + return fd; +} +