iLLD_TC29x
1.0
Ifx_Fifo.h
Go to the documentation of this file.
1
/**
2
* \file Ifx_Fifo.h
3
* \brief FIFO buffer functions
4
* \ingroup IfxLld_lib_datahandling_fifo
5
*
6
* \version iLLD_1_0_0_11_0
7
* \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8
*
9
*
10
* IMPORTANT NOTICE
11
*
12
*
13
* Infineon Technologies AG (Infineon) is supplying this file for use
14
* exclusively with Infineon's microcontroller products. This file can be freely
15
* distributed within development tools that are supporting such microcontroller
16
* products.
17
*
18
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21
* INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23
*
24
* \defgroup IfxLld_lib_datahandling_fifo FIFO
25
* This module implements the FIFO buffer functionality.
26
* \ingroup IfxLld_lib_datahandling
27
*
28
*/
29
30
#ifndef IFX_FIFO_H
31
#define IFX_FIFO_H 1
32
//------------------------------------------------------------------------------
33
#include "Ifx_Cfg.h"
34
#include "
Cpu/Std/IfxCpu_Intrinsics.h
"
35
//------------------------------------------------------------------------------
36
37
/** Shared data of the FIFO
38
*
39
*/
40
typedef
struct
41
{
42
Ifx_SizeT
count
;
/**< \brief number of bytes contained in the buffer */
43
sint32
readerWaitx
;
/**< \brief Number of bytes that the reader is waiting for. When the writer modify it to 0 the reader get signaled */
44
sint32
writerWaitx
;
/**< \brief Number of byte that the writer expect to be free. When the reader modify it to 0 the reader get signaled */
45
Ifx_SizeT
maxcount
;
/**< \brief Highest value seen in the count */
46
}
Ifx_Fifo_Shared
;
47
48
/** \addtogroup IfxLld_lib_datahandling_fifo
49
* \{ */
50
/** Fifo object
51
*
52
*/
53
typedef
struct
_Fifo
54
{
55
void
*
buffer
;
/**< \brief aligned on 64 bit boundary */
56
Ifx_Fifo_Shared
shared
;
/**< \brief data shared between reader / writer */
57
Ifx_SizeT
startIndex
;
/**< \brief buffer valid data start index */
58
Ifx_SizeT
endIndex
;
/**< \brief buffer valid data end index */
59
Ifx_SizeT
size
;
/**< \brief multiple of 8 bit, max 0xFFF8 */
60
Ifx_SizeT
elementSize
;
/**< \brief minimum number of bytes (block) added / removed to / from the buffer */
61
volatile
boolean
eventReader
;
/**< \brief event set by the writer to signal the reader that the required data are available in the buffer */
62
volatile
boolean
eventWriter
;
/**< \brief event set by the reader to signal the writer that the required free space are available in the buffer */
63
}
Ifx_Fifo
;
64
65
/** \brief Indicates if the required number of bytes are available in the buffer
66
*
67
* Should not be called from an interrupt as this function may wait forever
68
* \param fifo Pointer on the Fifo object
69
* \param count in bytes
70
* \param timeout in system timer ticks
71
*
72
* \return TRUE if at least count bytes can be read from the buffer, else
73
* the Event is armed to be set when the buffer count is bigger or equal to the requested count
74
*/
75
IFX_EXTERN
boolean
Ifx_Fifo_canReadCount
(
Ifx_Fifo
*fifo,
Ifx_SizeT
count,
Ifx_TickTime
timeout);
76
/** \brief Indicates if there is enough free space to write the data in the buffer
77
*
78
* Should not be called from an interrupt as this function may wait forever
79
*
80
* \param fifo Pointer on the Fifo object
81
* \param count in bytes
82
* \param timeout in system timer ticks
83
*
84
* \return TRUE if at least count bytes can be written to the buffer,
85
* if not the Event is armed to be set when the buffer free count is bigger or equal to the requested count
86
*/
87
IFX_EXTERN
boolean
Ifx_Fifo_canWriteCount
(
Ifx_Fifo
*fifo,
Ifx_SizeT
count,
Ifx_TickTime
timeout);
88
89
/** \brief Clear fifo contents.
90
*
91
* \param fifo Pointer on the Fifo object
92
*
93
* \return void
94
*/
95
IFX_EXTERN
void
Ifx_Fifo_clear
(
Ifx_Fifo
*fifo);
96
97
/** \brief Create a Fifo object
98
*
99
* The memory required for the object is allocated dynamically.
100
*
101
* \param size Specifies the FIFO buffer size in bytes
102
* \param elementSize Specifies data element size in bytes. size must be bigger or equal to elemenntSize.
103
*
104
* \return returns a pointer to the FIFO object
105
*
106
* \see Ifx_Fifo_destroy()
107
*/
108
IFX_EXTERN
Ifx_Fifo
*
Ifx_Fifo_create
(
Ifx_SizeT
size,
Ifx_SizeT
elementSize);
109
110
/** \brief Destroy the FIFO object
111
*
112
* This function must be called to destroy the fifo object when created with \ref Ifx_Fifo_create()
113
*
114
* \param fifo Pointer on the Fifo object
115
* \return void
116
*
117
* \see Ifx_Fifo_create()
118
*/
119
IFX_EXTERN
void
Ifx_Fifo_destroy
(
Ifx_Fifo
*fifo);
120
121
/** \brief Initialize the FIFO buffer object
122
*
123
* \param buffer Specifies the FIFO object address.
124
* \param size Specifies the FIFO buffer size in bytes
125
* \param elementSize Specifies data element size in bytes. size must be bigger or equal to elemenntSize.
126
*
127
* \return Returns a pointer on the FIFO object
128
*
129
* \note: The buffer parameter must point on a free memory location where the
130
* buffer object will be initialised. The size of this area must be at least
131
* equals to "size + sizeof(Ifx_Fifo) + 8". Not taking this in account may result
132
* in unpredictable behavior.
133
*/
134
IFX_EXTERN
Ifx_Fifo
*
Ifx_Fifo_init
(
void
*buffer,
Ifx_SizeT
size,
Ifx_SizeT
elementSize);
135
136
/** \brief Read data from a fifo and remove them from the buffer.
137
*
138
* Only complete elements are returned, if count is not a multiple of
139
* elementSize then the incomplete element is not read/removed from the buffer.
140
*
141
* \param fifo Pointer on the Fifo object
142
* \param data Pointer to the data buffer for storing values
143
* \param count in bytes
144
* \param timeout in system timer ticks
145
*
146
* \return return the number of byte that could not be read
147
*/
148
IFX_EXTERN
Ifx_SizeT
Ifx_Fifo_read
(
Ifx_Fifo
*fifo,
void
*data,
Ifx_SizeT
count,
Ifx_TickTime
timeout);
149
150
/** \brief Write data into a fifo.
151
*
152
* Only complete elements are written to the buffer, if count is not a multiple of
153
* elementSize then the incomplete element are not written to the buffer.
154
*
155
* \param fifo Pointer on the Fifo object
156
* \param data Pointer to the data buffer to write into the Fifo
157
* \param count in bytes
158
* \param timeout in system timer ticks
159
*/
160
IFX_EXTERN
Ifx_SizeT
Ifx_Fifo_write
(
Ifx_Fifo
*fifo,
const
void
*data,
Ifx_SizeT
count,
Ifx_TickTime
timeout);
161
162
/** \brief Empty the fifo
163
*
164
* \param fifo Pointer on the Fifo object
165
* \param timeout in system timer ticks
166
*
167
* \return TRUE if the buffer is emptied.
168
*/
169
IFX_INLINE
boolean
Ifx_Fifo_flush
(
Ifx_Fifo
*fifo,
Ifx_TickTime
timeout)
170
{
171
return
Ifx_Fifo_canWriteCount
(fifo, fifo->
size
, timeout);
172
}
173
174
175
/**
176
* \brief Returns the size of the data in the buffer in bytes
177
*
178
* \param fifo Pointer on the Fifo object
179
*
180
* Note as the Ifx_Fifo_write / Ifx_Fifo_read function does only write blocks which are
181
* a multiple of fifo->elementSize, the Ifx_Fifo_readCount / Ifx_Fifo_writeCount return
182
* a multiple of fifo->elementSize
183
*
184
* \return Returns the size of the data in the buffer in bytes
185
*/
186
IFX_INLINE
Ifx_SizeT
Ifx_Fifo_readCount
(
Ifx_Fifo
*fifo)
187
{
188
return
fifo->
shared
.
count
;
189
}
190
191
192
/** \brief Returns the free size in bytes
193
*
194
* \param fifo Pointer on the Fifo object
195
*
196
* Note as the Ifx_Fifo_write / Ifx_Fifo_read function does only write blocks which are
197
* a multiple of fifo->elementSize, the Ifx_Fifo_readCount / Ifx_Fifo_writeCount return
198
* a multiple of fifo->elementSize
199
*
200
* \return Returns the free size in bytes
201
*/
202
IFX_INLINE
Ifx_SizeT
Ifx_Fifo_writeCount
(
Ifx_Fifo
*fifo)
203
{
204
return
(
Ifx_SizeT
)(fifo->
size
-
Ifx_Fifo_readCount
(fifo));
205
}
206
207
208
/** \brief Indicates if the fifo is empty
209
*
210
* \param fifo Pointer on the Ifx_Fifo object
211
*
212
* \retval TRUE is the buffer is empty
213
* \retval FALSE is the buffer is not empty
214
*/
215
IFX_INLINE
boolean
Ifx_Fifo_isEmpty
(
Ifx_Fifo
*fifo)
216
{
217
return
(
Ifx_Fifo_readCount
(fifo) !=
FALSE
) ?
FALSE
:
TRUE
;
218
}
219
220
221
/**\}*/
222
//------------------------------------------------------------------------------
223
#endif
home
mclld
Libraries
release
iLLD_1_0_0_11_0
src
ifx
TC29x
_Lib
DataHandling
Ifx_Fifo.h
Generated by
1.8.4