1 /* -------------------------------- Arctic Core ------------------------------
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
6 * This source code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by the
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * -------------------------------- Arctic Core ------------------------------*/
26 const WdgM_ConfigType *wdgMConfigPtr;
\r
27 static WdgM_SupervisedStatusType WdgM_GlobalSupervisionStatus = WDBG_ALIVE_OK;
\r
29 Std_ReturnType WdgM_UpdateAliveCounter (WdgM_SupervisedEntityIdType SEid)
\r
31 Wdgm_SupervisionType *supervisionPtr = &(wdgMConfigPtr->Wdgm_SupervisionPtr)[SEid];
\r
33 if (supervisionPtr->ActivationStatus == WDBG_SUPERVISION_ENABLED)
\r
35 supervisionPtr->AliveCounter++;
\r
40 Std_ReturnType WdgM_ActivateAliveSupervision (WdgM_SupervisedEntityIdType SEid)
\r
42 Wdgm_SupervisionType *supervisionPtr = &(wdgMConfigPtr->Wdgm_SupervisionPtr)[SEid];
\r
44 supervisionPtr->ActivationStatus = WDBG_SUPERVISION_ENABLED;
\r
49 Std_ReturnType WdgM_DeactivateAliveSupervision (WdgM_SupervisedEntityIdType SEid)
\r
51 Wdgm_SupervisionType *supervisionPtr = &(wdgMConfigPtr->Wdgm_SupervisionPtr)[SEid];
\r
53 supervisionPtr->ActivationStatus = WDBG_SUPERVISION_DISABLED;
\r
57 void WdgM_Init(const WdgM_ConfigType *ConfigPtr)
\r
59 WdgM_SupervisedEntityIdType SEid;
\r
60 Wdgm_SupervisionType *supervisionPtr;
\r
61 WdgM_SupervisedEntityType* supervisedEntityPtr;
\r
63 for (SEid = 0; SEid < WDBG_NBR_OF_ALIVE_SIGNALS; SEid++)
\r
65 supervisionPtr = &(ConfigPtr->Wdgm_SupervisionPtr)[SEid];
\r
66 supervisedEntityPtr = (WdgM_SupervisedEntityType*)&(ConfigPtr->WdgM_SupervisedEntityPtr)[SEid];
\r
67 supervisionPtr->ActivationStatus = supervisedEntityPtr->WdgM_ActivationStatus;
\r
69 wdgMConfigPtr = ConfigPtr;
\r
73 void WdgM_MainFunction_AliveSupervision (void)
\r
75 WdgM_SupervisedEntityIdType SEid;
\r
76 Wdgm_SupervisionType *supervisionPtr;
\r
77 const WdgM_SupervisedEntityType *entityPtr;
\r
78 WdgM_SupervisionCounterType aliveCalc, nSC, nAl, eai;
\r
79 WdgM_SupervisedStatusType maxLocal = WDBG_ALIVE_OK;
\r
80 static WdgM_SupervisionCounterType expiredSupervisionCycles = 0;
\r
82 for (SEid = 0; SEid < WDBG_NBR_OF_ALIVE_SIGNALS; SEid++)
\r
84 supervisionPtr = &(wdgMConfigPtr->Wdgm_SupervisionPtr)[SEid];
\r
85 entityPtr = &(wdgMConfigPtr->WdgM_SupervisedEntityPtr)[SEid];
\r
87 if (WDBG_SUPERVISION_ENABLED == supervisionPtr->ActivationStatus)
\r
89 supervisionPtr->SupervisionCycle++;
\r
90 /* Only perform supervision on the reference cycle. */
\r
91 if (supervisionPtr->SupervisionCycle == entityPtr->WdgM_SupervisionReferenceCycle)
\r
93 /* Alive algorithm. *
\r
94 * n (Al) - n(SC) + EAI == 0 */
\r
95 if (entityPtr->WdgM_ExpectedAliveIndications > entityPtr->WdgM_SupervisionReferenceCycle)
\r
98 eai = -entityPtr->WdgM_ExpectedAliveIndications + 1;
\r
104 eai = entityPtr->WdgM_SupervisionReferenceCycle - 1;
\r
106 nSC = supervisionPtr->SupervisionCycle;
\r
107 nAl = supervisionPtr->AliveCounter;
\r
108 aliveCalc = nAl - nSC + eai;
\r
110 if ((aliveCalc <= entityPtr->WdgM_MaxMargin) &&
\r
111 (aliveCalc >= -entityPtr->WdgM_MinMargin))
\r
113 /* Entity alive OK. */
\r
114 supervisionPtr->SupervisionStatus = WDBG_ALIVE_OK;
\r
118 /* Entity alive NOK. */
\r
119 supervisionPtr->SupervisionStatus = WDBG_ALIVE_FAILED;
\r
120 if (WDBG_ALIVE_FAILED > maxLocal)
\r
122 maxLocal = WDBG_ALIVE_FAILED;
\r
126 if (WDBG_ALIVE_FAILED == supervisionPtr->SupervisionStatus)
\r
128 if (supervisionPtr->NbrOfFailedRefCycles > entityPtr->WdgM_FailedSupervisionReferenceCycleTolerance)
\r
130 supervisionPtr->SupervisionStatus = WDBG_ALIVE_EXPIRED;
\r
131 if (WDBG_ALIVE_EXPIRED > maxLocal)
\r
133 maxLocal = WDBG_ALIVE_EXPIRED;
\r
138 supervisionPtr->NbrOfFailedRefCycles++;
\r
142 /* Reset counters. */
\r
143 supervisionPtr->SupervisionCycle = 0;
\r
144 supervisionPtr->AliveCounter = 0;
\r
149 /* Try to heal global status. */
\r
150 if (WDBG_ALIVE_EXPIRED != WdgM_GlobalSupervisionStatus)
\r
152 WdgM_GlobalSupervisionStatus = maxLocal;
\r
156 WdgM_GlobalSupervisionStatus = WDBG_ALIVE_EXPIRED;
\r
159 if (WDBG_ALIVE_EXPIRED == WdgM_GlobalSupervisionStatus)
\r
161 expiredSupervisionCycles++;
\r
164 if (expiredSupervisionCycles >= wdgMConfigPtr->WdgM_ExpiredSupervisionCycleTolerance)
\r
166 WdgM_GlobalSupervisionStatus = WDBG_ALIVE_STOPPED;
\r
170 boolean WdgM_IsAlive(void)
\r
173 if ( WDBG_ALIVE_STOPPED > WdgM_GlobalSupervisionStatus )
\r
183 void WdgM_MainFunction_Trigger (void)
\r
185 if ( WdgM_IsAlive() )
\r