I am trying to receive serial data, but I can't figure out the timing.
When serial data is received, when does SIGIO fire - upon receiving the first byte of data, or when a specific character is received (CR, NL...)?
Set up serial data port:
/* Open serial port.
* O_RDONLY - Only receive data
* O_NOCTTY - Leave process control to other 'jobs' for better portability.
* O_NDELAY - Enable non-blocking read
*/
fd = open(PORT_PATHNAME, O_RDONLY | O_NOCTTY | O_NDELAY);
fd = open(PORT_PATHNAME, O_RDONLY | O_NOCTTY | O_NDELAY);
/* Set process ID, that will receive SIGIO signals for file desc. events */
fcntl (fd, F_SETOWN, getpid());
/* Enable generation of signals */
fcntl (fd, F_SETFL, O_ASYNC);
...
options.c_oflag &= ~OPOST;
/* Set terminal options using the file descriptor */
tcsetattr(fd, TCSANOW, &options);
struct termios options;
tcgetattr(fd, &options);
/* Set baudrate */
options.c_cflag = B115200;
Set up signal interrupt:
/* Add UART handler function */
saio.sa_handler = signal_handler_IO;
/* Non-zero used for calling sighandler on alternative stacks and so on */
saio.sa_flags = 0;
/* Not specified by POSIX -> not in use */
saio.sa_restorer = NULL;
/* Bind SIGIO (async I/O signals) to the defined structure */
int status = sigaction(SIGIO, &saio, NULL);