sbgSplitBuffer.h
Go to the documentation of this file.
1 
21 #ifndef SBG_SPLIT_BUFFER_H
22 #define SBG_SPLIT_BUFFER_H
23 
24 #include <sbgCommon.h>
25 
26 //----------------------------------------------------------------------//
27 //- Header (open extern C block) -//
28 //----------------------------------------------------------------------//
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 //----------------------------------------------------------------------//
34 //- Structs definitions -//
35 //----------------------------------------------------------------------//
36 
40 typedef struct _SbgSplitBuffer
41 {
42  uint8_t *pLinkedBuffer;
44  size_t subBufferSize;
45  size_t subBufferNbr;
47 
48 //----------------------------------------------------------------------//
49 //- Public methods definitions -//
50 //----------------------------------------------------------------------//
51 
59 SBG_INLINE void sbgSplitBufferInitForRead(SbgSplitBuffer *pSplitBuffer, const void *pBuffer, size_t bufferSize, size_t subBufferSize)
60 {
61  //
62  // Test input arguments
63  //
64  assert(pSplitBuffer);
65 
66  //
67  // Initialize split buffer parameters
68  //
69  pSplitBuffer->pLinkedBuffer = (uint8_t*)pBuffer;
70  pSplitBuffer->linkedBufferSize = bufferSize;
71  pSplitBuffer->subBufferSize = subBufferSize;
72 
73  //
74  // Compute sub buffer number
75  //
76  pSplitBuffer->subBufferNbr = (bufferSize + (subBufferSize - 1)) / subBufferSize;
77 }
78 
86 SBG_INLINE void sbgSplitBufferInitForWrite(SbgSplitBuffer *pSplitBuffer, void *pBuffer, size_t bufferSize, size_t subBufferSize)
87 {
88  //
89  // Test input arguments
90  //
91  assert(pSplitBuffer);
92 
93  //
94  // Initialize split buffer parameters
95  //
96  pSplitBuffer->pLinkedBuffer = (uint8_t*)pBuffer;
97  pSplitBuffer->linkedBufferSize = bufferSize;
98  pSplitBuffer->subBufferSize = subBufferSize;
99 
100  //
101  // Compute sub buffer number
102  //
103  pSplitBuffer->subBufferNbr = (bufferSize + (subBufferSize - 1)) / subBufferSize;
104 }
105 
112 {
113  //
114  // Test input arguments
115  //
116  assert(pSplitBuffer);
117 
118  //
119  // Return subBufferNbr parameter
120  //
121  return pSplitBuffer->subBufferNbr;
122 }
123 
130 SBG_INLINE void *sbgSplitBufferGetSubBuffer(const SbgSplitBuffer *pSplitBuffer, size_t subBufferIdx)
131 {
132  //
133  // Test input arguments
134  //
135  assert(pSplitBuffer);
136 
137  //
138  // Test input parameters
139  //
140  if (subBufferIdx < pSplitBuffer->subBufferNbr)
141  {
142  //
143  // Return pointer to buffer
144  //
145  return ((uint8_t*)pSplitBuffer->pLinkedBuffer + pSplitBuffer->subBufferSize*subBufferIdx);
146  }
147  else
148  {
149  //
150  // Invalid index
151  //
152  return NULL;
153  }
154 }
155 
162 SBG_INLINE size_t sbgSplitBufferGetSubBufferOffset(const SbgSplitBuffer *pSplitBuffer, size_t subBufferIdx)
163 {
164  //
165  // Test input arguments
166  //
167  assert(pSplitBuffer);
168 
169  //
170  // Test input parameters
171  //
172  if (subBufferIdx < pSplitBuffer->subBufferNbr)
173  {
174  //
175  // Return pointer to buffer
176  //
177  return (pSplitBuffer->subBufferSize * subBufferIdx);
178  }
179  else
180  {
181  //
182  // Invalid index
183  //
184  return 0;
185  }
186 }
187 
194 SBG_INLINE size_t sbgSplitBufferGetSubBufferSize(const SbgSplitBuffer *pSplitBuffer, size_t subBufferIdx)
195 {
196  size_t subBufferSize = 0;
197 
198  //
199  // Test input arguments
200  //
201  assert(pSplitBuffer);
202 
203  //
204  // Test input parameters
205  //
206  if (pSplitBuffer->subBufferNbr > 0)
207  {
208  //
209  // Test that the sub buffer index is not the last one
210  //
211  if (subBufferIdx < (pSplitBuffer->subBufferNbr-1))
212  {
213  //
214  // We can just return the sub buffer size because it's not the last sub buffer
215  //
216  subBufferSize = pSplitBuffer->subBufferSize;
217  }
218  else if (subBufferIdx == (pSplitBuffer->subBufferNbr-1) )
219  {
220  //
221  // It's the last sub buffer so return the remaining size
222  //
223  subBufferSize = pSplitBuffer->linkedBufferSize - (subBufferIdx * pSplitBuffer->subBufferSize);
224  }
225  }
226 
227  //
228  // Return computed size
229  //
230  return subBufferSize;
231 }
232 
233 //----------------------------------------------------------------------//
234 //- Footer (close extern C block) -//
235 //----------------------------------------------------------------------//
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /* SBG_SPLIT_BUFFER_H */
SBG_INLINE size_t sbgSplitBufferGetSubBufferNbr(const SbgSplitBuffer *pSplitBuffer)
struct _SbgSplitBuffer SbgSplitBuffer
uint8_t * pLinkedBuffer
SBG_INLINE size_t sbgSplitBufferGetSubBufferOffset(const SbgSplitBuffer *pSplitBuffer, size_t subBufferIdx)
size_t linkedBufferSize
SBG_INLINE size_t sbgSplitBufferGetSubBufferSize(const SbgSplitBuffer *pSplitBuffer, size_t subBufferIdx)
SBG_INLINE void * sbgSplitBufferGetSubBuffer(const SbgSplitBuffer *pSplitBuffer, size_t subBufferIdx)
#define NULL
Definition: sbgDefines.h:81
SBG_INLINE void sbgSplitBufferInitForWrite(SbgSplitBuffer *pSplitBuffer, void *pBuffer, size_t bufferSize, size_t subBufferSize)
#define SBG_INLINE
Definition: sbgDefines.h:186
Main header file for SBG Systems common C library.
SBG_INLINE void sbgSplitBufferInitForRead(SbgSplitBuffer *pSplitBuffer, const void *pBuffer, size_t bufferSize, size_t subBufferSize)


sbg_driver
Author(s): SBG Systems
autogenerated on Sat Sep 3 2022 02:53:36