FW Profile - C1 Implementation
FwDaMain.c
Go to the documentation of this file.
1 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include "FwSmConstants.h"
18 #include "FwSmCore.h"
19 #include "FwSmConfig.h"
20 #include "FwPrConstants.h"
21 #include "FwPrCore.h"
22 #include "FwPrConfig.h"
23 #include "FwDaHwDev.h"
24 #include "FwDaFDCheck.h"
25 #include "FwDaCurCheck.h"
26 #include "FwDaCurRecAction.h"
27 #include "FwDaTempCheck.h"
28 #include "FwDaTempRecAction.h"
29 #include "FwDaDeltaCheck.h"
30 
32 #define N_CYCLE 400
33 
59 int main() {
60  int i;
61  FwSmDesc_t hwDevSm = GetHwDevSm(); /* The HW Device State Machine */
62  FwSmDesc_t tempCheck = GetTempCheckSm(); /* The Temperature FD Check State Machine */
63  FwSmDesc_t curCheck = GetCurCheckSm(); /* The Current FD Check State Machine */
64  FwSmDesc_t deltaCheck = GetDeltaCheckSm(); /* The Delta FD Check State Machine */
65  FwPrDesc_t curRecAction = GetCurRecActionPr(); /* The Current Recovery Action Procedure */
66  FwPrDesc_t tempRecAction = GetTempRecActionPr(); /* The Temperature Recovery Action Procedure */
67 
68  /* Check configuration of all state machines */
69  if (FwSmCheckRec(hwDevSm) != smSuccess)
70  return EXIT_FAILURE;
71  if (FwSmCheckRec(tempCheck) != smSuccess)
72  return EXIT_FAILURE;
73  if (FwSmCheckRec(curCheck) != smSuccess)
74  return EXIT_FAILURE;
75  if (FwSmCheckRec(deltaCheck) != smSuccess)
76  return EXIT_FAILURE;
77 
78  /* Check configuration of all procedures */
79  if (FwPrCheck(curRecAction) != prSuccess)
80  return EXIT_FAILURE;
81  if (FwPrCheck(tempRecAction) != prSuccess)
82  return EXIT_FAILURE;
83 
84  /* Start all state machines */
85  FwSmStart(hwDevSm);
86  FwSmStart(tempCheck);
87  FwSmStart(curCheck);
88  FwSmStart(deltaCheck);
89 
90  /* Switch on the Hardware Device (HW Device SM enters STANDBY Mode) */
91  FwSmMakeTrans(hwDevSm, TR_HW_DEV_ON);
92 
93  /* Command the Hardware Device into its operational state */
94  FwSmMakeTrans(hwDevSm, TR_HW_DEV_OPER);
95 
96  /* Enable all the FD Checks */
99  FwSmMakeTrans(deltaCheck, TR_FD_CHECK_ENABLE);
100 
101  for (i=0; i<N_CYCLE; i++) {
102  FwSmExecute(hwDevSm); /* Execute HW Device State Machine */
103  printf("\nTemp = %3.0f, Current = %3.2f", GetHwDevTemp(), GetHwDevCur());
104 
105  /* Execute the three FD Check State Machines */
106  FwSmExecute(tempCheck);
107  FwSmExecute(curCheck);
108  FwSmExecute(deltaCheck);
109 
110  /* Execute the Recovery Action Procedures */
111  FwPrExecute(curRecAction);
112  FwPrExecute(tempRecAction);
113 
114  if (FwSmGetCurState(hwDevSm) == HW_DEV_OFF) {
115  /* Stop any recovery actions which may still be running */
116  FwPrStop(curRecAction);
117  FwPrStop(tempRecAction);
118  printf("\nStarting again after a failure has been detected and handled ...");
119  /* Switch On HW Device State Machine */
120  FwSmMakeTrans(hwDevSm, TR_HW_DEV_ON);
121  FwSmMakeTrans(hwDevSm, TR_HW_DEV_OPER);
122  /* Reset the three FD Check State Machines */
123  FwSmMakeTrans(tempCheck, TR_FD_CHECK_RESET);
124  FwSmMakeTrans(curCheck, TR_FD_CHECK_RESET);
125  FwSmMakeTrans(deltaCheck, TR_FD_CHECK_RESET);
126  }
127  }
128 
129  printf("\n");
130  return EXIT_SUCCESS;
131 }
#define TR_FD_CHECK_ENABLE
Name of the transition to enable a FD Check.
Definition: FwDaFDCheck.h:75
Declaration of the configuration interface for a FW Procedure.
Declaration of the execution interface for a FW State Machine.
float GetHwDevTemp()
This function returns the temperature of the Hardware Device.
Definition: FwDaHwDev.c:124
FwSmDesc_t GetCurCheckSm()
Retrieve the descriptor of the Current FD Check State Machine.
Definition: FwDaCurCheck.c:39
Definition of the Current Failure Detection (FD) Check.
Definition of the Temperature Failure Recovery Action (RA).
#define TR_FD_CHECK_RESET
Name of the transition to reset a FD Check.
Definition: FwDaFDCheck.h:79
Header file to define all constants and types for the procedure module of the FW Profile.
Declaration of the configuration interface for a FW State Machine.
Definition of the interface to access the Hardware Device.
void FwPrStop(FwPrDesc_t prDesc)
Stop a procedure.
Definition: FwPrCore.c:38
void FwSmExecute(FwSmDesc_t smDesc)
Convenience method to execute a state machine.
Definition: FwSmCore.c:142
Definition of the Current Failure Recovery Action (RA).
Definition of the Delta Failure Detection (FD) Check.
FwSmErrCode_t FwSmCheckRec(FwSmDesc_t smDesc)
Recursively check the configuration of a state machine and all its embedded state machines...
Definition: FwSmConfig.c:438
FwSmDesc_t GetDeltaCheckSm()
Retrieve the descriptor of the Delta FD Check State Machine.
#define N_CYCLE
Number of cycles executed by the Demo Application.
Definition: FwDaMain.c:32
Header file to define all constants and types for the state machine module of the FW Profile...
#define HW_DEV_OFF
Name of the OFF state in the HW Device State Machine.
Definition: FwDaHwDev.h:31
#define TR_HW_DEV_OPER
Name of the transition from STANDBY to OPERATIONAL in the HW Device State Machine.
Definition: FwDaHwDev.h:42
Definition of the Temperature Failure Detection (FD) Check.
void FwSmStart(FwSmDesc_t smDesc)
Start a state machine.
Definition: FwSmCore.c:52
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
Return codes of a function which has completed execution without errors.
Definition: FwPrConstants.h:85
void FwPrExecute(FwPrDesc_t prDesc)
Execute a procedure.
Definition: FwPrCore.c:43
FwSmCounterS1_t FwSmGetCurState(FwSmDesc_t smDesc)
Return the identifier of the current state in a state machine (or zero if the state machine is stoppe...
Definition: FwSmCore.c:222
Structure representing a procedure descriptor.
Definition: FwPrPrivate.h:254
FwSmDesc_t GetTempCheckSm()
Retrieve the descriptor of the Temperature FD Check State Machine.
Definition: FwDaTempCheck.c:38
#define TR_HW_DEV_ON
Name of the transition from OFF to ON in the HW Device State Machine.
Definition: FwDaHwDev.h:38
Definition of the Failure Detection (FD) Check State Machine.
int main()
Main program for the demo application.
Definition: FwDaMain.c:59
FwSmDesc_t GetHwDevSm()
Retrieve the descriptor of the Hardware Device State Machine.
Definition: FwDaHwDev.c:92
FwPrDesc_t GetTempRecActionPr()
Retrieve the descriptor of the Temperature Recovery Action Procedure.
FwPrErrCode_t FwPrCheck(FwPrDesc_t prDesc)
Check the correctness and completeness of the configuration of a procedure descriptor.
Definition: FwPrConfig.c:341
FwPrDesc_t GetCurRecActionPr()
Retrieve the descriptor of the Current Recovery Action Procedure.
Return codes of a function which has completed execution without errors.
Definition: FwSmConstants.h:86
Declaration of the execution interface for a FW Procedure.
P&P Software GmbH, Copyright 2011, All Rights Reserved