Rev 1233 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1232 | giacomo | 1 | #include <kernel/kern.h> |
2 | |||
3 | #include "fsf_contract.h" |
||
4 | #include "fsf_server.h" |
||
5 | #include "event_header.h" |
||
6 | #include "func.h" |
||
7 | |||
8 | /* Calibration Loops */ |
||
9 | #define CALIBRATION_DELTA 10000 |
||
10 | |||
11 | /* Activate task output */ |
||
12 | #define TASK_OUTPUT |
||
13 | |||
14 | int cal_cycles = 0; |
||
15 | struct timespec zero_time; |
||
16 | |||
17 | |||
18 | /* Soft and hard Task */ |
||
19 | TASK test_task(void *arg) |
||
20 | { |
||
21 | long long i,exec_cycles = 0; |
||
22 | int crit_start,crit_len; |
||
23 | long long crit_start_cycles = 0, crit_len_cycles = 0; |
||
24 | struct timespec next_time; |
||
25 | int act = 0; |
||
26 | struct loader_task *l = loader_task_list[get_current_exec_task()]; |
||
27 | char tmp[20]; |
||
28 | |||
29 | |||
30 | while((l->act_num)>act) { |
||
31 | |||
32 | //task_testcancel(); |
||
33 | |||
34 | act++; |
||
35 | |||
36 | #ifdef TASK_OUTPUT |
||
37 | sprintf(tmp,"X[%06d]",act); |
||
38 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
39 | #endif |
||
40 | |||
41 | |||
42 | generic_set_next_activationn(&l->act[act]); |
||
43 | |||
44 | exec_cycles = (long long)(TIMESPEC2USEC(l->exec[act])) * CALIBRATION_DELTA / cal_cycles; |
||
45 | |||
46 | #ifdef TASK_OUTPUT |
||
47 | sprintf(tmp,"X[%06d]",act); |
||
48 | printf_xy((get_current_exec_task() % 5) * 9 + 34, get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
49 | #endif |
||
50 | for (i=0;i<exec_cycles;i++) calibration_func(); |
||
51 | |||
52 | |||
53 | generic_task_endcycle(); |
||
54 | |||
55 | } |
||
56 | |||
57 | return NULL; |
||
58 | |||
59 | } |
||
60 | |||
61 | |||
62 | /* Mutex create */ |
||
63 | /* |
||
64 | void loader_mutex_create(struct loader_task *start_loader_task) |
||
65 | { |
||
66 | |||
67 | struct loader_task *current = start_loader_task; |
||
68 | int i,res = 0; |
||
69 | PI_mutexattr_t a; |
||
70 | int init_array[MAX_MUTEX]; |
||
71 | |||
72 | PI_mutexattr_default(a); |
||
73 | |||
74 | for (i = 0;i < MAX_MUTEX;i++) init_array[i] = 0; |
||
75 | |||
76 | while (current != NULL) { |
||
77 | |||
78 | if (current->crit_type == PAR_CRIT) { |
||
79 | if (init_array[current->resource] == 0) { |
||
80 | mutex_init(&mux_table[current->resource],&a); |
||
81 | init_array[current->resource] = 1; |
||
82 | res++; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | current = current->next; |
||
87 | |||
88 | } |
||
89 | |||
90 | cprintf("Created %d mutex\n",res); |
||
91 | |||
92 | } |
||
93 | */ |
||
94 | |||
95 | /* Task create */ |
||
96 | void loader_task_create(struct loader_task *start_loader_task) |
||
97 | { |
||
98 | |||
99 | struct loader_task *current = &loader_task_list[0]; |
||
100 | char tmp[30]; |
||
101 | int i=0,k=0, total_task; |
||
102 | int total_group = 0; |
||
103 | PID p; |
||
104 | |||
105 | total_task = sizeof(loader_task_list)/sizeof(loader_task); |
||
106 | |||
107 | while (k<total_task) { |
||
108 | k++; |
||
109 | total_group++; |
||
110 | current->group = total_group; |
||
111 | |||
112 | for (i=0; i < current->number; i++) { |
||
113 | |||
114 | pthread_t j; |
||
115 | int err; |
||
116 | |||
117 | err = generic_create_thread(current->server,&j,NULL,test_task,(void *)current,generic_get_task_model(current)); |
||
118 | if (err) { |
||
119 | cprintf("Error fsf task creating\n"); |
||
120 | sys_end(); |
||
121 | } |
||
122 | |||
123 | } |
||
124 | current = &loader_task_list[i]; |
||
125 | |||
126 | } |
||
127 | |||
128 | |||
129 | |||
130 | } |
||
131 | |||
132 | cprintf("Created %d tasks\n",total_task); |
||
133 | |||
134 | } |
||
135 | |||
136 | |||
137 | void generic_fsfinit(void); |
||
138 | |||
139 | int main() |
||
140 | { |
||
141 | |||
142 | struct loader_task *start_loader_task = &loader_task_list[0]; |
||
143 | struct timespec total; |
||
144 | |||
145 | generic_calibrate_cycle(); |
||
146 | |||
147 | generic_fsfinit(); |
||
148 | |||
149 | //loader_mutex_create(start_loader_task); |
||
150 | |||
151 | loader_task_create(start_loader_task); |
||
152 | |||
153 | generic_set_simulation_time(total); |
||
154 | |||
155 | |||
156 | |||
157 | return 0; |
||
158 | |||
159 | } |