]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/epl/EplStatusu.c
Staging: epl: run Lindent on *.h files
[linux-2.6-omap-h63xx.git] / drivers / staging / epl / EplStatusu.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 Statusu-Module
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: EplStatusu.c,v $
53
54                 $Author: D.Krueger $
55
56                 $Revision: 1.5 $  $Date: 2008/10/17 15:32:32 $
57
58                 $State: Exp $
59
60                 Build Environment:
61                     GCC V3.4
62
63   -------------------------------------------------------------------------
64
65   Revision History:
66
67   2006/11/15 d.k.:   start of the implementation
68
69 ****************************************************************************/
70
71 #include "user/EplStatusu.h"
72 #include "user/EplDlluCal.h"
73
74 /***************************************************************************/
75 /*                                                                         */
76 /*                                                                         */
77 /*          G L O B A L   D E F I N I T I O N S                            */
78 /*                                                                         */
79 /*                                                                         */
80 /***************************************************************************/
81
82 //---------------------------------------------------------------------------
83 // const defines
84 //---------------------------------------------------------------------------
85
86 //---------------------------------------------------------------------------
87 // local types
88 //---------------------------------------------------------------------------
89
90 //---------------------------------------------------------------------------
91 // modul globale vars
92 //---------------------------------------------------------------------------
93
94 //---------------------------------------------------------------------------
95 // local function prototypes
96 //---------------------------------------------------------------------------
97
98
99 /***************************************************************************/
100 /*                                                                         */
101 /*                                                                         */
102 /*          C L A S S  <xxxxx>                                             */
103 /*                                                                         */
104 /*                                                                         */
105 /***************************************************************************/
106 //
107 // Description:
108 //
109 //
110 /***************************************************************************/
111
112
113 //=========================================================================//
114 //                                                                         //
115 //          P R I V A T E   D E F I N I T I O N S                          //
116 //                                                                         //
117 //=========================================================================//
118
119 //---------------------------------------------------------------------------
120 // const defines
121 //---------------------------------------------------------------------------
122
123 //---------------------------------------------------------------------------
124 // local types
125 //---------------------------------------------------------------------------
126
127 typedef struct
128 {
129     tEplStatusuCbResponse m_apfnCbResponse[254];
130
131 } tEplStatusuInstance;
132
133 //---------------------------------------------------------------------------
134 // local vars
135 //---------------------------------------------------------------------------
136
137 static tEplStatusuInstance   EplStatusuInstance_g;
138
139 //---------------------------------------------------------------------------
140 // local function prototypes
141 //---------------------------------------------------------------------------
142
143 static tEplKernel PUBLIC EplStatusuCbStatusResponse(tEplFrameInfo * pFrameInfo_p);
144
145 //=========================================================================//
146 //                                                                         //
147 //          P U B L I C   F U N C T I O N S                                //
148 //                                                                         //
149 //=========================================================================//
150
151 //---------------------------------------------------------------------------
152 //
153 // Function:    EplStatusuInit
154 //
155 // Description: init first instance of the module
156 //
157 //
158 //
159 // Parameters:
160 //
161 //
162 // Returns:     tEplKernel  = errorcode
163 //
164 //
165 // State:
166 //
167 //---------------------------------------------------------------------------
168
169 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuInit()
170 {
171 tEplKernel Ret;
172
173     Ret = EplStatusuAddInstance();
174
175     return Ret;
176 }
177
178
179 //---------------------------------------------------------------------------
180 //
181 // Function:    EplStatusuAddInstance
182 //
183 // Description: init other instances of the module
184 //
185 //
186 //
187 // Parameters:
188 //
189 //
190 // Returns:     tEplKernel  = errorcode
191 //
192 //
193 // State:
194 //
195 //---------------------------------------------------------------------------
196
197 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuAddInstance()
198 {
199 tEplKernel Ret;
200
201     Ret = kEplSuccessful;
202
203     // reset instance structure
204     EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof (EplStatusuInstance_g));
205
206     // register StatusResponse callback function
207     Ret = EplDlluCalRegAsndService(kEplDllAsndStatusResponse, EplStatusuCbStatusResponse, kEplDllAsndFilterAny);
208
209     return Ret;
210
211 }
212
213
214 //---------------------------------------------------------------------------
215 //
216 // Function:    EplStatusuDelInstance
217 //
218 // Description: delete instance
219 //
220 //
221 //
222 // Parameters:
223 //
224 //
225 // Returns:     tEplKernel  = errorcode
226 //
227 //
228 // State:
229 //
230 //---------------------------------------------------------------------------
231
232 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuDelInstance()
233 {
234 tEplKernel  Ret;
235
236     Ret = kEplSuccessful;
237
238     // deregister StatusResponse callback function
239     Ret = EplDlluCalRegAsndService(kEplDllAsndStatusResponse, NULL, kEplDllAsndFilterNone);
240
241     return Ret;
242
243 }
244
245
246 //---------------------------------------------------------------------------
247 //
248 // Function:    EplStatusuReset
249 //
250 // Description: resets this instance
251 //
252 // Parameters:
253 //
254 // Returns:     tEplKernel  = errorcode
255 //
256 //
257 // State:
258 //
259 //---------------------------------------------------------------------------
260
261 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuReset()
262 {
263 tEplKernel  Ret;
264
265     Ret = kEplSuccessful;
266
267     // reset instance structure
268     EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof (EplStatusuInstance_g));
269
270     return Ret;
271
272 }
273
274
275 //---------------------------------------------------------------------------
276 //
277 // Function:    EplStatusuRequestStatusResponse
278 //
279 // Description: returns the StatusResponse for the specified node.
280 //
281 // Parameters:  uiNodeId_p                  = IN: node ID
282 //              pfnCbResponse_p             = IN: function pointer to callback function
283 //                                            which will be called if StatusResponse is received
284 //
285 // Return:      tEplKernel                  = error code
286 //
287 // State:       not tested
288 //
289 //---------------------------------------------------------------------------
290
291 tEplKernel PUBLIC EplStatusuRequestStatusResponse(
292                                   unsigned int        uiNodeId_p,
293                                   tEplStatusuCbResponse pfnCbResponse_p)
294 {
295 tEplKernel  Ret;
296
297     Ret = kEplSuccessful;
298
299     // decrement node ID, because array is zero based
300     uiNodeId_p--;
301     if (uiNodeId_p < tabentries (EplStatusuInstance_g.m_apfnCbResponse))
302     {
303 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
304         if (EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] != NULL)
305         {   // request already issued (maybe by someone else)
306             Ret = kEplInvalidOperation;
307         }
308         else
309         {
310             EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] = pfnCbResponse_p;
311             Ret = EplDlluCalIssueRequest(kEplDllReqServiceStatus, (uiNodeId_p + 1), 0xFF);
312         }
313 #else
314         Ret = kEplInvalidOperation;
315 #endif
316     }
317     else
318     {   // invalid node ID specified
319         Ret = kEplInvalidNodeId;
320     }
321
322     return Ret;
323
324 }
325
326
327 //=========================================================================//
328 //                                                                         //
329 //          P R I V A T E   F U N C T I O N S                              //
330 //                                                                         //
331 //=========================================================================//
332
333 //---------------------------------------------------------------------------
334 //
335 // Function:    EplStatusuCbStatusResponse
336 //
337 // Description: callback funktion for StatusResponse
338 //
339 //
340 //
341 // Parameters:  pFrameInfo_p            = Frame with the StatusResponse
342 //
343 //
344 // Returns:     tEplKernel              = error code
345 //
346 //
347 // State:
348 //
349 //---------------------------------------------------------------------------
350 static tEplKernel PUBLIC EplStatusuCbStatusResponse(tEplFrameInfo * pFrameInfo_p)
351 {
352 tEplKernel      Ret = kEplSuccessful;
353 unsigned int    uiNodeId;
354 unsigned int    uiIndex;
355 tEplStatusuCbResponse    pfnCbResponse;
356
357     uiNodeId = AmiGetByteFromLe(&pFrameInfo_p->m_pFrame->m_le_bSrcNodeId);
358
359     uiIndex = uiNodeId - 1;
360
361     if (uiIndex < tabentries (EplStatusuInstance_g.m_apfnCbResponse))
362     {
363         // memorize pointer to callback function
364         pfnCbResponse = EplStatusuInstance_g.m_apfnCbResponse[uiIndex];
365         if (pfnCbResponse == NULL)
366         {   // response was not requested
367             goto Exit;
368         }
369         // reset callback function pointer so that caller may issue next request
370         EplStatusuInstance_g.m_apfnCbResponse[uiIndex] = NULL;
371
372         if (pFrameInfo_p->m_uiFrameSize < EPL_C_DLL_MINSIZE_STATUSRES)
373         {   // StatusResponse not received or it has invalid size
374             Ret = pfnCbResponse(uiNodeId, NULL);
375         }
376         else
377         {   // StatusResponse received
378             Ret = pfnCbResponse(uiNodeId, &pFrameInfo_p->m_pFrame->m_Data.m_Asnd.m_Payload.m_StatusResponse);
379         }
380     }
381
382 Exit:
383     return Ret;
384 }
385
386 // EOF
387