-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusart_buffer.h
36 lines (26 loc) · 899 Bytes
/
usart_buffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* ringbuffer.h
*
* API for using a ring buffer for the purpose of storing key presses
*/
#include <inttypes.h>
#ifndef USARTt_BUFFER_H_
#define USART_BUFFER_H_
#define BUF_SIZE 15
typedef struct {
unsigned int put;
unsigned int get;
unsigned int used; // number of elements currently in the buffer
char buffer[BUF_SIZE];
} UsartBuffer;
// Adds element to buffer. Will block if there is no space in buffer.
void usart_put(UsartBuffer* buffer, char element);
// Gets element from buffer. Will block if buffer is empty.
char usart_get(UsartBuffer* buffer);
// Returns true (non-zero) if there is room for one element in buffer
int usart_hasSpace(UsartBuffer *);
// Return true (non-zero) if there is at least one element in buffer
int usart_hasElement(UsartBuffer *);
// Return 1 for same, 0 for mismatch
int usart_cmp(UsartBuffer* buffer1, UsartBuffer* buffer2);
#endif