pausa

Dependencies:   mbed

Fork of primercorte by edson antonio vargas villarreal

Committer:
ANTONIO_VARGAS
Date:
Wed Apr 11 02:19:13 2018 +0000
Revision:
0:0119b611fc51
nnhjk

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ANTONIO_VARGAS 0:0119b611fc51 1 #include "mbed.h"
ANTONIO_VARGAS 0:0119b611fc51 2 #include "memory.h"
ANTONIO_VARGAS 0:0119b611fc51 3
ANTONIO_VARGAS 0:0119b611fc51 4 int mem_head = 0;
ANTONIO_VARGAS 0:0119b611fc51 5 int mem_tail = 0;
ANTONIO_VARGAS 0:0119b611fc51 6 uint8_t full = 0;
ANTONIO_VARGAS 0:0119b611fc51 7
ANTONIO_VARGAS 0:0119b611fc51 8 MEM_TYPE buffer[MEM_SIZE];
ANTONIO_VARGAS 0:0119b611fc51 9
ANTONIO_VARGAS 0:0119b611fc51 10 void tail_reset()
ANTONIO_VARGAS 0:0119b611fc51 11 {
ANTONIO_VARGAS 0:0119b611fc51 12 mem_tail=0;
ANTONIO_VARGAS 0:0119b611fc51 13 }
ANTONIO_VARGAS 0:0119b611fc51 14
ANTONIO_VARGAS 0:0119b611fc51 15 void mem_free()
ANTONIO_VARGAS 0:0119b611fc51 16 {
ANTONIO_VARGAS 0:0119b611fc51 17 mem_head=0;
ANTONIO_VARGAS 0:0119b611fc51 18 full=0;
ANTONIO_VARGAS 0:0119b611fc51 19 }
ANTONIO_VARGAS 0:0119b611fc51 20
ANTONIO_VARGAS 0:0119b611fc51 21
ANTONIO_VARGAS 0:0119b611fc51 22 uint8_t mem_put(MEM_TYPE data)
ANTONIO_VARGAS 0:0119b611fc51 23 {
ANTONIO_VARGAS 0:0119b611fc51 24
ANTONIO_VARGAS 0:0119b611fc51 25 if (full)
ANTONIO_VARGAS 0:0119b611fc51 26 return 1;
ANTONIO_VARGAS 0:0119b611fc51 27 buffer[mem_head] = data;
ANTONIO_VARGAS 0:0119b611fc51 28 mem_head += 1;
ANTONIO_VARGAS 0:0119b611fc51 29 if (mem_head == MEM_SIZE)
ANTONIO_VARGAS 0:0119b611fc51 30 full =1;
ANTONIO_VARGAS 0:0119b611fc51 31 return 0;
ANTONIO_VARGAS 0:0119b611fc51 32 }
ANTONIO_VARGAS 0:0119b611fc51 33
ANTONIO_VARGAS 0:0119b611fc51 34 uint8_t mem_get(MEM_TYPE* data)
ANTONIO_VARGAS 0:0119b611fc51 35 {
ANTONIO_VARGAS 0:0119b611fc51 36 if (mem_head == 0)
ANTONIO_VARGAS 0:0119b611fc51 37 return 1;
ANTONIO_VARGAS 0:0119b611fc51 38 if (mem_head == mem_tail)
ANTONIO_VARGAS 0:0119b611fc51 39 return 1;
ANTONIO_VARGAS 0:0119b611fc51 40
ANTONIO_VARGAS 0:0119b611fc51 41
ANTONIO_VARGAS 0:0119b611fc51 42 *data = buffer[mem_tail];
ANTONIO_VARGAS 0:0119b611fc51 43 mem_tail += 1;
ANTONIO_VARGAS 0:0119b611fc51 44
ANTONIO_VARGAS 0:0119b611fc51 45 return 0;
ANTONIO_VARGAS 0:0119b611fc51 46 }