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
|
Circular buffer IO with file descriptor polling. More...
Go to the source code of this file.
Classes | |
struct | circular_buffer_io_fd_poll_struct |
Circular buffer IO with file descriptor polling struct. More... | |
Typedefs | |
typedef struct circular_buffer_io_fd_poll_struct | circular_buffer_io_fd_poll |
Circular buffer IO with file descriptor polling struct. | |
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) |
Circular buffer IO with file descriptor polling.
Usage:
Initialize circular buffers (or ASCII Serial Com object), and input and output files.
In the event loop:
Run circular_buffer_io_fd_poll_do_poll
Run circular_buffer_io_fd_poll_do_input
Run circular_buffer_io_fd_poll_do_output
Process data and/or push/pop from circular buffers either after running do_input or after running do_output
Definition in file circular_buffer_io_fd_poll.h.
typedef struct circular_buffer_io_fd_poll_struct circular_buffer_io_fd_poll |
Circular buffer IO with file descriptor polling struct.
Keeps track of the state of the IO
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.