-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcola_asyn.c
49 lines (44 loc) · 1.21 KB
/
cola_asyn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "cola_asyn.h"
static uint8_t first = 0, last = 0, full = 0;
static uint32_t colaVECES[COLA_EVENTOS_SIZE];
static uint32_t colaDATA[COLA_EVENTOS_SIZE];
static uint8_t colaID[COLA_EVENTOS_SIZE];
void cola_encolar_eventos(uint8_t ID_evento, uint32_t veces, uint32_t auxData) {
// Hay interrupciones que pueden encolar eventos
bloquear_interrupciones(); /*LOCK*/
if (full) { // overflow
colaID[last] = OVERFLOW_E; // last == first
} else {
colaVECES[last] = veces;
colaDATA[last] = auxData;
colaID[last] = ID_evento;
last++;
if (last == COLA_EVENTOS_SIZE) {
last = 0;
}
if (last == first) {
full = TRUE;
}
}
liberar_interrupciones(); /*UNLOCK*/
}
evento_t cola_desencolar_eventos(void) {
bloquear_interrupciones(); /*LOCK*/
evento_t evento;
evento.veces = colaVECES[first];
evento.auxData = colaDATA[first];
evento.ID_evento = colaID[first];
first++;
if (first == COLA_EVENTOS_SIZE) {
first = 0;
}
full = FALSE;
liberar_interrupciones(); /*UNLOCK*/
return evento;
}
int cola_hay_eventos(void) {
bloquear_interrupciones(); /*LOCK*/
int res = first != last || full;
liberar_interrupciones(); /*UNLOCK*/
return res;
}