Skip to content

Commit be2d86e

Browse files
committed
main file generator
1 parent 68984ba commit be2d86e

File tree

3 files changed

+85
-13
lines changed

3 files changed

+85
-13
lines changed

examples/patmos/s4noc_fed_lf/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
23
LF_MAIN=S4NoCFedLF
34
BIN_DIR=bin
45
CC=patmos-clang
@@ -32,6 +33,9 @@ for i in $(seq 1 $N); do
3233
A_FILES="$A_FILES ./$LF_MAIN/r$i/bin/$LF_MAIN.a"
3334
done
3435

36+
chmod +x ./gen_main.sh
37+
./gen_main.sh N=$N
38+
3539
$CC -O2 -Wall -Wextra main.c $A_FILES -o $BIN_DIR/$LF_MAIN
3640

3741
read -n 1 -t 10 -p "Choose action: [e]mulate or [f]pga? (default: e) " action
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# Number of federates
4+
N=2
5+
rm -rf main.c
6+
7+
cat >> main.c <<EOF
8+
#include <stdio.h>
9+
#include <pthread.h>
10+
11+
EOF
12+
13+
# Generate include headers for each federate
14+
for i in $(seq 1 $N); do
15+
cat >> main.c <<EOF
16+
#include "S4NoCFedLF/r$i/src-gen/S4NoCFedLF/r$i/lf_start.h"
17+
EOF
18+
done
19+
20+
cat >> main.c <<EOF
21+
22+
void* f1_thread(void* arg) {
23+
printf("Starting federate 1 on core/thread 1\\n");
24+
lf_start();
25+
return NULL;
26+
}
27+
EOF
28+
29+
# Generate thread functions for each federate
30+
for i in $(seq 2 $N); do
31+
cat >> main.c <<EOF
32+
33+
void* f${i}_thread(void* arg) {
34+
printf("Starting federate $i on core/thread $i\\n");
35+
lf_start_$i();
36+
return NULL;
37+
}
38+
EOF
39+
done
40+
41+
# Generate main() function
42+
cat >> main.c <<EOF
43+
44+
int main(void) {
45+
pthread_t threads[$N];
46+
printf("Starting S4NOC Federated LF Example\\n");
47+
EOF
48+
49+
for i in $(seq 1 $N); do
50+
cat >> main.c <<EOF
51+
pthread_create(&threads[$((i-1))], NULL, f${i}_thread, NULL);
52+
EOF
53+
done
54+
55+
cat >> main.c <<EOF
56+
57+
printf("Threads created for federates.\\n");
58+
59+
EOF
60+
61+
for i in $(seq 1 $N); do
62+
cat >> main.c <<EOF
63+
pthread_join(threads[$((i-1))], NULL);
64+
EOF
65+
done
66+
67+
cat >> main.c <<EOF
68+
69+
printf("All federates finished.\\n");
70+
return 0;
71+
}
72+
EOF

examples/patmos/s4noc_fed_lf/main.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,29 @@
44
#include "S4NoCFedLF/r1/src-gen/S4NoCFedLF/r1/lf_start.h"
55
#include "S4NoCFedLF/r2/src-gen/S4NoCFedLF/r2/lf_start.h"
66

7-
87
void* f1_thread(void* arg) {
98
printf("Starting federate 1 on core/thread 1\n");
10-
lf_start();
9+
lf_start();
1110
return NULL;
1211
}
1312

1413
void* f2_thread(void* arg) {
1514
printf("Starting federate 2 on core/thread 2\n");
16-
lf_start_2();
15+
lf_start_2();
1716
return NULL;
1817
}
1918

2019
int main(void) {
21-
pthread_t thread1, thread2;
20+
pthread_t threads[2];
2221
printf("Starting S4NOC Federated LF Example\n");
23-
24-
// Create threads for each federate
25-
pthread_create(&thread1, NULL, f1_thread, NULL);
26-
pthread_create(&thread2, NULL, f2_thread, NULL);
22+
pthread_create(&threads[0], NULL, f1_thread, NULL);
23+
pthread_create(&threads[1], NULL, f2_thread, NULL);
2724

2825
printf("Threads created for federates.\n");
2926

30-
// Wait for both federates to finish
31-
pthread_join(thread1, NULL);
32-
pthread_join(thread2, NULL);
27+
pthread_join(threads[0], NULL);
28+
pthread_join(threads[1], NULL);
3329

3430
printf("All federates finished.\n");
35-
return 0;
36-
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)