forked from vsamtuc/tinyos3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtask.c
106 lines (78 loc) · 2.09 KB
/
mtask.c
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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include "tinyoslib.h"
#include "symposium.h"
/*
A standalone program to launch the Dining Philisophers
symposium implementation.
*/
/*
* This is the initial task, which starts all the other tasks (except for the idle task).
*/
int boot_symposium(int argl, void* args)
{
tinyos_replace_stdio();
if(GetTerminalDevices()>0) {
int fid = OpenTerminal(0);
if(fid!=NOFILE && fid!=0) {
Dup2(fid,0);
Close(fid);
}
/* Open standard output */
fid = OpenTerminal(0);
if(fid!=NOFILE && fid!=1) {
Dup2(fid,1);
Close(fid);
}
} else {
tinyos_pseudo_console();
}
/* Open standard input */
/* Just start task Symposium */
Exec(SymposiumOfProcesses, argl, args);
Close(0);
Close(1);
while( WaitChild(NOPROC, NULL)!=NOPROC ); /* Wait for all children */
tinyos_restore_stdio();
return 0;
}
/****************************************************/
void usage(const char* pname)
{
printf("usage:\n %s <ncores> <nterm> <philosophers> <bites>\n\n \
where:\n\
<ncores> is the number of cpu cores to use,\n\
<nterm> is the number of terminals to use,\n\
<philosiphers> is from 1 to %d\n\
<bites> is the number of times each philisopher eats.\n",
pname, MAX_PROC);
exit(1);
}
int FMIN= FBASE;
int FMAX= FBASE+FGAP;
int main(int argc, const char** argv)
{
unsigned int ncores, nterm;
int nphil, bites;
if(argc!=5) usage(argv[0]);
ncores = atoi(argv[1]);
nterm = atoi(argv[2]);
nphil = atoi(argv[3]);
bites = atoi(argv[4]);
/* check arguments */
if( (nphil <= 0) || (nphil > MAX_PROC) ) usage(argv[0]);
if( (bites <= 0) ) usage(argv[0]);
/* adjust work per fibo call (to adapt to many philosophers/bites) */
symposium_t symp;
symp.N = nphil;
symp.bites = bites;
adjust_symposium(&symp, 0, 0);
printf("FMIN = %d FMAX = %d\n",symp.fmin,symp.fmax);
/* boot TinyOS */
printf("*** Booting TinyOS\n");
boot(ncores, nterm, boot_symposium, sizeof(symp), &symp);
printf("*** TinyOS halted. Bye!\n");
return 0;
}