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
Classes | Typedefs | Functions
circular_buffer_io_fd_poll.h File Reference

Circular buffer IO with file descriptor polling. More...

#include "circular_buffer.h"
#include <poll.h>
#include <stdio.h>
Include dependency graph for circular_buffer_io_fd_poll.h:
This graph shows which files directly or indirectly include this file:

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)
 

Detailed Description

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 Documentation

◆ circular_buffer_io_fd_poll

Circular buffer IO with file descriptor polling struct.

Keeps track of the state of the IO

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.