Rev 1360 | Rev 1394 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1173 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://shark.sssup.it |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * This program is free software; you can redistribute it and/or modify |
||
20 | * it under the terms of the GNU General Public License as published by |
||
21 | * the Free Software Foundation; either version 2 of the License, or |
||
22 | * (at your option) any later version. |
||
23 | * |
||
24 | * This program is distributed in the hope that it will be useful, |
||
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
27 | * GNU General Public License for more details. |
||
28 | * |
||
29 | * You should have received a copy of the GNU General Public License |
||
30 | * along with this program; if not, write to the Free Software |
||
31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
32 | */ |
||
33 | |||
34 | /* |
||
35 | * Advanced Timer Demo |
||
36 | * |
||
37 | */ |
||
38 | |||
39 | #include "kernel/kern.h" |
||
40 | #include "ll/i386/cons.h" |
||
41 | #include "ll/i386/advtimer.h" |
||
42 | |||
1374 | giacomo | 43 | #include "drivers/shark_linuxc26.h" |
44 | #include "drivers/shark_input26.h" |
||
1360 | giacomo | 45 | #include "drivers/shark_keyb26.h" |
1173 | giacomo | 46 | |
47 | #define UPDATE_PERIOD 10000 |
||
48 | #define UPDATE_WCET 1000 |
||
49 | |||
1211 | giacomo | 50 | extern unsigned int clk_per_msec; |
51 | extern unsigned int apic_clk_per_msec; |
||
1173 | giacomo | 52 | |
1374 | giacomo | 53 | volatile int shark_running = 1; |
54 | |||
55 | int device_drivers_close() |
||
56 | { |
||
57 | |||
58 | KEYB26_close(); |
||
59 | INPUT26_close(); |
||
60 | |||
61 | return 0; |
||
62 | |||
63 | } |
||
64 | |||
65 | int device_drivers_init() |
||
66 | { |
||
67 | |||
68 | KEYB_PARMS kparms = BASE_KEYB; |
||
69 | |||
70 | LINUXC26_register_module(); |
||
71 | |||
72 | INPUT26_init(); |
||
73 | |||
74 | KEYB26_init(&kparms); |
||
75 | |||
76 | return 0; |
||
77 | |||
78 | } |
||
79 | |||
1173 | giacomo | 80 | void program_key_end(KEY_EVT *k) |
81 | { |
||
82 | |||
1374 | giacomo | 83 | shark_running = 0; |
1173 | giacomo | 84 | |
85 | } |
||
86 | |||
87 | TASK Update(void *arg) |
||
88 | { |
||
89 | struct timespec actual_timer; |
||
90 | |||
91 | long nsec,sec,min,hrs,day; |
||
92 | long mean_delay,tot_delay,num_delay; |
||
93 | |||
94 | signed long long start,end,res; |
||
95 | struct timespec s_test,startts,endts; |
||
96 | |||
97 | task_nopreempt(); |
||
98 | |||
99 | num_delay = tot_delay = mean_delay = 0; |
||
100 | |||
101 | while (1) { |
||
102 | |||
103 | if (clk_per_msec != 0) { |
||
104 | |||
105 | rdtscll(start); |
||
106 | sys_gettime(&actual_timer); |
||
107 | rdtscll(end); |
||
108 | res = end - start; |
||
109 | rdtscll(start); |
||
110 | rdtscll(end); |
||
111 | res -= (end - start); |
||
112 | s_test.tv_nsec = res * 1000000 / clk_per_msec; |
||
113 | |||
114 | |||
115 | } else { |
||
116 | |||
117 | sys_gettime(&startts); |
||
118 | sys_gettime(&actual_timer); |
||
119 | sys_gettime(&endts); |
||
120 | SUBTIMESPEC(&endts,&startts,&s_test); |
||
121 | sys_gettime(&startts); |
||
122 | sys_gettime(&endts); |
||
123 | SUBTIMESPEC(&endts,&startts,&endts); |
||
124 | SUBTIMESPEC(&s_test,&endts,&s_test); |
||
125 | |||
126 | } |
||
127 | |||
128 | if (tot_delay < 1000000000) { |
||
129 | tot_delay += s_test.tv_nsec; |
||
130 | num_delay ++; |
||
131 | mean_delay = tot_delay / num_delay; |
||
132 | } |
||
133 | |||
134 | nsec = actual_timer.tv_nsec; |
||
135 | sec = actual_timer.tv_sec; |
||
136 | min = sec / 60; |
||
137 | sec %= 60; |
||
138 | hrs = min / 60; |
||
139 | min %= 60; |
||
140 | day = hrs / 24; |
||
141 | hrs %= 24; |
||
142 | |||
1211 | giacomo | 143 | printf_xy(0,5,WHITE,"Actual CPU Clk/msec: %12d",clk_per_msec); |
144 | printf_xy(0,6,WHITE,"Actual APIC Clk/msec: %12d",apic_clk_per_msec); |
||
145 | printf_xy(0,7,WHITE,"Actual Timer: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec); |
||
1173 | giacomo | 146 | |
1211 | giacomo | 147 | printf_xy(0,9,WHITE,"Timer Access Delay: %12ld ns",mean_delay); |
1173 | giacomo | 148 | |
149 | task_endcycle(); |
||
150 | |||
151 | } |
||
152 | |||
153 | } |
||
154 | |||
155 | void set_screen() |
||
156 | { |
||
157 | |||
158 | printf_xy(20,0,WHITE," Advanced Timer Demo "); |
||
159 | printf_xy(20,1,WHITE,"Giacomo Guidi <giacomo@gandalf.sssup.it>"); |
||
160 | printf_xy(20,2,WHITE," Press Alt + c to exit "); |
||
161 | |||
162 | } |
||
163 | |||
164 | |||
165 | int main(int argc, char **argv) |
||
166 | { |
||
167 | |||
168 | HARD_TASK_MODEL mp; //Show current setting |
||
169 | PID update; |
||
170 | KEY_EVT k; |
||
1374 | giacomo | 171 | |
172 | device_drivers_init(); |
||
173 | |||
1173 | giacomo | 174 | k.flag = ALTL_BIT; |
175 | k.scan = KEY_C; |
||
176 | k.ascii = 'c'; |
||
1360 | giacomo | 177 | k.status = KEY_PRESSED; |
178 | keyb_hook(k,program_key_end,FALSE); |
||
1173 | giacomo | 179 | |
180 | set_screen(); |
||
181 | |||
182 | hard_task_default_model(mp); |
||
183 | hard_task_def_ctrl_jet(mp); |
||
184 | hard_task_def_group(mp, 1); |
||
185 | hard_task_def_wcet(mp,UPDATE_WCET); |
||
186 | hard_task_def_mit(mp,UPDATE_PERIOD); |
||
187 | hard_task_def_usemath(mp); |
||
188 | update = task_create("Update", Update, &mp, NULL); |
||
189 | if (update != NIL) task_activate(update); |
||
190 | |||
1374 | giacomo | 191 | while(shark_running); |
192 | |||
193 | device_drivers_close(); |
||
194 | |||
195 | sys_end(); |
||
196 | |||
1173 | giacomo | 197 | return 0; |
198 | |||
199 | } |