Merge branch 'next' into for-linus
[linux-2.6] / drivers / staging / epl / SharedBuff.h
1 /****************************************************************************
2
3   (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4       www.systec-electronic.com
5
6   Project:      Project independend shared buffer (linear + circular)
7
8   Description:  Declaration of platform independend part for the
9                 shared buffer
10
11   License:
12
13     Redistribution and use in source and binary forms, with or without
14     modification, are permitted provided that the following conditions
15     are met:
16
17     1. Redistributions of source code must retain the above copyright
18        notice, this list of conditions and the following disclaimer.
19
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.
23
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.
28
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.
41
42     Severability Clause:
43
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.
50
51   -------------------------------------------------------------------------
52
53   2006/06/27 -rs:   V 1.00 (initial version)
54
55 ****************************************************************************/
56
57 #ifndef _SHAREDBUFF_H_
58 #define _SHAREDBUFF_H_
59
60 //---------------------------------------------------------------------------
61 //  Type definitions
62 //---------------------------------------------------------------------------
63
64 typedef enum {
65         kShbOk = 0,
66         kShbNoReadableData = 1,
67         kShbDataTruncated = 2,
68         kShbBufferFull = 3,
69         kShbDataOutsideBufferArea = 4,
70         kShbBufferAlreadyCompleted = 5,
71         kShbMemUsedByOtherProcs = 6,
72         kShbOpenMismatch = 7,
73         kShbInvalidBufferType = 8,
74         kShbInvalidArg = 9,
75         kShbBufferInvalid = 10,
76         kShbOutOfMem = 11,
77         kShbAlreadyReseting = 12,
78         kShbAlreadySignaling = 13,
79         kShbExceedDataSizeLimit = 14,
80
81 } tShbError;
82
83 // 2006/08/24 d.k.: Priority for threads (new data, job signaling)
84 typedef enum {
85         kShbPriorityLow = 0,
86         kShbPriorityNormal = 1,
87         kshbPriorityHigh = 2
88 } tShbPriority;
89
90 typedef struct {
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
95
96 } tShbCirChunk;
97
98 typedef void *tShbInstance;
99
100 typedef void (*tShbCirSigHndlrNewData) (tShbInstance pShbInstance_p,
101                                         unsigned long ulDataBlockSize_p);
102 typedef void (*tShbCirSigHndlrReset) (tShbInstance pShbInstance_p,
103                                       unsigned int fTimeOut_p);
104
105 //---------------------------------------------------------------------------
106 //  Prototypes
107 //---------------------------------------------------------------------------
108
109 #ifdef __cplusplus
110 extern "C" {
111 #endif
112
113         tShbError ShbInit(void);
114         tShbError ShbExit(void);
115
116 // Circular Shared Buffer
117         tShbError ShbCirAllocBuffer(unsigned long ulBufferSize_p,
118                                     const char *pszBufferID_p,
119                                     tShbInstance * ppShbInstance_p,
120                                     unsigned int *pfShbNewCreated_p);
121         tShbError ShbCirReleaseBuffer(tShbInstance pShbInstance_p);
122
123
124         tShbError ShbCirResetBuffer(tShbInstance pShbInstance_p,
125                                     unsigned long ulTimeOut_p,
126                                     tShbCirSigHndlrReset
127                                     pfnSignalHandlerReset_p);
128         tShbError ShbCirWriteDataBlock(tShbInstance pShbInstance_p,
129                                        const void *pSrcDataBlock_p,
130                                        unsigned long ulDataBlockSize_p);
131         tShbError ShbCirAllocDataBlock(tShbInstance pShbInstance_p,
132                                        tShbCirChunk * pShbCirChunk_p,
133                                        unsigned long ulDataBufferSize_p);
134         tShbError ShbCirWriteDataChunk(tShbInstance pShbInstance_p,
135                                        tShbCirChunk * pShbCirChunk_p,
136                                        const void *pSrcDataChunk_p,
137                                        unsigned long ulDataChunkSize_p,
138                                        unsigned int *pfBufferCompleted_p);
139         tShbError ShbCirReadDataBlock(tShbInstance pShbInstance_p,
140                                       void *pDstDataBlock_p,
141                                       unsigned long ulRdBuffSize_p,
142                                       unsigned long *pulDataBlockSize_p);
143         tShbError ShbCirGetReadDataSize(tShbInstance pShbInstance_p,
144                                         unsigned long *pulDataBlockSize_p);
145         tShbError ShbCirGetReadBlockCount(tShbInstance pShbInstance_p,
146                                           unsigned long *pulDataBlockCount_p);
147         tShbError ShbCirSetSignalHandlerNewData(tShbInstance pShbInstance_p,
148                                                 tShbCirSigHndlrNewData
149                                                 pfnShbSignalHandlerNewData_p,
150                                                 tShbPriority ShbPriority_p);
151
152
153 // Linear Shared Buffer
154         tShbError ShbLinAllocBuffer(unsigned long ulBufferSize_p,
155                                     const char *pszBufferID_p,
156                                     tShbInstance * ppShbInstance_p,
157                                     unsigned int *pfShbNewCreated_p);
158         tShbError ShbLinReleaseBuffer(tShbInstance pShbInstance_p);
159
160
161         tShbError ShbLinWriteDataBlock(tShbInstance pShbInstance_p,
162                                        unsigned long ulDstBufferOffs_p,
163                                        const void *pSrcDataBlock_p,
164                                        unsigned long ulDataBlockSize_p);
165         tShbError ShbLinReadDataBlock(tShbInstance pShbInstance_p,
166                                       void *pDstDataBlock_p,
167                                       unsigned long ulSrcBufferOffs_p,
168                                       unsigned long ulDataBlockSize_p);
169
170
171 #ifndef NDEBUG
172         tShbError ShbCirTraceBuffer(tShbInstance pShbInstance_p);
173         tShbError ShbLinTraceBuffer(tShbInstance pShbInstance_p);
174         tShbError ShbTraceDump(const unsigned char *pabStartAddr_p,
175                                unsigned long ulDataSize_p,
176                                unsigned long ulAddrOffset_p,
177                                const char *pszInfoText_p);
178 #else
179 #define ShbCirTraceBuffer(p0)
180 #define ShbLinTraceBuffer(p0)
181 #define ShbTraceDump(p0, p1, p2, p3)
182 #endif
183
184 #ifdef __cplusplus
185 }
186 #endif
187 #endif                          // #ifndef _SHAREDBUFF_H_