1 // --------------------------------------------------------------------------
2 // --
3 // -- FBUFFERS - FIFO buffers Header.
4 // --
5 // --
6 // --------------------------------------------------------------------------
7
8 // --------------------------------------------------------------------------
9 // -- Includes
10 // --------------------------------------------------------------------------
11
12 // --------------------------------------------------------------------------
13 // -- Definitions
14 // --------------------------------------------------------------------------
15 #define FB_MAX_BUFFER_SIZE 1024
16
17 enum FB_ERROR_T { FB_NO_ERROR = 0, FB_OVERRUN, FB_EMPTY };
18
19 // --------------------------------------------------------------------------
20 // -- Classes
21 // --------------------------------------------------------------------------
22
23 class FBuffer {
24
25 unsigned char *buffer;
26
27 // To avoid multiplication, we will keep pointers
28 unsigned char *roverStart;
29 unsigned char *roverEnd;
30 unsigned int currentStop;
31 unsigned int currentSize;
32 unsigned int currentStart;
33
34 public:
35
36 FBuffer(unsigned int size);
37 ~FBuffer();
38
39 Boolean HasData(void) { if(currentSize)return TRUE; return FALSE; };
40
41 // Lets try and inline these bugs. The interrupt handler will
42 // thanks us
43 FB_ERROR_T In(unsigned char byte) {
44 if (currentSize==FB_MAX_BUFFER_SIZE) return FB_OVERRUN;
45 currentSize++;
46 *roverEnd = byte;
47 if (currentStop == (FB_MAX_BUFFER_SIZE-1)) {
48 currentStop = 0;
49 roverEnd = buffer;
50 } else {
51 currentStop++;
52 roverEnd++;
53 }
54 return FB_NO_ERROR;
55 };
56
57 FB_ERROR_T Out(unsigned char &byte) {
58 if (currentSize==0) return FB_EMPTY;
59 currentSize--;
60 byte = *roverStart;
61 if (currentStart == (FB_MAX_BUFFER_SIZE-1)) {
62 currentStart = 0;
63 roverStart = buffer;
64 } else {
65 currentStart++;
66 roverStart++;
67 }
68 return FB_NO_ERROR;
69 };
70
71 };
72
73
|