Rev 1172 | Rev 1185 | 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 | * Copyright (C) 2000 Paolo Gai |
||
20 | * |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | */ |
||
35 | |||
36 | /* |
||
37 | * Advanced Timer Demo |
||
38 | * |
||
39 | */ |
||
40 | |||
41 | #include "kernel/kern.h" |
||
42 | #include "ll/i386/cons.h" |
||
43 | |||
44 | #include "ll/i386/advtimer.h" |
||
45 | |||
46 | #include "drivers/keyb.h" |
||
47 | |||
48 | #define UPDATE_PERIOD 10000 |
||
49 | #define UPDATE_WCET 1000 |
||
50 | |||
51 | extern signed long long clk_per_msec; |
||
52 | |||
53 | extern signed long last_delta_clk_per_msec; |
||
54 | extern signed long total_delta_clk_per_msec; |
||
55 | |||
56 | extern unsigned char use_tsc; |
||
57 | extern unsigned char use_cmos; |
||
58 | |||
59 | void program_key_end(KEY_EVT *k) |
||
60 | { |
||
61 | |||
62 | sys_end(); |
||
63 | |||
64 | } |
||
65 | |||
66 | TASK Update(void *arg) |
||
67 | { |
||
68 | struct timespec actual_timer; |
||
69 | |||
70 | long nsec,sec,min,hrs,day; |
||
71 | long mean_delay,tot_delay,num_delay; |
||
72 | long total_percent; |
||
73 | |||
74 | signed long long start,end,res; |
||
75 | struct timespec s_test,startts,endts; |
||
76 | |||
77 | task_nopreempt(); |
||
78 | |||
79 | num_delay = tot_delay = mean_delay = 0; |
||
80 | |||
81 | while (1) { |
||
82 | |||
83 | if (clk_per_msec != 0) { |
||
84 | |||
85 | rdtscll(start); |
||
86 | sys_gettime(&actual_timer); |
||
87 | rdtscll(end); |
||
88 | res = end - start; |
||
89 | rdtscll(start); |
||
90 | rdtscll(end); |
||
91 | res -= (end - start); |
||
92 | s_test.tv_nsec = res * 1000000 / clk_per_msec; |
||
93 | |||
94 | |||
95 | } else { |
||
96 | |||
97 | sys_gettime(&startts); |
||
98 | sys_gettime(&actual_timer); |
||
99 | sys_gettime(&endts); |
||
100 | SUBTIMESPEC(&endts,&startts,&s_test); |
||
101 | sys_gettime(&startts); |
||
102 | sys_gettime(&endts); |
||
103 | SUBTIMESPEC(&endts,&startts,&endts); |
||
104 | SUBTIMESPEC(&s_test,&endts,&s_test); |
||
105 | |||
106 | } |
||
107 | |||
108 | if (tot_delay < 1000000000) { |
||
109 | tot_delay += s_test.tv_nsec; |
||
110 | num_delay ++; |
||
111 | mean_delay = tot_delay / num_delay; |
||
112 | } |
||
113 | |||
114 | nsec = actual_timer.tv_nsec; |
||
115 | sec = actual_timer.tv_sec; |
||
116 | min = sec / 60; |
||
117 | sec %= 60; |
||
118 | hrs = min / 60; |
||
119 | min %= 60; |
||
120 | day = hrs / 24; |
||
121 | hrs %= 24; |
||
122 | |||
123 | if (use_tsc) |
||
124 | if (use_cmos) |
||
125 | printf_xy(0,4,WHITE,"Timer Mode: TSC + CMOS"); |
||
126 | else |
||
127 | printf_xy(0,4,WHITE,"Timer Mode: TSC"); |
||
128 | else |
||
129 | printf_xy(0,4,WHITE,"Timer Mode: 8254"); |
||
130 | |||
131 | printf_xy(0,5,WHITE,"Actual Clk/msec: %12ld",(long)clk_per_msec); |
||
132 | printf_xy(0,6,WHITE,"Actual Timer: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec); |
||
133 | |||
134 | printf_xy(0,8,WHITE,"CMOS Adjustement setting"); |
||
135 | printf_xy(0,9,WHITE,"CMOS last delta Clk/msec: %12ld",(long)last_delta_clk_per_msec); |
||
136 | |||
137 | if (total_delta_clk_per_msec != 0) |
||
138 | total_percent = clk_per_msec / abs(total_delta_clk_per_msec); |
||
139 | else |
||
140 | total_percent = 0; |
||
141 | |||
142 | printf_xy(0,10,WHITE,"CMOS total delta Clk/msec: %12ld (1/%ld)",(long)total_delta_clk_per_msec,total_percent); |
||
143 | |||
144 | printf_xy(0,12,WHITE,"Timer Access Delay: %12ld ns",mean_delay); |
||
145 | |||
146 | task_endcycle(); |
||
147 | |||
148 | } |
||
149 | |||
150 | sys_end(); |
||
151 | |||
152 | } |
||
153 | |||
154 | void set_screen() |
||
155 | { |
||
156 | |||
157 | printf_xy(20,0,WHITE," Advanced Timer Demo "); |
||
158 | printf_xy(20,1,WHITE,"Giacomo Guidi <giacomo@gandalf.sssup.it>"); |
||
159 | printf_xy(20,2,WHITE," Press Alt + c to exit "); |
||
160 | |||
161 | } |
||
162 | |||
163 | |||
164 | int main(int argc, char **argv) |
||
165 | { |
||
166 | |||
167 | HARD_TASK_MODEL mp; //Show current setting |
||
168 | PID update; |
||
169 | KEY_EVT k; |
||
170 | |||
171 | k.flag = ALTL_BIT; |
||
172 | k.scan = KEY_C; |
||
173 | k.ascii = 'c'; |
||
174 | keyb_hook(k,program_key_end); |
||
175 | |||
176 | clear(); |
||
177 | |||
178 | set_screen(); |
||
179 | |||
180 | hard_task_default_model(mp); |
||
181 | hard_task_def_ctrl_jet(mp); |
||
182 | hard_task_def_group(mp, 1); |
||
183 | hard_task_def_wcet(mp,UPDATE_WCET); |
||
184 | hard_task_def_mit(mp,UPDATE_PERIOD); |
||
185 | hard_task_def_usemath(mp); |
||
186 | update = task_create("Update", Update, &mp, NULL); |
||
187 | if (update != NIL) task_activate(update); |
||
188 | |||
189 | return 0; |
||
190 | |||
191 | } |