CO_fifo.h
Go to the documentation of this file.
#ifndef CO_FIFO_H
#define CO_FIFO_H
#include "301/CO_driver.h"
/* default configuration, see CO_config.h */
#ifndef CO_CONFIG_FIFO
#define CO_CONFIG_FIFO (0)
#endif
#if ((CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ENABLE) || defined CO_DOXYGEN
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char *buf;
size_t bufSize;
size_t writePtr;
size_t readPtr;
#if ((CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ALT_READ) || defined CO_DOXYGEN
size_t altReadPtr;
#endif
#if ((CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ASCII_DATATYPES) || defined CO_DOXYGEN
bool_t started;
uint32_t aux;
#endif
} CO_fifo_t;
void CO_fifo_init(CO_fifo_t *fifo, char *buf, size_t bufSize);
static inline void CO_fifo_reset(CO_fifo_t *fifo) {
if (fifo != NULL) {
fifo->readPtr = 0;
fifo->writePtr = 0;
#if (CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ASCII_DATATYPES
fifo->started = false;
#endif
}
return;
}
static inline bool_t CO_fifo_purge(CO_fifo_t *fifo) {
if (fifo != NULL && fifo->readPtr != fifo->writePtr) {
fifo->readPtr = 0;
fifo->writePtr = 0;
return true;
}
return false;
}
static inline size_t CO_fifo_getSpace(CO_fifo_t *fifo) {
int sizeLeft = (int)fifo->readPtr - fifo->writePtr - 1;
if (sizeLeft < 0) {
sizeLeft += fifo->bufSize;
}
return (size_t) sizeLeft;
}
static inline size_t CO_fifo_getOccupied(CO_fifo_t *fifo) {
int sizeOccupied = (int)fifo->writePtr - fifo->readPtr;
if (sizeOccupied < 0) {
sizeOccupied += fifo->bufSize;
}
return (size_t) sizeOccupied;
}
static inline bool_t CO_fifo_putc(CO_fifo_t *fifo, const char c) {
if (fifo != NULL && fifo->buf != NULL) {
size_t writePtrNext = fifo->writePtr + 1;
if (writePtrNext != fifo->readPtr &&
!(writePtrNext == fifo->bufSize && fifo->readPtr == 0))
{
fifo->buf[fifo->writePtr] = c;
fifo->writePtr = (writePtrNext == fifo->bufSize) ? 0 : writePtrNext;
return true;
}
}
return false;
}
static inline void CO_fifo_putc_ov(CO_fifo_t *fifo, const char c) {
if (fifo != NULL && fifo->buf != NULL) {
fifo->buf[fifo->writePtr] = c;
if (++fifo->writePtr == fifo->bufSize) fifo->writePtr = 0;
if (fifo->readPtr == fifo->writePtr) {
if (++fifo->readPtr == fifo->bufSize) fifo->readPtr = 0;
}
}
}
static inline bool_t CO_fifo_getc(CO_fifo_t *fifo, char *buf) {
if (fifo != NULL && buf != NULL && fifo->readPtr != fifo->writePtr) {
*buf = fifo->buf[fifo->readPtr];
if (++fifo->readPtr == fifo->bufSize) {
fifo->readPtr = 0;
}
return true;
}
return false;
}
size_t CO_fifo_write(CO_fifo_t *fifo,
const char *buf,
size_t count,
uint16_t *crc);
size_t CO_fifo_read(CO_fifo_t *fifo, char *buf, size_t count, bool_t *eof);
#if ((CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ALT_READ) || defined CO_DOXYGEN
size_t CO_fifo_altBegin(CO_fifo_t *fifo, size_t offset);
void CO_fifo_altFinish(CO_fifo_t *fifo, uint16_t *crc);
static inline size_t CO_fifo_altGetOccupied(CO_fifo_t *fifo) {
int sizeOccupied = (int)fifo->writePtr - fifo->altReadPtr;
if (sizeOccupied < 0) {
sizeOccupied += fifo->bufSize;
}
return (size_t) sizeOccupied;
}
size_t CO_fifo_altRead(CO_fifo_t *fifo, char *buf, size_t count);
#endif /* #if (CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ALT_READ */
#if ((CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ASCII_COMMANDS) || defined CO_DOXYGEN
bool_t CO_fifo_CommSearch(CO_fifo_t *fifo, bool_t clear);
bool_t CO_fifo_trimSpaces(CO_fifo_t *fifo, bool_t *insideComment);
size_t CO_fifo_readToken(CO_fifo_t *fifo,
char *buf,
size_t count,
char *closed,
bool_t *err);
#endif /* (CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ASCII_COMMANDS */
#if ((CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ASCII_DATATYPES) || defined CO_DOXYGEN
size_t CO_fifo_readU82a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readU162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readU322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readU642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readX82a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readX162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readX322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readX642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readI82a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readI162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readI322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readI642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readR322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readR642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readHex2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readVs2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
size_t CO_fifo_readB642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end);
typedef enum {
CO_fifo_st_closed = 0x01U,
CO_fifo_st_partial = 0x02U,
CO_fifo_st_errTok = 0x10U,
CO_fifo_st_errVal = 0x20U,
CO_fifo_st_errBuf = 0x40U,
CO_fifo_st_errInt = 0x80U,
CO_fifo_st_errMask = 0xF0U
} CO_fifo_st;
size_t CO_fifo_cpyTok2U8 (CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2U16(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2U32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2U64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2I8 (CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2I16(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2I32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2I64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2R32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2R64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2Hex(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2Vs(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
size_t CO_fifo_cpyTok2B64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status);
#endif /* (CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ASCII_DATATYPES */
/* CO_CANopen_301_fifo */
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#endif /* (CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ENABLE */
#endif /* CO_FIFO_H */
CO_fifo_readI82a
size_t CO_fifo_readI82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read int8_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_readU642a
size_t CO_fifo_readU642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint64_t variable from fifo as ascii string, see CO_fifo_readU82a.
uint32_t
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition: CO_driver.h:155
CO_fifo_readU322a
size_t CO_fifo_readU322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint32_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_st_errVal
@ CO_fifo_st_errVal
Bit is set, if value is not valid or out of limits.
Definition: CO_fifo.h:481
CO_driver.h
Interface between CAN hardware and CANopenNode.
CO_fifo_cpyTok2Hex
size_t CO_fifo_cpyTok2Hex(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy bytes written as two hex digits into to data.
CO_fifo_readU82a
size_t CO_fifo_readU82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint8_t variable from fifo and output as ascii string.
CO_fifo_readX82a
size_t CO_fifo_readX82a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint8_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_t::writePtr
size_t writePtr
Location in the buffer, which will be next written.
Definition: CO_fifo.h:66
CO_fifo_cpyTok2B64
size_t CO_fifo_cpyTok2B64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Read ascii mime-base64 encoded string from src fifo and copy as binary data to dest fifo.
CO_fifo_reset
static void CO_fifo_reset(CO_fifo_t *fifo)
Reset fifo object, make it empty.
Definition: CO_fifo.h:100
uint16_t
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition: CO_driver.h:153
CO_fifo_t::altReadPtr
size_t altReadPtr
Location in the buffer, which will be next read.
Definition: CO_fifo.h:71
CO_fifo_altGetOccupied
static size_t CO_fifo_altGetOccupied(CO_fifo_t *fifo)
Get alternate size of remaining data, see CO_fifo_altRead.
Definition: CO_fifo.h:297
CO_fifo_cpyTok2U32
size_t CO_fifo_cpyTok2U32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to uint32_t variable, see CO_fifo_cpyTok2U8.
bool_t
unsigned char bool_t
Boolean data type for general use.
Definition: CO_driver.h:141
CO_fifo_getc
static bool_t CO_fifo_getc(CO_fifo_t *fifo, char *buf)
Get one character from CO_fifo_t buffer object.
Definition: CO_fifo.h:216
CO_fifo_t::buf
char * buf
Buffer of size bufSize.
Definition: CO_fifo.h:62
CO_fifo_readR642a
size_t CO_fifo_readR642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read float64_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_t::started
bool_t started
helper variable, set to false in CO_fifo_reset(), used in some functions.
Definition: CO_fifo.h:76
CO_fifo_st_errInt
@ CO_fifo_st_errInt
Bit is set, if internal error.
Definition: CO_fifo.h:485
CO_fifo_readB642a
size_t CO_fifo_readB642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read data from fifo and output as mime-base64 encoded string.
CO_fifo_readR322a
size_t CO_fifo_readR322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read float32_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_cpyTok2U8
size_t CO_fifo_cpyTok2U8(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Read ascii string from src fifo and copy as uint8_t variable to dest fifo.
CO_fifo_t::bufSize
size_t bufSize
Initialized by CO_fifo_init()
Definition: CO_fifo.h:64
CO_fifo_st_errMask
@ CO_fifo_st_errMask
Bitmask for error bits.
Definition: CO_fifo.h:487
CO_fifo_st_errBuf
@ CO_fifo_st_errBuf
Bit is set, if destination buffer is to small.
Definition: CO_fifo.h:483
CO_fifo_init
void CO_fifo_init(CO_fifo_t *fifo, char *buf, size_t bufSize)
Initialize fifo object.
CO_fifo_st
CO_fifo_st
Bitfields for status argument from CO_fifo_cpyTok2U8 function and similar.
Definition: CO_fifo.h:472
CO_fifo_readI642a
size_t CO_fifo_readI642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read int64_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_cpyTok2Vs
size_t CO_fifo_cpyTok2Vs(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy visible string to data.
CO_fifo_getOccupied
static size_t CO_fifo_getOccupied(CO_fifo_t *fifo)
Get size of data inside CO_fifo_t buffer object.
Definition: CO_fifo.h:155
CO_fifo_cpyTok2I32
size_t CO_fifo_cpyTok2I32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to int32_t variable, see CO_fifo_cpyTok2U8.
CO_fifo_readU162a
size_t CO_fifo_readU162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint16_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_altBegin
size_t CO_fifo_altBegin(CO_fifo_t *fifo, size_t offset)
Initializes alternate read with CO_fifo_altRead.
CO_fifo_cpyTok2I16
size_t CO_fifo_cpyTok2I16(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to int16_t variable, see CO_fifo_cpyTok2U8.
CO_fifo_t::readPtr
size_t readPtr
Location in the buffer, which will be next read.
Definition: CO_fifo.h:68
CO_fifo_t
Fifo object.
Definition: CO_fifo.h:60
CO_fifo_putc
static bool_t CO_fifo_putc(CO_fifo_t *fifo, const char c)
Put one character into CO_fifo_t buffer object.
Definition: CO_fifo.h:173
CO_fifo_readX642a
size_t CO_fifo_readX642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint64_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_cpyTok2I8
size_t CO_fifo_cpyTok2I8(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to int8_t variable, see CO_fifo_cpyTok2U8.
CO_fifo_st_partial
@ CO_fifo_st_partial
Bit is set, if copy was partial and more data are available.
Definition: CO_fifo.h:477
CO_fifo_cpyTok2U16
size_t CO_fifo_cpyTok2U16(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to uint16_t variable, see CO_fifo_cpyTok2U8.
CO_fifo_write
size_t CO_fifo_write(CO_fifo_t *fifo, const char *buf, size_t count, uint16_t *crc)
Write data into CO_fifo_t object.
CO_fifo_readX322a
size_t CO_fifo_readX322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint32_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_readI322a
size_t CO_fifo_readI322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read int32_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_readVs2a
size_t CO_fifo_readVs2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read data from fifo and output as visible string.
CO_fifo_purge
static bool_t CO_fifo_purge(CO_fifo_t *fifo)
Purge all data in fifo object, keep other properties.
Definition: CO_fifo.h:120
CO_fifo_read
size_t CO_fifo_read(CO_fifo_t *fifo, char *buf, size_t count, bool_t *eof)
Read data from CO_fifo_t object.
CO_fifo_altRead
size_t CO_fifo_altRead(CO_fifo_t *fifo, char *buf, size_t count)
Alternate read data from CO_fifo_t object.
CO_fifo_altFinish
void CO_fifo_altFinish(CO_fifo_t *fifo, uint16_t *crc)
Ends alternate read with CO_fifo_altRead and calculate crc checksum.
CO_fifo_cpyTok2R64
size_t CO_fifo_cpyTok2R64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to float64_t variable, see CO_fifo_cpyTok2U8.
NULL
#define NULL
NULL, for general usage.
Definition: CO_driver.h:135
CO_fifo_t::aux
uint32_t aux
auxiliary variable, used in some functions.
Definition: CO_fifo.h:78
CO_fifo_cpyTok2I64
size_t CO_fifo_cpyTok2I64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to int64_t variable, see CO_fifo_cpyTok2U8.
CO_fifo_CommSearch
bool_t CO_fifo_CommSearch(CO_fifo_t *fifo, bool_t clear)
Search command inside FIFO.
CO_fifo_putc_ov
static void CO_fifo_putc_ov(CO_fifo_t *fifo, const char c)
Put one character into CO_fifo_t buffer object.
Definition: CO_fifo.h:196
CO_fifo_cpyTok2U64
size_t CO_fifo_cpyTok2U64(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to uint64_t variable, see CO_fifo_cpyTok2U8.
CO_fifo_readI162a
size_t CO_fifo_readI162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read int16_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_cpyTok2R32
size_t CO_fifo_cpyTok2R32(CO_fifo_t *dest, CO_fifo_t *src, CO_fifo_st *status)
Copy ascii string to float32_t variable, see CO_fifo_cpyTok2U8.
CO_fifo_readToken
size_t CO_fifo_readToken(CO_fifo_t *fifo, char *buf, size_t count, char *closed, bool_t *err)
Get token from FIFO buffer.
CO_fifo_st_errTok
@ CO_fifo_st_errTok
Bit is set, if no valid token found.
Definition: CO_fifo.h:479
CO_fifo_readX162a
size_t CO_fifo_readX162a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read uint16_t variable from fifo as ascii string, see CO_fifo_readU82a.
CO_fifo_readHex2a
size_t CO_fifo_readHex2a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end)
Read data from fifo and output as space separated two digit ascii string, see also CO_fifo_readU82a.
CO_fifo_st_closed
@ CO_fifo_st_closed
Bit is set, if command delimiter is reached in src.
Definition: CO_fifo.h:474
CO_fifo_getSpace
static size_t CO_fifo_getSpace(CO_fifo_t *fifo)
Get free buffer space in CO_fifo_t object.
Definition: CO_fifo.h:138
CO_fifo_trimSpaces
bool_t CO_fifo_trimSpaces(CO_fifo_t *fifo, bool_t *insideComment)
Trim spaces inside FIFO.