CORDET Framework - C2 Implementation
CrFwBaseCmp.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include framework files */
21 #include "CrFwConstants.h"
23 #include "CrFwBaseCmp.h"
24 #include "CrFwInitProc.h"
25 #include "CrFwResetProc.h"
26 /* Include FW Profile files */
27 #include "FwSmConstants.h"
28 #include "FwSmDCreate.h"
29 #include "FwSmConfig.h"
30 #include "FwSmCore.h"
31 #include "FwPrConstants.h"
32 #include "FwPrDCreate.h"
33 #include "FwPrConfig.h"
34 #include "FwPrCore.h"
35 /* Include configuration files */
36 #include "CrFwCmpData.h"
37 
39 static FwSmDesc_t baseCmpSmDesc = NULL;
40 
46 static void RunCIP(FwSmDesc_t smDesc);
47 
53 static void RunCRP(FwSmDesc_t smDesc);
54 
60 static void StartCEP(FwSmDesc_t smDesc);
61 
67 static void ExecCEP(FwSmDesc_t smDesc);
68 
74 static void StopCEP(FwSmDesc_t smDesc);
75 
76 /*-----------------------------------------------------------------------------------------*/
77 FwSmDesc_t CrFwBaseCmpMake() {
78  FwSmCounterS1_t nOfStates = 3; /* Number of states */
79  FwSmCounterS1_t nOfChoicePseudoStates = 2; /* Number of choice pseudo-states */
80  FwSmCounterS1_t nOfTrans = 9; /* Number of transitions */
81  FwSmCounterS1_t nOfActions = 6; /* Number of actions */
82  FwSmCounterS1_t nOfGuards = 1; /* Number of guards */
83  FwSmCounterS1_t CPS_1 = 1; /* Identifier of first choice pseudo-state */
84  FwSmCounterS1_t CPS_2 = 2; /* Identifier of second choice pseudo-state */
85 
86  if (baseCmpSmDesc != NULL)
87  return baseCmpSmDesc;
88 
89  /* Create the base component state machine */
90  baseCmpSmDesc = FwSmCreate(nOfStates, nOfChoicePseudoStates, nOfTrans, nOfActions, nOfGuards);
91 
92  /* Configure the base component state machine */
93  FwSmAddState(baseCmpSmDesc, CR_FW_BASE_STATE_CREATED, 1, NULL, &RunCIP, NULL, NULL);
94  FwSmAddState(baseCmpSmDesc, CR_FW_BASE_STATE_INITIALIZED, 1, NULL, &RunCRP, NULL, NULL);
96  FwSmAddChoicePseudoState(baseCmpSmDesc, CPS_1, 2);
97  FwSmAddChoicePseudoState(baseCmpSmDesc, CPS_2, 2);
98  FwSmAddTransIpsToSta(baseCmpSmDesc, CR_FW_BASE_STATE_CREATED, NULL);
99  FwSmAddTransStaToCps(baseCmpSmDesc, CR_FW_BASE_TR_INIT, CR_FW_BASE_STATE_CREATED, CPS_1, NULL, NULL);
100  FwSmAddTransCpsToSta(baseCmpSmDesc, CPS_1, CR_FW_BASE_STATE_INITIALIZED, NULL, &CrFwIsSmOutcomeOne);
101  FwSmAddTransCpsToSta(baseCmpSmDesc, CPS_1, CR_FW_BASE_STATE_CREATED, NULL, NULL); /* Else Transition */
102  FwSmAddTransStaToCps(baseCmpSmDesc, CR_FW_BASE_TR_RESET, CR_FW_BASE_STATE_INITIALIZED, CPS_2, NULL, NULL);
103  FwSmAddTransCpsToSta(baseCmpSmDesc, CPS_2, CR_FW_BASE_STATE_CONFIGURED, NULL, &CrFwIsSmOutcomeOne);
104  FwSmAddTransCpsToSta(baseCmpSmDesc, CPS_2, CR_FW_BASE_STATE_INITIALIZED, NULL, NULL); /* Else Transition */
105  FwSmAddTransStaToCps(baseCmpSmDesc, CR_FW_BASE_TR_RESET, CR_FW_BASE_STATE_CONFIGURED, CPS_2, &RunCRP, NULL);
107 
108  return baseCmpSmDesc;
109 }
110 
111 /*-----------------------------------------------------------------------------------------*/
112 void CrFwCmpInit(FwSmDesc_t smDesc) {
113  FwSmMakeTrans(smDesc, CR_FW_BASE_TR_INIT);
114 }
115 
116 /*-----------------------------------------------------------------------------------------*/
117 void CrFwCmpReset(FwSmDesc_t smDesc) {
118  FwSmMakeTrans(smDesc, CR_FW_BASE_TR_RESET);
119 }
120 
121 /*-----------------------------------------------------------------------------------------*/
122 void CrFwCmpShutdown(FwSmDesc_t smDesc) {
123  FwSmMakeTrans(smDesc, CR_FW_BASE_TR_SHUTDOWN);
124 }
125 
126 /*-----------------------------------------------------------------------------------------*/
127 void CrFwCmpExecute(FwSmDesc_t smDesc) {
128  FwSmMakeTrans(smDesc, FW_TR_EXECUTE);
129 }
130 
131 /*-----------------------------------------------------------------------------------------*/
132 FwPrDesc_t CrFwCmpGetInitPr(FwSmDesc_t smDesc) {
133  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
134  return baseData->initProc;
135 }
136 
137 /*-----------------------------------------------------------------------------------------*/
138 FwPrDesc_t CrFwCmpGetResetPr(FwSmDesc_t smDesc) {
139  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
140  return baseData->resetProc;
141 }
142 
143 /*-----------------------------------------------------------------------------------------*/
144 FwPrDesc_t CrFwCmpGetExecPr(FwSmDesc_t smDesc) {
145  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
146  return baseData->execProc;
147 }
148 
149 /*-----------------------------------------------------------------------------------------*/
151  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
152  return baseData->instanceId;
153 }
154 
155 /*-----------------------------------------------------------------------------------------*/
156 CrFwTypeId_t CrFwCmpGetTypeId(FwSmDesc_t smDesc) {
157  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
158  return baseData->typeId;
159 }
160 
161 /*-----------------------------------------------------------------------------------------*/
162 CrFwBool_t CrFwCmpIsStarted(FwSmDesc_t smDesc) {
163  return FwSmIsStarted(smDesc);
164 }
165 
166 /*-----------------------------------------------------------------------------------------*/
167 CrFwBool_t CrFwCmpIsInCreated(FwSmDesc_t smDesc) {
168  return (FwSmGetCurState(smDesc) == CR_FW_BASE_STATE_CREATED);
169 }
170 
171 /*-----------------------------------------------------------------------------------------*/
172 CrFwBool_t CrFwCmpIsInInitialized(FwSmDesc_t smDesc) {
173  return (FwSmGetCurState(smDesc) == CR_FW_BASE_STATE_INITIALIZED);
174 }
175 
176 /*-----------------------------------------------------------------------------------------*/
177 CrFwBool_t CrFwCmpIsInConfigured(FwSmDesc_t smDesc) {
178  return (FwSmGetCurState(smDesc) == CR_FW_BASE_STATE_CONFIGURED);
179 }
180 
181 /*-----------------------------------------------------------------------------------------*/
182 static void RunCIP(FwSmDesc_t smDesc) {
183  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
184  FwPrRun(baseData->initProc);
185  return;
186 }
187 
188 /*-----------------------------------------------------------------------------------------*/
189 static void RunCRP(FwSmDesc_t smDesc) {
190  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
191  FwPrRun(baseData->resetProc);
192  return;
193 }
194 
195 /*-----------------------------------------------------------------------------------------*/
196 static void StartCEP(FwSmDesc_t smDesc) {
197  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
198  FwPrStart(baseData->execProc);
199  return;
200 }
201 
202 /*-----------------------------------------------------------------------------------------*/
203 static void StopCEP(FwSmDesc_t smDesc) {
204  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
205  FwPrStop(baseData->execProc);
206  return;
207 }
208 
209 /*-----------------------------------------------------------------------------------------*/
210 static void ExecCEP(FwSmDesc_t smDesc) {
211  CrFwCmpData_t* baseData = (CrFwCmpData_t*)FwSmGetData(smDesc);
212  FwPrExecute(baseData->execProc);
213  return;
214 }
215 
216 /*-----------------------------------------------------------------------------------------*/
217 void CrFwBaseCmpDefShutdownAction(FwSmDesc_t smDesc) {
218  CRFW_UNUSED(smDesc);
219  return;
220 }
221 
222 
223 
CrFwInstanceId_t CrFwCmpGetInstanceId(FwSmDesc_t smDesc)
Return the instance identifier of the argument component.
Definition: CrFwBaseCmp.c:150
CrFwBool_t CrFwCmpIsStarted(FwSmDesc_t smDesc)
Return true if the state machine of the argument component has been started.
Definition: CrFwBaseCmp.c:162
FwPrDesc_t CrFwCmpGetResetPr(FwSmDesc_t smDesc)
Return the descriptor of the Reset Procedure of the argument component.
Definition: CrFwBaseCmp.c:138
FwPrDesc_t CrFwCmpGetExecPr(FwSmDesc_t smDesc)
Return the descriptor of the Execution Procedure of the argument component.
Definition: CrFwBaseCmp.c:144
void CrFwCmpInit(FwSmDesc_t smDesc)
Initialize a framework component.
Definition: CrFwBaseCmp.c:112
CrFwBool_t CrFwCmpIsInInitialized(FwSmDesc_t smDesc)
Return true if the argument component is in state INITIALIZED.
Definition: CrFwBaseCmp.c:172
void CrFwCmpShutdown(FwSmDesc_t smDesc)
Shutdown a framework component.
Definition: CrFwBaseCmp.c:122
void CrFwBaseCmpDefShutdownAction(FwSmDesc_t smDesc)
Function which performs the Shutdown Action for the Base State Machine.
Definition: CrFwBaseCmp.c:217
CrFwBool_t CrFwCmpIsInConfigured(FwSmDesc_t smDesc)
Return true if the argument component is in state CONFIGURED.
Definition: CrFwBaseCmp.c:177
void CrFwCmpReset(FwSmDesc_t smDesc)
Reset a framework component.
Definition: CrFwBaseCmp.c:117
CrFwBool_t CrFwCmpIsInCreated(FwSmDesc_t smDesc)
Return true if the argument component is in state CREATED.
Definition: CrFwBaseCmp.c:167
FwPrDesc_t CrFwCmpGetInitPr(FwSmDesc_t smDesc)
Return the descriptor of the Initialization Procedure of the argument component.
Definition: CrFwBaseCmp.c:132
static void RunCIP(FwSmDesc_t smDesc)
Function which runs the Component Initialization Procedure.
Definition: CrFwBaseCmp.c:182
static void StartCEP(FwSmDesc_t smDesc)
Function which starts the Component Execution Procedure.
Definition: CrFwBaseCmp.c:196
void CrFwCmpExecute(FwSmDesc_t smDesc)
Execute a framework component.
Definition: CrFwBaseCmp.c:127
static void ExecCEP(FwSmDesc_t smDesc)
Function which executes the Component Execution Procedure.
Definition: CrFwBaseCmp.c:210
static FwSmDesc_t baseCmpSmDesc
The singleton instance of the Base State Machine.
Definition: CrFwBaseCmp.c:39
static void StopCEP(FwSmDesc_t smDesc)
Function which stops the Component Execution Procedure.
Definition: CrFwBaseCmp.c:203
static void RunCRP(FwSmDesc_t smDesc)
Function which runs the Component Reset Procedure.
Definition: CrFwBaseCmp.c:189
FwSmDesc_t CrFwBaseCmpMake()
Retrieve the singleton instance of the Base State Machine.
Definition: CrFwBaseCmp.c:77
CrFwTypeId_t CrFwCmpGetTypeId(FwSmDesc_t smDesc)
Return the type identifier of the argument component.
Definition: CrFwBaseCmp.c:156
Definition of Base Component.
Definition of the Framework Component Data (FCD) Type.
Header file to define all invariant publicly available constants and types for the CORDET Framework.
#define CRFW_UNUSED(x)
A macro that can be used to specify that a function parameter is not used.
Definition: CrFwConstants.h:29
#define CR_FW_BASE_TR_INIT
Identifier for transition command "Init" in the Base State Machine.
#define CR_FW_BASE_STATE_INITIALIZED
State identifier for state INITIALIZED in the Base State Machine.
#define CR_FW_BASE_STATE_CREATED
State identifier for state CREATED in the Base State Machine.
#define CR_FW_BASE_TR_RESET
Identifier for transition command "Reset" in the Base State Machine.
#define CR_FW_BASE_TR_SHUTDOWN
Identifier for transition command "Shutdown" in the Base State Machine.
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
#define CR_FW_BASE_STATE_CONFIGURED
State identifier for state CONFIGURED in the Base State Machine.
Component Initialization Procedure (CIP) for the Base Component.
Component Reset Procedure (CRP) for the Base Component.
unsigned short int CrFwTypeId_t
Type used for the identifier of a component type.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
FwSmBool_t CrFwIsSmOutcomeOne(FwSmDesc_t smDesc)
Convenience function to check whether the outcome of the last check or action is equal to 1 ("true").
Definition of the utility functions for the CORDET Framework.
Type for the Framework Component Data (FCD).
Definition: CrFwCmpData.h:79
FwPrDesc_t initProc
The Component Initialization Procedure (CIP) (see CrFwInitProc.h).
Definition: CrFwCmpData.h:95
CrFwInstanceId_t instanceId
The instance identifier of the framework component.
Definition: CrFwCmpData.h:81
FwPrDesc_t resetProc
The Component Reset Procedure (CRP) (see CrFwResetProc.h).
Definition: CrFwCmpData.h:97
FwPrDesc_t execProc
The Component Execution Procedure (CEP) (see CrFwBaseCmp.h).
Definition: CrFwCmpData.h:99
CrFwTypeId_t typeId
The type identifier of the framework component.
Definition: CrFwCmpData.h:83
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved