Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1470 - 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
 
24
/** \brief initialize of a fifo
25
 * sets all the information in your given fifo structure
26
 * @param fifo pointer to an allocated fifo_t structure
27
 * @param buffer pointer to an a allocated memory space for the fifo of size = sizeof(uint8_t) * size
28
 * @param size max number of entrys the fifo will hold
29
 */
30
void fifo_init (fifo_t *fifo, uint8_t *buffer, uint16_t size);
31
 
32
/** \brief checks if fifo is empty
33
 * @param fifo pointer to your initialized fifo_t structure
34
 * @return true if empty otherwise false
35
 */
36
bool fifo_is_empty (const fifo_t *fifo);
37
 
38
/** \brief checks if fifo is full
39
 * @param fifo pointer to your initialized fifo_t structure
40
 * @return true if full otherwise false
41
 */
42
bool fifo_is_full (const fifo_t *fifo);
43
 
44
/** \brief clears the fifo
45
 * resets your fifo structure to 0 elements
46
 * @param fifo pointer to your initialized fifo_t structure
47
 * @return always true (never fails)
48
 */
49
bool fifo_clear (fifo_t *fifo);
50
 
51
/** \brief reads head of fifo
52
 * reads the first element and removes it
53
 * @param fifo pointer to your initialized fifo_t structure
54
 * @return false if fifo is empty false otherwise
55
 */
56
bool fifo_read (fifo_t *fifo, char *data);
57
 
58
/** \brief inserts a char into the fifo
59
 * adds a char to the end of the fifo
60
 * @param fifo pointer to your initialized fifo_t structure
61
 * @param data the char data to be inserted
62
 * @return false if fifo is full true otherwise
63
 */
64
bool fifo_write (fifo_t *fifo, const char data);
65
 
66
/** \brief compares first elements with prog_char string
67
 * if pgm equals the first elements of the fifo these elements are removed
68
 * @param fifo pointer to your initialized fifo_t structure
69
 * @param pgm a prog_char string for comparison
70
 * @return true if pgm is equal to the first entrys in the fifo, false otherwise
71
 */
72
bool fifo_cmp_pgm (fifo_t* fifo, const prog_char* pgm);
73
 
74
/** \brief searches a string in the whole fifo
75
 * starts at the beginning and searches for the pgm string in the fifo,
76
 * if they are found previous entrys and the string are removed from the fifo
77
 * @param fifo pointer to your initialized fifo_t structure
78
 * @param pgm a prog_char with the search string
79
 * @return true if found, false otherwise
80
 */
81
bool fifo_strstr_pgm (fifo_t *fifo, const prog_char *pgm);
82
 
83
#endif /* _FIFO_H_ */