FW Profile - C1 Implementation
FwRtConfig.c
Go to the documentation of this file.
1 
18 #include "FwRtConfig.h"
19 #include "FwRtConstants.h"
20 #include <pthread.h>
21 #include <stdlib.h>
22 
30 
31 void FwRtReset(FwRtDesc_t rtDesc) {
32  rtDesc->state = rtContUninitialized;
33  rtDesc->activPrStarted = 0;
34  rtDesc->notifPrStarted = 0;
35  rtDesc->errCode = 0;
36  rtDesc->execFuncBehaviour = &DummyAction;
37  rtDesc->finalizeActivPr = &DummyAction;
38  rtDesc->finalizeNotifPr = &DummyAction;
41  rtDesc->initializeActivPr = &DummyAction;
42  rtDesc->initializeNotifPr = &DummyAction;
43  rtDesc->setUpNotification = &DummyAction;
44  rtDesc->notifCounter = 0;
45  rtDesc->pThreadAttr = NULL;
46  rtDesc->pCondAttr = NULL;
47  rtDesc->pMutexAttr = NULL;
48  rtDesc->rtData = NULL;
49 }
50 
51 /*--------------------------------------------------------------------------------------*/
52 void FwRtInit(FwRtDesc_t rtDesc) {
53  int errCode;
54 
55  if (rtDesc->state != rtContUninitialized) {
56  rtDesc->state = rtConfigErr;
57  return;
58  }
59 
60  /* Initialize mutex attributes */
61  if (rtDesc->pMutexAttr != NULL) {
62  if ((errCode = pthread_mutexattr_init(rtDesc->pMutexAttr)) != 0) {
63  rtDesc->errCode = errCode;
64  rtDesc->state = rtMutexAttrInitErr;
65  return;
66  }
67  }
68 
69  /* Initialize condition variable attributes */
70  if (rtDesc->pCondAttr != NULL) {
71  if ((errCode = pthread_condattr_init(rtDesc->pCondAttr)) != 0) {
72  rtDesc->errCode = errCode;
73  rtDesc->state = rtCondAttrInitErr;
74  return;
75  }
76  }
77 
78  /* Initialize thread attributes */
79  if (rtDesc->pThreadAttr != NULL) {
80  if ((errCode = pthread_attr_init(rtDesc->pThreadAttr)) != 0) {
81  rtDesc->errCode = errCode;
82  rtDesc->state = rtThreadAttrInitErr;
83  return;
84  }
85  }
86 
87  /* Initialize mutex */
88  if ((errCode = pthread_mutex_init(&(rtDesc->mutex), rtDesc->pMutexAttr)) != 0) {
89  rtDesc->errCode = errCode;
90  rtDesc->state = rtMutexInitErr;
91  return;
92  }
93 
94  /* Initialize condition variable */
95  if ((errCode = pthread_cond_init(&(rtDesc->cond), rtDesc->pCondAttr)) != 0) {
96  rtDesc->errCode = errCode;
97  rtDesc->state = rtCondInitErr;
98  return;
99  }
100 
101  rtDesc->state = rtContStopped;
102 }
103 
104 /*--------------------------------------------------------------------------------------*/
105 void FwRtShutdown(FwRtDesc_t rtDesc) {
106  int errCode;
107 
108  /* Destroy mutex attributes */
109  if (rtDesc->pMutexAttr != NULL) {
110  if ((errCode = pthread_mutexattr_destroy(rtDesc->pMutexAttr)) != 0) {
111  rtDesc->errCode = errCode;
112  rtDesc->state = rtMutexAttrDestroyErr;
113  return;
114  }
115  }
116 
117  /* Destroy condition variable attributes */
118  if (rtDesc->pCondAttr != NULL) {
119  if ((errCode = pthread_condattr_destroy(rtDesc->pCondAttr)) != 0) {
120  rtDesc->errCode = errCode;
121  rtDesc->state = rtCondAttrDestroyErr;
122  return;
123  }
124  }
125 
126  /* Destroy thread attributes */
127  if (rtDesc->pThreadAttr != NULL) {
128  if ((errCode = pthread_attr_destroy(rtDesc->pThreadAttr)) != 0) {
129  rtDesc->errCode = errCode;
130  rtDesc->state = rtThreadAttrDestroyErr;
131  return;
132  }
133  }
134 
135  if ((errCode = pthread_cond_destroy(&(rtDesc->cond))) != 0) {
136  rtDesc->errCode = errCode;
137  rtDesc->state = rtCondDestroyErr;
138  return;
139  }
140 
141  if ((errCode = pthread_mutex_destroy(&(rtDesc->mutex))) != 0) {
142  rtDesc->errCode = errCode;
143  rtDesc->state = rtMutexDestroyErr;
144  return;
145  }
146 
147  rtDesc->state = rtContUninitialized;
148 }
149 
150 /*--------------------------------------------------------------------------------------*/
151 void FwRtSetPosixAttr(FwRtDesc_t rtDesc, pthread_attr_t* pThreadAttr, pthread_mutexattr_t* pMutexAttr,
152  pthread_condattr_t* pCondAttr) {
153 
154  if (rtDesc->state != rtContUninitialized) {
155  rtDesc->state = rtConfigErr;
156  return;
157  }
158 
159  rtDesc->pThreadAttr = pThreadAttr;
160  rtDesc->pMutexAttr = pMutexAttr;
161  rtDesc->pCondAttr = pCondAttr;
162 }
163 
164 /*--------------------------------------------------------------------------------------*/
165 pthread_attr_t* FwRtGetActivThreadAttr(FwRtDesc_t rtDesc) {
166  return rtDesc->pThreadAttr;
167 }
168 
169 /*--------------------------------------------------------------------------------------*/
170 pthread_mutexattr_t* FwRtGetMutexAttr(FwRtDesc_t rtDesc) {
171  return rtDesc->pMutexAttr;
172 }
173 
174 /*--------------------------------------------------------------------------------------*/
175 pthread_condattr_t* FwRtGetCondAttr(FwRtDesc_t rtDesc) {
176  return rtDesc->pCondAttr;
177 }
178 
179 /* -------------------------------------------------------------------------------------*/
180 void FwRtSetData(FwRtDesc_t rtDesc, void* rtData) {
181  rtDesc->rtData = rtData;
182 }
183 
184 /* -------------------------------------------------------------------------------------*/
185 void* FwRtGetData(FwRtDesc_t rtDesc) {
186  return rtDesc->rtData;
187 }
188 
189 /* -------------------------------------------------------------------------------------*/
190 void FwRtSetInitializeNotifPr(FwRtDesc_t rtDesc, FwRtAction_t initializeNotifPr) {
191  if (rtDesc->state != rtContUninitialized) {
192  rtDesc->state = rtConfigErr;
193  return;
194  }
195  rtDesc->initializeNotifPr = initializeNotifPr;
196 }
197 
198 /* -------------------------------------------------------------------------------------*/
199 void FwRtSetFinalizeNotifPr(FwRtDesc_t rtDesc, FwRtAction_t finalizeNotifPr) {
200  if (rtDesc->state != rtContUninitialized) {
201  rtDesc->state = rtConfigErr;
202  return;
203  }
204  rtDesc->finalizeNotifPr = finalizeNotifPr;
205 }
206 
207 /* -------------------------------------------------------------------------------------*/
208 void FwRtSetImplementNotifLogic(FwRtDesc_t rtDesc, FwRtAction_t implementNotifLogicPr) {
209  if (rtDesc->state != rtContUninitialized) {
210  rtDesc->state = rtConfigErr;
211  return;
212  }
213  rtDesc->implementNotifLogic = implementNotifLogicPr;
214 }
215 
216 /* -------------------------------------------------------------------------------------*/
217 void FwRtSetInitializeActivPr(FwRtDesc_t rtDesc, FwRtAction_t initializeActivPr) {
218  if (rtDesc->state != rtContUninitialized) {
219  rtDesc->state = rtConfigErr;
220  return;
221  }
222  rtDesc->initializeActivPr = initializeActivPr;
223 }
224 
225 /* -------------------------------------------------------------------------------------*/
226 void FwRtSetFinalizeActivPr(FwRtDesc_t rtDesc, FwRtAction_t finalizeActivPr) {
227  if (rtDesc->state != rtContUninitialized) {
228  rtDesc->state = rtConfigErr;
229  return;
230  }
231  rtDesc->finalizeActivPr = finalizeActivPr;
232 }
233 
234 /* -------------------------------------------------------------------------------------*/
235 void FwRtSetSetUpNotif(FwRtDesc_t rtDesc, FwRtAction_t setUpNotification) {
236  if (rtDesc->state != rtContUninitialized) {
237  rtDesc->state = rtConfigErr;
238  return;
239  }
240  rtDesc->setUpNotification = setUpNotification;
241 }
242 
243 /* -------------------------------------------------------------------------------------*/
244 void FwRtSetImplementActivLogic(FwRtDesc_t rtDesc, FwRtAction_t implementActivLogic) {
245  if (rtDesc->state != rtContUninitialized) {
246  rtDesc->state = rtConfigErr;
247  return;
248  }
249  rtDesc->implementActivLogic = implementActivLogic;
250 }
251 
252 /* -------------------------------------------------------------------------------------*/
253 void FwRtSetExecFuncBehaviour(FwRtDesc_t rtDesc, FwRtAction_t execFuncBehaviour) {
254  if (rtDesc->state != rtContUninitialized) {
255  rtDesc->state = rtConfigErr;
256  return;
257  }
258  rtDesc->execFuncBehaviour = execFuncBehaviour;
259 }
260 
261 /* -------------------------------------------------------------------------------------*/
263  (void)(rtDesc);
264  return 1;
265 }
void * rtData
The pointer to the RT Container data.
void FwRtSetInitializeActivPr(FwRtDesc_t rtDesc, FwRtAction_t initializeActivPr)
Define the function implementing the Initialization Action for the Activation Procedure.
Definition: FwRtConfig.c:217
void FwRtSetPosixAttr(FwRtDesc_t rtDesc, pthread_attr_t *pThreadAttr, pthread_mutexattr_t *pMutexAttr, pthread_condattr_t *pCondAttr)
Set the pointers to the attribute objects of the POSIX thread, mutex and condition variable used by t...
Definition: FwRtConfig.c:151
FwRtState_t state
The state of the RT Container.
Header file to define all constants and types for the RT Container Module of the FW Profile...
The RT Container is in state STOPPED.
Definition: FwRtConstants.h:64
FwRtAction_t initializeNotifPr
Pointer to the function encapsulating the initialization action for the Notification Procedure...
void FwRtSetImplementActivLogic(FwRtDesc_t rtDesc, FwRtAction_t implementActivLogic)
Define the function implementing the activation logic for the RT Container.
Definition: FwRtConfig.c:244
void FwRtSetInitializeNotifPr(FwRtDesc_t rtDesc, FwRtAction_t initializeNotifPr)
Define the function implementing the Initialization Action for the Notification Procedure.
Definition: FwRtConfig.c:190
Declaration of the configuration interface for a RT Container.
FwRtAction_t implementNotifLogic
Pointer to the function encapsulating the implementation of the notification logic.
pthread_condattr_t * FwRtGetCondAttr(FwRtDesc_t rtDesc)
Get the value of the attributes of the condition variable associated to the RT Container.
Definition: FwRtConfig.c:175
The function to destroy the container mutex has reported an error.
Definition: FwRtConstants.h:72
FwRtCounterU2_t notifCounter
The notification counter.
void FwRtReset(FwRtDesc_t rtDesc)
Reset the RT Container descriptor (RTD).
Definition: FwRtConfig.c:31
pthread_cond_t cond
The condition variable associated to the RT Container.
The function to initialize a thread attribute has reported an error.
Definition: FwRtConstants.h:90
FwRtAction_t finalizeActivPr
Pointer to the function encapsulating the finalization action for the Activation Procedure.
int errCode
The return value of the last system call which failed.
FwRtAction_t implementActivLogic
Pointer to the function encapsulating the implementation of the activation logic. ...
The function to initialize the container mutex has reported an error.
Definition: FwRtConstants.h:70
FwRtOutcome_t(* FwRtAction_t)(FwRtDesc_t)
Type for a pointer to a container action.
Definition: FwRtConstants.h:50
The function to initialize the container condition has reported an error.
Definition: FwRtConstants.h:74
void FwRtSetFinalizeActivPr(FwRtDesc_t rtDesc, FwRtAction_t finalizeActivPr)
Define the function implementing the Finalization Action for the Activation Procedure.
Definition: FwRtConfig.c:226
The function to destroy the container condition has reported an error.
Definition: FwRtConstants.h:76
void FwRtShutdown(FwRtDesc_t rtDesc)
Shutdown the RT Container.
Definition: FwRtConfig.c:105
FwRtAction_t setUpNotification
Pointer to the function encapsulating the logic to set up the notification for the RT Container...
FwRtAction_t execFuncBehaviour
Pointer to the function encapsulating the execution of the functional behaviour associated to the RT ...
The RT Container has not yet been initialized.
Definition: FwRtConstants.h:62
pthread_mutex_t mutex
The mutex associated to the RT Container.
pthread_mutexattr_t * FwRtGetMutexAttr(FwRtDesc_t rtDesc)
Get the value of the attributes of the mutex associated to the RT Container.
Definition: FwRtConfig.c:170
void FwRtSetImplementNotifLogic(FwRtDesc_t rtDesc, FwRtAction_t implementNotifLogicPr)
Define the function implementing the Notification Logic for the Notification Procedure.
Definition: FwRtConfig.c:208
void FwRtSetSetUpNotif(FwRtDesc_t rtDesc, FwRtAction_t setUpNotification)
Define the function implementing the logic to set up a notification for the RT Container.
Definition: FwRtConfig.c:235
FwRtOutcome_t DummyAction(FwRtDesc_t rtDesc)
Dummy function which always returns 1.
Definition: FwRtConfig.c:262
pthread_attr_t * FwRtGetActivThreadAttr(FwRtDesc_t rtDesc)
Get the value of the attributes of the Activation Thread.
Definition: FwRtConfig.c:165
pthread_attr_t * pThreadAttr
The pointer to the Activation Thread attributes.
The function to destroy a mutex attribute has reported an error.
Definition: FwRtConstants.h:94
A configuration function has been called during the container&#39;s normal operation (i.e.
FwRtAction_t initializeActivPr
Pointer to the function encapsulating the initialization action for the Activation Procedure...
pthread_mutexattr_t * pMutexAttr
The pointer to the mutex attributes.
void FwRtSetFinalizeNotifPr(FwRtDesc_t rtDesc, FwRtAction_t finalizeNotifPr)
Define the function implementing the Finalization Action for the Notification Procedure.
Definition: FwRtConfig.c:199
The function to destroy a mutex attribute has reported an error.
Definition: FwRtConstants.h:92
FwRtBool_t notifPrStarted
The flag indicating whether the Notification Procedure is STÂRTED.
void FwRtSetData(FwRtDesc_t rtDesc, void *rtData)
Set the pointer to the RT Container data in the container descriptor.
Definition: FwRtConfig.c:180
void FwRtInit(FwRtDesc_t rtDesc)
Initialize a RT Container.
Definition: FwRtConfig.c:52
FwRtAction_t finalizeNotifPr
Pointer to the function encapsulating the finalization action for the Notification Procedure...
The function to initialize a mutex attribute has reported an error.
Definition: FwRtConstants.h:88
void * FwRtGetData(FwRtDesc_t rtDesc)
Get the pointer to the container data in the container descriptor.
Definition: FwRtConfig.c:185
The function to destroy a thread attribute has reported an error.
Definition: FwRtConstants.h:96
Structure representing a RT Container Descriptor.
pthread_condattr_t * pCondAttr
The pointer to the condition variable attributes.
int FwRtOutcome_t
Type used for the outcome of a container action.
Definition: FwRtConstants.h:37
FwRtBool_t activPrStarted
The flag indicating whether the Activation Procedure is STÂRTED.
The function to initialize a mutex attribute has reported an error.
Definition: FwRtConstants.h:86
void FwRtSetExecFuncBehaviour(FwRtDesc_t rtDesc, FwRtAction_t execFuncBehaviour)
Define the function which executes the functional behaviour associated to the RT Container.
Definition: FwRtConfig.c:253
P&P Software GmbH, Copyright 2011, All Rights Reserved