forked from airbus/a653lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartition_b.c
More file actions
273 lines (215 loc) · 7.81 KB
/
partition_b.c
File metadata and controls
273 lines (215 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/**
* @file prcs_a.c
* @author nicolaus.baer@airbus.com
* @date Tue Oct 24 15:53:18 CEST 2023
* @brief partition main function
* @details
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//--------------------
#include <errno.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include "a653Lib.h"
#include "a653Init.h"
/* #include "a653_config.h" */
/* a653_global_config_t global_config = A653_PARTITION_CONFIG_DEF; */
/* a653_process_config_t A653_PROCESS_CONFIG[] = A653_PROCESS_CONFIG_DEF; */
/* a653_sampling_port_config_t A653_SP_CONFIG[] = A653_SP_CONFIG_DEF; */
/* a653_queuing_port_config_t A653_QP_CONFIG[] = A653_QP_CONFIG_DEF; */
char semaphore_name[] = "myTestSem ";
SEMAPHORE_VALUE_TYPE current_value = 1;
SEMAPHORE_VALUE_TYPE maximum_value = 1;
QUEUING_DISCIPLINE_TYPE queuing_discipline = 0;
SEMAPHORE_ID_TYPE semaphore_id;
SEMAPHORE_STATUS_TYPE semaphore_status;
//RETURN_CODE_TYPE return_code;
void PeriodicProcess(void){
RETURN_CODE_TYPE return_code;
MESSAGE_SIZE_TYPE length;
VALIDITY_TYPE validity;
A653_BYTE data_sp_tx[32] = "sp_test1234";
A653_BYTE data_sp_rx[32] = " ";
A653_BYTE data_qp_tx[32] = "qp_test1234";
A653_BYTE data_qp_rx[32] = " ";
SAMPLING_PORT_ID_TYPE sp_id_tx;
SAMPLING_PORT_ID_TYPE sp_id_rx;
QUEUING_PORT_ID_TYPE qp_id_tx;
QUEUING_PORT_ID_TYPE qp_id_rx;
GET_SAMPLING_PORT_ID("SP_Prcs_A to Prcs B ",
&sp_id_rx,
&return_code);
GET_SAMPLING_PORT_ID("SP_Prcs_B to Prcs A ",
&sp_id_tx,
&return_code);
GET_QUEUING_PORT_ID("QP_Prcs_B to Prcs A ",
&qp_id_tx,
&return_code);
GET_QUEUING_PORT_ID("QP_Prcs_A to Prcs B ",
&qp_id_rx,
&return_code);
int index = 0;
while (1){
length = 0;
index++;
sprintf((char *)data_sp_tx,"Hello on SP %d",index);
sprintf((char *)data_qp_tx,"Hello on QP %d",index);
READ_SAMPLING_MESSAGE(sp_id_rx,
data_sp_rx,
&length,
&validity,
&return_code);
if (validity == VALID && length > 0){
printDebug(3,"Prcs B: SP we got this : >%s< validity >%d< length >%d<\n",(char *)data_sp_rx,validity,length);
WRITE_SAMPLING_MESSAGE(sp_id_tx, /* sampling port id */
data_sp_tx, /* pointer to data */
32, /* send size */
&return_code); /* return code */
}
RECEIVE_QUEUING_MESSAGE(qp_id_rx,
0, /* time out */
data_qp_rx, /* pointer to data */
&length, /* received length */
&return_code); /* return code */
if(return_code == NO_ERROR && length !=0){
printDebug(3,"Prcs B: QP we got this : >%s<\n",(char *)data_qp_rx);
SEND_QUEUING_MESSAGE(qp_id_tx,
data_qp_tx,
30, // size
0, //timeout
&return_code);
}
/* SIGNAL_SEMAPHORE(semaphore_id, */
/* &return_code); */
PERIODIC_WAIT(&return_code);
}
}
void PeriodicProcess_2(void){
RETURN_CODE_TYPE return_code;
while (1){
printDebug(3,"Prcs C: activated\n");
SIGNAL_SEMAPHORE(semaphore_id,
&return_code);
PERIODIC_WAIT(&return_code);
}
}
void APeriodicProcess(void){
RETURN_CODE_TYPE return_code;
while (1){
WAIT_SEMAPHORE(semaphore_id,
0,
&return_code);
printDebug(3,"Prcs D: activated\n");
TIMED_WAIT(1000000,&return_code);
}
}
/* have a look to init.c beforeMain is called before main!!!!! */
int main (int argc, char *argv[]){
RETURN_CODE_TYPE return_code;
RETURN_CODE_TYPE Init_Process_ret;
PROCESS_ID_TYPE Init_process_ID;
PROCESS_ATTRIBUTE_TYPE process_data;
A653_INTEGER PortId;
int ret_val = 0;
/* 0 1 2 3 */
/* 01234567890123456789012345678901 */
CREATE_SAMPLING_PORT("SP_Prcs_A to Prcs B ",
32, // Size in Bytes
1, // 0 tx : 1 rx
40000000, // currently unused
&PortId,
&return_code
);
/* 0 1 2 3 */
/* 01234567890123456789012345678901 */
CREATE_SAMPLING_PORT("SP_Prcs_B to Prcs A ",
32, // Size in Bytes
0, // 0 tx : 1 rx
40000000, // currently unused
&PortId,
&return_code
);
/* 0 1 2 3 */
/* 01234567890123456789012345678901 */
CREATE_QUEUING_PORT("QP_Prcs_A to Prcs B ",
32, // Size in Bytes
4, // number of entries
1, // 0 tx : 1 rx
FIFO,
&PortId,
&return_code
);
/* 0 1 2 3 */
/* 01234567890123456789012345678901 */
CREATE_QUEUING_PORT("QP_Prcs_B to Prcs A ",
32, // Size in Bytes
4, // number of entries
0, // 0 tx : 1 rx
FIFO,
&PortId,
&return_code
);
current_value = 2;
maximum_value = 2;
queuing_discipline = FIFO;
CREATE_SEMAPHORE(semaphore_name,
current_value,
maximum_value,
queuing_discipline,
&semaphore_id,
&return_code);
GET_SEMAPHORE_STATUS(semaphore_id,
&semaphore_status,
&return_code);
printDebug(3,"semaphore: %d : %d\n",
semaphore_status.CURRENT_VALUE,
semaphore_status.MAXIMUM_VALUE);
usleep(50000);
//Start initialization
//InitSamplingPorts();
//Initialization of the processes
memset((char*)(&process_data.NAME), 0, sizeof(process_data.NAME));
sprintf((char*)(&process_data.NAME), "Process B ");
process_data.PERIOD = 100000000LL; /* nsec -> 0,1sec */
process_data.TIME_CAPACITY = 0;
process_data.STACK_SIZE = 0x500000;
process_data.ENTRY_POINT = &PeriodicProcess; //Entrypoint to periodic process
process_data.BASE_PRIORITY = 10 ;
process_data.DEADLINE = SOFT;
CREATE_PROCESS(&process_data, &Init_process_ID, &Init_Process_ret);
//Starting processes
START(Init_process_ID, &Init_Process_ret);
memset((char*)(&process_data.NAME), 0, sizeof(process_data.NAME));
sprintf((char*)(&process_data.NAME), "Process C ");
process_data.PERIOD = 200000000LL; /* nsec -> 0,2sec */
process_data.TIME_CAPACITY = 0;
process_data.STACK_SIZE = 0x500000;
process_data.ENTRY_POINT = &PeriodicProcess_2; //Entrypoint to periodic process
process_data.BASE_PRIORITY = 20 ;
process_data.DEADLINE = SOFT;
CREATE_PROCESS(&process_data, &Init_process_ID, &Init_Process_ret);
//Starting processes
START(Init_process_ID, &Init_Process_ret);
memset((char*)(&process_data.NAME), 0, sizeof(process_data.NAME));
sprintf((char*)(&process_data.NAME), "Process D ");
process_data.PERIOD = -1LL;
process_data.TIME_CAPACITY = 0;
process_data.STACK_SIZE = 0x500000;
process_data.ENTRY_POINT = &APeriodicProcess; //Entrypoint to periodic process
process_data.BASE_PRIORITY = 30 ;
process_data.DEADLINE = SOFT;
CREATE_PROCESS(&process_data, &Init_process_ID, &Init_Process_ret);
//Starting processes
START(Init_process_ID, &Init_Process_ret);
/* if( Init_Process_ret != NO_ERROR )
RAISE_APPLICATION_ERROR( APPLICATION_ERROR, errorMsgs[Init_Process_ret], 10, &raiseErrorRet ); */
//Set normal mode
SET_PARTITION_MODE(NORMAL, &Init_Process_ret);
/* if( Init_Process_ret != NO_ERROR )
RAISE_APPLICATION_ERROR( APPLICATION_ERROR, errorMsgs[Init_Process_ret], 10, &raiseErrorRet ); */
return ret_val;
}