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