Rev 1236 | Rev 1241 | 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 | |
7 | /* Activate task output */ |
||
8 | #define TASK_OUTPUT |
||
9 | |||
1233 | giacomo | 10 | int cal_cycles=0; |
11 | struct timespec zero_time; |
||
1239 | giacomo | 12 | extern struct loader_task *loader_task_list; |
1232 | giacomo | 13 | |
1239 | giacomo | 14 | /* oneshot Soft and hard Task */ |
15 | void *oneshot_task(void *arg) |
||
1232 | giacomo | 16 | { |
17 | long long i,exec_cycles = 0; |
||
18 | int act = 0; |
||
1234 | giacomo | 19 | struct loader_task *l = (struct loader_task *)(arg); |
1232 | giacomo | 20 | char tmp[20]; |
21 | |||
1236 | giacomo | 22 | #ifdef TASK_OUTPUT |
23 | sprintf(tmp,"X[%06d]",act); |
||
24 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
25 | #endif |
||
1232 | giacomo | 26 | |
1236 | giacomo | 27 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[act])) * CALIBRATION_DELTA / cal_cycles; |
1232 | giacomo | 28 | |
1236 | giacomo | 29 | for (i=0;i<exec_cycles;i++) calibration_func(); |
1232 | giacomo | 30 | |
1236 | giacomo | 31 | generic_task_endcycle(); |
1239 | giacomo | 32 | |
33 | return NULL; |
||
34 | |||
35 | } |
||
36 | |||
37 | void * periodic_task(void *arg) |
||
38 | { |
||
39 | long long i,exec_cycles = 0; |
||
40 | int act = 0; |
||
41 | struct loader_task *l = (struct loader_task *)(arg); |
||
42 | char tmp[20]; |
||
43 | |||
44 | while(1) { |
||
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 |
||
1235 | giacomo | 50 | |
1239 | giacomo | 51 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[act])) * CALIBRATION_DELTA / cal_cycles; |
52 | |||
53 | for (i=0;i<exec_cycles;i++) calibration_func(); |
||
54 | |||
55 | generic_task_endcycle(); |
||
56 | |||
57 | act++; |
||
58 | |||
59 | } |
||
1232 | giacomo | 60 | return NULL; |
61 | |||
62 | } |
||
63 | |||
1239 | giacomo | 64 | void * back_task(void *arg) |
65 | { |
||
66 | long long i,exec_cycles = 0; |
||
67 | int act = 0; |
||
68 | struct loader_task *l = (struct loader_task *)(arg); |
||
69 | char tmp[20]; |
||
70 | |||
71 | while(1) { |
||
72 | |||
73 | #ifdef TASK_OUTPUT |
||
74 | sprintf(tmp,"X[%06d]",act); |
||
75 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
||
76 | #endif |
||
77 | |||
78 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[0])) * CALIBRATION_DELTA / cal_cycles; |
||
79 | |||
80 | for (i=0;i<exec_cycles;i++) calibration_func(); |
||
81 | |||
82 | act++; |
||
83 | |||
84 | } |
||
85 | return NULL; |
||
86 | |||
87 | } |
||
88 | |||
1232 | giacomo | 89 | /* Task create */ |
1239 | giacomo | 90 | /* this function create the task struct in memory */ |
91 | |||
1234 | giacomo | 92 | void loader_task_create() |
1232 | giacomo | 93 | { |
94 | |||
1234 | giacomo | 95 | struct loader_task *current = loader_task_list; |
96 | int i=0, k=0, total_task; |
||
1232 | giacomo | 97 | int total_group = 0; |
98 | |||
1233 | giacomo | 99 | total_task = sizeof(loader_task_list)/sizeof(struct loader_task); |
1239 | giacomo | 100 | |
1235 | giacomo | 101 | cprintf("Created 1 %d loader tasks\n",total_task); |
1239 | giacomo | 102 | |
1234 | giacomo | 103 | while (k < total_task) { |
1232 | giacomo | 104 | k++; |
105 | total_group++; |
||
106 | current->group = total_group; |
||
1239 | giacomo | 107 | |
1232 | giacomo | 108 | for (i=0; i < current->number; i++) { |
1239 | giacomo | 109 | |
1232 | giacomo | 110 | pthread_t j; |
111 | int err; |
||
1239 | giacomo | 112 | void *func=NULL; |
113 | switch(current->task_type) { |
||
114 | case PAR_TASK_OS: |
||
115 | func=oneshot_task; |
||
116 | break; |
||
117 | case PAR_TASK_BT: |
||
118 | func=back_task; |
||
119 | break; |
||
120 | case PAR_TASK_CT: |
||
121 | func=periodic_task; |
||
122 | break; |
||
123 | } |
||
124 | err = generic_create_thread(current->server,&j,NULL,func,(void *)current,generic_get_task_model(current)); |
||
1232 | giacomo | 125 | if (err) { |
126 | cprintf("Error fsf task creating\n"); |
||
127 | sys_end(); |
||
128 | } |
||
129 | |||
130 | } |
||
131 | |||
1234 | giacomo | 132 | current = &loader_task_list[k]; |
133 | |||
1232 | giacomo | 134 | } |
135 | |||
1234 | giacomo | 136 | cprintf("Created %d loader tasks\n",total_task); |
137 | |||
1232 | giacomo | 138 | |
139 | } |
||
140 | |||
141 | |||
1239 | giacomo | 142 | int start_environment() |
1232 | giacomo | 143 | { |
144 | |||
1234 | giacomo | 145 | struct timespec total = {20,0}; |
1233 | giacomo | 146 | |
1232 | giacomo | 147 | generic_calibrate_cycle(); |
1234 | giacomo | 148 | |
1233 | giacomo | 149 | kern_gettime(&zero_time); |
1232 | giacomo | 150 | |
151 | generic_fsfinit(); |
||
152 | |||
1234 | giacomo | 153 | loader_task_create(); |
1232 | giacomo | 154 | |
1233 | giacomo | 155 | generic_set_simulation_time(&total); |
1232 | giacomo | 156 | |
1239 | giacomo | 157 | generic_start_simulation(); |
158 | |||
1232 | giacomo | 159 | return 0; |
160 | |||
161 | } |