embeddedlibrary
reusable software modules for embedded systems
buffer.h
Go to the documentation of this file.
1 //x comments which begin with //x are for beginner student information only
2 //x these comments would normally not be required
3 
4 //x in every .h file it is recommended to use the following pattern:
5 //x 1. at the top check if a special flag is set (recommended _FILENAME_H_)
6 //x 2. if not define the flag
7 //x 3. put a matching endif at the end of the file
8 //x this will avoid many errors and issues if you ever include a .h file twice
9 //x since the second time it is included the flag _FILENAME_H_ will be defined
10 //x thus the contents of the file will be ignored
11 #ifndef _BUFFER_H_
12 #define _BUFFER_H_
13 
14 //x include any standard headers which will be required by the module here
15 #include <stdint.h>
16 #include <stdbool.h>
17 //x include headers for dependent modules or any other headers required here
18 
19 //x the following is a doxygen comment block. Read doxygen documentation for more
20 //x details
52 typedef struct {
53  uint16_t size;
54  uint16_t max_size;
55  char *front;
56  char *rear;
57  char *buffer_start;
58  char *buffer_end;
59  void (*Callback)(void * buf);
61  //x the input to the Callback should be a buffer_t pointer; however, buffer_t
62  //x has not been defined thus the pointer is cast as a void pointer.
63 } buffer_t;
64 
80 void Push(buffer_t *buffer, char data);
81 
96 char Pop(buffer_t *buffer);
97 
106 uint16_t GetSize(buffer_t *buffer);
107 
124 void BufferInit(buffer_t *buffer, char *data_array, uint16_t max_size);
125 
161 void BufferSetCallback(buffer_t * buffer, void (*Callback)(buffer_t * buffer));
162 
167 void BufferClearCallback(buffer_t * buffer);
168 
187 char PushData(buffer_t * buffer, char * data, uint16_t length);
188 
189 #define BUFFER_PUSH_FAILED 1
190 #define BUFFER_PUSH_SUCCEEDED 0
191 
192 //x this is a special doxygen command to end a grouping of doxygen comment blocks
195 //x when a #endif compiler directive is not immediately after the matching #if...
196 //x then it is recommended to add a comment to indicate which #if it pairs with
197 #endif // _BUFFER_H_
198 //x some compilers will produce warnings if there is no blank newline at the end of a file
uint16_t size
Definition: buffer.h:53
char * rear
Definition: buffer.h:56
char * buffer_start
Definition: buffer.h:57
Definition: buffer.h:52
uint16_t max_size
Definition: buffer.h:54
char * buffer_end
Definition: buffer.h:58
void BufferInit(buffer_t *buffer, char *data_array, uint16_t max_size)
Definition: buffer.c:67
char * front
Definition: buffer.h:55
uint16_t GetSize(buffer_t *buffer)
Definition: buffer.c:63
void Push(buffer_t *buffer, char data)
Definition: buffer.c:19
char PushData(buffer_t *buffer, char *data, uint16_t length)
Definition: buffer.c:85
void BufferSetCallback(buffer_t *buffer, void(*Callback)(buffer_t *buffer))
Definition: buffer.c:76
void BufferClearCallback(buffer_t *buffer)
Definition: buffer.c:83
char Pop(buffer_t *buffer)
Definition: buffer.c:47