Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 01-04EntregaPrimerCorte by
Diff: memory.cpp
- Revision:
- 0:89b318e49395
diff -r 000000000000 -r 89b318e49395 memory.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/memory.cpp Sat Mar 17 00:57:56 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
