blob: 6baed04ef11cc09687cf4f691ad90d7619e7df05 [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 error handler 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: EplErrorHandlerk.c,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.9 $ $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/10/02 d.k.: start of the implementation
68
69****************************************************************************/
70
71#include "kernel/EplErrorHandlerk.h"
72#include "EplNmt.h"
73#include "kernel/EplEventk.h"
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080074#include "kernel/EplObdk.h" // function prototyps of the EplOBD-Modul
Daniel Krueger9d7164c2008-12-19 11:41:57 -080075#include "kernel/EplDllk.h"
76
77#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
78
79#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) == 0)
80#error "EPL ErrorHandler module needs EPL module OBDK!"
81#endif
82
Daniel Krueger9d7164c2008-12-19 11:41:57 -080083/***************************************************************************/
84/* */
85/* */
86/* G L O B A L D E F I N I T I O N S */
87/* */
88/* */
89/***************************************************************************/
90
91//---------------------------------------------------------------------------
92// const defines
93//---------------------------------------------------------------------------
94
Daniel Krueger9d7164c2008-12-19 11:41:57 -080095//---------------------------------------------------------------------------
96// local types
97//---------------------------------------------------------------------------
98
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080099typedef struct {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700100 u32 m_dwCumulativeCnt; // subindex 1
101 u32 m_dwThresholdCnt; // subindex 2
102 u32 m_dwThreshold; // subindex 3
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800103
104} tEplErrorHandlerkErrorCounter;
105
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800106typedef struct {
107 tEplErrorHandlerkErrorCounter m_CnLossSoc; // object 0x1C0B
108 tEplErrorHandlerkErrorCounter m_CnLossPreq; // object 0x1C0D
109 tEplErrorHandlerkErrorCounter m_CnCrcErr; // object 0x1C0F
110 unsigned long m_ulDllErrorEvents;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800111
112#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800113 tEplErrorHandlerkErrorCounter m_MnCrcErr; // object 0x1C00
114 tEplErrorHandlerkErrorCounter m_MnCycTimeExceed; // object 0x1C02
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700115 u32 m_adwMnCnLossPresCumCnt[254]; // object 0x1C07
116 u32 m_adwMnCnLossPresThrCnt[254]; // object 0x1C08
117 u32 m_adwMnCnLossPresThreshold[254]; // object 0x1C09
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800118 BOOL m_afMnCnLossPresEvent[254];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800119#endif
120
121} tEplErrorHandlerkInstance;
122
123//---------------------------------------------------------------------------
124// modul globale vars
125//---------------------------------------------------------------------------
126
127static tEplErrorHandlerkInstance EplErrorHandlerkInstance_g;
128
129//---------------------------------------------------------------------------
130// local function prototypes
131//---------------------------------------------------------------------------
132
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800133static tEplKernel EplErrorHandlerkLinkErrorCounter(tEplErrorHandlerkErrorCounter
134 * pErrorCounter_p,
135 unsigned int uiIndex_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800136
137#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700138static tEplKernel EplErrorHandlerkLinkArray(u32 * pdwValue_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800139 unsigned int uiValueCount_p,
140 unsigned int uiIndex_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800141#endif
142
143/***************************************************************************/
144/* */
145/* */
146/* C L A S S <Epl-Kernelspace-Error-Handler> */
147/* */
148/* */
149/***************************************************************************/
150//
151// Description:
152//
153//
154/***************************************************************************/
155
156//=========================================================================//
157// //
158// P U B L I C F U N C T I O N S //
159// //
160//=========================================================================//
161
162//---------------------------------------------------------------------------
163//
164// Function: EplErrorHandlerkInit
165//
166// Description: function initialize the first instance
167//
168//
169//
170// Parameters:
171//
172//
173// Returns: tEpKernel = errorcode
174//
175//
176// State:
177//
178//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700179tEplKernel EplErrorHandlerkInit(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800180{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800181 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800182
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800183 Ret = EplErrorHandlerkAddInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800184
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800185 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800186
187}
188
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800189//---------------------------------------------------------------------------
190//
191// Function: EplErrorHandlerkAddInstance
192//
193// Description: function add one more instance
194//
195//
196//
197// Parameters:
198//
199//
200// Returns: tEpKernel = errorcode
201//
202//
203// State:
204//
205//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700206tEplKernel EplErrorHandlerkAddInstance(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800207{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800208 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800209
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800210 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800211
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800212 // reset only event variable,
213 // all other instance members are reset by OD or may keep their current value
214 // d.k.: this is necessary for the cumulative counters, which shall not be reset
215 EplErrorHandlerkInstance_g.m_ulDllErrorEvents = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800216
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800217 // link counters to OD
218 // $$$ d.k. if OD resides in userspace, fetch pointer to shared memory,
219 // which shall have the same structure as the instance (needs to be declared globally).
220 // Other idea: error counter shall belong to the process image
221 // (reset of counters by SDO write are a little bit tricky).
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800222
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800223 Ret =
224 EplErrorHandlerkLinkErrorCounter(&EplErrorHandlerkInstance_g.
225 m_CnLossSoc, 0x1C0B);
226 if (Ret != kEplSuccessful) {
227 goto Exit;
228 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800229
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800230 Ret =
231 EplErrorHandlerkLinkErrorCounter(&EplErrorHandlerkInstance_g.
232 m_CnLossPreq, 0x1C0D);
233 // ignore return code, because object 0x1C0D is conditional
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800234
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800235 Ret =
236 EplErrorHandlerkLinkErrorCounter(&EplErrorHandlerkInstance_g.
237 m_CnCrcErr, 0x1C0F);
238 if (Ret != kEplSuccessful) {
239 goto Exit;
240 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800241#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800242 Ret =
243 EplErrorHandlerkLinkErrorCounter(&EplErrorHandlerkInstance_g.
244 m_MnCrcErr, 0x1C00);
245 if (Ret != kEplSuccessful) {
246 goto Exit;
247 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800248
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800249 Ret =
250 EplErrorHandlerkLinkErrorCounter(&EplErrorHandlerkInstance_g.
251 m_MnCycTimeExceed, 0x1C02);
252 if (Ret != kEplSuccessful) {
253 goto Exit;
254 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800255
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800256 Ret =
257 EplErrorHandlerkLinkArray(EplErrorHandlerkInstance_g.
258 m_adwMnCnLossPresCumCnt,
259 tabentries(EplErrorHandlerkInstance_g.
260 m_adwMnCnLossPresCumCnt),
261 0x1C07);
262 if (Ret != kEplSuccessful) {
263 goto Exit;
264 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800265
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800266 Ret =
267 EplErrorHandlerkLinkArray(EplErrorHandlerkInstance_g.
268 m_adwMnCnLossPresThrCnt,
269 tabentries(EplErrorHandlerkInstance_g.
270 m_adwMnCnLossPresThrCnt),
271 0x1C08);
272 if (Ret != kEplSuccessful) {
273 goto Exit;
274 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800275
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800276 Ret =
277 EplErrorHandlerkLinkArray(EplErrorHandlerkInstance_g.
278 m_adwMnCnLossPresThreshold,
279 tabentries(EplErrorHandlerkInstance_g.
280 m_adwMnCnLossPresThreshold),
281 0x1C09);
282 if (Ret != kEplSuccessful) {
283 goto Exit;
284 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800285#endif
286
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800287 Exit:
288 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800289
290}
291
292//---------------------------------------------------------------------------
293//
294// Function: EplErrorHandlerkDelInstance
295//
296// Description: function delete instance an free the bufferstructure
297//
298//
299//
300// Parameters:
301//
302//
303// Returns: tEpKernel = errorcode
304//
305//
306// State:
307//
308//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700309tEplKernel EplErrorHandlerkDelInstance(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800310{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800311 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800312
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800313 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800314
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800315 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800316
317}
318
319//---------------------------------------------------------------------------
320//
321// Function: EplErrorHandlerkProcess
322//
323// Description: processes error events from DLL
324//
325//
326//
327// Parameters: pEvent_p = pointer to event-structur from buffer
328//
329//
330// Returns: tEpKernel = errorcode
331//
332//
333// State:
334//
335//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700336tEplKernel EplErrorHandlerkProcess(tEplEvent *pEvent_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800337{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800338 tEplKernel Ret;
339 unsigned long ulDllErrorEvents;
340 tEplEvent Event;
341 tEplNmtEvent NmtEvent;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800342
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800343 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800344
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800345 // check m_EventType
346 switch (pEvent_p->m_EventType) {
347 case kEplEventTypeDllError:
348 {
349 tEplErrorHandlerkEvent *pErrHandlerEvent =
350 (tEplErrorHandlerkEvent *) pEvent_p->m_pArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800351
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800352 ulDllErrorEvents = pErrHandlerEvent->m_ulDllErrorEvents;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800353
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800354 // check the several error events
355 if ((EplErrorHandlerkInstance_g.m_CnLossSoc.
356 m_dwThreshold > 0)
357 && ((ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_SOC) != 0)) { // loss of SoC event occured
358 // increment cumulative counter by 1
359 EplErrorHandlerkInstance_g.m_CnLossSoc.
360 m_dwCumulativeCnt++;
361 // increment threshold counter by 8
362 EplErrorHandlerkInstance_g.m_CnLossSoc.
363 m_dwThresholdCnt += 8;
364 if (EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThresholdCnt >= EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThreshold) { // threshold is reached
365 // $$$ d.k.: generate error history entry E_DLL_LOSS_SOC_TH
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800366
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800367 // post event to NMT state machine
368 NmtEvent = kEplNmtEventNmtCycleError;
369 Event.m_EventSink = kEplEventSinkNmtk;
370 Event.m_EventType =
371 kEplEventTypeNmtEvent;
372 Event.m_pArg = &NmtEvent;
373 Event.m_uiSize = sizeof(NmtEvent);
374 Ret = EplEventkPost(&Event);
375 }
376 EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
377 EPL_DLL_ERR_CN_LOSS_SOC;
378 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800379
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800380 if ((EplErrorHandlerkInstance_g.m_CnLossPreq.
381 m_dwThreshold > 0)
382 && ((ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_PREQ) != 0)) { // loss of PReq event occured
383 // increment cumulative counter by 1
384 EplErrorHandlerkInstance_g.m_CnLossPreq.
385 m_dwCumulativeCnt++;
386 // increment threshold counter by 8
387 EplErrorHandlerkInstance_g.m_CnLossPreq.
388 m_dwThresholdCnt += 8;
389 if (EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt >= EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThreshold) { // threshold is reached
390 // $$$ d.k.: generate error history entry E_DLL_LOSS_PREQ_TH
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800391
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800392 // post event to NMT state machine
393 NmtEvent = kEplNmtEventNmtCycleError;
394 Event.m_EventSink = kEplEventSinkNmtk;
395 Event.m_EventType =
396 kEplEventTypeNmtEvent;
397 Event.m_pArg = &NmtEvent;
398 Event.m_uiSize = sizeof(NmtEvent);
399 Ret = EplEventkPost(&Event);
400 }
401 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800402
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800403 if ((EplErrorHandlerkInstance_g.m_CnLossPreq.
404 m_dwThresholdCnt > 0)
405 && ((ulDllErrorEvents & EPL_DLL_ERR_CN_RECVD_PREQ) != 0)) { // PReq correctly received
406 // decrement threshold counter by 1
407 EplErrorHandlerkInstance_g.m_CnLossPreq.
408 m_dwThresholdCnt--;
409 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800410
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800411 if ((EplErrorHandlerkInstance_g.m_CnCrcErr.
412 m_dwThreshold > 0)
413 && ((ulDllErrorEvents & EPL_DLL_ERR_CN_CRC) != 0)) { // CRC error event occured
414 // increment cumulative counter by 1
415 EplErrorHandlerkInstance_g.m_CnCrcErr.
416 m_dwCumulativeCnt++;
417 // increment threshold counter by 8
418 EplErrorHandlerkInstance_g.m_CnCrcErr.
419 m_dwThresholdCnt += 8;
420 if (EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThresholdCnt >= EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThreshold) { // threshold is reached
421 // $$$ d.k.: generate error history entry E_DLL_CRC_TH
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800422
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800423 // post event to NMT state machine
424 NmtEvent = kEplNmtEventNmtCycleError;
425 Event.m_EventSink = kEplEventSinkNmtk;
426 Event.m_EventType =
427 kEplEventTypeNmtEvent;
428 Event.m_pArg = &NmtEvent;
429 Event.m_uiSize = sizeof(NmtEvent);
430 Ret = EplEventkPost(&Event);
431 }
432 EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
433 EPL_DLL_ERR_CN_CRC;
434 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800435
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800436 if ((ulDllErrorEvents & EPL_DLL_ERR_INVALID_FORMAT) != 0) { // invalid format error occured (only direct reaction)
437 // $$$ d.k.: generate error history entry E_DLL_INVALID_FORMAT
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800438#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800439 if (pErrHandlerEvent->m_NmtState >= kEplNmtMsNotActive) { // MN is active
440 if (pErrHandlerEvent->m_uiNodeId != 0) {
441 tEplHeartbeatEvent
442 HeartbeatEvent;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800443
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800444 // remove node from isochronous phase
445 Ret =
446 EplDllkDeleteNode
447 (pErrHandlerEvent->
448 m_uiNodeId);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800449
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800450 // inform NmtMnu module about state change, which shall send NMT command ResetNode to this CN
451 HeartbeatEvent.m_uiNodeId =
452 pErrHandlerEvent->
453 m_uiNodeId;
454 HeartbeatEvent.m_NmtState =
455 kEplNmtCsNotActive;
456 HeartbeatEvent.m_wErrorCode =
457 EPL_E_DLL_INVALID_FORMAT;
458 Event.m_EventSink =
459 kEplEventSinkNmtMnu;
460 Event.m_EventType =
461 kEplEventTypeHeartbeat;
462 Event.m_uiSize =
463 sizeof(HeartbeatEvent);
464 Event.m_pArg = &HeartbeatEvent;
465 Ret = EplEventkPost(&Event);
466 }
467 // $$$ and else should lead to InternComError
468 } else
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800469#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800470 { // CN is active
471 // post event to NMT state machine
472 NmtEvent = kEplNmtEventInternComError;
473 Event.m_EventSink = kEplEventSinkNmtk;
474 Event.m_EventType =
475 kEplEventTypeNmtEvent;
476 Event.m_pArg = &NmtEvent;
477 Event.m_uiSize = sizeof(NmtEvent);
478 Ret = EplEventkPost(&Event);
479 }
480 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800481#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800482 if ((EplErrorHandlerkInstance_g.m_MnCrcErr.
483 m_dwThreshold > 0)
484 && ((ulDllErrorEvents & EPL_DLL_ERR_MN_CRC) != 0)) { // CRC error event occured
485 // increment cumulative counter by 1
486 EplErrorHandlerkInstance_g.m_MnCrcErr.
487 m_dwCumulativeCnt++;
488 // increment threshold counter by 8
489 EplErrorHandlerkInstance_g.m_MnCrcErr.
490 m_dwThresholdCnt += 8;
491 if (EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThresholdCnt >= EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThreshold) { // threshold is reached
492 // $$$ d.k.: generate error history entry E_DLL_CRC_TH
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800493
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800494 // post event to NMT state machine
495 NmtEvent = kEplNmtEventNmtCycleError;
496 Event.m_EventSink = kEplEventSinkNmtk;
497 Event.m_EventType =
498 kEplEventTypeNmtEvent;
499 Event.m_pArg = &NmtEvent;
500 Event.m_uiSize = sizeof(NmtEvent);
501 Ret = EplEventkPost(&Event);
502 }
503 EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
504 EPL_DLL_ERR_MN_CRC;
505 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800506
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800507 if ((EplErrorHandlerkInstance_g.m_MnCycTimeExceed.
508 m_dwThreshold > 0)
509 && ((ulDllErrorEvents & EPL_DLL_ERR_MN_CYCTIMEEXCEED) != 0)) { // cycle time exceeded event occured
510 // increment cumulative counter by 1
511 EplErrorHandlerkInstance_g.m_MnCycTimeExceed.
512 m_dwCumulativeCnt++;
513 // increment threshold counter by 8
514 EplErrorHandlerkInstance_g.m_MnCycTimeExceed.
515 m_dwThresholdCnt += 8;
516 if (EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThresholdCnt >= EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThreshold) { // threshold is reached
517 // $$$ d.k.: generate error history entry E_DLL_CYCLE_EXCEED_TH
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800518
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800519 // post event to NMT state machine
520 NmtEvent = kEplNmtEventNmtCycleError;
521 Event.m_EventSink = kEplEventSinkNmtk;
522 Event.m_EventType =
523 kEplEventTypeNmtEvent;
524 Event.m_pArg = &NmtEvent;
525 Event.m_uiSize = sizeof(NmtEvent);
526 Ret = EplEventkPost(&Event);
527 }
528 // $$$ d.k.: else generate error history entry E_DLL_CYCLE_EXCEED
529 EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
530 EPL_DLL_ERR_MN_CYCTIMEEXCEED;
531 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800532
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800533 if ((ulDllErrorEvents & EPL_DLL_ERR_MN_CN_LOSS_PRES) != 0) { // CN loss PRes event occured
534 unsigned int uiNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800535
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800536 uiNodeId = pErrHandlerEvent->m_uiNodeId - 1;
537 if ((uiNodeId <
538 tabentries(EplErrorHandlerkInstance_g.
539 m_adwMnCnLossPresCumCnt))
540 && (EplErrorHandlerkInstance_g.
541 m_adwMnCnLossPresThreshold[uiNodeId] >
542 0)) {
543 // increment cumulative counter by 1
544 EplErrorHandlerkInstance_g.
545 m_adwMnCnLossPresCumCnt[uiNodeId]++;
546 // increment threshold counter by 8
547 EplErrorHandlerkInstance_g.
548 m_adwMnCnLossPresThrCnt[uiNodeId] +=
549 8;
550 if (EplErrorHandlerkInstance_g.
551 m_adwMnCnLossPresThrCnt[uiNodeId]
552 >= EplErrorHandlerkInstance_g.m_adwMnCnLossPresThreshold[uiNodeId]) { // threshold is reached
553 tEplHeartbeatEvent
554 HeartbeatEvent;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800555
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800556 // $$$ d.k.: generate error history entry E_DLL_LOSS_PRES_TH
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800557
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800558 // remove node from isochronous phase
559 Ret =
560 EplDllkDeleteNode
561 (pErrHandlerEvent->
562 m_uiNodeId);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800563
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800564 // inform NmtMnu module about state change, which shall send NMT command ResetNode to this CN
565 HeartbeatEvent.m_uiNodeId =
566 pErrHandlerEvent->
567 m_uiNodeId;
568 HeartbeatEvent.m_NmtState =
569 kEplNmtCsNotActive;
570 HeartbeatEvent.m_wErrorCode =
571 EPL_E_DLL_LOSS_PRES_TH;
572 Event.m_EventSink =
573 kEplEventSinkNmtMnu;
574 Event.m_EventType =
575 kEplEventTypeHeartbeat;
576 Event.m_uiSize =
577 sizeof(HeartbeatEvent);
578 Event.m_pArg = &HeartbeatEvent;
579 Ret = EplEventkPost(&Event);
580 }
581 EplErrorHandlerkInstance_g.
582 m_afMnCnLossPresEvent[uiNodeId] =
583 TRUE;
584 }
585 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800586#endif
587
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800588 break;
589 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800590
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800591 // NMT event
592 case kEplEventTypeNmtEvent:
593 {
594 if ((*(tEplNmtEvent *) pEvent_p->m_pArg) == kEplNmtEventDllCeSoa) { // SoA event of CN -> decrement threshold counters
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800595
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800596 if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_SOC) == 0) { // decrement loss of SoC threshold counter, because it didn't occur last cycle
597 if (EplErrorHandlerkInstance_g.
598 m_CnLossSoc.m_dwThresholdCnt > 0) {
599 EplErrorHandlerkInstance_g.
600 m_CnLossSoc.
601 m_dwThresholdCnt--;
602 }
603 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800604
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800605 if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_CN_CRC) == 0) { // decrement CRC threshold counter, because it didn't occur last cycle
606 if (EplErrorHandlerkInstance_g.
607 m_CnCrcErr.m_dwThresholdCnt > 0) {
608 EplErrorHandlerkInstance_g.
609 m_CnCrcErr.
610 m_dwThresholdCnt--;
611 }
612 }
613 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800614#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800615 else if ((*(tEplNmtEvent *) pEvent_p->m_pArg) == kEplNmtEventDllMeSoaSent) { // SoA event of MN -> decrement threshold counters
616 tEplDllkNodeInfo *pIntNodeInfo;
617 unsigned int uiNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800618
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800619 Ret = EplDllkGetFirstNodeInfo(&pIntNodeInfo);
620 if (Ret != kEplSuccessful) {
621 break;
622 }
623 // iterate through node info structure list
624 while (pIntNodeInfo != NULL) {
625 uiNodeId = pIntNodeInfo->m_uiNodeId - 1;
626 if (uiNodeId <
627 tabentries
628 (EplErrorHandlerkInstance_g.
629 m_adwMnCnLossPresCumCnt)) {
630 if (EplErrorHandlerkInstance_g.
631 m_afMnCnLossPresEvent
632 [uiNodeId] == FALSE) {
633 if (EplErrorHandlerkInstance_g.m_adwMnCnLossPresThrCnt[uiNodeId] > 0) {
634 EplErrorHandlerkInstance_g.
635 m_adwMnCnLossPresThrCnt
636 [uiNodeId]--;
637 }
638 } else {
639 EplErrorHandlerkInstance_g.
640 m_afMnCnLossPresEvent
641 [uiNodeId] = FALSE;
642 }
643 }
644 pIntNodeInfo =
645 pIntNodeInfo->m_pNextNodeInfo;
646 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800647
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800648 if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_MN_CRC) == 0) { // decrement CRC threshold counter, because it didn't occur last cycle
649 if (EplErrorHandlerkInstance_g.
650 m_MnCrcErr.m_dwThresholdCnt > 0) {
651 EplErrorHandlerkInstance_g.
652 m_MnCrcErr.
653 m_dwThresholdCnt--;
654 }
655 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800656
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800657 if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_MN_CYCTIMEEXCEED) == 0) { // decrement cycle exceed threshold counter, because it didn't occur last cycle
658 if (EplErrorHandlerkInstance_g.
659 m_MnCycTimeExceed.m_dwThresholdCnt >
660 0) {
661 EplErrorHandlerkInstance_g.
662 m_MnCycTimeExceed.
663 m_dwThresholdCnt--;
664 }
665 }
666 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800667#endif
668
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800669 // reset error events
670 EplErrorHandlerkInstance_g.m_ulDllErrorEvents = 0L;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800671
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800672 break;
673 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800674
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800675 // unknown type
676 default:
677 {
678 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800679
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800680 } // end of switch(pEvent_p->m_EventType)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800681
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800682 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800683
684}
685
686//=========================================================================//
687// //
688// P R I V A T E F U N C T I O N S //
689// //
690//=========================================================================//
691
692//---------------------------------------------------------------------------
693//
694// Function: EplErrorHandlerkLinkErrorCounter
695//
696// Description: link specified error counter structure to OD entry
697//
698// Parameters: pErrorCounter_p = pointer to error counter structure
699// uiIndex_p = OD index
700//
701// Returns: tEplKernel = error code
702//
703//
704// State:
705//
706//---------------------------------------------------------------------------
707
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800708static tEplKernel EplErrorHandlerkLinkErrorCounter(tEplErrorHandlerkErrorCounter
709 * pErrorCounter_p,
710 unsigned int uiIndex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800711{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800712 tEplKernel Ret = kEplSuccessful;
713 tEplVarParam VarParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800714
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800715 VarParam.m_pData = &pErrorCounter_p->m_dwCumulativeCnt;
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700716 VarParam.m_Size = sizeof(u32);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800717 VarParam.m_uiIndex = uiIndex_p;
718 VarParam.m_uiSubindex = 0x01;
719 VarParam.m_ValidFlag = kVarValidAll;
720 Ret = EplObdDefineVar(&VarParam);
721 if (Ret != kEplSuccessful) {
722 goto Exit;
723 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800724
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800725 VarParam.m_pData = &pErrorCounter_p->m_dwThresholdCnt;
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700726 VarParam.m_Size = sizeof(u32);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800727 VarParam.m_uiIndex = uiIndex_p;
728 VarParam.m_uiSubindex = 0x02;
729 VarParam.m_ValidFlag = kVarValidAll;
730 Ret = EplObdDefineVar(&VarParam);
731 if (Ret != kEplSuccessful) {
732 goto Exit;
733 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800734
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800735 VarParam.m_pData = &pErrorCounter_p->m_dwThreshold;
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700736 VarParam.m_Size = sizeof(u32);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800737 VarParam.m_uiIndex = uiIndex_p;
738 VarParam.m_uiSubindex = 0x03;
739 VarParam.m_ValidFlag = kVarValidAll;
740 Ret = EplObdDefineVar(&VarParam);
741 if (Ret != kEplSuccessful) {
742 goto Exit;
743 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800744
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800745 Exit:
746 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800747}
748
749//---------------------------------------------------------------------------
750//
751// Function: EplErrorHandlerkLinkErrorCounter
752//
753// Description: link specified error counter structure to OD entry
754//
755// Parameters: pErrorCounter_p = pointer to error counter structure
756// uiIndex_p = OD index
757//
758// Returns: tEplKernel = error code
759//
760//
761// State:
762//
763//---------------------------------------------------------------------------
764
765#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700766static tEplKernel EplErrorHandlerkLinkArray(u32 * pdwValue_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800767 unsigned int uiValueCount_p,
768 unsigned int uiIndex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800769{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800770 tEplKernel Ret = kEplSuccessful;
771 tEplVarParam VarParam;
772 tEplObdSize EntrySize;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700773 u8 bIndexEntries;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800774
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800775 EntrySize = (tEplObdSize) sizeof(bIndexEntries);
776 Ret = EplObdReadEntry(uiIndex_p,
Greg Kroah-Hartmanbd3966d2009-03-23 11:37:22 -0700777 0x00, (void *)&bIndexEntries, &EntrySize);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800778
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800779 if ((Ret != kEplSuccessful) || (bIndexEntries == 0x00)) {
780 // Object doesn't exist or invalid entry number
781 Ret = kEplObdIndexNotExist;
782 goto Exit;
783 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800784
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800785 if (bIndexEntries < uiValueCount_p) {
786 uiValueCount_p = bIndexEntries;
787 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800788
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700789 VarParam.m_Size = sizeof(u32);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800790 VarParam.m_uiIndex = uiIndex_p;
791 VarParam.m_ValidFlag = kVarValidAll;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800792
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800793 for (VarParam.m_uiSubindex = 0x01;
794 VarParam.m_uiSubindex <= uiValueCount_p; VarParam.m_uiSubindex++) {
795 VarParam.m_pData = pdwValue_p;
796 Ret = EplObdDefineVar(&VarParam);
797 if (Ret != kEplSuccessful) {
798 goto Exit;
799 }
800 pdwValue_p++;
801 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800802
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800803 Exit:
804 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800805}
806#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
807
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800808#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
809
810// EOF