FW Profile - C1 Implementation
FwDaDeltaCheck.c
Go to the documentation of this file.
1 
10 #include <math.h>
11 #include <stdlib.h>
12 #include "FwDaFDCheck.h"
13 #include "FwDaHwDev.h"
14 #include "FwDaDeltaCheck.h"
15 #include "FwSmCore.h"
16 #include "FwSmConfig.h"
17 #include "FwSmDCreate.h"
18 
27 static float prevCurMeasurement = 0;
28 
37 static float prevTempMeasurement = 0;
38 
39 /* --------------------------------------------------------------------- */
52 static void DeltaAnomalyDetCheck(FwSmDesc_t smDesc);
53 
54 /* --------------------------------------------------------------------- */
61 static void DeltaRecoveryAction(FwSmDesc_t smDesc);
62 
63 /* --------------------------------------------------------------------- */
65  static FwSmDesc_t delFdcSm = NULL; /* Delta FD Check SM */
66  static FDCheckData_t smData;
67  FwSmDesc_t esmEnabled;
68 
69  if (delFdcSm != NULL) /* Current FD Check SM was already created */
70  return delFdcSm;
71 
72  /* Extend the generic FD Check State Machine */
73  delFdcSm = FwSmCreateDer(GetFailDetCheckSm());
74 
75  /* Retrieve the SM embedded in state ENABLED */
76  esmEnabled = FwSmGetEmbSm(delFdcSm, FD_CHECK_ENABLED);
77 
78  /* Load the data into the outer SM and into the SM embedded in state ENABLED */
80  smData.fdCheckId = deltaFDCheckId;
81  FwSmSetData(delFdcSm, &smData);
82  FwSmSetData(esmEnabled, &smData);
83 
84  /* Override the Anomaly Detection Check in the outer SM */
85  FwSmOverrideAction(delFdcSm, &DefAnomalyDetCheck, &DeltaAnomalyDetCheck);
86 
87  /* Override the Recovery Action in the SM embedded in state ENABLED */
88  FwSmOverrideAction(esmEnabled, &DefRecoveryAction, &DeltaRecoveryAction);
89 
90  return delFdcSm;
91 }
92 
93 /* --------------------------------------------------------------------- */
94 static void DeltaAnomalyDetCheck(FwSmDesc_t smDesc) {
95  FDCheckData_t* dfdCheckData = GetFDCheckData(smDesc);
96 
98 
99  /* Check whether the temperature measurement has "jumped" */
100  if (fabs(GetHwDevTemp()-prevTempMeasurement) > HW_DEV_TEMP_MAX_DELTA)
101  dfdCheckData->detectionCheckOutcome = anomalyDetected;
102  else
103  prevTempMeasurement = GetHwDevTemp();
104 
105  /* Check whether the current measurement has "jumped" */
106  if (fabs(GetHwDevCur()-prevCurMeasurement) > HW_DEV_CUR_MAX_DELTA)
107  dfdCheckData->detectionCheckOutcome = anomalyDetected;
108  else
109  prevCurMeasurement = GetHwDevCur();
110 
111  return;
112 }
113 
114 /* --------------------------------------------------------------------- */
115 static void DeltaRecoveryAction(FwSmDesc_t smDesc) {
117 }
118 
119 
FDCheckOutcome_t detectionCheckOutcome
The outcome of the last call to the Anomaly Detection Check.
Definition: FwDaFDCheck.h:126
FwSmDesc_t GetFailDetCheckSm()
Retrieve the descriptor of the FD Check State Machine.
Definition: FwDaFDCheck.c:176
Outcome generated when the Anomaly Detection Check detects an anomaly.
Definition: FwDaFDCheck.h:96
#define FD_CHECK_ENABLED
Name of the ENABLED state in the FD Check State Machine.
Definition: FwDaFDCheck.h:66
Declaration of the dynamical creation interface for a FW State Machine.
Declaration of the execution interface for a FW State Machine.
void DefRecoveryAction(FwSmDesc_t smDesc)
Default implementation of the Recovery Action.
Definition: FwDaFDCheck.c:171
float GetHwDevTemp()
This function returns the temperature of the Hardware Device.
Definition: FwDaHwDev.c:124
Identifier of the Delta FD Check (see FwDaDeltaCheck.h)
Definition: FwDaFDCheck.h:88
void DefAnomalyDetCheck(FwSmDesc_t smDesc)
Default implementation of the Anomaly Detection Check.
Definition: FwDaFDCheck.c:164
Outcome generated when the Anomaly Detection Check detects no anomaly.
Definition: FwDaFDCheck.h:94
#define HW_DEV_CUR_MAX_DELTA
Maximum nominal change in current absorbed by the Hardware Device.
Declaration of the configuration interface for a FW State Machine.
Definition of the interface to access the Hardware Device.
int cntLimit
The number of consecutive anomalies which must be detected in order for the FD Check to enter state F...
Definition: FwDaFDCheck.h:122
Definition of the Delta Failure Detection (FD) Check.
FwSmDesc_t GetDeltaCheckSm()
Retrieve the descriptor of the Delta FD Check State Machine.
FDCheckId_t fdCheckId
Identity of the FD Check to which this data structure is attached.
Definition: FwDaFDCheck.h:112
void FwSmOverrideAction(FwSmDesc_t smDesc, FwSmAction_t oldAction, FwSmAction_t newAction)
Override an action (either a state action or a transition action) in a derived state machine...
Definition: FwSmConfig.c:456
FwSmDesc_t FwSmCreateDer(FwSmDesc_t smDesc)
Create the descriptor of a derived state machine.
Definition: FwSmDCreate.c:137
#define TR_HW_DEV_OFF
Name of the transition from ON to OFF in the HW Device State Machine.
Definition: FwDaHwDev.h:40
Type for the data of an FD Check State Machine.
Definition: FwDaFDCheck.h:108
FwSmDesc_t FwSmGetEmbSm(FwSmDesc_t smDesc, FwSmCounterS1_t i)
Return the state machine embedded in the i-th state of the argument state machine.
Definition: FwSmCore.c:217
float GetHwDevCur()
This function returns the current absorbed by the Hardware Device.
Definition: FwDaHwDev.c:129
void FwSmMakeTrans(FwSmDesc_t smDesc, FwSmCounterU2_t transId)
Trigger a transition in a state machine.
Definition: FwSmCore.c:92
Structure representing a state machine descriptor.
Definition: FwSmPrivate.h:303
void FwSmSetData(FwSmDesc_t smDesc, void *smData)
Set the pointer to the state machine data in the state machine descriptor.
Definition: FwSmConfig.c:83
#define HW_DEV_DELTA_CNT_LIMIT
Counter limit for the Delta FD Check.
Definition of the Failure Detection (FD) Check State Machine.
FwSmDesc_t GetHwDevSm()
Retrieve the descriptor of the Hardware Device State Machine.
Definition: FwDaHwDev.c:92
FDCheckData_t * GetFDCheckData(FwSmDesc_t smDesc)
Get the pointer to the state machine data of an FD Check State Machine.
Definition: FwDaFDCheck.c:159
#define HW_DEV_TEMP_MAX_DELTA
Maximum nominal change in temperature of the Hardware Device.
P&P Software GmbH, Copyright 2011, All Rights Reserved