VSF Documented
vsf_fifo.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_FIFO_H__
19#define __VSF_FIFO_H__
20
21/* example:
22
23 // 0. Include vsf header file
24 #include "vsf.h"
25
26 // 1. Defining type of fifo member
27 typedef struct xxxx_t {
28 ......
29 } xxxx_t;
30
31 // 2. Declare the fifo with user type
32 dcl_vsf_fifo(xxxx_fifo)
33
34 // 3. Defining the fifo
35 def_vsf_fifo(xxxx_fifo, xxxx_t, 8)
36
37 // 4. Defining fifo variable
38 static VSF_CAL_NO_INIT vsf_fifo(xxxx_fifo) __xxxx_fifo;
39
40 void user_example_task(void)
41 {
42 ......
43
44 // 5. Initialization user fifo.
45
46 vsf_fifo_init((vsf_fifo_t *)&__xxxx_fifo);
47
48 ......
49
50 // 6. Push to user fifo
51
52 xxxx_t xxxx_to_push = {
53 ........
54 };
55 vsf_fifo_push((vsf_fifo_t *)&__xxxx_fifo, &xxxx_to_push, sizeof(xxxx_t));
56
57 // 7. Pop from user fifo
58
59 xxxx_t xxxx_to_pop;
60 vsf_fifo_pop((vsf_fifo_t *)&__xxxx_fifo, &xxxx_to_pop, sizeof(xxxx_t));
61
62 // 8. Get pointer of head/tail element
63
64 xxxx_t *xxxx_head_ptr = vsf_fifo_get_head(&__xxxx_fifo);
65 write members pointed by xxxx_head_ptr;
66 vsf_fifo_push((vsf_fifo_t *)&__xxxx_fifo, NULL, sizeof(xxxx_t));
67
68 xxxx_t *xxxx_tail_ptr = vsf_fifo_get_tail(&__xxxx_fifo);
69 read members pointed by xxxx_head_ptr
70 vsf_fifo_pop((vsf_fifo_t *)&__xxxx_fifo, NULL, sizeof(xxxx_t));
71
72 ......
73 }
74 */
75
76/*============================ INCLUDES ======================================*/
79
80#if VSF_USE_FIFO == ENABLED
86#if defined(__VSF_FIFO_CLASS_IMPLEMENT)
87# define __VSF_CLASS_IMPLEMENT__
88# undef __VSF_FIFO_CLASS_IMPLEMENT
89#elif defined(__VSF_FIFO_CLASS_INHERIT__)
90# define __VSF_CLASS_INHERIT__
91# undef __VSF_FIFO_CLASS_INHERIT__
92#endif
93
94#include "utilities/ooc_class.h"
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99/*============================ MACROS ========================================*/
100
101#define __vsf_fifo(__name) __name##_fifo_t
102
103#define __declare_vsf_fifo(__name) \
104 vsf_dcl_class(vsf_fifo(__name))
105
106#define __define_vsf_fifo(__name, __item_type, __depth) \
107 vsf_class(vsf_fifo(__name)) { \
108 private_member( \
109 implement(vsf_fifo_base_t) \
110 __item_type __mem[__depth]; \
111 ) \
112 };
113
116#define vsf_fifo(__name) __vsf_fifo(__name)
117
118#define declare_vsf_fifo(__name) /* the name of the fifo */ \
119 __declare_vsf_fifo(__name)
120
121#define dcl_vsf_fifo(__name) /* the name of the fifo */ \
122 declare_vsf_fifo(__name)
123
124#define define_vsf_fifo(__name, /* the name of the fifo */ \
125 __item_type, /* the type of the item */ \
126 __depth) /* the depth of the fifo */ \
127 __define_vsf_fifo(__name, __item_type, (__depth))
128
129#define def_vsf_fifo( __name, /* the name of the fifo */ \
130 __item_type, /* the type of the item */ \
131 __depth) /* the depth of the fifo */ \
132 define_vsf_fifo(__name, __item_type, (__depth))
133
134#define end_def_fifo(__name)
135#define end_define_fifo(__name)
136
137// upper-case for simplified user interface
138#define VSF_FIFO_INIT(__FIFO) /* the address of the fifo */ \
139 vsf_fifo_init((vsf_fifo_t *)(__FIFO), dimof((__FIFO)->__mem));
140
141#define VSF_FIFO_GET_HEAD(__FIFO) /* the address of the fifo */ \
142 vsf_fifo_get_head((vsf_fifo_t *)(__FIFO), sizeof((__FIFO)->__mem[0]))
143
144#define VSF_FIFO_GET_TAIL(__FIFO) /* the address of the fifo */ \
145 vsf_fifo_get_tail((vsf_fifo_t *)(__FIFO), sizeof((__FIFO)->__mem[0]))
146
147#define VSF_FIFO_PUSH( __FIFO, /* the address of the fifo */ \
148 __ITEM) /* the address of the item to push */ \
149 vsf_fifo_push((vsf_fifo_t *)(__FIFO), (uintptr_t)(__ITEM), sizeof((__FIFO)->__mem[0]))
150
151#define VSF_FIFO_POP( __FIFO, /* the address of the fifo */ \
152 __ITEM) /* the address of the item to pop */ \
153 vsf_fifo_pop((vsf_fifo_t *)(__FIFO), (uintptr_t)(__ITEM), sizeof((__FIFO)->__mem[0]))
154
155#define VSF_FIFO_GET_NUMBER(__FIFO) /* the address of the fifo */ \
156 vsf_fifo_get_number((vsf_fifo_t *)(__FIFO))
157
159
160#ifndef vsf_fifo_index_t
161# define vsf_fifo_index_t uint8_t
162#endif
163#ifndef vsf_fifo_fast_index_t
164# define vsf_fifo_fast_index_t uint_fast8_t
165#endif
166#ifndef vsf_fifo_item_size_t
167# define vsf_fifo_item_size_t uint16_t
168#endif
169#ifndef vsf_fifo_fast_item_size_t
170# define vsf_fifo_fast_item_size_t uint_fast16_t
171#endif
172
173/*============================ TYPES =========================================*/
174
176 private_member(
179 vsf_fifo_index_t number;
180 vsf_fifo_index_t depth;
181 )
182};
183
187 private_member(
188 implement(vsf_fifo_base_t)
189 uint32_t nodes[0];
190 )
191};
193
194/*============================ GLOBAL VARIABLES ==============================*/
195/*============================ PROTOTYPES ====================================*/
196
197extern void vsf_fifo_init(vsf_fifo_t *fifo, vsf_fifo_fast_index_t fifo_depth);
200
201VSF_CAL_SECTION(".text.vsf.utilities.vsf_fifo_get_head")
203
204VSF_CAL_SECTION(".text.vsf.utilities.vsf_fifo_get_tail")
206
207VSF_CAL_SECTION(".text.vsf.utilities.vsf_fifo_get_number")
209
210#ifdef __cplusplus
211}
212#endif
213
214#endif
215#endif
#define VSF_CAL_SECTION(__SEC)
Definition __compiler.h:181
Definition vsf_fifo.h:175
Definition vsf_fifo.h:186
#define vsf_class(__name)
Definition ooc_class.h:48
uint32_t uintptr_t
Definition stdint.h:38
unsigned uint32_t
Definition stdint.h:9
#define vsf_fifo_index_t
Definition vsf_fifo.h:161
#define vsf_fifo_fast_index_t
Definition vsf_fifo.h:164
uintptr_t vsf_fifo_get_tail(vsf_fifo_t *fifo, vsf_fifo_fast_item_size_t item_size)
Definition vsf_fifo.c:139
vsf_fifo_index_t vsf_fifo_get_number(vsf_fifo_t *fifo)
Definition vsf_fifo.c:154
bool vsf_fifo_pop(vsf_fifo_t *fifo, uintptr_t item, vsf_fifo_fast_item_size_t item_size)
Definition vsf_fifo.c:96
bool vsf_fifo_push(vsf_fifo_t *fifo, uintptr_t item, vsf_fifo_fast_item_size_t item_size)
Definition vsf_fifo.c:68
#define vsf_fifo_fast_item_size_t
Definition vsf_fifo.h:170
uintptr_t vsf_fifo_get_head(vsf_fifo_t *fifo, vsf_fifo_fast_item_size_t item_size)
Definition vsf_fifo.c:124
void vsf_fifo_init(vsf_fifo_t *fifo, vsf_fifo_fast_index_t fifo_depth)
Definition vsf_fifo.c:61
__bfs_node_fifo_t fifo
Definition vsf_msg_tree.h:247
uintptr_t uint_fast32_t item_size
Definition vsf_pool.h:477
uint16_t tail
Definition vsf_queue.h:632
uint16_t head
Definition vsf_queue.h:632