Piccolo

Dependencies:   mbed

Fork of Piccolo1 by Steven Vasquez

Revision:
0:4828681bf1f8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/memory.cpp	Tue Apr 17 00:28:17 2018 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "memory.h"
+
+int mem_head = 0;
+int mem_tail = 0;
+uint8_t full = 0;
+
+MEM_TYPE buffer[MEM_SIZE];
+
+void tail_reset()
+{
+ mem_tail=0;
+}
+
+void mem_free()
+{
+ mem_head=0;
+ full=0;
+}
+
+
+uint8_t mem_put(MEM_TYPE data)
+{
+ 
+    if (full)
+        return 1;
+    buffer[mem_head] = data;
+    mem_head += 1;
+    if (mem_head == MEM_SIZE)
+        full =1;
+    return 0;
+}
+
+uint8_t mem_get(MEM_TYPE* data)
+{
+    if (mem_head == 0)
+        return 1; 
+    if (mem_head == mem_tail)
+        return 1; 
+    
+ 
+    *data = buffer[mem_tail];
+    mem_tail += 1;
+  
+    return 0;
+}
\ No newline at end of file