aboutsummaryrefslogtreecommitdiffstats
path: root/Lab6.X/circBuffer.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Lab6.X/circBuffer.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/Lab6.X/circBuffer.c b/Lab6.X/circBuffer.c
index d4d120f..6ce4ee0 100644
--- a/Lab6.X/circBuffer.c
+++ b/Lab6.X/circBuffer.c
@@ -1,28 +1,25 @@
-#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;
-}
+#include "xc.h"
+#include "circBuffer.h"
+#define SIZE 1024
+
+volatile unsigned long buffer[SIZE];
+int buffSize = 0;
+void initBuffer(){
+ int i;
+ for (i=0; i<SIZE; i++) {
+ buffer[i]=0;
+ }
+ buffSize = 0;
+}
+
+void putVal(long newValue){
+ buffer[buffSize++] = newValue;
+ if (buffSize > SIZE)
+ buffSize = 0;
+}
+long getAvg(){
+ int i, sum = 0;
+ for (i=0; i<SIZE; i++) {
+ sum += buffer[i];
+ } return sum / SIZE;
+}