1 /****************************************************************************
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
6 Project: Project independend shared buffer (linear + circular)
8 Description: Declaration of platform independend part for the
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
24 3. Neither the name of SYSTEC electronic GmbH nor the names of its
25 contributors may be used to endorse or promote products derived
26 from this software without prior written permission. For written
27 permission, please contact info@systec-electronic.com.
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
33 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
35 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
39 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 POSSIBILITY OF SUCH DAMAGE.
44 If a provision of this License is or becomes illegal, invalid or
45 unenforceable in any jurisdiction, that shall not affect:
46 1. the validity or enforceability in that jurisdiction of any other
47 provision of this License; or
48 2. the validity or enforceability in other jurisdictions of that or
49 any other provision of this License.
51 -------------------------------------------------------------------------
53 2006/06/27 -rs: V 1.00 (initial version)
55 ****************************************************************************/
57 #ifndef _SHAREDBUFF_H_
58 #define _SHAREDBUFF_H_
60 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
66 kShbNoReadableData
= 1,
67 kShbDataTruncated
= 2,
69 kShbDataOutsideBufferArea
= 4,
70 kShbBufferAlreadyCompleted
= 5,
71 kShbMemUsedByOtherProcs
= 6,
73 kShbInvalidBufferType
= 8,
75 kShbBufferInvalid
= 10,
77 kShbAlreadyReseting
= 12,
78 kShbAlreadySignaling
= 13,
79 kShbExceedDataSizeLimit
= 14,
83 // 2006/08/24 d.k.: Priority for threads (new data, job signaling)
86 kShbPriorityNormal
= 1,
91 unsigned int m_uiFullBlockSize
; // real size of allocated block (incl. alignment fill bytes)
92 unsigned long m_ulAvailableSize
; // still available size for data
93 unsigned long m_ulWrIndex
; // current write index
94 unsigned int m_fBufferCompleted
; // TRUE if allocated block is complete filled with data
98 typedef void *tShbInstance
;
100 typedef void (*tShbCirSigHndlrNewData
) (tShbInstance pShbInstance_p
,
101 unsigned long ulDataBlockSize_p
);
102 typedef void (*tShbCirSigHndlrReset
) (tShbInstance pShbInstance_p
,
103 unsigned int fTimeOut_p
);
105 //---------------------------------------------------------------------------
107 //---------------------------------------------------------------------------
113 /*#if defined(INLINE_FUNCTION_DEF)
114 #undef INLINE_FUNCTION
115 #define INLINE_FUNCTION INLINE_FUNCTION_DEF
116 #define INLINE_ENABLED TRUE
117 #define SHAREDBUFF_INLINED
118 #include "SharedBuff.c"
122 tShbError
ShbInit(void);
123 tShbError
ShbExit(void);
125 // Circular Shared Buffer
126 tShbError
ShbCirAllocBuffer(unsigned long ulBufferSize_p
,
127 const char *pszBufferID_p
,
128 tShbInstance
* ppShbInstance_p
,
129 unsigned int *pfShbNewCreated_p
);
130 tShbError
ShbCirReleaseBuffer(tShbInstance pShbInstance_p
);
132 #if !defined(INLINE_ENABLED)
134 tShbError
ShbCirResetBuffer(tShbInstance pShbInstance_p
,
135 unsigned long ulTimeOut_p
,
137 pfnSignalHandlerReset_p
);
138 tShbError
ShbCirWriteDataBlock(tShbInstance pShbInstance_p
,
139 const void *pSrcDataBlock_p
,
140 unsigned long ulDataBlockSize_p
);
141 tShbError
ShbCirAllocDataBlock(tShbInstance pShbInstance_p
,
142 tShbCirChunk
* pShbCirChunk_p
,
143 unsigned long ulDataBufferSize_p
);
144 tShbError
ShbCirWriteDataChunk(tShbInstance pShbInstance_p
,
145 tShbCirChunk
* pShbCirChunk_p
,
146 const void *pSrcDataChunk_p
,
147 unsigned long ulDataChunkSize_p
,
148 unsigned int *pfBufferCompleted_p
);
149 tShbError
ShbCirReadDataBlock(tShbInstance pShbInstance_p
,
150 void *pDstDataBlock_p
,
151 unsigned long ulRdBuffSize_p
,
152 unsigned long *pulDataBlockSize_p
);
153 tShbError
ShbCirGetReadDataSize(tShbInstance pShbInstance_p
,
154 unsigned long *pulDataBlockSize_p
);
155 tShbError
ShbCirGetReadBlockCount(tShbInstance pShbInstance_p
,
156 unsigned long *pulDataBlockCount_p
);
157 tShbError
ShbCirSetSignalHandlerNewData(tShbInstance pShbInstance_p
,
158 tShbCirSigHndlrNewData
159 pfnShbSignalHandlerNewData_p
,
160 tShbPriority ShbPriority_p
);
164 // Linear Shared Buffer
165 tShbError
ShbLinAllocBuffer(unsigned long ulBufferSize_p
,
166 const char *pszBufferID_p
,
167 tShbInstance
* ppShbInstance_p
,
168 unsigned int *pfShbNewCreated_p
);
169 tShbError
ShbLinReleaseBuffer(tShbInstance pShbInstance_p
);
171 #if !defined(INLINE_ENABLED)
173 tShbError
ShbLinWriteDataBlock(tShbInstance pShbInstance_p
,
174 unsigned long ulDstBufferOffs_p
,
175 const void *pSrcDataBlock_p
,
176 unsigned long ulDataBlockSize_p
);
177 tShbError
ShbLinReadDataBlock(tShbInstance pShbInstance_p
,
178 void *pDstDataBlock_p
,
179 unsigned long ulSrcBufferOffs_p
,
180 unsigned long ulDataBlockSize_p
);
185 tShbError
ShbCirTraceBuffer(tShbInstance pShbInstance_p
);
186 tShbError
ShbLinTraceBuffer(tShbInstance pShbInstance_p
);
187 tShbError
ShbTraceDump(const unsigned char *pabStartAddr_p
,
188 unsigned long ulDataSize_p
,
189 unsigned long ulAddrOffset_p
,
190 const char *pszInfoText_p
);
192 #define ShbCirTraceBuffer(p0)
193 #define ShbLinTraceBuffer(p0)
194 #define ShbTraceDump(p0, p1, p2, p3)
197 #undef INLINE_ENABLED // disable actual inlining of functions
198 #undef INLINE_FUNCTION
199 #define INLINE_FUNCTION // define INLINE_FUNCTION to nothing
204 #endif // #ifndef _SHAREDBUFF_H_