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  CrFwCounterU3_t targetKey) {
138 
139  CrFwCounterU2_t pos_lower, pos_upper, pos_half;
140 
141  pos_lower = 0;
142  pos_upper = (length-1);
143 
144  while (pos_lower < pos_upper) {
145  pos_half = (pos_lower+(pos_upper-pos_lower)/2);
146  if (pos_half == pos_lower)
147  break;
148  if (targetKey > keyValArray[pos_half]) {
149  pos_lower = pos_half;
150  } else if (targetKey < keyValArray[pos_half]) {
151  pos_upper = pos_half;
152  } else
153  return pos_half;
154  }
155 
156  if (targetKey == keyValArray[pos_lower])
157  return pos_lower;
158 
159  if (targetKey == keyValArray[pos_upper])
160  return pos_upper;
161 
162  return length;
163 }
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
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
Component Initialization Procedure (CIP) for the Base Component.
Component Reset Procedure (CRP) for the Base Component.
unsigned char CrFwOutcome_t
Type used for the outcome of a check (see CrFwCmpData).
unsigned int CrFwCounterU3_t
Type used for unsigned integers with a "long" range.
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
CrFwAppErrCode_t
Application error code for the framework components.
@ crNoAppErr
No application errors have been detected.
FwSmBool_t CrFwIsSmOutcomeZero(FwSmDesc_t smDesc)
Convenience function to check whether the outcome of the last check or action is equal to 0 ("false")...
FwSmBool_t CrFwIsSmOutcomeOne(FwSmDesc_t smDesc)
Convenience function to check whether the outcome of the last check or action is equal to 1 ("true").
CrFwOutcome_t CrFwGetSmOutcome(FwSmDesc_t smDesc)
Convenience function to get the outcome of the last check or action of a state machine.
CrFwAppErrCode_t CrFwGetAppErrCode()
Return the value of the application error code.
void CrFwSetAppErrCode(CrFwAppErrCode_t errCode)
Set the value of the application error code (see CrFwGetAppErrCode).
static CrFwAppErrCode_t appErrCode
The application error code.
void CrFwSetSmOutcome(FwSmDesc_t smDesc, CrFwOutcome_t outcome)
Convenience function to set the outcome of the last check or action of a state machine.
void CrFwSmEmptyAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which retu...
CrFwBool_t CrFwPrCheckAlwaysTrue(FwPrDesc_t prDesc)
Convenience function to be used in a procedure as default implementation for a check which always ret...
CrFwBool_t CrFwSmCheckAlwaysFalse(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for a check which always...
void CrFwSetPrOutcome(FwPrDesc_t prDesc, CrFwOutcome_t outcome)
Convenience function to set the outcome field of the component data of a procedure.
FwPrBool_t CrFwWaitOnePrCycle(FwPrDesc_t prDesc)
Convenience function which returns true when a procedure has spent more than one cycle in the current...
void CrFwPrEmptyAction(FwPrDesc_t prDesc)
Convenience function to be used in a procedure as default implementation for an action which returns ...
CrFwBool_t CrFwSmCheckAlwaysTrue(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for a check which always...
CrFwCounterU2_t CrFwFindKeyIndex(CrFwCounterU3_t *keyValArray, CrFwCounterU2_t length, CrFwCounterU3_t targetKey)
Convenience function to retrieve the index of an array where a certain target value is located.
void CrFwSmSuccessAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which sets...
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...
FwSmBool_t CrFwIsSmOutcomeTwo(FwSmDesc_t smDesc)
Convenience function to check whether the outcome of the last check or action is equal to 2.
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
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved