ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
|
#include "circular_buffer_io_fd_poll.h"
#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <unistd.h>
Go to the source code of this file.
Macros | |
#define | inflags(cb_io) cb_io->fds[0].revents |
#define | outflags(cb_io) cb_io->fds[1].revents |
#define | outsetflags(cb_io) cb_io->fds[1].events |
Functions | |
void | circular_buffer_io_fd_poll_init (circular_buffer_io_fd_poll *cb_io, circular_buffer_uint8 *in_buf, circular_buffer_uint8 *out_buf, int fd_in, int fd_out) |
Initialize circular buffer IO with file descriptor polling object. | |
uint8_t | circular_buffer_io_fd_poll_do_poll (circular_buffer_io_fd_poll *cb_io, int timeout) |
poll circular buffer IO with file descriptor polling object | |
size_t | circular_buffer_io_fd_poll_do_output (circular_buffer_io_fd_poll *cb_io) |
circular buffer IO with file descriptor polling object: write to output fd | |
size_t | circular_buffer_io_fd_poll_do_input (circular_buffer_io_fd_poll *cb_io) |
circular buffer IO with file descriptor polling object: read from input fd | |
void | circular_buffer_io_fd_poll_print (circular_buffer_io_fd_poll *cb_io, FILE *stream) |
#define inflags | ( | cb_io | ) | cb_io->fds[0].revents |
Definition at line 10 of file circular_buffer_io_fd_poll.c.
#define outflags | ( | cb_io | ) | cb_io->fds[1].revents |
Definition at line 11 of file circular_buffer_io_fd_poll.c.
#define outsetflags | ( | cb_io | ) | cb_io->fds[1].events |
Definition at line 12 of file circular_buffer_io_fd_poll.c.
size_t circular_buffer_io_fd_poll_do_input | ( | circular_buffer_io_fd_poll * | cb_io | ) |
circular buffer IO with file descriptor polling object: read from input fd
Read from input fd to input circular buffer. Only does anything if input fd has something to read, which is taken care of by circular_buffer_io_fd_poll_do_poll.
Elements are pushed to the back of the input circular buffer.
initialized | circular_buffer_io_fd_poll object |
Definition at line 78 of file circular_buffer_io_fd_poll.c.
References circular_buffer_push_back_from_fd_uint8().
size_t circular_buffer_io_fd_poll_do_output | ( | circular_buffer_io_fd_poll * | cb_io | ) |
circular buffer IO with file descriptor polling object: write to output fd
Write to output fd from output circular buffer. Only does anything if output circular buffer not empty and output fd ready for write, the latter of which is taken care of by circular_buffer_io_fd_poll_do_poll.
Elements are popped from the front of the output circular buffer.
initialized | circular_buffer_io_fd_poll object |
Definition at line 71 of file circular_buffer_io_fd_poll.c.
References circular_buffer_pop_front_to_fd_uint8().
uint8_t circular_buffer_io_fd_poll_do_poll | ( | circular_buffer_io_fd_poll * | cb_io, |
int | timeout ) |
poll circular buffer IO with file descriptor polling object
Poll file descriptors. Always polls on input file descriptor, but only polls on output file descriptor when output circular buffer is not empty.
initialized | circular_buffer_io_fd_poll object |
timeout | timout after waiting for input or output fds for this long, in ms. If 0, return immediately. If -1, wait indefinetly for fds to be ready. See poll documentation (man 2 poll) |
Definition at line 27 of file circular_buffer_io_fd_poll.c.
References circular_buffer_is_empty_uint8().
void circular_buffer_io_fd_poll_init | ( | circular_buffer_io_fd_poll * | cb_io, |
circular_buffer_uint8 * | in_buf, | ||
circular_buffer_uint8 * | out_buf, | ||
int | fd_in, | ||
int | fd_out ) |
Initialize circular buffer IO with file descriptor polling object.
Initialize object
uninitialized | circular_buffer_io_fd_poll object |
All other arguments should already be initialized
Definition at line 14 of file circular_buffer_io_fd_poll.c.
void circular_buffer_io_fd_poll_print | ( | circular_buffer_io_fd_poll * | cb_io, |
FILE * | stream ) |
Definition at line 85 of file circular_buffer_io_fd_poll.c.