diff options
Diffstat (limited to '')
-rw-r--r-- | Lab6.X/circBuffer.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lab6.X/circBuffer.c b/Lab6.X/circBuffer.c new file mode 100644 index 0000000..d4d120f --- /dev/null +++ b/Lab6.X/circBuffer.c @@ -0,0 +1,28 @@ +#include "xc.h" +#include "circBuffer.h" +#define SIZE 1024 + +volatile unsigned int buffer[SIZE]; +int buffSize = 0, write = 0, read = 0; +void initBuffer(){ + int i; + for (i=0; i<SIZE; i++) { + buffer[i]=0; + } + buffSize = 0, write = 0, read = 0; +} + +void putVal(int newValue){ + if (buffSize < SIZE) { + buffer[write++] = newValue; + write %= SIZE; + ++buffSize; + } + //Otherwise get rid of the data. +} +int getAvg(){ + int i, sum = 0; + for (i=0; i<SIZE; i++) { + sum += buffer[i]; + } return sum / SIZE; +} |