OpenCores
URL https://opencores.org/ocsvn/aic1106_avalon_ip/aic1106_avalon_ip/trunk

Subversion Repositories aic1106_avalon_ip

[/] [aic1106_avalon_ip/] [trunk/] [software driver example/] [fifo.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 AlexO
/*
2
 * fifo.h
3
 *
4
 *  Created on: Jun 27, 2014
5
 *      Author: AlexO
6
 */
7
 
8
#ifndef FIFO_H_
9
#define FIFO_H_
10
 
11
#ifndef FALSE
12
#define FALSE 0
13
#endif
14
 
15
#ifndef TRUE
16
#define TRUE  1
17
#endif
18
 
19
#define MAKE_FIFO_INSTANCE(FIFO_NAME, FIFO_SIZE, ELEMENT_TYPE, LOCK, UNLOCK)\
20
\
21
int             FIFO_NAME##_head = 0;\
22
int             FIFO_NAME##_tail = 0;\
23
ELEMENT_TYPE    FIFO_NAME##_fifo[FIFO_SIZE];\
24
\
25
static inline int FIFO_NAME##_full()\
26
{\
27
        void* ctx = LOCK();\
28
        int ret_val = (FIFO_NAME##_tail==0 && FIFO_NAME##_head==FIFO_SIZE-1) || (FIFO_NAME##_head==FIFO_NAME##_tail-1);\
29
        UNLOCK(ctx);\
30
        return ret_val;\
31
}\
32
\
33
static inline int FIFO_NAME##_empty()\
34
{\
35
        void* ctx = LOCK();\
36
        int ret_val = (FIFO_NAME##_head == FIFO_NAME##_tail);\
37
        UNLOCK(ctx);\
38
        return ret_val;\
39
}\
40
\
41
static inline int FIFO_NAME##_put(ELEMENT_TYPE ELM)\
42
{\
43
        void* ctx = LOCK();\
44
        if (!((FIFO_NAME##_tail==0 && FIFO_NAME##_head==FIFO_SIZE-1) || (FIFO_NAME##_head==FIFO_NAME##_tail-1)))\
45
        {\
46
                FIFO_NAME##_fifo[FIFO_NAME##_head] = ELM;\
47
                if (FIFO_NAME##_head==(FIFO_SIZE-1))\
48
                        FIFO_NAME##_head=0; \
49
                else \
50
                        FIFO_NAME##_head++;\
51
                UNLOCK(ctx);\
52
                return TRUE;\
53
        }\
54
        UNLOCK(ctx);\
55
        return FALSE;\
56
}\
57
\
58
static inline int FIFO_NAME##_get(ELEMENT_TYPE* ELM)\
59
{\
60
        void* ctx = LOCK();\
61
        if (!(FIFO_NAME##_head == FIFO_NAME##_tail))\
62
        {\
63
                *ELM = FIFO_NAME##_fifo[FIFO_NAME##_tail];\
64
                if (FIFO_NAME##_tail==(FIFO_SIZE-1))\
65
                        FIFO_NAME##_tail=0; \
66
                else \
67
                        FIFO_NAME##_tail++;\
68
                UNLOCK(ctx);\
69
                return TRUE;\
70
        }\
71
        UNLOCK(ctx);\
72
        return FALSE;\
73
}\
74
\
75
static inline void FIFO_NAME##_clean()\
76
{\
77
        void* ctx = LOCK();\
78
        FIFO_NAME##_head = FIFO_NAME##_tail;\
79
        UNLOCK(ctx);\
80
}\
81
 
82
 
83
 
84
#endif /* FIFO_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.