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
Loading...
Searching...
No Matches
Macros | Functions
circular_buffer_io_fd_poll.c File Reference
#include "circular_buffer_io_fd_poll.h"
#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <unistd.h>
Include dependency graph for circular_buffer_io_fd_poll.c:

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)
 

Macro Definition Documentation

◆ inflags

#define inflags ( cb_io)    cb_io->fds[0].revents

Definition at line 10 of file circular_buffer_io_fd_poll.c.

◆ outflags

#define outflags ( cb_io)    cb_io->fds[1].revents

Definition at line 11 of file circular_buffer_io_fd_poll.c.

◆ outsetflags

#define outsetflags ( cb_io)    cb_io->fds[1].events

Definition at line 12 of file circular_buffer_io_fd_poll.c.

Function Documentation

◆ circular_buffer_io_fd_poll_do_input()

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.

Parameters
initializedcircular_buffer_io_fd_poll object
Returns
the number of elements read from the fd and pushed to the input circular buffer

Definition at line 78 of file circular_buffer_io_fd_poll.c.

References circular_buffer_push_back_from_fd_uint8().

◆ circular_buffer_io_fd_poll_do_output()

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.

Parameters
initializedcircular_buffer_io_fd_poll object
Returns
the number of elements written to the fd and popped from output circular buffer

Definition at line 71 of file circular_buffer_io_fd_poll.c.

References circular_buffer_pop_front_to_fd_uint8().

◆ circular_buffer_io_fd_poll_do_poll()

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.

Parameters
initializedcircular_buffer_io_fd_poll object
timeouttimout 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)
Returns
status: if 0 success, otherwise failure

Definition at line 27 of file circular_buffer_io_fd_poll.c.

References circular_buffer_is_empty_uint8().

◆ circular_buffer_io_fd_poll_init()

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

Parameters
uninitializedcircular_buffer_io_fd_poll object

All other arguments should already be initialized

Definition at line 14 of file circular_buffer_io_fd_poll.c.

◆ circular_buffer_io_fd_poll_print()

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.