ISF  2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
isf_fifo.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015, Freescale Semiconductor, Inc.
4  *
5 */
6 /*
7  * isf_fifo.h
8  *
9  * Created on: Oct 1, 2013,
10  * Author: B37804
11  */
12 
13 #ifndef ISF_FIFO_H_
14 #define ISF_FIFO_H_
15 #include "isf.h"
17 
18 
19 typedef struct {
20  uint8 *pDataBuffer; /*!< Pointer to the data buffer for the new sensor data samples */
21  uint8 *pInsertPtr; /*!< Pointer to where the next sample goes when buffering multiple samples */
22  uint8 *pLastEntry; /*!< Pointer to the last entry in the fifo. When the pInsertPtr equals lastEntry the fifo is full */
23  uint16 sampleSize; /*!< The size of a single sample in bytes */
24  semaphore_t bufferLock; /*!< Lock for the shared data buffer */
25  uint8 fifoState; /*!< Contains fifo state info including initialization state and buffer allocation type */
26 } isf_fifo_t;
27 
28 #define ISF_FIFO_ERR_NO_MEM (1)
29 #define ISF_FIFO_ERR_USER_BUF (2)
30 #define ISF_FIFO_ERR_BUSY (3)
31 #define ISF_FIFO_ERR_INVALID_PTR (4)
32 #define ISF_FIFO_ERR_NO_INIT (5)
33 #define ISF_FIFO_FULL (6)
34 #define ISF_FIFO_NO_MORE_ENTRIES (7)
35 /*!
36  * @brief Initializes a fifo structure and allocates a new fifo buffer.
37  */
38 isf_fifo_status_t isf_fifo_alloc ( isf_fifo_t *pFifo, uint16 sampleSize, uint16 bufferCapacity );
39 
40 /*!
41  * @brief Initializes a new fifo structure with a provided buffer.
42  */
43 isf_fifo_status_t isf_fifo_init ( isf_fifo_t *pFifo, void *pData, uint16 sampleSize, uint16 bufferCapacity );
44 
45 /*!
46  * @brief free a fifo's sample buffer.
47  */
49 
50 /*!
51  * @brief Routine to copy the whole sample buffer
52  */
53 isf_fifo_status_t isf_fifo_resize ( isf_fifo_t *pFifo, uint16 newCapacity );
54 
55 /*!
56  * @brief Routine to query the current fifo size (bytes)
57  */
59 
60 /*!
61  * @brief Routine to copy the whole sample buffer
62  */
63 isf_fifo_status_t isf_fifo_data_copy ( isf_fifo_t *pFifo, void *samplePtr );
64 
65 /*!
66  * @brief Lock a sample buffer for exclusive access.
67  */
69 
70 /*!
71  * @brief Attempt to lock a sample buffer for exclusive access.
72  */
74 
75 /*!
76  * @brief Release the exclusive access lock on a sample buffer.
77  */
79 
80 /*!
81  * @brief Routine returns the insert pointer for direct access
82  */
84 
85 /*!
86  * @brief Routine increments the insert pointer after direct access
87  */
89 
90 /*!
91  * @brief Routine to traverse a fifo
92  * To initiate the traversal set pSamplePtr to NULL.
93  * The function will set the pointer to the first available sample and returns ISF_SUCCESS.
94  * Subsequent calls will increment the pointer to each available sample and return ISF_SUCCESS.
95  * When ISF_SUCCESS is returned, pSamplePtr may be dereferenced to obtain a fifo entry.
96  * When no more samples are available, the function returns ISF_FIFO_NO_MORE_ENTRIES.
97  */
98 isf_fifo_status_t isf_fifo_el_traverse ( isf_fifo_t *pFifo, void **pSamplePtr );
99 
100 /*!
101  * @brief Routine to clear the fifo
102  */
104 
105 #endif /* ISF_FIFO_H_ */
106 
107 
108 /*
109  *
110  * Copyright (c) 2015, Freescale Semiconductor, Inc.
111  *
112 */
113 /*
114  * isf_fifo.h
115  *
116  * Created on: Oct 1, 2013,
117  * Author: B37804
118  */
119 
120 #ifndef ISF_FIFO_H_
121 #define ISF_FIFO_H_
122 #include "isf.h"
123 typedef uint32 isf_fifo_status_t;
124 
125 
126 typedef struct {
127  uint8 *pDataBuffer; /*!< Pointer to the data buffer for the new sensor data samples */
128  uint8 *pInsertPtr; /*!< Pointer to where the next sample goes when buffering multiple samples */
129  uint8 *pLastEntry; /*!< Pointer to the last entry in the fifo. When the pInsertPtr equals lastEntry the fifo is full */
130  uint16 sampleSize; /*!< The size of a single sample in bytes */
131  semaphore_t bufferLock; /*!< Lock for the shared data buffer */
132  uint8 fifoState; /*!< Contains fifo state info including initialization state and buffer allocation type */
133 } isf_fifo_t;
134 
135 #define ISF_FIFO_ERR_NO_MEM (1)
136 #define ISF_FIFO_ERR_USER_BUF (2)
137 #define ISF_FIFO_ERR_BUSY (3)
138 #define ISF_FIFO_ERR_INVALID_PTR (4)
139 #define ISF_FIFO_ERR_NO_INIT (5)
140 #define ISF_FIFO_FULL (6)
141 #define ISF_FIFO_NO_MORE_ENTRIES (7)
142 /*!
143  * @brief Initializes a fifo structure and allocates a new fifo buffer.
144  */
145 isf_fifo_status_t isf_fifo_alloc ( isf_fifo_t *pFifo, uint16 sampleSize, uint16 bufferCapacity );
146 
147 /*!
148  * @brief Initializes a new fifo structure with a provided buffer.
149  */
150 isf_fifo_status_t isf_fifo_init ( isf_fifo_t *pFifo, void *pData, uint16 sampleSize, uint16 bufferCapacity );
151 
152 /*!
153  * @brief free a fifo's sample buffer.
154  */
156 
157 /*!
158  * @brief Routine to copy the whole sample buffer
159  */
160 isf_fifo_status_t isf_fifo_resize ( isf_fifo_t *pFifo, uint16 newCapacity );
161 
162 /*!
163  * @brief Routine to query the current fifo size (bytes)
164  */
166 
167 /*!
168  * @brief Routine to copy the whole sample buffer
169  */
170 isf_fifo_status_t isf_fifo_data_copy ( isf_fifo_t *pFifo, void *samplePtr );
171 
172 /*!
173  * @brief Lock a sample buffer for exclusive access.
174  */
176 
177 /*!
178  * @brief Attempt to lock a sample buffer for exclusive access.
179  */
181 
182 /*!
183  * @brief Release the exclusive access lock on a sample buffer.
184  */
186 
187 /*!
188  * @brief Routine returns the insert pointer for direct access
189  */
191 
192 /*!
193  * @brief Routine increments the insert pointer after direct access
194  */
196 
197 /*!
198  * @brief Routine to traverse a fifo
199  * To initiate the traversal set pSamplePtr to NULL.
200  * The function will set the pointer to the first available sample and returns ISF_SUCCESS.
201  * Subsequent calls will increment the pointer to each available sample and return ISF_SUCCESS.
202  * When ISF_SUCCESS is returned, pSamplePtr may be dereferenced to obtain a fifo entry.
203  * When no more samples are available, the function returns ISF_FIFO_NO_MORE_ENTRIES.
204  */
205 isf_fifo_status_t isf_fifo_el_traverse ( isf_fifo_t *pFifo, void **pSamplePtr );
206 
207 /*!
208  * @brief Routine to clear the fifo
209  */
211 
212 #endif /* ISF_FIFO_H_ */
213 
isf_fifo_status_t isf_fifo_try_lock(isf_fifo_t *pFifo)
Attempt to lock a sample buffer for exclusive access.
Definition: isf_fifo.c:183
unsigned char uint8
Definition: isf_types.h:76
isf_fifo_status_t isf_fifo_lock(isf_fifo_t *pFifo)
Lock a sample buffer for exclusive access.
Definition: isf_fifo.c:170
isf_fifo_status_t isf_fifo_unlock(isf_fifo_t *pFifo)
Release the exclusive access lock on a sample buffer.
Definition: isf_fifo.c:199
isf_fifo_status_t isf_fifo_el_increment(isf_fifo_t *pFifo)
Routine increments the insert pointer after direct access.
Definition: isf_fifo.c:237
isf_fifo_status_t isf_fifo_el_clear(isf_fifo_t *pFifo)
Routine to clear the fifo.
Definition: isf_fifo.c:217
isf_fifo_status_t isf_fifo_resize(isf_fifo_t *pFifo, uint16 newCapacity)
Routine to copy the whole sample buffer.
Definition: isf_fifo.c:101
uint32 isf_fifo_status_t
Definition: isf_fifo.h:16
uint8 * pDataBuffer
Definition: isf_fifo.h:20
isf_fifo_status_t isf_fifo_init(isf_fifo_t *pFifo, void *pData, uint16 sampleSize, uint16 bufferCapacity)
Initializes a new fifo structure with a provided buffer.
Definition: isf_fifo.c:24
isf_fifo_status_t isf_fifo_alloc(isf_fifo_t *pFifo, uint16 sampleSize, uint16 bufferCapacity)
Initializes a fifo structure and allocates a new fifo buffer.
Definition: isf_fifo.c:71
isf_fifo_status_t isf_fifo_free(isf_fifo_t *pFifo)
free a fifo's sample buffer.
Definition: isf_fifo.c:79
uint16 sampleSize
Definition: isf_fifo.h:23
Main ISF header file. Contains code common to all ISF components.
uint16 isf_fifo_get_buffer_size(isf_fifo_t *pFifo)
Routine to query the current fifo size (bytes)
Definition: isf_fifo.c:133
unsigned short int uint16
Definition: isf_types.h:77
semaphore_t bufferLock
Definition: isf_fifo.h:24
uint8 * pLastEntry
Definition: isf_fifo.h:22
void * isf_fifo_el_get_insert_pointer(isf_fifo_t *pFifo)
Routine returns the insert pointer for direct access.
Definition: isf_fifo.c:229
unsigned long int uint32
Definition: isf_types.h:78
isf_fifo_status_t isf_fifo_data_copy(isf_fifo_t *pFifo, void *samplePtr)
Routine to copy the whole sample buffer.
Definition: isf_fifo.c:154
uint8 fifoState
Definition: isf_fifo.h:25
uint8 * pInsertPtr
Definition: isf_fifo.h:21
isf_fifo_status_t isf_fifo_el_traverse(isf_fifo_t *pFifo, void **pSamplePtr)
Routine to traverse a fifo To initiate the traversal set pSamplePtr to NULL. The function will set th...
Definition: isf_fifo.c:259