nicolas rojas
/
segundo_copy
pausa
Fork of primercorte by
Diff: memory.cpp
- Revision:
- 0:0119b611fc51
diff -r 000000000000 -r 0119b611fc51 memory.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memory.cpp Wed Apr 11 02:19:13 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