pausa

Dependencies:   mbed

Fork of primercorte by edson antonio vargas villarreal

memory.cpp

Committer:
ANTONIO_VARGAS
Date:
2018-04-11
Revision:
0:0119b611fc51

File content as of revision 0:0119b611fc51:

#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;
}