FW Profile - C1 Implementation
FwSmSCreate.c
Go to the documentation of this file.
1 
19 #include "FwSmSCreate.h"
20 #include "FwSmPrivate.h"
21 #include <stdlib.h>
22 
23 /* ----------------------------------------------------------------------------------------------------------------- */
24 void FwSmInit(FwSmDesc_t smDesc) {
25 
27  SmBaseDesc_t* smBase = smDesc->smBase;
28 
29  for (i = 0; i < smBase->nOfPStates; i++) {
30  smBase->pStates[i].outTransIndex = 0;
31  smDesc->esmDesc[i] = NULL;
32  }
33 
34  for (i = 0; i < smBase->nOfCStates; i++) {
35  smBase->cStates[i].outTransIndex = 0;
36  }
37 
38  for (i = 0; i < smBase->nOfTrans; i++) {
39  smBase->trans[i].iTrAction = -1;
40  }
41 
42  smDesc->smActions[0] = &SmDummyAction;
43  for (i = 1; i < smDesc->nOfActions; i++) {
44  smDesc->smActions[i] = NULL;
45  }
46 
47  smDesc->smGuards[0] = &SmDummyGuard;
48  for (i = 1; i < smDesc->nOfGuards; i++) {
49  smDesc->smGuards[i] = NULL;
50  }
51 }
52 
53 /* ----------------------------------------------------------------------------------------------------------------- */
54 void FwSmInitDer(FwSmDesc_t smDesc, FwSmDesc_t smDescBase) {
56  SmBaseDesc_t* smBase = smDescBase->smBase;
57 
58  if (smDesc->nOfActions != smDescBase->nOfActions) {
59  smDesc->errCode = smWrongNOfActions;
60  return;
61  }
62 
63  if (smDesc->nOfGuards != smDescBase->nOfGuards) {
64  smDesc->errCode = smWrongNOfGuards;
65  return;
66  }
67 
68  smDesc->smBase = smBase;
69 
70  /* This cycle will always be executed at least once because
71  * the number of actions (nOfActions) is always greater than
72  * zero (since all state machines have at least the dummy
73  * action which returns without doing anything)
74  */
75  for (i = 0; i < smDesc->nOfActions; i++) {
76  smDesc->smActions[i] = smDescBase->smActions[i];
77  }
78 
79  /* This cycle will always be executed at least once because
80  * the number of guards (nOfGuards) is always greater than
81  * zero (since all state machines have at least the dummy
82  * guard which always returns TRUE)
83  */
84  for (i = 0; i < smDesc->nOfGuards; i++) {
85  smDesc->smGuards[i] = smDescBase->smGuards[i];
86  }
87 
88  for (i = 0; i < smBase->nOfPStates; i++) {
89  smDesc->esmDesc[i] = NULL;
90  }
91 
92  smDesc->errCode = smDescBase->errCode;
93  smDesc->smExecCnt = 0;
94  smDesc->stateExecCnt = 0;
95  smDesc->transCnt = 0;
96  smDesc->curState = 0;
97 
98  return;
99 }
FwSmBool_t SmDummyGuard(FwSmDesc_t smDesc)
Dummy guard which always returns true.
Definition: FwSmCore.c:46
FwSmCounterS1_t curState
the current state of the state machine
Definition: FwSmPrivate.h:319
FwSmCounterS1_t outTransIndex
index of first out-going transition in transition array of SmBaseDesc_t
Definition: FwSmPrivate.h:151
void FwSmInit(FwSmDesc_t smDesc)
Initialize a state machine descriptor to represent an unconfigured state machine with no transitions...
Definition: FwSmSCreate.c:24
FwSmCounterS1_t nOfActions
the number of actions (state actions + transition actions) in the state machine
Definition: FwSmPrivate.h:313
FwSmAction_t * smActions
the state machine actions (state and transition actions)
Definition: FwSmPrivate.h:307
FwSmCounterS1_t nOfPStates
the number of states in the state machine
Definition: FwSmPrivate.h:243
SmCState_t * cStates
array holding the choice pseudo-states in the state machine
Definition: FwSmPrivate.h:239
The number of guards in the base state machine is not the same as in the derived state machine...
FwSmErrCode_t errCode
either &#39;success&#39; or the code of the last error encountered by the state machine
Definition: FwSmPrivate.h:325
void FwSmInitDer(FwSmDesc_t smDesc, FwSmDesc_t smDescBase)
Initialize a state machine descriptor to extend another state machine (the base state machine)...
Definition: FwSmSCreate.c:54
FwSmCounterS1_t outTransIndex
index of first out-going transition in the transition array of SmBaseDesc_t
Definition: FwSmPrivate.h:123
FwSmCounterS1_t transCnt
the counter for the number of transitions added to the state machine
Definition: FwSmPrivate.h:317
struct FwSmDesc ** esmDesc
the state machines embedded in the state machine
Definition: FwSmPrivate.h:311
FwSmCounterS1_t nOfCStates
the number of choice pseudo-states in the state machine
Definition: FwSmPrivate.h:245
FwSmCounterU3_t smExecCnt
the state machine execution counter
Definition: FwSmPrivate.h:321
FwSmCounterS1_t nOfTrans
the number of transitions in SM
Definition: FwSmPrivate.h:247
Structure representing a state machine descriptor.
Definition: FwSmPrivate.h:303
FwSmCounterU3_t stateExecCnt
the state execution counter
Definition: FwSmPrivate.h:323
FwSmCounterS1_t iTrAction
the index of the action associated to the transition
Definition: FwSmPrivate.h:201
Structure representing the base descriptor of a state machine.
Definition: FwSmPrivate.h:235
FwSmCounterS1_t nOfGuards
the number of guards in the state machine
Definition: FwSmPrivate.h:315
FwSmGuard_t * smGuards
the transition guards in the state machine
Definition: FwSmPrivate.h:309
void SmDummyAction(FwSmDesc_t smDesc)
Dummy action which returns without doing anything.
Definition: FwSmCore.c:40
SmPState_t * pStates
array holding the proper states in the state machine
Definition: FwSmPrivate.h:237
SmBaseDesc_t * smBase
pointer to the base descriptor
Definition: FwSmPrivate.h:305
Declaration of the static creation interface for a FW State Machine.
signed char FwSmCounterS1_t
Type used for signed counters with a "short" range.
Definition: FwSmConstants.h:79
The number of actions in the base state machine is not the same as in the derived state machine...
Declaration of the internal data structures of the FW State Machine Module.
SmTrans_t * trans
array holding the transitions in the state machine
Definition: FwSmPrivate.h:241
P&P Software GmbH, Copyright 2011, All Rights Reserved