DESPLAZAMIENTO PICCOLO

Dependencies:   mbed

Fork of 01-04EntregaPrimerCorte by ferney alberto beltran molina

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers memory.cpp Source File

memory.cpp

00001 #include "mbed.h"
00002 #include "memory.h"
00003 
00004 int mem_head = 0;
00005 int mem_tail = 0;
00006 uint8_t full = 0;
00007 
00008 MEM_TYPE buffer[MEM_SIZE];
00009 
00010 void tail_reset()
00011 {
00012  mem_tail=0;
00013 }
00014 
00015 void mem_free()
00016 {
00017  mem_head=0;
00018  full=0;
00019 }
00020 
00021 
00022 uint8_t mem_put(MEM_TYPE data)
00023 {
00024  
00025     if (full)
00026         return 1;
00027     buffer[mem_head] = data;
00028     mem_head += 1;
00029     if (mem_head == MEM_SIZE)
00030         full =1;
00031     return 0;
00032 }
00033 
00034 uint8_t mem_get(MEM_TYPE* data)
00035 {
00036     if (mem_head == 0)
00037         return 1; 
00038     if (mem_head == mem_tail)
00039         return 1; 
00040     
00041  
00042     *data = buffer[mem_tail];
00043     mem_tail += 1;
00044   
00045     return 0;
00046 }