|
|
@ -36,7 +36,6 @@ wait. |
|
|
|
int uartStart(struct UartDevice* dev) { |
|
|
|
struct termios* tty; |
|
|
|
int fd; |
|
|
|
int rc; |
|
|
|
|
|
|
|
fd = open(dev->name, O_RDWR | O_NOCTTY); |
|
|
|
if (fd < 0) { |
|
|
@ -49,6 +48,14 @@ int uartStart(struct UartDevice* dev) { |
|
|
|
printf("%s: failed to allocate tty instance\r\n", __func__); |
|
|
|
return UART_FAILURE; |
|
|
|
} |
|
|
|
|
|
|
|
dev->fd = fd; |
|
|
|
dev->tty = tty; |
|
|
|
|
|
|
|
return uartSetRate(dev, dev->rate); |
|
|
|
} |
|
|
|
|
|
|
|
int uartSetRate(struct UartDevice* dev, int rate) { |
|
|
|
// memset(tty, 0, sizeof(struct termios));
|
|
|
|
/*
|
|
|
|
BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed. |
|
|
@ -59,36 +66,34 @@ int uartStart(struct UartDevice* dev) { |
|
|
|
CREAD : enable receiving characters |
|
|
|
*/ |
|
|
|
// tty->c_cflag = dev->rate | CRTSCTS | CS8 | CLOCAL | CREAD;
|
|
|
|
tty->c_cflag = dev->rate | CS8 | CLOCAL | CREAD; |
|
|
|
dev->rate = rate; |
|
|
|
dev->tty->c_cflag = dev->rate | CS8 | CLOCAL | CREAD; |
|
|
|
// not canonic
|
|
|
|
/*
|
|
|
|
IGNPAR : ignore bytes with parity errorsc_cc[VTIME] |
|
|
|
*/ |
|
|
|
tty->c_iflag = IGNPAR; |
|
|
|
dev->tty->c_iflag = IGNPAR; |
|
|
|
/* set input mode (non-canonical, no echo,...) */ |
|
|
|
tty->c_lflag = 0; |
|
|
|
dev->tty->c_lflag = 0; |
|
|
|
/* Do not wait for data */ |
|
|
|
tty->c_cc[VTIME] = 0; /* inter-character timer unused */ |
|
|
|
tty->c_cc[VMIN] = 0; /* blocking read until 5 chars received */ |
|
|
|
dev->tty->c_cc[VTIME] = 0; /* inter-character timer unused */ |
|
|
|
dev->tty->c_cc[VMIN] = 0; /* blocking read until 5 chars received */ |
|
|
|
|
|
|
|
/*
|
|
|
|
Raw output. |
|
|
|
*/ |
|
|
|
tty->c_oflag = 0; |
|
|
|
dev->tty->c_oflag = 0; |
|
|
|
dev->rate = rate; |
|
|
|
|
|
|
|
/* Flush port */ |
|
|
|
tcflush(fd, TCIFLUSH); |
|
|
|
tcflush(dev->fd, TCIFLUSH); |
|
|
|
|
|
|
|
/* Apply attributes */ |
|
|
|
rc = tcsetattr(fd, TCSANOW, tty); |
|
|
|
int rc = tcsetattr(dev->fd, TCSANOW, dev->tty); |
|
|
|
if (rc) { |
|
|
|
printf("%s: failed to set TCSANOW attr\r\n", __func__); |
|
|
|
return UART_FAILURE; |
|
|
|
} |
|
|
|
|
|
|
|
dev->fd = fd; |
|
|
|
dev->tty = tty; |
|
|
|
|
|
|
|
return UART_SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|