CORDET Framework - C2 Implementation
CrFwUtilityFunctions.c
Go to the documentation of this file.
1 
18 #include <stdlib.h>
19 /* Include framework files */
20 #include "CrFwConstants.h"
21 #include "BaseCmp/CrFwBaseCmp.h"
22 #include "BaseCmp/CrFwInitProc.h"
23 #include "BaseCmp/CrFwResetProc.h"
24 /* Include FW Profile files */
25 #include "FwSmConstants.h"
26 #include "FwSmDCreate.h"
27 #include "FwSmConfig.h"
28 #include "FwSmCore.h"
29 #include "FwPrConstants.h"
30 #include "FwPrDCreate.h"
31 #include "FwPrConfig.h"
32 #include "FwPrCore.h"
33 /* Include configuration files */
34 #include "CrFwCmpData.h"
35 
38 
39 /*-----------------------------------------------------------------------------------------*/
41  return appErrCode;
42 }
43 
44 /*-----------------------------------------------------------------------------------------*/
46  appErrCode = errCode;
47 }
48 
49 /*-----------------------------------------------------------------------------------------*/
50 void CrFwSetPrOutcome(FwPrDesc_t prDesc, CrFwOutcome_t outcome) {
51  CrFwCmpData_t* prData = (CrFwCmpData_t*)FwPrGetData(prDesc);
52  prData->outcome = outcome;
53 }
54 
55 /*-----------------------------------------------------------------------------------------*/
56 FwPrBool_t CrFwIsPrOutcomeOne(FwPrDesc_t prDesc) {
57  CrFwCmpData_t* prData = (CrFwCmpData_t*)FwPrGetData(prDesc);
58  return (prData->outcome);
59 }
60 
61 /*-----------------------------------------------------------------------------------------*/
62 void CrFwSetSmOutcome(FwSmDesc_t smDesc, CrFwOutcome_t outcome) {
63  CrFwCmpData_t* smData = (CrFwCmpData_t*)FwSmGetData(smDesc);
64  smData->outcome = outcome;
65 }
66 
67 /*-----------------------------------------------------------------------------------------*/
68 CrFwOutcome_t CrFwGetSmOutcome(FwSmDesc_t smDesc) {
69  CrFwCmpData_t* smData = (CrFwCmpData_t*)FwSmGetData(smDesc);
70  return smData->outcome;
71 }
72 
73 /*-----------------------------------------------------------------------------------------*/
74 FwSmBool_t CrFwIsSmOutcomeZero(FwSmDesc_t smDesc) {
75  CrFwCmpData_t* smData = (CrFwCmpData_t*)FwSmGetData(smDesc);
76  return (smData->outcome == 0);
77 }
78 
79 /*-----------------------------------------------------------------------------------------*/
80 FwSmBool_t CrFwIsSmOutcomeOne(FwSmDesc_t smDesc) {
81  CrFwCmpData_t* smData = (CrFwCmpData_t*)FwSmGetData(smDesc);
82  return (smData->outcome == 1);
83 }
84 
85 /*-----------------------------------------------------------------------------------------*/
86 FwSmBool_t CrFwIsSmOutcomeTwo(FwSmDesc_t smDesc) {
87  CrFwCmpData_t* smData = (CrFwCmpData_t*)FwSmGetData(smDesc);
88  return (smData->outcome == 2);
89 }
90 
91 /*-----------------------------------------------------------------------------------------*/
92 FwPrBool_t CrFwWaitOnePrCycle(FwPrDesc_t prDesc) {
93  if (FwPrGetNodeExecCnt(prDesc) > 0)
94  return 1;
95  else
96  return 0;
97 }
98 
99 /*-----------------------------------------------------------------------------------------*/
100 CrFwBool_t CrFwPrCheckAlwaysTrue(FwPrDesc_t prDesc) {
101  CRFW_UNUSED(prDesc);
102  return 1;
103 }
104 
105 /*-----------------------------------------------------------------------------------------*/
106 CrFwBool_t CrFwSmCheckAlwaysTrue(FwSmDesc_t smDesc) {
107  CRFW_UNUSED(smDesc);
108  return 1;
109 }
110 
111 /*-----------------------------------------------------------------------------------------*/
112 CrFwBool_t CrFwSmCheckAlwaysFalse(FwSmDesc_t smDesc) {
113  CRFW_UNUSED(smDesc);
114  return 0;
115 }
116 
117 /*-----------------------------------------------------------------------------------------*/
118 void CrFwPrEmptyAction(FwPrDesc_t prDesc) {
119  CRFW_UNUSED(prDesc);
120  return;
121 }
122 
123 /*-----------------------------------------------------------------------------------------*/
124 void CrFwSmEmptyAction(FwSmDesc_t smDesc) {
125  CRFW_UNUSED(smDesc);
126  return;
127 }
128 
129 /*-----------------------------------------------------------------------------------------*/
130 void CrFwSmSuccessAction(FwSmDesc_t smDesc) {
131  CrFwCmpData_t* cmpData = (CrFwCmpData_t*)FwSmGetData(smDesc);
132  cmpData->outcome = 1;
133 }
134 
135 /*-----------------------------------------------------------------------------------------*/
137  CrFwCmdRepKindIndex_t length, CrFwCmdRepKindKey_t targetKey) {
138 
139  CrFwCmdRepKindIndex_t pos_lower, pos_upper, pos_half;
140 
141  pos_lower = 0;
142  pos_upper = (CrFwCmdRepKindIndex_t)(length-1);
143 
144  while (pos_lower < pos_upper) {
145  pos_half = (CrFwCmdRepKindIndex_t)(pos_lower+(pos_upper-pos_lower)/2);
146  if (pos_half == pos_lower)
147  break;
148  if (targetKey > cmdRepKindArray[pos_half]) {
149  pos_lower = pos_half;
150  } else if (targetKey < cmdRepKindArray[pos_half]) {
151  pos_upper = pos_half;
152  } else
153  return pos_half;
154  }
155 
156  if (targetKey == cmdRepKindArray[pos_lower])
157  return pos_lower;
158 
159  if (targetKey == cmdRepKindArray[pos_upper])
160  return pos_upper;
161 
162  return length;
163 }
Type for the Framework Component Data (FCD).
Definition: CrFwCmpData.h:79
CrFwOutcome_t outcome
The outcome of an action or check executed by a state machine or by one of its procedures.
Definition: CrFwCmpData.h:93
void CrFwSmEmptyAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which retu...
Definition of the Framework Component Data (FCD) Type.
#define CRFW_UNUSED(x)
A macro that can be used to specify that a function parameter is not used.
Definition: CrFwConstants.h:29
void CrFwSetAppErrCode(CrFwAppErrCode_t errCode)
Set the value of the application error code (see CrFwGetAppErrCode).
void CrFwSetPrOutcome(FwPrDesc_t prDesc, CrFwOutcome_t outcome)
Convenience function to set the outcome field of the component data of a procedure.
CrFwBool_t CrFwPrCheckAlwaysTrue(FwPrDesc_t prDesc)
Convenience function to be used in a procedure as default implementation for a check which always ret...
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
CrFwCmdRepKindIndex_t CrFwFindCmdRepKindIndex(CrFwCmdRepKindKey_t *cmdRepKindArray, CrFwCmdRepKindIndex_t length, CrFwCmdRepKindKey_t targetKey)
Convenience function to retrieve the index of an array where a certain target value is located...
unsigned char CrFwOutcome_t
Type used for the outcome of a check (see CrFwCmpData).
CrFwAppErrCode_t
Application error code for the framework components.
Header file to define all invariant publicly available constants and types for the CORDET Framework...
FwSmBool_t CrFwIsSmOutcomeZero(FwSmDesc_t smDesc)
Convenience function to check whether the outcome of the last check or action is equal to 0 ("false")...
unsigned int CrFwCmdRepKindKey_t
Type for the component kind key in CrFwInFactory.c and CrFwOutFactory.c.
unsigned short CrFwCmdRepKindIndex_t
Type for the index of a command or report kind.
CrFwBool_t CrFwSmCheckAlwaysTrue(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for a check which always...
void CrFwSmSuccessAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which sets...
void CrFwPrEmptyAction(FwPrDesc_t prDesc)
Convenience function to be used in a procedure as default implementation for an action which returns ...
CrFwOutcome_t CrFwGetSmOutcome(FwSmDesc_t smDesc)
Convenience function to get the outcome of the last check or action of a state machine.
void CrFwSetSmOutcome(FwSmDesc_t smDesc, CrFwOutcome_t outcome)
Convenience function to set the outcome of the last check or action of a state machine.
FwSmBool_t CrFwIsSmOutcomeTwo(FwSmDesc_t smDesc)
Convenience function to check whether the outcome of the last check or action is equal to 2...
Definition of Base Component.
Component Initialization Procedure (CIP) for the Base Component.
FwPrBool_t CrFwIsPrOutcomeOne(FwPrDesc_t prDesc)
Convenience function to check whether the outcome of the last check or action is equal to 1 ("true" o...
static CrFwAppErrCode_t appErrCode
The application error code.
No application errors have been detected.
CrFwAppErrCode_t CrFwGetAppErrCode()
Return the value of the application error code.
FwSmBool_t CrFwIsSmOutcomeOne(FwSmDesc_t smDesc)
Convenience function to check whether the outcome of the last check or action is equal to 1 ("true")...
CrFwBool_t CrFwSmCheckAlwaysFalse(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for a check which always...
Component Reset Procedure (CRP) for the Base Component.
FwPrBool_t CrFwWaitOnePrCycle(FwPrDesc_t prDesc)
Convenience function which returns true when a procedure has spent more than one cycle in the current...
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved