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