File tree Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ # copy this into the codegen/exe/user folder on the target machine
2
+ # then run it, it will build the binary in this folder
3
+ vpath % c ../../../stl
4
+ OBJ = thread1.o thread2.o thread3.o user.o user_initialize.o user_terminate.o main.o stl.o
5
+ CFLAGS += -I . -I ../../../stl
6
+ LIBS = -ldl -lpthread -lrt
7
+
8
+ user : $(OBJ )
9
+ $(CC ) -o main -fPIC $(OBJ ) $(LIBS )
Original file line number Diff line number Diff line change
1
+ % make.m
2
+
3
+ cfg = coder .config(' exe' )
4
+ cfg.TargetLang = ' C' ;
5
+ cfg.MultiInstanceCode = true ;
6
+
7
+ cfg.GenerateReport = true ;
8
+ % cfg.LaunchReport = true;
9
+
10
+ % build options
11
+ % cfg.GenerateExampleMain = 'DoNotGenerate';
12
+ cfg.GenCodeOnly = true ;
13
+
14
+ cfg.GenerateComments = true ;
15
+ cfg.MATLABSourceComments = true ; % lots of comments
16
+ cfg.PreserveVariableNames = ' UserNames' ;
17
+
18
+ % want to include some files from this directory, but this doesnt work??
19
+ cfg.CustomSource = ' main.c stl.c'
20
+ cfg.CustomInclude = ' ../../stl' ;
21
+
22
+ cfg.BuildConfiguration = ' Faster Builds' ;
23
+ % cfg.BuildConfiguration = 'Debug';
24
+
25
+ % would be nice if could set make -j to get some parallel building
26
+ % happening.
27
+
28
+ % for Raspberry Pi
29
+ % hw = coder.hardware('Raspberry Pi');
30
+ % cfg.Hardware = hw;
31
+ % cfg.GenCodeOnly = true;
32
+
33
+ cfg.PostCodeGenCommand = ' postbuild(projectName, buildInfo)' ;
34
+ %{
35
+ cfg.InlineThreshold = 0; % tone down the aggressive inlining
36
+ codegen user.m thread1.m -args int32(0) thread2.m thread3.m -O disable:inline -config cfg
37
+ %}
38
+
39
+ codegen user.m thread1.m -config cfg
40
+ % MAKE = gmake
41
+ % MAKE_FLAGS = -f $(MAKEFILE)
42
+ % hw = coder.hardware('Raspberry Pi');
43
+ % cfg.Hardware = hw;
Original file line number Diff line number Diff line change
1
+ function thread1() % #codegen
2
+
3
+ stllog(' hello from thread1' );
4
+
5
+ for i= 1 : 20
6
+ stl .semwait(0 )
7
+ stl .log(' wakeup' );
8
+ end
9
+ end
10
+
Original file line number Diff line number Diff line change
1
+ function user % #codegen
2
+
3
+
4
+
5
+ % z.a = 1
6
+ % z.b = 2
7
+ % coder.cstructname(z, 'arg_t')
8
+
9
+ s1 = stl .semaphore(' sem1' );
10
+ stllog(' sem id ' , s1 );
11
+
12
+ t1 = launch(' thread1' , 0 ) % pass a value to this thread
13
+ stllog(' thread id %d ' , t1 )
14
+
15
+ timer = stl .timer(' timer1' , 2.0 , s1 );
16
+ join(t1 ); % wait for thread 1 to finish
17
+
18
+
19
+ % done, exiting will tear down all the threads
20
+
21
+ end
22
+
You can’t perform that action at this time.
0 commit comments