blob: ae19e34cd7b35e016326ba2eaec1e338655f21d4 [file] [log] [blame]
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001/****************************************************************************
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 generic EPL API 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: EplApiGeneric.c,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.21 $ $Date: 2008/11/21 09:00:38 $
57
58 $State: Exp $
59
60 Build Environment:
61 GCC V3.4
62
63 -------------------------------------------------------------------------
64
65 Revision History:
66
67 2006/09/05 d.k.: start of the implementation, version 1.00
68
69****************************************************************************/
70
71#include "Epl.h"
72#include "kernel/EplDllk.h"
73#include "kernel/EplErrorHandlerk.h"
74#include "kernel/EplEventk.h"
75#include "kernel/EplNmtk.h"
76#include "kernel/EplObdk.h"
77#include "kernel/EplTimerk.h"
78#include "kernel/EplDllkCal.h"
79#include "kernel/EplPdokCal.h"
80#include "user/EplDlluCal.h"
81#include "user/EplLedu.h"
82#include "user/EplNmtCnu.h"
83#include "user/EplNmtMnu.h"
84#include "user/EplSdoComu.h"
85#include "user/EplIdentu.h"
86#include "user/EplStatusu.h"
87
88#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
89#include "kernel/EplPdok.h"
90#endif
91
92#include "SharedBuff.h"
93
Daniel Krueger9d7164c2008-12-19 11:41:57 -080094#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) == 0)
95#error "EPL API layer needs EPL module OBDK!"
96#endif
97
Daniel Krueger9d7164c2008-12-19 11:41:57 -080098/***************************************************************************/
99/* */
100/* */
101/* G L O B A L D E F I N I T I O N S */
102/* */
103/* */
104/***************************************************************************/
105
106//---------------------------------------------------------------------------
107// const defines
108//---------------------------------------------------------------------------
109
110//---------------------------------------------------------------------------
111// local types
112//---------------------------------------------------------------------------
113
114//---------------------------------------------------------------------------
115// modul globale vars
116//---------------------------------------------------------------------------
117
118//---------------------------------------------------------------------------
119// local function prototypes
120//---------------------------------------------------------------------------
121
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800122/***************************************************************************/
123/* */
124/* */
125/* C L A S S EplApi */
126/* */
127/* */
128/***************************************************************************/
129//
130// Description:
131//
132//
133/***************************************************************************/
134
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800135//=========================================================================//
136// //
137// P R I V A T E D E F I N I T I O N S //
138// //
139//=========================================================================//
140
141//---------------------------------------------------------------------------
142// const defines
143//---------------------------------------------------------------------------
144
145//---------------------------------------------------------------------------
146// local types
147//---------------------------------------------------------------------------
148
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800149typedef struct {
150 tEplApiInitParam m_InitParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800151
152} tEplApiInstance;
153
154//---------------------------------------------------------------------------
155// local vars
156//---------------------------------------------------------------------------
157
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800158static tEplApiInstance EplApiInstance_g;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800159
160//---------------------------------------------------------------------------
161// local function prototypes
162//---------------------------------------------------------------------------
163
164// NMT state change event callback function
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800165static tEplKernel PUBLIC EplApiCbNmtStateChange(tEplEventNmtStateChange
166 NmtStateChange_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800167
168// update DLL configuration from OD
169static tEplKernel PUBLIC EplApiUpdateDllConfig(BOOL fUpdateIdentity_p);
170
171// update OD from init param
172static tEplKernel PUBLIC EplApiUpdateObd(void);
173
174// process events from user event queue
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800175static tEplKernel PUBLIC EplApiProcessEvent(tEplEvent * pEplEvent_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800176
177#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
178// callback function of SDO module
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800179static tEplKernel PUBLIC EplApiCbSdoCon(tEplSdoComFinished * pSdoComFinished_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800180#endif
181
182#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
183// callback functions of NmtMnu module
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800184static tEplKernel PUBLIC EplApiCbNodeEvent(unsigned int uiNodeId_p,
185 tEplNmtNodeEvent NodeEvent_p,
186 tEplNmtState NmtState_p,
187 WORD wErrorCode_p,
188 BOOL fMandatory_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800189
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800190static tEplKernel PUBLIC EplApiCbBootEvent(tEplNmtBootEvent BootEvent_p,
191 tEplNmtState NmtState_p,
192 WORD wErrorCode_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800193#endif
194
195#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
196// callback function of Ledu module
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800197static tEplKernel PUBLIC EplApiCbLedStateChange(tEplLedType LedType_p,
198 BOOL fOn_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800199#endif
200
201// OD initialization function (implemented in Objdict.c)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800202tEplKernel PUBLIC EplObdInitRam(tEplObdInitParam MEM * pInitParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800203
204//=========================================================================//
205// //
206// P U B L I C F U N C T I O N S //
207// //
208//=========================================================================//
209
210//---------------------------------------------------------------------------
211//
212// Function: EplApiInitialize()
213//
214// Description: add and initialize new instance of EPL stack.
215// After return from this function the application must start
216// the NMT state machine via
217// EplApiExecNmtCommand(kEplNmtEventSwReset)
218// and thereby the whole EPL stack :-)
219//
220// Parameters: pInitParam_p = initialisation parameters
221//
222// Returns: tEplKernel = error code
223//
224//
225// State:
226//
227//---------------------------------------------------------------------------
228
229tEplKernel PUBLIC EplApiInitialize(tEplApiInitParam * pInitParam_p)
230{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800231 tEplKernel Ret = kEplSuccessful;
232 tEplObdInitParam ObdInitParam;
233 tEplDllkInitParam DllkInitParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800234#ifndef EPL_NO_FIFO
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800235 tShbError ShbError;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800236#endif
237
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800238 // reset instance structure
239 EPL_MEMSET(&EplApiInstance_g, 0, sizeof(EplApiInstance_g));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800240
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800241 EPL_MEMCPY(&EplApiInstance_g.m_InitParam, pInitParam_p,
242 min(sizeof(tEplApiInitParam),
243 pInitParam_p->m_uiSizeOfStruct));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800244
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800245 // check event callback function pointer
246 if (EplApiInstance_g.m_InitParam.m_pfnCbEvent == NULL) { // application must always have an event callback function
247 Ret = kEplApiInvalidParam;
248 goto Exit;
249 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800250#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800251 // init OD
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800252// FIXME
253// Ret = EplObdInitRam(&ObdInitParam);
254// if (Ret != kEplSuccessful)
255// {
256// goto Exit;
257// }
258
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800259 // initialize EplObd module
260 Ret = EplObdInit(&ObdInitParam);
261 if (Ret != kEplSuccessful) {
262 goto Exit;
263 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800264#endif
265
266#ifndef EPL_NO_FIFO
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800267 ShbError = ShbInit();
268 if (ShbError != kShbOk) {
269 Ret = kEplNoResource;
270 goto Exit;
271 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800272#endif
273
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800274 // initialize EplEventk module
275 Ret = EplEventkInit(EplApiInstance_g.m_InitParam.m_pfnCbSync);
276 if (Ret != kEplSuccessful) {
277 goto Exit;
278 }
279 // initialize EplEventu module
280 Ret = EplEventuInit(EplApiProcessEvent);
281 if (Ret != kEplSuccessful) {
282 goto Exit;
283 }
284 // init EplTimerk module
285 Ret = EplTimerkInit();
286 if (Ret != kEplSuccessful) {
287 goto Exit;
288 }
289 // initialize EplNmtk module before DLL
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800290#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800291 Ret = EplNmtkInit();
292 if (Ret != kEplSuccessful) {
293 goto Exit;
294 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800295#endif
296
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800297 // initialize EplDllk module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800298#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800299 EPL_MEMCPY(DllkInitParam.m_be_abSrcMac,
300 EplApiInstance_g.m_InitParam.m_abMacAddress, 6);
301 Ret = EplDllkAddInstance(&DllkInitParam);
302 if (Ret != kEplSuccessful) {
303 goto Exit;
304 }
305 // initialize EplErrorHandlerk module
306 Ret = EplErrorHandlerkInit();
307 if (Ret != kEplSuccessful) {
308 goto Exit;
309 }
310 // initialize EplDllkCal module
311 Ret = EplDllkCalAddInstance();
312 if (Ret != kEplSuccessful) {
313 goto Exit;
314 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800315#endif
316
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800317 // initialize EplDlluCal module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800318#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800319 Ret = EplDlluCalAddInstance();
320 if (Ret != kEplSuccessful) {
321 goto Exit;
322 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800323#endif
324
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800325 // initialize EplPdok module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800326#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800327 Ret = EplPdokAddInstance();
328 if (Ret != kEplSuccessful) {
329 goto Exit;
330 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800331
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800332 Ret = EplPdokCalAddInstance();
333 if (Ret != kEplSuccessful) {
334 goto Exit;
335 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800336#endif
337
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800338 // initialize EplNmtCnu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800339#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800340 Ret = EplNmtCnuAddInstance(EplApiInstance_g.m_InitParam.m_uiNodeId);
341 if (Ret != kEplSuccessful) {
342 goto Exit;
343 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800344#endif
345
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800346 // initialize EplNmtu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800347#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800348 Ret = EplNmtuInit();
349 if (Ret != kEplSuccessful) {
350 goto Exit;
351 }
352 // register NMT event callback function
353 Ret = EplNmtuRegisterStateChangeCb(EplApiCbNmtStateChange);
354 if (Ret != kEplSuccessful) {
355 goto Exit;
356 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800357#endif
358
359#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800360 // initialize EplNmtMnu module
361 Ret = EplNmtMnuInit(EplApiCbNodeEvent, EplApiCbBootEvent);
362 if (Ret != kEplSuccessful) {
363 goto Exit;
364 }
365 // initialize EplIdentu module
366 Ret = EplIdentuInit();
367 if (Ret != kEplSuccessful) {
368 goto Exit;
369 }
370 // initialize EplStatusu module
371 Ret = EplStatusuInit();
372 if (Ret != kEplSuccessful) {
373 goto Exit;
374 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800375#endif
376
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800377 // initialize EplLedu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800378#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800379 Ret = EplLeduInit(EplApiCbLedStateChange);
380 if (Ret != kEplSuccessful) {
381 goto Exit;
382 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800383#endif
384
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800385 // init SDO module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800386#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0) || \
387 (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0))
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800388 // init sdo command layer
389 Ret = EplSdoComInit();
390 if (Ret != kEplSuccessful) {
391 goto Exit;
392 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800393#endif
394
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800395 // the application must start NMT state machine
396 // via EplApiExecNmtCommand(kEplNmtEventSwReset)
397 // and thereby the whole EPL stack
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800398
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800399 Exit:
400 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800401}
402
403//---------------------------------------------------------------------------
404//
405// Function: EplApiShutdown()
406//
407// Description: deletes an instance of EPL stack
408//
409// Parameters: (none)
410//
411// Returns: tEplKernel = error code
412//
413//
414// State:
415//
416//---------------------------------------------------------------------------
417
418tEplKernel PUBLIC EplApiShutdown(void)
419{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800420 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800421
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800422 // $$$ d.k.: check if NMT state is NMT_GS_OFF
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800423
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800424 // $$$ d.k.: maybe delete event queues at first, but this implies that
425 // no other module must not use the event queues for communication
426 // during shutdown.
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800427
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800428 // delete instance for all modules
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800429
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800430 // deinitialize EplSdoCom module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800431#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0) || \
432 (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0))
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800433 Ret = EplSdoComDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800434// PRINTF1("EplSdoComDelInstance(): 0x%X\n", Ret);
435#endif
436
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800437 // deinitialize EplLedu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800438#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800439 Ret = EplLeduDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800440// PRINTF1("EplLeduDelInstance(): 0x%X\n", Ret);
441#endif
442
443#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800444 // deinitialize EplNmtMnu module
445 Ret = EplNmtMnuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800446// PRINTF1("EplNmtMnuDelInstance(): 0x%X\n", Ret);
447
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800448 // deinitialize EplIdentu module
449 Ret = EplIdentuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800450// PRINTF1("EplIdentuDelInstance(): 0x%X\n", Ret);
451
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800452 // deinitialize EplStatusu module
453 Ret = EplStatusuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800454// PRINTF1("EplStatusuDelInstance(): 0x%X\n", Ret);
455#endif
456
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800457 // deinitialize EplNmtCnu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800458#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800459 Ret = EplNmtCnuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800460// PRINTF1("EplNmtCnuDelInstance(): 0x%X\n", Ret);
461#endif
462
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800463 // deinitialize EplNmtu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800464#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800465 Ret = EplNmtuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800466// PRINTF1("EplNmtuDelInstance(): 0x%X\n", Ret);
467#endif
468
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800469 // deinitialize EplDlluCal module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800470#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800471 Ret = EplDlluCalDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800472// PRINTF1("EplDlluCalDelInstance(): 0x%X\n", Ret);
473
474#endif
475
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800476 // deinitialize EplEventu module
477 Ret = EplEventuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800478// PRINTF1("EplEventuDelInstance(): 0x%X\n", Ret);
479
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800480 // deinitialize EplNmtk module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800481#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800482 Ret = EplNmtkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800483// PRINTF1("EplNmtkDelInstance(): 0x%X\n", Ret);
484#endif
485
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800486 // deinitialize EplDllk module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800487#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800488 Ret = EplDllkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800489// PRINTF1("EplDllkDelInstance(): 0x%X\n", Ret);
490
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800491 // deinitialize EplDllkCal module
492 Ret = EplDllkCalDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800493// PRINTF1("EplDllkCalDelInstance(): 0x%X\n", Ret);
494#endif
495
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800496 // deinitialize EplEventk module
497 Ret = EplEventkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800498// PRINTF1("EplEventkDelInstance(): 0x%X\n", Ret);
499
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800500 // deinitialize EplTimerk module
501 Ret = EplTimerkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800502// PRINTF1("EplTimerkDelInstance(): 0x%X\n", Ret);
503
504#ifndef EPL_NO_FIFO
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800505 ShbExit();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800506#endif
507
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800508 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800509}
510
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800511//----------------------------------------------------------------------------
512// Function: EplApiExecNmtCommand()
513//
514// Description: executes a NMT command, i.e. post the NMT command/event to the
515// NMTk module. NMT commands which are not appropriate in the current
516// NMT state are silently ignored. Please keep in mind that the
517// NMT state may change until the NMT command is actually executed.
518//
519// Parameters: NmtEvent_p = NMT command/event
520//
521// Returns: tEplKernel = error code
522//
523// State:
524//----------------------------------------------------------------------------
525
526tEplKernel PUBLIC EplApiExecNmtCommand(tEplNmtEvent NmtEvent_p)
527{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800528 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800529
530#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800531 Ret = EplNmtuNmtEvent(NmtEvent_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800532#endif
533
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800534 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800535}
536
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800537//----------------------------------------------------------------------------
538// Function: EplApiLinkObject()
539//
540// Description: Function maps array of application variables onto specified object in OD
541//
542// Parameters: uiObjIndex_p = Function maps variables for this object index
543// pVar_p = Pointer to data memory area for the specified object
544// puiVarEntries_p = IN: pointer to number of entries to map
545// OUT: pointer to number of actually used entries
546// pEntrySize_p = IN: pointer to size of one entry;
547// if size is zero, the actual size will be read from OD
548// OUT: pointer to entire size of all entries mapped
549// uiFirstSubindex_p = This is the first subindex to be mapped.
550//
551// Returns: tEplKernel = error code
552//
553// State:
554//----------------------------------------------------------------------------
555
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800556tEplKernel PUBLIC EplApiLinkObject(unsigned int uiObjIndex_p,
557 void *pVar_p,
558 unsigned int *puiVarEntries_p,
559 tEplObdSize * pEntrySize_p,
560 unsigned int uiFirstSubindex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800561{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800562 BYTE bVarEntries;
563 BYTE bIndexEntries;
564 BYTE MEM *pbData;
565 unsigned int uiSubindex;
566 tEplVarParam VarParam;
567 tEplObdSize EntrySize;
568 tEplObdSize UsedSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800569
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800570 tEplKernel RetCode = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800571
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800572 if ((pVar_p == NULL)
573 || (puiVarEntries_p == NULL)
574 || (*puiVarEntries_p == 0)
575 || (pEntrySize_p == NULL)) {
576 RetCode = kEplApiInvalidParam;
577 goto Exit;
578 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800579
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800580 pbData = (BYTE MEM *) pVar_p;
581 bVarEntries = (BYTE) * puiVarEntries_p;
582 UsedSize = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800583
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800584 // init VarParam structure with default values
585 VarParam.m_uiIndex = uiObjIndex_p;
586 VarParam.m_ValidFlag = kVarValidAll;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800587
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800588 if (uiFirstSubindex_p != 0) { // check if object exists by reading subindex 0x00,
589 // because user wants to link a variable to a subindex unequal 0x00
590 // read number of entries
591 EntrySize = (tEplObdSize) sizeof(bIndexEntries);
592 RetCode = EplObdReadEntry(uiObjIndex_p,
593 0x00,
594 (void GENERIC *)&bIndexEntries,
595 &EntrySize);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800596
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800597 if ((RetCode != kEplSuccessful) || (bIndexEntries == 0x00)) {
598 // Object doesn't exist or invalid entry number
599 RetCode = kEplObdIndexNotExist;
600 goto Exit;
601 }
602 } else { // user wants to link a variable to subindex 0x00
603 // that's OK
604 bIndexEntries = 0;
605 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800606
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800607 // Correct number of entries if number read from OD is greater
608 // than the specified number.
609 // This is done, so that we do not set more entries than subindexes the
610 // object actually has.
611 if ((bIndexEntries > (bVarEntries + uiFirstSubindex_p - 1)) &&
612 (bVarEntries != 0x00)) {
613 bIndexEntries = (BYTE) (bVarEntries + uiFirstSubindex_p - 1);
614 }
615 // map entries
616 for (uiSubindex = uiFirstSubindex_p; uiSubindex <= bIndexEntries;
617 uiSubindex++) {
618 // if passed entry size is 0, then get size from OD
619 if (*pEntrySize_p == 0x00) {
620 // read entry size
621 EntrySize = EplObdGetDataSize(uiObjIndex_p, uiSubindex);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800622
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800623 if (EntrySize == 0x00) {
624 // invalid entry size (maybe object doesn't exist or entry of type DOMAIN is empty)
625 RetCode = kEplObdSubindexNotExist;
626 break;
627 }
628 } else { // use passed entry size
629 EntrySize = *pEntrySize_p;
630 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800631
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800632 VarParam.m_uiSubindex = uiSubindex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800633
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800634 // set pointer to user var
635 VarParam.m_Size = EntrySize;
636 VarParam.m_pData = pbData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800637
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800638 UsedSize += EntrySize;
639 pbData += EntrySize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800640
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800641 RetCode = EplObdDefineVar(&VarParam);
642 if (RetCode != kEplSuccessful) {
643 break;
644 }
645 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800646
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800647 // set number of mapped entries and entry size
648 *puiVarEntries_p = ((bIndexEntries - uiFirstSubindex_p) + 1);
649 *pEntrySize_p = UsedSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800650
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800651 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800652
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800653 return (RetCode);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800654
655}
656
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800657// ----------------------------------------------------------------------------
658//
659// Function: EplApiReadObject()
660//
661// Description: reads the specified entry from the OD of the specified node.
662// If this node is a remote node, it performs a SDO transfer, which
663// means this function returns kEplApiTaskDeferred and the application
664// is informed via the event callback function when the task is completed.
665//
666// Parameters: pSdoComConHdl_p = INOUT: pointer to SDO connection handle (may be NULL in case of local OD access)
667// uiNodeId_p = IN: node ID (0 = itself)
668// uiIndex_p = IN: index of object in OD
669// uiSubindex_p = IN: sub-index of object in OD
670// pDstData_le_p = OUT: pointer to data in little endian
671// puiSize_p = INOUT: pointer to size of data
672// SdoType_p = IN: type of SDO transfer
673// pUserArg_p = IN: user-definable argument pointer,
674// which will be passed to the event callback function
675//
676// Return: tEplKernel = error code
677//
678// ----------------------------------------------------------------------------
679
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800680tEplKernel PUBLIC EplApiReadObject(tEplSdoComConHdl * pSdoComConHdl_p,
681 unsigned int uiNodeId_p,
682 unsigned int uiIndex_p,
683 unsigned int uiSubindex_p,
684 void *pDstData_le_p,
685 unsigned int *puiSize_p,
686 tEplSdoType SdoType_p, void *pUserArg_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800687{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800688 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800689
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800690 if ((uiIndex_p == 0) || (pDstData_le_p == NULL) || (puiSize_p == NULL)
691 || (*puiSize_p == 0)) {
692 Ret = kEplApiInvalidParam;
693 goto Exit;
694 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800695
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800696 if (uiNodeId_p == 0 || uiNodeId_p == EplObdGetNodeId()) { // local OD access can be performed
697 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800698
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800699 ObdSize = (tEplObdSize) * puiSize_p;
700 Ret =
701 EplObdReadEntryToLe(uiIndex_p, uiSubindex_p, pDstData_le_p,
702 &ObdSize);
703 *puiSize_p = (unsigned int)ObdSize;
704 } else { // perform SDO transfer
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800705#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800706 tEplSdoComTransParamByIndex TransParamByIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800707// tEplSdoComConHdl SdoComConHdl;
708
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800709 // check if application provides space for handle
710 if (pSdoComConHdl_p == NULL) {
711 Ret = kEplApiInvalidParam;
712 goto Exit;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800713// pSdoComConHdl_p = &SdoComConHdl;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800714 }
715 // init command layer connection
716 Ret = EplSdoComDefineCon(pSdoComConHdl_p, uiNodeId_p, // target node id
717 SdoType_p); // SDO type
718 if ((Ret != kEplSuccessful) && (Ret != kEplSdoComHandleExists)) {
719 goto Exit;
720 }
721 TransParamByIndex.m_pData = pDstData_le_p;
722 TransParamByIndex.m_SdoAccessType = kEplSdoAccessTypeRead;
723 TransParamByIndex.m_SdoComConHdl = *pSdoComConHdl_p;
724 TransParamByIndex.m_uiDataSize = *puiSize_p;
725 TransParamByIndex.m_uiIndex = uiIndex_p;
726 TransParamByIndex.m_uiSubindex = uiSubindex_p;
727 TransParamByIndex.m_pfnSdoFinishedCb = EplApiCbSdoCon;
728 TransParamByIndex.m_pUserArg = pUserArg_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800729
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800730 Ret = EplSdoComInitTransferByIndex(&TransParamByIndex);
731 if (Ret != kEplSuccessful) {
732 goto Exit;
733 }
734 Ret = kEplApiTaskDeferred;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800735
736#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800737 Ret = kEplApiInvalidParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800738#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800739 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800740
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800741 Exit:
742 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800743}
744
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800745// ----------------------------------------------------------------------------
746//
747// Function: EplApiWriteObject()
748//
749// Description: writes the specified entry to the OD of the specified node.
750// If this node is a remote node, it performs a SDO transfer, which
751// means this function returns kEplApiTaskDeferred and the application
752// is informed via the event callback function when the task is completed.
753//
754// Parameters: pSdoComConHdl_p = INOUT: pointer to SDO connection handle (may be NULL in case of local OD access)
755// uiNodeId_p = IN: node ID (0 = itself)
756// uiIndex_p = IN: index of object in OD
757// uiSubindex_p = IN: sub-index of object in OD
758// pSrcData_le_p = IN: pointer to data in little endian
759// uiSize_p = IN: size of data in bytes
760// SdoType_p = IN: type of SDO transfer
761// pUserArg_p = IN: user-definable argument pointer,
762// which will be passed to the event callback function
763//
764// Return: tEplKernel = error code
765//
766// ----------------------------------------------------------------------------
767
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800768tEplKernel PUBLIC EplApiWriteObject(tEplSdoComConHdl * pSdoComConHdl_p,
769 unsigned int uiNodeId_p,
770 unsigned int uiIndex_p,
771 unsigned int uiSubindex_p,
772 void *pSrcData_le_p,
773 unsigned int uiSize_p,
774 tEplSdoType SdoType_p, void *pUserArg_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800775{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800776 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800777
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800778 if ((uiIndex_p == 0) || (pSrcData_le_p == NULL) || (uiSize_p == 0)) {
779 Ret = kEplApiInvalidParam;
780 goto Exit;
781 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800782
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800783 if (uiNodeId_p == 0 || uiNodeId_p == EplObdGetNodeId()) { // local OD access can be performed
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800784
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800785 Ret =
786 EplObdWriteEntryFromLe(uiIndex_p, uiSubindex_p,
787 pSrcData_le_p, uiSize_p);
788 } else { // perform SDO transfer
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800789#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800790 tEplSdoComTransParamByIndex TransParamByIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800791// tEplSdoComConHdl SdoComConHdl;
792
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800793 // check if application provides space for handle
794 if (pSdoComConHdl_p == NULL) {
795 Ret = kEplApiInvalidParam;
796 goto Exit;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800797// pSdoComConHdl_p = &SdoComConHdl;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800798 }
799 // d.k.: How to recycle command layer connection?
800 // Try to redefine it, which will return kEplSdoComHandleExists
801 // and the existing command layer handle.
802 // If the returned handle is busy, EplSdoComInitTransferByIndex()
803 // will return with error.
804 // $$$ d.k.: Collisions may occur with Configuration Manager, if both the application and
805 // Configuration Manager, are trying to communicate with the very same node.
806 // possible solution: disallow communication by application if Configuration Manager is busy
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800807
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800808 // init command layer connection
809 Ret = EplSdoComDefineCon(pSdoComConHdl_p, uiNodeId_p, // target node id
810 SdoType_p); // SDO type
811 if ((Ret != kEplSuccessful) && (Ret != kEplSdoComHandleExists)) {
812 goto Exit;
813 }
814 TransParamByIndex.m_pData = pSrcData_le_p;
815 TransParamByIndex.m_SdoAccessType = kEplSdoAccessTypeWrite;
816 TransParamByIndex.m_SdoComConHdl = *pSdoComConHdl_p;
817 TransParamByIndex.m_uiDataSize = uiSize_p;
818 TransParamByIndex.m_uiIndex = uiIndex_p;
819 TransParamByIndex.m_uiSubindex = uiSubindex_p;
820 TransParamByIndex.m_pfnSdoFinishedCb = EplApiCbSdoCon;
821 TransParamByIndex.m_pUserArg = pUserArg_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800822
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800823 Ret = EplSdoComInitTransferByIndex(&TransParamByIndex);
824 if (Ret != kEplSuccessful) {
825 goto Exit;
826 }
827 Ret = kEplApiTaskDeferred;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800828
829#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800830 Ret = kEplApiInvalidParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800831#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800832 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800833
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800834 Exit:
835 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800836}
837
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800838// ----------------------------------------------------------------------------
839//
840// Function: EplApiFreeSdoChannel()
841//
842// Description: frees the specified SDO channel.
843// This function must be called after each call to EplApiReadObject()/EplApiWriteObject()
844// which returns kEplApiTaskDeferred and the application
845// is informed via the event callback function when the task is completed.
846//
847// Parameters: SdoComConHdl_p = IN: SDO connection handle
848//
849// Return: tEplKernel = error code
850//
851// ----------------------------------------------------------------------------
852
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800853tEplKernel PUBLIC EplApiFreeSdoChannel(tEplSdoComConHdl SdoComConHdl_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800854{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800855 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800856
857#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
858
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800859 // init command layer connection
860 Ret = EplSdoComUndefineCon(SdoComConHdl_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800861
862#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800863 Ret = kEplApiInvalidParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800864#endif
865
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800866 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800867}
868
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800869// ----------------------------------------------------------------------------
870//
871// Function: EplApiReadLocalObject()
872//
873// Description: reads the specified entry from the local OD.
874//
875// Parameters: uiIndex_p = IN: index of object in OD
876// uiSubindex_p = IN: sub-index of object in OD
877// pDstData_p = OUT: pointer to data in platform byte order
878// puiSize_p = INOUT: pointer to size of data
879//
880// Return: tEplKernel = error code
881//
882// ----------------------------------------------------------------------------
883
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800884tEplKernel PUBLIC EplApiReadLocalObject(unsigned int uiIndex_p,
885 unsigned int uiSubindex_p,
886 void *pDstData_p,
887 unsigned int *puiSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800888{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800889 tEplKernel Ret = kEplSuccessful;
890 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800891
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800892 ObdSize = (tEplObdSize) * puiSize_p;
893 Ret = EplObdReadEntry(uiIndex_p, uiSubindex_p, pDstData_p, &ObdSize);
894 *puiSize_p = (unsigned int)ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800895
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800896 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800897}
898
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800899// ----------------------------------------------------------------------------
900//
901// Function: EplApiWriteLocalObject()
902//
903// Description: writes the specified entry to the local OD.
904//
905// Parameters: uiIndex_p = IN: index of object in OD
906// uiSubindex_p = IN: sub-index of object in OD
907// pSrcData_p = IN: pointer to data in platform byte order
908// uiSize_p = IN: size of data in bytes
909//
910// Return: tEplKernel = error code
911//
912// ----------------------------------------------------------------------------
913
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800914tEplKernel PUBLIC EplApiWriteLocalObject(unsigned int uiIndex_p,
915 unsigned int uiSubindex_p,
916 void *pSrcData_p,
917 unsigned int uiSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800918{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800919 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800920
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800921 Ret =
922 EplObdWriteEntry(uiIndex_p, uiSubindex_p, pSrcData_p,
923 (tEplObdSize) uiSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800924
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800925 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800926}
927
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800928#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
929// ----------------------------------------------------------------------------
930//
931// Function: EplApiMnTriggerStateChange()
932//
933// Description: triggers the specified node command for the specified node.
934//
935// Parameters: uiNodeId_p = node ID for which the node command will be executed
936// NodeCommand_p = node command
937//
938// Return: tEplKernel = error code
939//
940// ----------------------------------------------------------------------------
941
942tEplKernel PUBLIC EplApiMnTriggerStateChange(unsigned int uiNodeId_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800943 tEplNmtNodeCommand NodeCommand_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800944{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800945 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800946
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800947 Ret = EplNmtMnuTriggerStateChange(uiNodeId_p, NodeCommand_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800948
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800949 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800950}
951
952#endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
953
954//---------------------------------------------------------------------------
955//
956// Function: EplApiCbObdAccess
957//
958// Description: callback function for OD accesses
959//
960// Parameters: pParam_p = OBD parameter
961//
962// Returns: tEplKernel = error code
963//
964//
965// State:
966//
967//---------------------------------------------------------------------------
968
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800969tEplKernel PUBLIC EplApiCbObdAccess(tEplObdCbParam MEM * pParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800970{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800971 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800972
973#if (EPL_API_OBD_FORWARD_EVENT != FALSE)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800974 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800975
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800976 // call user callback
977 // must be disabled for EplApiLinuxKernel.c, because of reentrancy problem
978 // for local OD access. This is not so bad as user callback function in
979 // application does not use OD callbacks at the moment.
980 EventArg.m_ObdCbParam = *pParam_p;
981 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventObdAccess,
982 &EventArg,
983 EplApiInstance_g.
984 m_InitParam.
985 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800986#endif
987
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800988 switch (pParam_p->m_uiIndex) {
989 //case 0x1006: // NMT_CycleLen_U32 (valid on reset)
990 case 0x1C14: // DLL_LossOfFrameTolerance_U32
991 //case 0x1F98: // NMT_CycleTiming_REC (valid on reset)
992 {
993 if (pParam_p->m_ObdEvent == kEplObdEvPostWrite) {
994 // update DLL configuration
995 Ret = EplApiUpdateDllConfig(FALSE);
996 }
997 break;
998 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800999
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001000 case 0x1020: // CFM_VerifyConfiguration_REC.ConfId_U32 != 0
1001 {
1002 if ((pParam_p->m_ObdEvent == kEplObdEvPostWrite)
1003 && (pParam_p->m_uiSubIndex == 3)
1004 && (*((DWORD *) pParam_p->m_pArg) != 0)) {
1005 DWORD dwVerifyConfInvalid = 0;
1006 // set CFM_VerifyConfiguration_REC.VerifyConfInvalid_U32 to 0
1007 Ret =
1008 EplObdWriteEntry(0x1020, 4,
1009 &dwVerifyConfInvalid, 4);
1010 // ignore any error because this objekt is optional
1011 Ret = kEplSuccessful;
1012 }
1013 break;
1014 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001015
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001016 case 0x1F9E: // NMT_ResetCmd_U8
1017 {
1018 if (pParam_p->m_ObdEvent == kEplObdEvPreWrite) {
1019 BYTE bNmtCommand;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001020
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001021 bNmtCommand = *((BYTE *) pParam_p->m_pArg);
1022 // check value range
1023 switch ((tEplNmtCommand) bNmtCommand) {
1024 case kEplNmtCmdResetNode:
1025 case kEplNmtCmdResetCommunication:
1026 case kEplNmtCmdResetConfiguration:
1027 case kEplNmtCmdSwReset:
1028 case kEplNmtCmdInvalidService:
1029 // valid command identifier specified
1030 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001031
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001032 default:
1033 pParam_p->m_dwAbortCode =
1034 EPL_SDOAC_VALUE_RANGE_EXCEEDED;
1035 Ret = kEplObdAccessViolation;
1036 break;
1037 }
1038 } else if (pParam_p->m_ObdEvent == kEplObdEvPostWrite) {
1039 BYTE bNmtCommand;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001040
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001041 bNmtCommand = *((BYTE *) pParam_p->m_pArg);
1042 // check value range
1043 switch ((tEplNmtCommand) bNmtCommand) {
1044 case kEplNmtCmdResetNode:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001045#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001046 Ret =
1047 EplNmtuNmtEvent
1048 (kEplNmtEventResetNode);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001049#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001050 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001051
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001052 case kEplNmtCmdResetCommunication:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001053#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001054 Ret =
1055 EplNmtuNmtEvent
1056 (kEplNmtEventResetCom);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001057#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001058 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001059
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001060 case kEplNmtCmdResetConfiguration:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001061#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001062 Ret =
1063 EplNmtuNmtEvent
1064 (kEplNmtEventResetConfig);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001065#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001066 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001067
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001068 case kEplNmtCmdSwReset:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001069#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001070 Ret =
1071 EplNmtuNmtEvent
1072 (kEplNmtEventSwReset);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001073#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001074 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001075
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001076 case kEplNmtCmdInvalidService:
1077 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001078
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001079 default:
1080 pParam_p->m_dwAbortCode =
1081 EPL_SDOAC_VALUE_RANGE_EXCEEDED;
1082 Ret = kEplObdAccessViolation;
1083 break;
1084 }
1085 }
1086 break;
1087 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001088
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001089 default:
1090 break;
1091 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001092
1093//Exit:
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001094 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001095}
1096
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001097//=========================================================================//
1098// //
1099// P R I V A T E F U N C T I O N S //
1100// //
1101//=========================================================================//
1102
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001103//---------------------------------------------------------------------------
1104//
1105// Function: EplApiProcessEvent
1106//
1107// Description: processes events from event queue and forwards these to
1108// the application's event callback function
1109//
1110// Parameters: pEplEvent_p = pointer to event
1111//
1112// Returns: tEplKernel = errorcode
1113//
1114// State:
1115//
1116//---------------------------------------------------------------------------
1117
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001118static tEplKernel PUBLIC EplApiProcessEvent(tEplEvent * pEplEvent_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001119{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001120 tEplKernel Ret;
1121 tEplEventError *pEventError;
1122 tEplApiEventType EventType;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001123
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001124 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001125
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001126 // process event
1127 switch (pEplEvent_p->m_EventType) {
1128 // error event
1129 case kEplEventTypeError:
1130 {
1131 pEventError = (tEplEventError *) pEplEvent_p->m_pArg;
1132 switch (pEventError->m_EventSource) {
1133 // treat the errors from the following sources as critical
1134 case kEplEventSourceEventk:
1135 case kEplEventSourceEventu:
1136 case kEplEventSourceDllk:
1137 {
1138 EventType = kEplApiEventCriticalError;
1139 // halt the stack by entering NMT state Off
1140 Ret =
1141 EplNmtuNmtEvent
1142 (kEplNmtEventCriticalError);
1143 break;
1144 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001145
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001146 // the other errors are just warnings
1147 default:
1148 {
1149 EventType = kEplApiEventWarning;
1150 break;
1151 }
1152 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001153
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001154 // call user callback
1155 Ret =
1156 EplApiInstance_g.m_InitParam.m_pfnCbEvent(EventType,
1157 (tEplApiEventArg
1158 *)
1159 pEventError,
1160 EplApiInstance_g.
1161 m_InitParam.
1162 m_pEventUserArg);
1163 // discard error from callback function, because this could generate an endless loop
1164 Ret = kEplSuccessful;
1165 break;
1166 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001167
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001168 // at present, there are no other events for this module
1169 default:
1170 break;
1171 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001172
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001173 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001174}
1175
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001176//---------------------------------------------------------------------------
1177//
1178// Function: EplApiCbNmtStateChange
1179//
1180// Description: callback function for NMT state changes
1181//
1182// Parameters: NmtStateChange_p = NMT state change event
1183//
1184// Returns: tEplKernel = error code
1185//
1186//
1187// State:
1188//
1189//---------------------------------------------------------------------------
1190
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001191static tEplKernel PUBLIC EplApiCbNmtStateChange(tEplEventNmtStateChange
1192 NmtStateChange_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001193{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001194 tEplKernel Ret = kEplSuccessful;
1195 BYTE bNmtState;
1196 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001197
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001198 // save NMT state in OD
1199 bNmtState = (BYTE) NmtStateChange_p.m_NewNmtState;
1200 Ret = EplObdWriteEntry(0x1F8C, 0, &bNmtState, 1);
1201 if (Ret != kEplSuccessful) {
1202 goto Exit;
1203 }
1204 // do work which must be done in that state
1205 switch (NmtStateChange_p.m_NewNmtState) {
1206 // EPL stack is not running
1207 case kEplNmtGsOff:
1208 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001209
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001210 // first init of the hardware
1211 case kEplNmtGsInitialising:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001212#if 0
1213#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDO_UDP)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001214 // configure SDO via UDP (i.e. bind it to the EPL ethernet interface)
1215 Ret =
1216 EplSdoUdpuConfig(EplApiInstance_g.m_InitParam.m_dwIpAddress,
1217 EPL_C_SDO_EPL_PORT);
1218 if (Ret != kEplSuccessful) {
1219 goto Exit;
1220 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001221#endif
1222#endif
1223
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001224 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001225
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001226 // init of the manufacturer-specific profile area and the
1227 // standardised device profile area
1228 case kEplNmtGsResetApplication:
1229 {
1230 // reset application part of OD
1231 Ret = EplObdAccessOdPart(kEplObdPartApp,
1232 kEplObdDirLoad);
1233 if (Ret != kEplSuccessful) {
1234 goto Exit;
1235 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001236
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001237 break;
1238 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001239
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001240 // init of the communication profile area
1241 case kEplNmtGsResetCommunication:
1242 {
1243 // reset communication part of OD
1244 Ret = EplObdAccessOdPart(kEplObdPartGen,
1245 kEplObdDirLoad);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001246
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001247 if (Ret != kEplSuccessful) {
1248 goto Exit;
1249 }
1250 // $$$ d.k.: update OD only if OD was not loaded from non-volatile memory
1251 Ret = EplApiUpdateObd();
1252 if (Ret != kEplSuccessful) {
1253 goto Exit;
1254 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001255
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001256 break;
1257 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001258
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001259 // build the configuration with infos from OD
1260 case kEplNmtGsResetConfiguration:
1261 {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001262
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001263 Ret = EplApiUpdateDllConfig(TRUE);
1264 if (Ret != kEplSuccessful) {
1265 goto Exit;
1266 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001267
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001268 break;
1269 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001270
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001271 //-----------------------------------------------------------
1272 // CN part of the state machine
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001273
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001274 // node liste for EPL-Frames and check timeout
1275 case kEplNmtCsNotActive:
1276 {
1277 // indicate completion of reset in NMT_ResetCmd_U8
1278 bNmtState = (BYTE) kEplNmtCmdInvalidService;
1279 Ret = EplObdWriteEntry(0x1F9E, 0, &bNmtState, 1);
1280 if (Ret != kEplSuccessful) {
1281 goto Exit;
1282 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001283
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001284 break;
1285 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001286
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001287 // node process only async frames
1288 case kEplNmtCsPreOperational1:
1289 {
1290 break;
1291 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001292
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001293 // node process isochronus and asynchronus frames
1294 case kEplNmtCsPreOperational2:
1295 {
1296 break;
1297 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001298
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001299 // node should be configured und application is ready
1300 case kEplNmtCsReadyToOperate:
1301 {
1302 break;
1303 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001304
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001305 // normal work state
1306 case kEplNmtCsOperational:
1307 {
1308 break;
1309 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001310
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001311 // node stopped by MN
1312 // -> only process asynchronus frames
1313 case kEplNmtCsStopped:
1314 {
1315 break;
1316 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001317
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001318 // no EPL cycle
1319 // -> normal ethernet communication
1320 case kEplNmtCsBasicEthernet:
1321 {
1322 break;
1323 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001324
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001325 //-----------------------------------------------------------
1326 // MN part of the state machine
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001327
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001328 // node listens for EPL-Frames and check timeout
1329 case kEplNmtMsNotActive:
1330 {
1331 break;
1332 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001333
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001334 // node processes only async frames
1335 case kEplNmtMsPreOperational1:
1336 {
1337 break;
1338 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001339
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001340 // node processes isochronous and asynchronous frames
1341 case kEplNmtMsPreOperational2:
1342 {
1343 break;
1344 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001345
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001346 // node should be configured und application is ready
1347 case kEplNmtMsReadyToOperate:
1348 {
1349 break;
1350 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001351
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001352 // normal work state
1353 case kEplNmtMsOperational:
1354 {
1355 break;
1356 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001357
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001358 // no EPL cycle
1359 // -> normal ethernet communication
1360 case kEplNmtMsBasicEthernet:
1361 {
1362 break;
1363 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001364
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001365 default:
1366 {
1367 TRACE0
1368 ("EplApiCbNmtStateChange(): unhandled NMT state\n");
1369 }
1370 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001371
1372#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001373 // forward event to Led module
1374 Ret = EplLeduCbNmtStateChange(NmtStateChange_p);
1375 if (Ret != kEplSuccessful) {
1376 goto Exit;
1377 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001378#endif
1379
1380#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001381 // forward event to NmtMn module
1382 Ret = EplNmtMnuCbNmtStateChange(NmtStateChange_p);
1383 if (Ret != kEplSuccessful) {
1384 goto Exit;
1385 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001386#endif
1387
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001388 // call user callback
1389 EventArg.m_NmtStateChange = NmtStateChange_p;
1390 Ret =
1391 EplApiInstance_g.m_InitParam.
1392 m_pfnCbEvent(kEplApiEventNmtStateChange, &EventArg,
1393 EplApiInstance_g.m_InitParam.m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001394
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001395 Exit:
1396 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001397}
1398
1399//---------------------------------------------------------------------------
1400//
1401// Function: EplApiUpdateDllConfig
1402//
1403// Description: update configuration of DLL
1404//
1405// Parameters: fUpdateIdentity_p = TRUE, if identity must be updated
1406//
1407// Returns: tEplKernel = error code
1408//
1409//
1410// State:
1411//
1412//---------------------------------------------------------------------------
1413
1414static tEplKernel PUBLIC EplApiUpdateDllConfig(BOOL fUpdateIdentity_p)
1415{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001416 tEplKernel Ret = kEplSuccessful;
1417 tEplDllConfigParam DllConfigParam;
1418 tEplDllIdentParam DllIdentParam;
1419 tEplObdSize ObdSize;
1420 WORD wTemp;
1421 BYTE bTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001422
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001423 // configure Dll
1424 EPL_MEMSET(&DllConfigParam, 0, sizeof(DllConfigParam));
1425 DllConfigParam.m_uiNodeId = EplObdGetNodeId();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001426
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001427 // Cycle Length (0x1006: NMT_CycleLen_U32) in [us]
1428 ObdSize = 4;
1429 Ret =
1430 EplObdReadEntry(0x1006, 0, &DllConfigParam.m_dwCycleLen, &ObdSize);
1431 if (Ret != kEplSuccessful) {
1432 goto Exit;
1433 }
1434 // 0x1F82: NMT_FeatureFlags_U32
1435 ObdSize = 4;
1436 Ret =
1437 EplObdReadEntry(0x1F82, 0, &DllConfigParam.m_dwFeatureFlags,
1438 &ObdSize);
1439 if (Ret != kEplSuccessful) {
1440 goto Exit;
1441 }
1442 // d.k. There is no dependance between FeatureFlags and async-only CN
1443 DllConfigParam.m_fAsyncOnly = EplApiInstance_g.m_InitParam.m_fAsyncOnly;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001444
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001445 // 0x1C14: DLL_LossOfFrameTolerance_U32 in [ns]
1446 ObdSize = 4;
1447 Ret =
1448 EplObdReadEntry(0x1C14, 0, &DllConfigParam.m_dwLossOfFrameTolerance,
1449 &ObdSize);
1450 if (Ret != kEplSuccessful) {
1451 goto Exit;
1452 }
1453 // 0x1F98: NMT_CycleTiming_REC
1454 // 0x1F98.1: IsochrTxMaxPayload_U16
1455 ObdSize = 2;
1456 Ret = EplObdReadEntry(0x1F98, 1, &wTemp, &ObdSize);
1457 if (Ret != kEplSuccessful) {
1458 goto Exit;
1459 }
1460 DllConfigParam.m_uiIsochrTxMaxPayload = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001461
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001462 // 0x1F98.2: IsochrRxMaxPayload_U16
1463 ObdSize = 2;
1464 Ret = EplObdReadEntry(0x1F98, 2, &wTemp, &ObdSize);
1465 if (Ret != kEplSuccessful) {
1466 goto Exit;
1467 }
1468 DllConfigParam.m_uiIsochrRxMaxPayload = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001469
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001470 // 0x1F98.3: PResMaxLatency_U32
1471 ObdSize = 4;
1472 Ret =
1473 EplObdReadEntry(0x1F98, 3, &DllConfigParam.m_dwPresMaxLatency,
1474 &ObdSize);
1475 if (Ret != kEplSuccessful) {
1476 goto Exit;
1477 }
1478 // 0x1F98.4: PReqActPayloadLimit_U16
1479 ObdSize = 2;
1480 Ret = EplObdReadEntry(0x1F98, 4, &wTemp, &ObdSize);
1481 if (Ret != kEplSuccessful) {
1482 goto Exit;
1483 }
1484 DllConfigParam.m_uiPreqActPayloadLimit = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001485
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001486 // 0x1F98.5: PResActPayloadLimit_U16
1487 ObdSize = 2;
1488 Ret = EplObdReadEntry(0x1F98, 5, &wTemp, &ObdSize);
1489 if (Ret != kEplSuccessful) {
1490 goto Exit;
1491 }
1492 DllConfigParam.m_uiPresActPayloadLimit = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001493
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001494 // 0x1F98.6: ASndMaxLatency_U32
1495 ObdSize = 4;
1496 Ret =
1497 EplObdReadEntry(0x1F98, 6, &DllConfigParam.m_dwAsndMaxLatency,
1498 &ObdSize);
1499 if (Ret != kEplSuccessful) {
1500 goto Exit;
1501 }
1502 // 0x1F98.7: MultiplCycleCnt_U8
1503 ObdSize = 1;
1504 Ret = EplObdReadEntry(0x1F98, 7, &bTemp, &ObdSize);
1505 if (Ret != kEplSuccessful) {
1506 goto Exit;
1507 }
1508 DllConfigParam.m_uiMultiplCycleCnt = bTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001509
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001510 // 0x1F98.8: AsyncMTU_U16
1511 ObdSize = 2;
1512 Ret = EplObdReadEntry(0x1F98, 8, &wTemp, &ObdSize);
1513 if (Ret != kEplSuccessful) {
1514 goto Exit;
1515 }
1516 DllConfigParam.m_uiAsyncMtu = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001517
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001518 // $$$ Prescaler
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001519
1520#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001521 // 0x1F8A.1: WaitSoCPReq_U32 in [ns]
1522 ObdSize = 4;
1523 Ret =
1524 EplObdReadEntry(0x1F8A, 1, &DllConfigParam.m_dwWaitSocPreq,
1525 &ObdSize);
1526 if (Ret != kEplSuccessful) {
1527 goto Exit;
1528 }
1529 // 0x1F8A.2: AsyncSlotTimeout_U32 in [ns] (optional)
1530 ObdSize = 4;
1531 Ret =
1532 EplObdReadEntry(0x1F8A, 2, &DllConfigParam.m_dwAsyncSlotTimeout,
1533 &ObdSize);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001534/* if(Ret != kEplSuccessful)
1535 {
1536 goto Exit;
1537 }*/
1538#endif
1539
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001540 DllConfigParam.m_uiSizeOfStruct = sizeof(DllConfigParam);
1541 Ret = EplDllkConfig(&DllConfigParam);
1542 if (Ret != kEplSuccessful) {
1543 goto Exit;
1544 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001545
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001546 if (fUpdateIdentity_p != FALSE) {
1547 // configure Identity
1548 EPL_MEMSET(&DllIdentParam, 0, sizeof(DllIdentParam));
1549 ObdSize = 4;
1550 Ret =
1551 EplObdReadEntry(0x1000, 0, &DllIdentParam.m_dwDeviceType,
1552 &ObdSize);
1553 if (Ret != kEplSuccessful) {
1554 goto Exit;
1555 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001556
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001557 ObdSize = 4;
1558 Ret =
1559 EplObdReadEntry(0x1018, 1, &DllIdentParam.m_dwVendorId,
1560 &ObdSize);
1561 if (Ret != kEplSuccessful) {
1562 goto Exit;
1563 }
1564 ObdSize = 4;
1565 Ret =
1566 EplObdReadEntry(0x1018, 2, &DllIdentParam.m_dwProductCode,
1567 &ObdSize);
1568 if (Ret != kEplSuccessful) {
1569 goto Exit;
1570 }
1571 ObdSize = 4;
1572 Ret =
1573 EplObdReadEntry(0x1018, 3,
1574 &DllIdentParam.m_dwRevisionNumber,
1575 &ObdSize);
1576 if (Ret != kEplSuccessful) {
1577 goto Exit;
1578 }
1579 ObdSize = 4;
1580 Ret =
1581 EplObdReadEntry(0x1018, 4, &DllIdentParam.m_dwSerialNumber,
1582 &ObdSize);
1583 if (Ret != kEplSuccessful) {
1584 goto Exit;
1585 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001586
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001587 DllIdentParam.m_dwIpAddress =
1588 EplApiInstance_g.m_InitParam.m_dwIpAddress;
1589 DllIdentParam.m_dwSubnetMask =
1590 EplApiInstance_g.m_InitParam.m_dwSubnetMask;
1591 EPL_MEMCPY(DllIdentParam.m_sHostname,
1592 EplApiInstance_g.m_InitParam.m_sHostname,
1593 sizeof(DllIdentParam.m_sHostname));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001594
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001595 ObdSize = 4;
1596 Ret =
1597 EplObdReadEntry(0x1020, 1,
1598 &DllIdentParam.m_dwVerifyConfigurationDate,
1599 &ObdSize);
1600 // ignore any error, because this object is optional
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001601
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001602 ObdSize = 4;
1603 Ret =
1604 EplObdReadEntry(0x1020, 2,
1605 &DllIdentParam.m_dwVerifyConfigurationTime,
1606 &ObdSize);
1607 // ignore any error, because this object is optional
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001608
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001609 // $$$ d.k.: fill rest of ident structure
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001610
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001611 DllIdentParam.m_uiSizeOfStruct = sizeof(DllIdentParam);
1612 Ret = EplDllkSetIdentity(&DllIdentParam);
1613 if (Ret != kEplSuccessful) {
1614 goto Exit;
1615 }
1616 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001617
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001618 Exit:
1619 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001620}
1621
1622//---------------------------------------------------------------------------
1623//
1624// Function: EplApiUpdateObd
1625//
1626// Description: update OD from init param
1627//
1628// Parameters: (none)
1629//
1630// Returns: tEplKernel = error code
1631//
1632//
1633// State:
1634//
1635//---------------------------------------------------------------------------
1636
1637static tEplKernel PUBLIC EplApiUpdateObd(void)
1638{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001639 tEplKernel Ret = kEplSuccessful;
1640 WORD wTemp;
1641 BYTE bTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001642
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001643 // set node id in OD
1644 Ret = EplObdSetNodeId(EplApiInstance_g.m_InitParam.m_uiNodeId, // node id
1645 kEplObdNodeIdHardware); // set by hardware
1646 if (Ret != kEplSuccessful) {
1647 goto Exit;
1648 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001649
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001650 if (EplApiInstance_g.m_InitParam.m_dwCycleLen != -1) {
1651 Ret =
1652 EplObdWriteEntry(0x1006, 0,
1653 &EplApiInstance_g.m_InitParam.m_dwCycleLen,
1654 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001655/* if(Ret != kEplSuccessful)
1656 {
1657 goto Exit;
1658 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001659 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001660
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001661 if (EplApiInstance_g.m_InitParam.m_dwLossOfFrameTolerance != -1) {
1662 Ret =
1663 EplObdWriteEntry(0x1C14, 0,
1664 &EplApiInstance_g.m_InitParam.
1665 m_dwLossOfFrameTolerance, 4);
1666 /* if(Ret != kEplSuccessful)
1667 {
1668 goto Exit;
1669 } */
1670 }
1671 // d.k. There is no dependance between FeatureFlags and async-only CN.
1672 if (EplApiInstance_g.m_InitParam.m_dwFeatureFlags != -1) {
1673 Ret =
1674 EplObdWriteEntry(0x1F82, 0,
1675 &EplApiInstance_g.m_InitParam.
1676 m_dwFeatureFlags, 4);
1677 /* if(Ret != kEplSuccessful)
1678 {
1679 goto Exit;
1680 } */
1681 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001682
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001683 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiIsochrTxMaxPayload;
1684 Ret = EplObdWriteEntry(0x1F98, 1, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001685/* if(Ret != kEplSuccessful)
1686 {
1687 goto Exit;
1688 }*/
1689
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001690 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiIsochrRxMaxPayload;
1691 Ret = EplObdWriteEntry(0x1F98, 2, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001692/* if(Ret != kEplSuccessful)
1693 {
1694 goto Exit;
1695 }*/
1696
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001697 Ret =
1698 EplObdWriteEntry(0x1F98, 3,
1699 &EplApiInstance_g.m_InitParam.m_dwPresMaxLatency,
1700 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001701/* if(Ret != kEplSuccessful)
1702 {
1703 goto Exit;
1704 }*/
1705
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001706 if (EplApiInstance_g.m_InitParam.m_uiPreqActPayloadLimit <=
1707 EPL_C_DLL_ISOCHR_MAX_PAYL) {
1708 wTemp =
1709 (WORD) EplApiInstance_g.m_InitParam.m_uiPreqActPayloadLimit;
1710 Ret = EplObdWriteEntry(0x1F98, 4, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001711/* if(Ret != kEplSuccessful)
1712 {
1713 goto Exit;
1714 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001715 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001716
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001717 if (EplApiInstance_g.m_InitParam.m_uiPresActPayloadLimit <=
1718 EPL_C_DLL_ISOCHR_MAX_PAYL) {
1719 wTemp =
1720 (WORD) EplApiInstance_g.m_InitParam.m_uiPresActPayloadLimit;
1721 Ret = EplObdWriteEntry(0x1F98, 5, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001722/* if(Ret != kEplSuccessful)
1723 {
1724 goto Exit;
1725 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001726 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001727
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001728 Ret =
1729 EplObdWriteEntry(0x1F98, 6,
1730 &EplApiInstance_g.m_InitParam.m_dwAsndMaxLatency,
1731 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001732/* if(Ret != kEplSuccessful)
1733 {
1734 goto Exit;
1735 }*/
1736
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001737 if (EplApiInstance_g.m_InitParam.m_uiMultiplCycleCnt <= 0xFF) {
1738 bTemp = (BYTE) EplApiInstance_g.m_InitParam.m_uiMultiplCycleCnt;
1739 Ret = EplObdWriteEntry(0x1F98, 7, &bTemp, 1);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001740/* if(Ret != kEplSuccessful)
1741 {
1742 goto Exit;
1743 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001744 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001745
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001746 if (EplApiInstance_g.m_InitParam.m_uiAsyncMtu <=
1747 EPL_C_DLL_MAX_ASYNC_MTU) {
1748 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiAsyncMtu;
1749 Ret = EplObdWriteEntry(0x1F98, 8, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001750/* if(Ret != kEplSuccessful)
1751 {
1752 goto Exit;
1753 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001754 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001755
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001756 if (EplApiInstance_g.m_InitParam.m_uiPrescaler <= 1000) {
1757 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiPrescaler;
1758 Ret = EplObdWriteEntry(0x1F98, 9, &wTemp, 2);
1759 // ignore return code
1760 Ret = kEplSuccessful;
1761 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001762#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001763 if (EplApiInstance_g.m_InitParam.m_dwWaitSocPreq != -1) {
1764 Ret =
1765 EplObdWriteEntry(0x1F8A, 1,
1766 &EplApiInstance_g.m_InitParam.
1767 m_dwWaitSocPreq, 4);
1768 /* if(Ret != kEplSuccessful)
1769 {
1770 goto Exit;
1771 } */
1772 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001773
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001774 if ((EplApiInstance_g.m_InitParam.m_dwAsyncSlotTimeout != 0)
1775 && (EplApiInstance_g.m_InitParam.m_dwAsyncSlotTimeout != -1)) {
1776 Ret =
1777 EplObdWriteEntry(0x1F8A, 2,
1778 &EplApiInstance_g.m_InitParam.
1779 m_dwAsyncSlotTimeout, 4);
1780 /* if(Ret != kEplSuccessful)
1781 {
1782 goto Exit;
1783 } */
1784 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001785#endif
1786
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001787 // configure Identity
1788 if (EplApiInstance_g.m_InitParam.m_dwDeviceType != -1) {
1789 Ret =
1790 EplObdWriteEntry(0x1000, 0,
1791 &EplApiInstance_g.m_InitParam.
1792 m_dwDeviceType, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001793/* if(Ret != kEplSuccessful)
1794 {
1795 goto Exit;
1796 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001797 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001798
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001799 if (EplApiInstance_g.m_InitParam.m_dwVendorId != -1) {
1800 Ret =
1801 EplObdWriteEntry(0x1018, 1,
1802 &EplApiInstance_g.m_InitParam.m_dwVendorId,
1803 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001804/* if(Ret != kEplSuccessful)
1805 {
1806 goto Exit;
1807 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001808 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001809
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001810 if (EplApiInstance_g.m_InitParam.m_dwProductCode != -1) {
1811 Ret =
1812 EplObdWriteEntry(0x1018, 2,
1813 &EplApiInstance_g.m_InitParam.
1814 m_dwProductCode, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001815/* if(Ret != kEplSuccessful)
1816 {
1817 goto Exit;
1818 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001819 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001820
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001821 if (EplApiInstance_g.m_InitParam.m_dwRevisionNumber != -1) {
1822 Ret =
1823 EplObdWriteEntry(0x1018, 3,
1824 &EplApiInstance_g.m_InitParam.
1825 m_dwRevisionNumber, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001826/* if(Ret != kEplSuccessful)
1827 {
1828 goto Exit;
1829 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001830 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001831
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001832 if (EplApiInstance_g.m_InitParam.m_dwSerialNumber != -1) {
1833 Ret =
1834 EplObdWriteEntry(0x1018, 4,
1835 &EplApiInstance_g.m_InitParam.
1836 m_dwSerialNumber, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001837/* if(Ret != kEplSuccessful)
1838 {
1839 goto Exit;
1840 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001841 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001842
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001843 if (EplApiInstance_g.m_InitParam.m_pszDevName != NULL) {
1844 // write Device Name (0x1008)
1845 Ret =
1846 EplObdWriteEntry(0x1008, 0,
1847 (void GENERIC *)EplApiInstance_g.
1848 m_InitParam.m_pszDevName,
1849 (tEplObdSize) strlen(EplApiInstance_g.
1850 m_InitParam.
1851 m_pszDevName));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001852/* if (Ret != kEplSuccessful)
1853 {
1854 goto Exit;
1855 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001856 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001857
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001858 if (EplApiInstance_g.m_InitParam.m_pszHwVersion != NULL) {
1859 // write Hardware version (0x1009)
1860 Ret =
1861 EplObdWriteEntry(0x1009, 0,
1862 (void GENERIC *)EplApiInstance_g.
1863 m_InitParam.m_pszHwVersion,
1864 (tEplObdSize) strlen(EplApiInstance_g.
1865 m_InitParam.
1866 m_pszHwVersion));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001867/* if (Ret != kEplSuccessful)
1868 {
1869 goto Exit;
1870 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001871 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001872
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001873 if (EplApiInstance_g.m_InitParam.m_pszSwVersion != NULL) {
1874 // write Software version (0x100A)
1875 Ret =
1876 EplObdWriteEntry(0x100A, 0,
1877 (void GENERIC *)EplApiInstance_g.
1878 m_InitParam.m_pszSwVersion,
1879 (tEplObdSize) strlen(EplApiInstance_g.
1880 m_InitParam.
1881 m_pszSwVersion));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001882/* if (Ret != kEplSuccessful)
1883 {
1884 goto Exit;
1885 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001886 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001887
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001888 Exit:
1889 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001890}
1891
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001892//---------------------------------------------------------------------------
1893//
1894// Function: EplApiCbSdoCon
1895//
1896// Description: callback function for SDO transfers
1897//
1898// Parameters: pSdoComFinished_p = SDO parameter
1899//
1900// Returns: tEplKernel = error code
1901//
1902//
1903// State:
1904//
1905//---------------------------------------------------------------------------
1906
1907#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001908static tEplKernel PUBLIC EplApiCbSdoCon(tEplSdoComFinished * pSdoComFinished_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001909{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001910 tEplKernel Ret;
1911 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001912
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001913 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001914
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001915 // call user callback
1916 EventArg.m_Sdo = *pSdoComFinished_p;
1917 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventSdo,
1918 &EventArg,
1919 EplApiInstance_g.
1920 m_InitParam.
1921 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001922
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001923 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001924
1925}
1926#endif
1927
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001928#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
1929
1930//---------------------------------------------------------------------------
1931//
1932// Function: EplApiCbNodeEvent
1933//
1934// Description: callback function for node events
1935//
1936// Parameters: uiNodeId_p = node ID of the CN
1937// NodeEvent_p = event from the specified CN
1938// NmtState_p = current NMT state of the CN
1939// wErrorCode_p = EPL error code if NodeEvent_p==kEplNmtNodeEventError
1940// fMandatory_p = flag if CN is mandatory
1941//
1942// Returns: tEplKernel = error code
1943//
1944//
1945// State:
1946//
1947//---------------------------------------------------------------------------
1948
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001949static tEplKernel PUBLIC EplApiCbNodeEvent(unsigned int uiNodeId_p,
1950 tEplNmtNodeEvent NodeEvent_p,
1951 tEplNmtState NmtState_p,
1952 WORD wErrorCode_p, BOOL fMandatory_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001953{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001954 tEplKernel Ret;
1955 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001956
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001957 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001958
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001959 // call user callback
1960 EventArg.m_Node.m_uiNodeId = uiNodeId_p;
1961 EventArg.m_Node.m_NodeEvent = NodeEvent_p;
1962 EventArg.m_Node.m_NmtState = NmtState_p;
1963 EventArg.m_Node.m_wErrorCode = wErrorCode_p;
1964 EventArg.m_Node.m_fMandatory = fMandatory_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001965
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001966 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventNode,
1967 &EventArg,
1968 EplApiInstance_g.
1969 m_InitParam.
1970 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001971
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001972 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001973
1974}
1975
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001976//---------------------------------------------------------------------------
1977//
1978// Function: EplApiCbBootEvent
1979//
1980// Description: callback function for boot events
1981//
1982// Parameters: BootEvent_p = event from the boot-up process
1983// NmtState_p = current local NMT state
1984// wErrorCode_p = EPL error code if BootEvent_p==kEplNmtBootEventError
1985//
1986// Returns: tEplKernel = error code
1987//
1988//
1989// State:
1990//
1991//---------------------------------------------------------------------------
1992
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001993static tEplKernel PUBLIC EplApiCbBootEvent(tEplNmtBootEvent BootEvent_p,
1994 tEplNmtState NmtState_p,
1995 WORD wErrorCode_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001996{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001997 tEplKernel Ret;
1998 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001999
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002000 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002001
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002002 // call user callback
2003 EventArg.m_Boot.m_BootEvent = BootEvent_p;
2004 EventArg.m_Boot.m_NmtState = NmtState_p;
2005 EventArg.m_Boot.m_wErrorCode = wErrorCode_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002006
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002007 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventBoot,
2008 &EventArg,
2009 EplApiInstance_g.
2010 m_InitParam.
2011 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002012
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002013 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002014
2015}
2016
2017#endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
2018
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002019#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
2020
2021//---------------------------------------------------------------------------
2022//
2023// Function: EplApiCbLedStateChange
2024//
2025// Description: callback function for LED change events.
2026//
2027// Parameters: LedType_p = type of LED
2028// fOn_p = state of LED
2029//
2030// Returns: tEplKernel = errorcode
2031//
2032// State:
2033//
2034//---------------------------------------------------------------------------
2035
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002036static tEplKernel PUBLIC EplApiCbLedStateChange(tEplLedType LedType_p,
2037 BOOL fOn_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002038{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002039 tEplKernel Ret;
2040 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002041
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002042 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002043
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002044 // call user callback
2045 EventArg.m_Led.m_LedType = LedType_p;
2046 EventArg.m_Led.m_fOn = fOn_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002047
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002048 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventLed,
2049 &EventArg,
2050 EplApiInstance_g.
2051 m_InitParam.
2052 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002053
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002054 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002055
2056}
2057
2058#endif
2059
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002060// EOF