Data Structures | |
struct | _PERCI_RECORD |
struct | _PERCI_WRITER |
struct | _PERCI_READER |
Defines | |
#define | PERCI_MAX_RECORDS 256 |
#define | PERCI_RECSIZE 256 |
#define | PERCI_DATASIZE (PERCI_RECSIZE - sizeof(perci_reclen_t)) |
Typedefs | |
typedef uint8_t | perci_recnum_t |
typedef uint_fast8_t | perci_fast_recnum_t |
typedef uint8_t | perci_reclen_t |
typedef uint_fast8_t | perci_fast_reclen_t |
typedef struct _PERCI_RECORD | PERCI_RECORD |
typedef struct _PERCI_WRITER | PERCI_WRITER |
typedef struct _PERCI_READER | PERCI_READER |
Functions | |
int | PerCiInit (char *path, int recs) |
Initialize a ring buffer file. | |
PERCI_WRITER * | PerCiOpen (char *path) |
Open a ring buffer file. | |
void | PerCiClose (PERCI_WRITER *writer) |
Close a ring buffer file. | |
void | PerCiFlush (PERCI_WRITER *writer) |
Flush the current write buffer. | |
int | PerCiWrite (PERCI_WRITER *writer, CONST char *data, int len) |
Write to a ring buffer file. | |
int | PerCiWriteFormat (PERCI_WRITER *writer, CONST char *fmt,...) |
Write formatted line to a ring buffer file. | |
int | PerCiWriteVarList (PERCI_WRITER *writer, CONST char *fmt, va_list ap) |
Write formatted line to a ring buffer file. | |
PERCI_READER * | PerCiAttachReader (PERCI_WRITER *writer) |
Start reading from a ring buffer file. | |
void | PerCiDetachReader (PERCI_READER *reader) |
Stop reading from a ring buffer file. | |
int | PerCiRead (PERCI_READER *reader, char *data, int len) |
Read data from a ring buffer file. | |
int | PerCiReadLine (PERCI_READER *reader, char *line, int len) |
Read a text line from a ring buffer file. | |
void | PerCiDump (FILE *stream, char *path) |
Dump ring buffer file to given stream. | |
Variables | |
perci_reclen_t | _PERCI_RECORD::pcd_len |
uint8_t | _PERCI_RECORD::pcd_data [PERCI_RECSIZE] |
int | _PERCI_WRITER::pcw_fd |
long | _PERCI_WRITER::pcw_size |
HANDLE | _PERCI_WRITER::pcw_mutex |
perci_fast_recnum_t | _PERCI_WRITER::pcw_recnum |
PERCI_RECORD | _PERCI_WRITER::pcw_rec |
PERCI_WRITER * | _PERCI_READER::pcr_cil |
perci_fast_recnum_t | _PERCI_READER::pcr_recnum |
perci_fast_reclen_t | _PERCI_READER::pcr_reclen |
perci_fast_reclen_t | _PERCI_READER::pcr_recpos |
#define PERCI_MAX_RECORDS 256 |
Definition at line 59 of file perci.h.
Referenced by PerCiOpen().
#define PERCI_RECSIZE 256 |
Definition at line 75 of file perci.h.
Referenced by PerCiFlush(), PerCiInit(), PerCiOpen(), and PerCiWrite().
#define PERCI_DATASIZE (PERCI_RECSIZE - sizeof(perci_reclen_t)) |
Definition at line 89 of file perci.h.
Referenced by PerCiDump(), PerCiOpen(), PerCiWrite(), and PerCiWriteVarList().
typedef uint8_t perci_recnum_t |
typedef uint_fast8_t perci_fast_recnum_t |
typedef uint8_t perci_reclen_t |
typedef uint_fast8_t perci_fast_reclen_t |
typedef struct _PERCI_RECORD PERCI_RECORD |
typedef struct _PERCI_WRITER PERCI_WRITER |
typedef struct _PERCI_READER PERCI_READER |
int PerCiInit | ( | char * | path, |
int | recs | ||
) |
Initialize a ring buffer file.
If the file doesn't exist, a new file will be created. If the file exists, any buffered data will be erased.
The total size of the file is
recs * PERCI_RECSIZE + sizeof(perci_reclen_t)
bytes.
The available data space is
recs * PERCI_DATASIZE
bytes.
path | Path name of the file. |
recs | Number of buffer records, at least 2. |
Definition at line 151 of file perci.c.
References _close(), _O_BINARY, _O_CREAT, _O_RDWR, _O_TRUNC, _open(), _write(), calloc, free(), NUTASSERT, and PERCI_RECSIZE.
PERCI_WRITER * PerCiOpen | ( | char * | path | ) |
Open a ring buffer file.
The file must have been created by a previous call to PerCiInit().
The function failes, if the file doesn't exist or if it is corrupted. Applications may use the following sequence to open a circular buffer.
PERCI_WRITER *perci; char *path = "UFLASH0:data.log"; while ((perci = PerCiOpen(path)) == NULL) { if (PerCiInit(path, 128)) { printf("Error %d creating %s\n", errno, path); break; } }
path | Path name of the file. |
Definition at line 202 of file perci.c.
References _close(), _filelength(), _O_BINARY, _O_RDWR, _open(), _read(), _seek(), calloc, free(), NUTASSERT, NutEventPost(), _PERCI_RECORD::pcd_data, _PERCI_RECORD::pcd_len, _PERCI_WRITER::pcw_fd, _PERCI_WRITER::pcw_mutex, _PERCI_WRITER::pcw_rec, _PERCI_WRITER::pcw_recnum, _PERCI_WRITER::pcw_size, PERCI_DATASIZE, PERCI_MAX_RECORDS, PERCI_RECSIZE, SEEK_CUR, and SEEK_SET.
void PerCiClose | ( | PERCI_WRITER * | writer | ) |
Close a ring buffer file.
writer | Pointer to a PERCI_WRITER structure obtained by a previous call to PerCiOpen(). |
Definition at line 285 of file perci.c.
References _close(), free(), NUTASSERT, _PERCI_RECORD::pcd_len, _PERCI_WRITER::pcw_fd, _PERCI_WRITER::pcw_rec, and PerCiFlush().
void PerCiFlush | ( | PERCI_WRITER * | writer | ) |
Flush the current write buffer.
writer | Pointer to a PERCI_WRITER structure obtained by a previous call to PerCiOpen(). |
Definition at line 269 of file perci.c.
References _seek(), _write(), NUTASSERT, _PERCI_RECORD::pcd_len, _PERCI_WRITER::pcw_fd, _PERCI_WRITER::pcw_rec, _PERCI_WRITER::pcw_recnum, PERCI_RECSIZE, and SEEK_SET.
Referenced by PerCiClose().
int PerCiWrite | ( | PERCI_WRITER * | writer, |
CONST char * | data, | ||
int | len | ||
) |
Write to a ring buffer file.
writer | Pointer to a PERCI_WRITER structure obtained by a previous call to PerCiOpen(). |
Definition at line 305 of file perci.c.
References _seek(), _write(), memcpy(), NUT_WAIT_INFINITE, NUTASSERT, NutEventPost(), NutEventWait(), _PERCI_RECORD::pcd_data, _PERCI_RECORD::pcd_len, _PERCI_WRITER::pcw_fd, _PERCI_WRITER::pcw_mutex, _PERCI_WRITER::pcw_rec, _PERCI_WRITER::pcw_recnum, _PERCI_WRITER::pcw_size, PERCI_DATASIZE, PERCI_RECSIZE, and SEEK_SET.
Referenced by PerCiWriteVarList().
int PerCiWriteFormat | ( | PERCI_WRITER * | writer, |
CONST char * | fmt, | ||
... | |||
) |
Write formatted line to a ring buffer file.
writer | Pointer to a PERCI_WRITER structure obtained by a previous call to PerCiOpen(). |
fmt | Format string containing conversion specifications like printf. |
Definition at line 404 of file perci.c.
References NUTASSERT, and PerCiWriteVarList().
int PerCiWriteVarList | ( | PERCI_WRITER * | writer, |
CONST char * | fmt, | ||
va_list | ap | ||
) |
Write formatted line to a ring buffer file.
Alternate form of PerCiWriteFormat(), in which the arguments have already been captured using the variable-length argument facilities.
writer | Pointer to a PERCI_WRITER structure obtained by a previous call to PerCiOpen(). |
fmt | Format string containing conversion specifications like printf. |
ap | Pointer to the list of arguments. |
Definition at line 372 of file perci.c.
References free(), malloc(), NUTASSERT, PERCI_DATASIZE, PerCiWrite(), strlen(), and vsprintf().
Referenced by PerCiWriteFormat().
PERCI_READER * PerCiAttachReader | ( | PERCI_WRITER * | writer | ) |
Start reading from a ring buffer file.
It is assumed, that the ring buffer is kept open while the application is running. From time to time the buffered data will be retrieved. Therefore, a reader is attached to a previously open file and reading starts at the oldest record.
When all data has been read, the application must call PerCiDetachReader() to relase all allocated resources for reading.
Multiple readers may be concurrently attached to the same file.
writer | Pointer to a PERCI_WRITER structure obtained by a previous call to PerCiOpen(). |
Definition at line 490 of file perci.c.
References malloc(), NUTASSERT, _PERCI_READER::pcr_cil, _PERCI_READER::pcr_reclen, _PERCI_READER::pcr_recnum, _PERCI_READER::pcr_recpos, and _PERCI_WRITER::pcw_recnum.
void PerCiDetachReader | ( | PERCI_READER * | reader | ) |
Stop reading from a ring buffer file.
reader | Pointer to a PERCI_READER structure obtained by a previous call to PerCiAttachReader(). |
Definition at line 514 of file perci.c.
References free(), and NUTASSERT.
int PerCiRead | ( | PERCI_READER * | reader, |
char * | data, | ||
int | len | ||
) |
Read data from a ring buffer file.
reader | Pointer to a PERCI_READER structure obtained by a previous call to PerCiAttachReader(). |
data | Pointer to the buffer that receives the data. |
len | Number of bytes to read. |
Definition at line 532 of file perci.c.
References _read(), memcpy(), NUTASSERT, _PERCI_RECORD::pcd_data, _PERCI_READER::pcr_cil, _PERCI_READER::pcr_reclen, _PERCI_READER::pcr_recnum, _PERCI_READER::pcr_recpos, _PERCI_WRITER::pcw_fd, _PERCI_WRITER::pcw_rec, and _PERCI_WRITER::pcw_recnum.
Referenced by PerCiReadLine().
int PerCiReadLine | ( | PERCI_READER * | reader, |
char * | line, | ||
int | len | ||
) |
Read a text line from a ring buffer file.
reader | Pointer to a PERCI_READER structure obtained by a previous call to PerCiAttachReader(). |
data | Pointer to the buffer that receives the data. |
len | Number of bytes to read. |
Definition at line 602 of file perci.c.
References NUTASSERT, and PerCiRead().
void PerCiDump | ( | FILE * | stream, |
char * | path | ||
) |
Dump ring buffer file to given stream.
path | Path name of the file. |
stream | Stream to dump the contents to. |
Definition at line 71 of file perci.c.
References _close(), _filelength(), _O_BINARY, _O_RDWR, _open(), _read(), errno, fprintf(), fputc(), fputs(), free(), malloc(), and PERCI_DATASIZE.
Definition at line 92 of file perci.h.
Referenced by PerCiClose(), PerCiFlush(), PerCiOpen(), and PerCiWrite().
uint8_t _PERCI_RECORD::pcd_data[PERCI_RECSIZE] |
Definition at line 93 of file perci.h.
Referenced by PerCiOpen(), PerCiRead(), and PerCiWrite().
Definition at line 97 of file perci.h.
Referenced by PerCiClose(), PerCiFlush(), PerCiOpen(), PerCiRead(), and PerCiWrite().
Definition at line 98 of file perci.h.
Referenced by PerCiOpen(), and PerCiWrite().
Definition at line 99 of file perci.h.
Referenced by PerCiOpen(), and PerCiWrite().
Definition at line 100 of file perci.h.
Referenced by PerCiAttachReader(), PerCiFlush(), PerCiOpen(), PerCiRead(), and PerCiWrite().
Definition at line 101 of file perci.h.
Referenced by PerCiClose(), PerCiFlush(), PerCiOpen(), PerCiRead(), and PerCiWrite().
Definition at line 105 of file perci.h.
Referenced by PerCiAttachReader(), and PerCiRead().
Definition at line 106 of file perci.h.
Referenced by PerCiAttachReader(), and PerCiRead().
Definition at line 107 of file perci.h.
Referenced by PerCiAttachReader(), and PerCiRead().
Definition at line 108 of file perci.h.
Referenced by PerCiAttachReader(), and PerCiRead().