Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2136 - 1
/**
2
 * a simple Fifo
3
 * @file fifo.h
4
 * @author Pascal Schnurr
5
*/
6
 
7
//############################################################################
8
//# HISTORY  fifo.c
9
//#
10
//# 26.06.2014 OG
11
//# - add: fifo_isstr()
12
//#
13
//# 16.04.2013 Cebra
14
//# - chg: PROGMEM angepasst auf neue avr-libc und GCC, prog_char depreciated
15
//############################################################################
16
 
17
 
18
#include <avr/pgmspace.h>
19
#include <stdbool.h>
20
#ifndef _FIFO_H_
21
#define _FIFO_H_
22
 
23
/**
24
*fifo data structure all vital fifo information
25
*/
26
typedef struct
27
{
28
    uint16_t count; /**< current number of elements */
29
    uint16_t head; /**< position of the head element */
30
    uint16_t size; /**< size equals max number of entrys*/
31
    uint8_t* buffer; /**< pointer to memory area where the fifo is to be saved */
32
} fifo_t;
33
 
34
uint16_t fifo_getcount (const fifo_t * fifo);
35
 
36
/** \brief initialize of a fifo
37
 * sets all the information in your given fifo structure
38
 * @param fifo pointer to an allocated fifo_t structure
39
 * @param buffer pointer to an a allocated memory space for the fifo of size = sizeof(uint8_t) * size
40
 * @param size max number of entrys the fifo will hold
41
 */
42
void fifo_init (fifo_t *fifo, uint8_t *buffer, uint16_t size);
43
 
44
/** \brief checks if fifo is empty
45
 * @param fifo pointer to your initialized fifo_t structure
46
 * @return true if empty otherwise false
47
 */
48
bool fifo_is_empty (const fifo_t *fifo);
49
 
50
/** \brief checks if fifo is full
51
 * @param fifo pointer to your initialized fifo_t structure
52
 * @return true if full otherwise false
53
 */
54
bool fifo_is_full (const fifo_t *fifo);
55
 
56
/** \brief clears the fifo
57
 * resets your fifo structure to 0 elements
58
 * @param fifo pointer to your initialized fifo_t structure
59
 * @return always true (never fails)
60
 */
61
bool fifo_clear (fifo_t *fifo);
62
 
63
/** \brief reads head of fifo
64
 * reads the first element and removes it
65
 * @param fifo pointer to your initialized fifo_t structure
66
 * @return false if fifo is empty false otherwise
67
 */
68
bool fifo_read (fifo_t *fifo, char *data);
69
 
70
/** \brief inserts a char into the fifo
71
 * adds a char to the end of the fifo
72
 * @param fifo pointer to your initialized fifo_t structure
73
 * @param data the char data to be inserted
74
 * @return false if fifo is full true otherwise
75
 */
76
bool fifo_write (fifo_t *fifo, const char data);
77
 
78
/** \brief compares first elements with prog_char string
79
 * if pgm equals the first elements of the fifo these elements are removed
80
 * @param fifo pointer to your initialized fifo_t structure
81
 * @param pgm a prog_char string for comparison
82
 * @return true if pgm is equal to the first entrys in the fifo, false otherwise
83
 */
84
bool fifo_cmp_pgm (fifo_t* fifo, const char* pgm);
85
 
86
/** \brief searches a string in the whole fifo
87
 * starts at the beginning and searches for the pgm string in the fifo,
88
 *
89
 * @param fifo pointer to your initialized fifo_t structure
90
 * @param pgm a prog_char with the search string
91
 * @return true if found, false otherwise
92
 */
93
 bool fifo_search (fifo_t * fifo, const char * pgm);
94
 
95
 /** \brief searches a string in the whole fifo
96
 * starts at the beginning and searches for the pgm string in the fifo,
97
 * if they are found previous entrys and the string are removed from the fifo
98
 * @param fifo pointer to your initialized fifo_t structure
99
 * @param pgm a prog_char with the search string
100
 * @return true if found, false otherwise
101
 */
102
bool fifo_strstr_pgm (fifo_t *fifo, const char *pgm);
103
 
104
 
105
bool fifo_isstr( fifo_t * fifo, const char * str);
106
 
107
#endif /* _FIFO_H_ */