Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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