CORDET Framework - C2 Implementation
CrFwAppSm.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include framework files */
21 #include "CrFwConstants.h"
23 #include "CrFwAppSm.h"
24 #include "CrFwAppStartUpProc.h"
25 #include "CrFwAppResetProc.h"
26 #include "CrFwAppShutdownProc.h"
27 /* Include FW Profile files */
28 #include "FwSmConstants.h"
29 #include "FwSmDCreate.h"
30 #include "FwSmConfig.h"
31 #include "FwSmCore.h"
32 #include "FwPrConstants.h"
33 #include "FwPrDCreate.h"
34 #include "FwPrConfig.h"
35 #include "FwPrCore.h"
36 /* Include FW Profile files */
37 #include "CrFwAppSmUserPar.h"
38 
40 #define CR_FW_APP_STATE_START_UP 1
41 
43 #define CR_FW_APP_STATE_NORMAL 2
44 
46 #define CR_FW_APP_STATE_RESET 3
47 
49 #define CR_FW_APP_STATE_SHUTDOWN 4
50 
52 #define CR_FW_APP_TR_RESET CR_FW_APP_TYPE*CR_FW_MAX_NOF_TRANS_CMDS+0
53 
55 #define CR_FW_APP_TR_SHUTDOWN CR_FW_APP_TYPE*CR_FW_MAX_NOF_TRANS_CMDS+1
56 
58 static FwSmDesc_t appSmDesc = NULL;
59 
65 static void StartAppStartUpPr(FwSmDesc_t smDesc);
66 
72 static void StartAppResetPr(FwSmDesc_t smDesc);
73 
79 static void StartAppShutdownPr(FwSmDesc_t smDesc);
80 
87 static FwSmBool_t IsStartUpPrTerminated(FwSmDesc_t smDesc);
88 
95 static FwSmBool_t IsResetPrTerminated(FwSmDesc_t smDesc);
96 
103 static FwSmBool_t IsShutdownPrTerminated(FwSmDesc_t smDesc);
104 
105 /*-----------------------------------------------------------------------------------------*/
106 FwSmDesc_t CrFwAppSmMake() {
107  FwSmCounterS1_t nOfStates = 4; /* Number of states */
108  FwSmCounterS1_t nOfChoicePseudoStates = 0; /* Number of choice pseudo-states */
109  FwSmCounterS1_t nOfTrans = 6; /* Number of transitions */
110  FwSmCounterS1_t nOfActions = 3; /* Number of actions */
111  FwSmCounterS1_t nOfGuards = 3; /* Number of guards */
112 
113  if (appSmDesc != NULL)
114  return appSmDesc;
115 
116  /* Create the application state machine */
117  appSmDesc = FwSmCreate(nOfStates, nOfChoicePseudoStates, nOfTrans, nOfActions, nOfGuards);
118 
119  /* Configure the application state machine */
121  FwSmAddState(appSmDesc, CR_FW_APP_STATE_NORMAL, 2, NULL, NULL, NULL, CR_FW_APPSM_NORMAL_ESM);
122  FwSmAddState(appSmDesc, CR_FW_APP_STATE_RESET, 1, &StartAppResetPr, NULL, NULL, CR_FW_APPSM_RESET_ESM);
124  FwSmAddTransIpsToSta(appSmDesc, CR_FW_APP_STATE_START_UP, NULL);
125  FwSmAddTransStaToSta(appSmDesc, FW_TR_EXECUTE, CR_FW_APP_STATE_START_UP, CR_FW_APP_STATE_NORMAL,
126  NULL, &IsStartUpPrTerminated);
128  NULL, NULL);
129  FwSmAddTransStaToSta(appSmDesc, FW_TR_EXECUTE, CR_FW_APP_STATE_RESET, CR_FW_APP_STATE_NORMAL,
130  NULL, &IsResetPrTerminated);
132  NULL, NULL);
133  FwSmAddTransStaToFps(appSmDesc, FW_TR_EXECUTE, CR_FW_APP_STATE_SHUTDOWN, NULL, &IsShutdownPrTerminated);
134 
135  return appSmDesc;
136 }
137 
138 /*-----------------------------------------------------------------------------------------*/
140  FwSmStart(appSmDesc);
141 }
142 
143 /*-----------------------------------------------------------------------------------------*/
145  FwSmExecute(appSmDesc);
146 }
147 
148 /*-----------------------------------------------------------------------------------------*/
150  FwSmMakeTrans(appSmDesc, CR_FW_APP_TR_RESET);
151 }
152 
153 /*-----------------------------------------------------------------------------------------*/
155  FwSmMakeTrans(appSmDesc, CR_FW_APP_TR_SHUTDOWN);
156 }
157 
158 /*-----------------------------------------------------------------------------------------*/
160  return FwSmIsStarted(appSmDesc);
161 }
162 
163 /*-----------------------------------------------------------------------------------------*/
165  return (FwSmGetCurState(appSmDesc) == CR_FW_APP_STATE_START_UP);
166 }
167 
168 /*-----------------------------------------------------------------------------------------*/
170  return (FwSmGetCurState(appSmDesc) == CR_FW_APP_STATE_NORMAL);
171 }
172 
173 /*-----------------------------------------------------------------------------------------*/
175  return (FwSmGetCurState(appSmDesc) == CR_FW_APP_STATE_RESET);
176 }
177 
178 /*-----------------------------------------------------------------------------------------*/
180  return (FwSmGetCurState(appSmDesc) == CR_FW_APP_STATE_SHUTDOWN);
181 }
182 
183 /*-----------------------------------------------------------------------------------------*/
184 static void StartAppStartUpPr(FwSmDesc_t smDesc) {
185  (void)(smDesc);
186  FwPrStart(CrFwAppSmGetAppStartUpProc());
187  return;
188 }
189 
190 /*-----------------------------------------------------------------------------------------*/
191 static void StartAppResetPr(FwSmDesc_t smDesc) {
192  (void)(smDesc);
193  FwPrStart(CrFwAppSmGetAppResetProc());
194  return;
195 }
196 
197 /*-----------------------------------------------------------------------------------------*/
198 static void StartAppShutdownPr(FwSmDesc_t smDesc) {
199  (void)(smDesc);
200  FwPrStart(CrFwAppSmGetAppShutdownProc());
201  return;
202 }
203 
204 /*-----------------------------------------------------------------------------------------*/
205 static FwSmBool_t IsStartUpPrTerminated(FwSmDesc_t smDesc) {
206  (void)(smDesc);
207  return (FwPrIsStarted(CrFwAppSmGetAppStartUpProc()) == 0);
208 }
209 
210 /*-----------------------------------------------------------------------------------------*/
211 static FwSmBool_t IsResetPrTerminated(FwSmDesc_t smDesc) {
212  (void)(smDesc);
213  return (FwPrIsStarted(CrFwAppSmGetAppResetProc()) == 0);
214 }
215 
216 /*-----------------------------------------------------------------------------------------*/
217 static FwSmBool_t IsShutdownPrTerminated(FwSmDesc_t smDesc) {
218  (void)(smDesc);
219  return (FwPrIsStarted(CrFwAppSmGetAppShutdownProc()) == 0);
220 }
221 
222 /*-----------------------------------------------------------------------------------------*/
224  return FwSmGetEmbSm(appSmDesc, CR_FW_APP_STATE_START_UP);
225 }
226 
227 /*-----------------------------------------------------------------------------------------*/
228 FwSmDesc_t CrFwAppSmGetEsmNormal() {
229  return FwSmGetEmbSm(appSmDesc, CR_FW_APP_STATE_NORMAL);
230 }
231 
232 /*-----------------------------------------------------------------------------------------*/
233 FwSmDesc_t CrFwAppSmGetEsmReset() {
234  return FwSmGetEmbSm(appSmDesc, CR_FW_APP_STATE_RESET);
235 }
236 
237 /*-----------------------------------------------------------------------------------------*/
239  return FwSmGetEmbSm(appSmDesc, CR_FW_APP_STATE_SHUTDOWN);
240 }
Interface to the Application Reset Procedure.
FwPrDesc_t CrFwAppSmGetAppResetProc()
Retrieve the singleton instance of the Application Reset Procedure.
Interface to the Application Shutdown Procedure.
FwPrDesc_t CrFwAppSmGetAppShutdownProc()
Retrieve the singleton instance of the Application Shutdown Procedure.
FwSmDesc_t CrFwAppSmGetEsmReset()
Return the state machine embedded in state RESET (or NULL if no state machine is embedded in RESET).
Definition: CrFwAppSm.c:233
CrFwBool_t CrFwAppSmIsInNormal()
Return true if the Application State Machine is in state NORMAL.
Definition: CrFwAppSm.c:169
static FwSmBool_t IsShutdownPrTerminated(FwSmDesc_t smDesc)
Function which checks whether the Application Shutdown Procedure has terminated.
Definition: CrFwAppSm.c:217
#define CR_FW_APP_STATE_RESET
State identifier for state RESET in the application State Machine.
Definition: CrFwAppSm.c:46
FwSmDesc_t CrFwAppSmGetEsmShutdown()
Return the state machine embedded in state SHUTDOWN (or NULL if no state machine is embedded in SHUTD...
Definition: CrFwAppSm.c:238
void CrFwAppSmExecute()
Execute the Application State Machine.
Definition: CrFwAppSm.c:144
static void StartAppResetPr(FwSmDesc_t smDesc)
Function which starts the Application Reset Procedure.
Definition: CrFwAppSm.c:191
CrFwBool_t CrFwAppSmIsStarted()
Return true if the Application State Machine has been started.
Definition: CrFwAppSm.c:159
CrFwBool_t CrFwAppSmIsInStartUp()
Return true if the Application State Machine is in state START_UP.
Definition: CrFwAppSm.c:164
void CrFwAppSmReset()
Reset the Application State Machine.
Definition: CrFwAppSm.c:149
#define CR_FW_APP_STATE_START_UP
State identifier for state START_UP in the application State Machine.
Definition: CrFwAppSm.c:40
CrFwBool_t CrFwAppSmIsInReset()
Return true if the Application State Machine is in state RESET.
Definition: CrFwAppSm.c:174
static FwSmDesc_t appSmDesc
The singleton instance of the Application State Machine.
Definition: CrFwAppSm.c:58
FwSmDesc_t CrFwAppSmMake()
Retrieve the singleton instance of the Application State Machine.
Definition: CrFwAppSm.c:106
void CrFwAppSmStart()
Start the Application State Machine.
Definition: CrFwAppSm.c:139
static void StartAppStartUpPr(FwSmDesc_t smDesc)
Function which starts the Application Start-Up Procedure.
Definition: CrFwAppSm.c:184
void CrFwAppSmShutdown()
Shutdown the Application State Machine.
Definition: CrFwAppSm.c:154
CrFwBool_t CrFwAppSmIsInShutdown()
Return true if the Application State Machine is in state SHUTDOWN.
Definition: CrFwAppSm.c:179
#define CR_FW_APP_STATE_SHUTDOWN
State identifier for state SHUTDOWN in the application State Machine.
Definition: CrFwAppSm.c:49
FwSmDesc_t CrFwAppSmGetEsmStartUp()
Return the state machine embedded in state START-UP (or NULL if no state machine is embedded in START...
Definition: CrFwAppSm.c:223
static FwSmBool_t IsResetPrTerminated(FwSmDesc_t smDesc)
Function which checks whether the Application Reset Procedure has terminated.
Definition: CrFwAppSm.c:211
FwSmDesc_t CrFwAppSmGetEsmNormal()
Return the state machine embedded in state NORMAL (or NULL if no state machine is embedded in NORMAL)...
Definition: CrFwAppSm.c:228
#define CR_FW_APP_STATE_NORMAL
State identifier for state NORMAL in the application State Machine.
Definition: CrFwAppSm.c:43
#define CR_FW_APP_TR_SHUTDOWN
Identifier for transition command "Shutdown" in the Application State Machine.
Definition: CrFwAppSm.c:55
static void StartAppShutdownPr(FwSmDesc_t smDesc)
Function which starts the Application Shutdown Procedure.
Definition: CrFwAppSm.c:198
static FwSmBool_t IsStartUpPrTerminated(FwSmDesc_t smDesc)
Function which checks whether the Application Start-Up Procedure has terminated.
Definition: CrFwAppSm.c:205
#define CR_FW_APP_TR_RESET
Identifier for transition command "Reset" in the Application State Machine.
Definition: CrFwAppSm.c:52
Definition of Application State Machine.
User-modifiable parameters for the Application State Machine (see CrFwAppSm.h).
#define CR_FW_APPSM_RESET_ESM
The pointer to the state machine embedded in state RESET.
#define CR_FW_APPSM_NORMAL_ESM
The pointer to the state machine embedded in state NORMAL.
#define CR_FW_APPSM_SHUTDOWN_ESM
The pointer to the state machine embedded in state SHUTDOWN.
#define CR_FW_APPSM_STARTUP_ESM
The pointer to the state machine embedded in state START-UP.
Interface to the Application Start-Up Procedure.
FwPrDesc_t CrFwAppSmGetAppStartUpProc()
Retrieve the singleton instance of the Application Start-Up Procedure.
Header file to define all invariant publicly available constants and types for the CORDET Framework.
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
Definition of the utility functions for the CORDET Framework.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved