]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/epl/EplApiProcessImage.c
b433369d7373809ab8bc637a26085156dce540c4
[linux-2.6-omap-h63xx.git] / drivers / staging / epl / EplApiProcessImage.c
1 /****************************************************************************
2
3   (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4       www.systec-electronic.com
5
6   Project:      openPOWERLINK
7
8   Description:  source file for EPL API module (process image)
9
10   License:
11
12     Redistribution and use in source and binary forms, with or without
13     modification, are permitted provided that the following conditions
14     are met:
15
16     1. Redistributions of source code must retain the above copyright
17        notice, this list of conditions and the following disclaimer.
18
19     2. Redistributions in binary form must reproduce the above copyright
20        notice, this list of conditions and the following disclaimer in the
21        documentation and/or other materials provided with the distribution.
22
23     3. Neither the name of SYSTEC electronic GmbH nor the names of its
24        contributors may be used to endorse or promote products derived
25        from this software without prior written permission. For written
26        permission, please contact info@systec-electronic.com.
27
28     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32     COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39     POSSIBILITY OF SUCH DAMAGE.
40
41     Severability Clause:
42
43         If a provision of this License is or becomes illegal, invalid or
44         unenforceable in any jurisdiction, that shall not affect:
45         1. the validity or enforceability in that jurisdiction of any other
46            provision of this License; or
47         2. the validity or enforceability in other jurisdictions of that or
48            any other provision of this License.
49
50   -------------------------------------------------------------------------
51
52                 $RCSfile: EplApiProcessImage.c,v $
53
54                 $Author: D.Krueger $
55
56                 $Revision: 1.7 $  $Date: 2008/11/13 17:13:09 $
57
58                 $State: Exp $
59
60                 Build Environment:
61                     GCC V3.4
62
63   -------------------------------------------------------------------------
64
65   Revision History:
66
67   2006/10/10 d.k.:   start of the implementation, version 1.00
68
69 ****************************************************************************/
70
71 #include "Epl.h"
72 //#include "kernel/EplPdokCal.h"
73
74 #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
75 #include <asm/uaccess.h>
76 #endif
77
78
79 /***************************************************************************/
80 /*                                                                         */
81 /*                                                                         */
82 /*          G L O B A L   D E F I N I T I O N S                            */
83 /*                                                                         */
84 /*                                                                         */
85 /***************************************************************************/
86
87 //---------------------------------------------------------------------------
88 // const defines
89 //---------------------------------------------------------------------------
90
91 //---------------------------------------------------------------------------
92 // local types
93 //---------------------------------------------------------------------------
94
95 //---------------------------------------------------------------------------
96 // modul globale vars
97 //---------------------------------------------------------------------------
98
99 //---------------------------------------------------------------------------
100 // local function prototypes
101 //---------------------------------------------------------------------------
102
103
104 /***************************************************************************/
105 /*                                                                         */
106 /*                                                                         */
107 /*          C L A S S  EplApi                                              */
108 /*                                                                         */
109 /*                                                                         */
110 /***************************************************************************/
111 //
112 // Description:
113 //
114 //
115 /***************************************************************************/
116
117
118 //=========================================================================//
119 //                                                                         //
120 //          P R I V A T E   D E F I N I T I O N S                          //
121 //                                                                         //
122 //=========================================================================//
123
124 //---------------------------------------------------------------------------
125 // const defines
126 //---------------------------------------------------------------------------
127
128 //---------------------------------------------------------------------------
129 // local types
130 //---------------------------------------------------------------------------
131
132 #if ((EPL_API_PROCESS_IMAGE_SIZE_IN > 0) || (EPL_API_PROCESS_IMAGE_SIZE_OUT > 0))
133     typedef struct
134     {
135         #if EPL_API_PROCESS_IMAGE_SIZE_IN > 0
136             BYTE        m_abProcessImageInput[EPL_API_PROCESS_IMAGE_SIZE_IN];
137         #endif
138         #if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0
139             BYTE        m_abProcessImageOutput[EPL_API_PROCESS_IMAGE_SIZE_OUT];
140         #endif
141
142     } tEplApiProcessImageInstance;
143
144 //---------------------------------------------------------------------------
145 // local vars
146 //---------------------------------------------------------------------------
147
148 static tEplApiProcessImageInstance  EplApiProcessImageInstance_g;
149 #endif
150
151 //---------------------------------------------------------------------------
152 // local function prototypes
153 //---------------------------------------------------------------------------
154
155
156 //=========================================================================//
157 //                                                                         //
158 //          P U B L I C   F U N C T I O N S                                //
159 //                                                                         //
160 //=========================================================================//
161
162
163 //---------------------------------------------------------------------------
164 //
165 // Function:    EplApiProcessImageSetup()
166 //
167 // Description: sets up static process image
168 //
169 // Parameters:  (none)
170 //
171 // Returns:     tEplKernel              = error code
172 //
173 //
174 // State:
175 //
176 //---------------------------------------------------------------------------
177
178 tEplKernel PUBLIC EplApiProcessImageSetup(void)
179 {
180 tEplKernel      Ret = kEplSuccessful;
181 #if ((EPL_API_PROCESS_IMAGE_SIZE_IN > 0) || (EPL_API_PROCESS_IMAGE_SIZE_OUT > 0))
182 unsigned int    uiVarEntries;
183 tEplObdSize     ObdSize;
184 #endif
185
186 #if EPL_API_PROCESS_IMAGE_SIZE_IN > 0
187     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN;
188     ObdSize = 1;
189     Ret = EplApiLinkObject(
190                             0x2000,
191                             EplApiProcessImageInstance_g.m_abProcessImageInput,
192                             &uiVarEntries,
193                             &ObdSize,
194                             1);
195
196     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN;
197     ObdSize = 1;
198     Ret = EplApiLinkObject(
199                             0x2001,
200                             EplApiProcessImageInstance_g.m_abProcessImageInput,
201                             &uiVarEntries,
202                             &ObdSize,
203                             1);
204
205     ObdSize = 2;
206     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
207     Ret = EplApiLinkObject(
208                             0x2010,
209                             EplApiProcessImageInstance_g.m_abProcessImageInput,
210                             &uiVarEntries,
211                             &ObdSize,
212                             1);
213
214     ObdSize = 2;
215     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
216     Ret = EplApiLinkObject(
217                             0x2011,
218                             EplApiProcessImageInstance_g.m_abProcessImageInput,
219                             &uiVarEntries,
220                             &ObdSize,
221                             1);
222
223     ObdSize = 4;
224     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
225     Ret = EplApiLinkObject(
226                             0x2020,
227                             EplApiProcessImageInstance_g.m_abProcessImageInput,
228                             &uiVarEntries,
229                             &ObdSize,
230                             1);
231
232     ObdSize = 4;
233     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
234     Ret = EplApiLinkObject(
235                             0x2021,
236                             EplApiProcessImageInstance_g.m_abProcessImageInput,
237                             &uiVarEntries,
238                             &ObdSize,
239                             1);
240 #endif
241
242 #if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0
243     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT;
244     ObdSize = 1;
245     Ret = EplApiLinkObject(
246                             0x2030,
247                             EplApiProcessImageInstance_g.m_abProcessImageOutput,
248                             &uiVarEntries,
249                             &ObdSize,
250                             1);
251
252     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT;
253     ObdSize = 1;
254     Ret = EplApiLinkObject(
255                             0x2031,
256                             EplApiProcessImageInstance_g.m_abProcessImageOutput,
257                             &uiVarEntries,
258                             &ObdSize,
259                             1);
260
261     ObdSize = 2;
262     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
263     Ret = EplApiLinkObject(
264                             0x2040,
265                             EplApiProcessImageInstance_g.m_abProcessImageOutput,
266                             &uiVarEntries,
267                             &ObdSize,
268                             1);
269
270     ObdSize = 2;
271     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
272     Ret = EplApiLinkObject(
273                             0x2041,
274                             EplApiProcessImageInstance_g.m_abProcessImageOutput,
275                             &uiVarEntries,
276                             &ObdSize,
277                             1);
278
279     ObdSize = 4;
280     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
281     Ret = EplApiLinkObject(
282                             0x2050,
283                             EplApiProcessImageInstance_g.m_abProcessImageOutput,
284                             &uiVarEntries,
285                             &ObdSize,
286                             1);
287
288     ObdSize = 4;
289     uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
290     Ret = EplApiLinkObject(
291                             0x2051,
292                             EplApiProcessImageInstance_g.m_abProcessImageOutput,
293                             &uiVarEntries,
294                             &ObdSize,
295                             1);
296 #endif
297
298     return Ret;
299 }
300
301 //----------------------------------------------------------------------------
302 // Function:    EplApiProcessImageExchangeIn()
303 //
304 // Description: replaces passed input process image with the one of EPL stack
305 //
306 // Parameters:  pPI_p                   = input process image
307 //
308 // Returns:     tEplKernel              = error code
309 //
310 // State:
311 //----------------------------------------------------------------------------
312
313 tEplKernel PUBLIC EplApiProcessImageExchangeIn(tEplApiProcessImage* pPI_p)
314 {
315 tEplKernel      Ret = kEplSuccessful;
316
317 #if EPL_API_PROCESS_IMAGE_SIZE_IN > 0
318     #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
319         copy_to_user(pPI_p->m_pImage,
320             EplApiProcessImageInstance_g.m_abProcessImageInput,
321             min(pPI_p->m_uiSize, sizeof (EplApiProcessImageInstance_g.m_abProcessImageInput)));
322     #else
323         EPL_MEMCPY(pPI_p->m_pImage,
324             EplApiProcessImageInstance_g.m_abProcessImageInput,
325             min(pPI_p->m_uiSize, sizeof (EplApiProcessImageInstance_g.m_abProcessImageInput)));
326     #endif
327 #endif
328
329     return Ret;
330 }
331
332
333 //----------------------------------------------------------------------------
334 // Function:    EplApiProcessImageExchangeOut()
335 //
336 // Description: copies passed output process image to EPL stack.
337 //
338 // Parameters:  pPI_p                   = output process image
339 //
340 // Returns:     tEplKernel              = error code
341 //
342 // State:
343 //----------------------------------------------------------------------------
344
345 tEplKernel PUBLIC EplApiProcessImageExchangeOut(tEplApiProcessImage* pPI_p)
346 {
347 tEplKernel      Ret = kEplSuccessful;
348
349 #if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0
350     #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
351         copy_from_user(EplApiProcessImageInstance_g.m_abProcessImageOutput,
352             pPI_p->m_pImage,
353             min(pPI_p->m_uiSize, sizeof (EplApiProcessImageInstance_g.m_abProcessImageOutput)));
354     #else
355         EPL_MEMCPY(EplApiProcessImageInstance_g.m_abProcessImageOutput,
356             pPI_p->m_pImage,
357             min(pPI_p->m_uiSize, sizeof (EplApiProcessImageInstance_g.m_abProcessImageOutput)));
358     #endif
359 #endif
360
361     return Ret;
362 }
363
364
365 //=========================================================================//
366 //                                                                         //
367 //          P R I V A T E   F U N C T I O N S                              //
368 //                                                                         //
369 //=========================================================================//
370
371
372
373 // EOF
374