Rev 1153 | Rev 1173 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1151 | 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 : |
||
1152 | giacomo | 9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
1151 | giacomo | 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 | |||
1152 | giacomo | 36 | /* |
37 | * Advanced Timer Demo |
||
38 | * |
||
39 | */ |
||
40 | |||
1151 | giacomo | 41 | #include "kernel/kern.h" |
42 | #include "ll/i386/cons.h" |
||
43 | |||
1172 | giacomo | 44 | #include "ll/i386/advtimer.h" |
45 | |||
1151 | giacomo | 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 | |||
1172 | giacomo | 72 | signed long long start,end,res; |
73 | struct timespec s_test; |
||
1151 | giacomo | 74 | |
1172 | giacomo | 75 | task_nopreempt(); |
76 | |||
1151 | giacomo | 77 | while (1) { |
1172 | giacomo | 78 | |
79 | rdtscll(start); |
||
80 | sys_gettime(&actual_timer); |
||
81 | rdtscll(end); |
||
82 | res = end - start; |
||
83 | rdtscll(start); |
||
84 | rdtscll(end); |
||
85 | res -= (end - start); |
||
86 | s_test.tv_nsec = res * 1000000 / clk_per_msec; |
||
1151 | giacomo | 87 | |
88 | nsec = actual_timer.tv_nsec; |
||
89 | sec = actual_timer.tv_sec; |
||
90 | min = sec / 60; |
||
91 | sec %= 60; |
||
92 | hrs = min / 60; |
||
93 | min %= 60; |
||
94 | day = hrs / 24; |
||
95 | hrs %= 24; |
||
96 | |||
97 | if (use_tsc) |
||
98 | if (use_cmos) |
||
99 | printf_xy(0,4,WHITE,"Timer Mode: TSC + CMOS"); |
||
100 | else |
||
101 | printf_xy(0,4,WHITE,"Timer Mode: TSC"); |
||
102 | else |
||
103 | printf_xy(0,4,WHITE,"Timer Mode: 8254"); |
||
104 | |||
105 | printf_xy(0,5,WHITE,"Actual Clk/msec: %12ld",(long)clk_per_msec); |
||
106 | printf_xy(0,6,WHITE,"Actual Timer: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec); |
||
107 | |||
1153 | giacomo | 108 | printf_xy(0,8,WHITE,"CMOS Adjustement setting"); |
1151 | giacomo | 109 | printf_xy(0,9,WHITE,"CMOS last delta Clk/msec: %12ld",(long)last_delta_clk_per_msec); |
110 | printf_xy(0,10,WHITE,"CMOS total delta Clk/msec: %12ld",(long)total_delta_clk_per_msec); |
||
111 | |||
1172 | giacomo | 112 | printf_xy(0,12,WHITE,"Timer Access Delay: %12ld ns",s_test.tv_nsec); |
1151 | giacomo | 113 | |
114 | task_endcycle(); |
||
115 | |||
116 | } |
||
117 | |||
118 | sys_end(); |
||
119 | |||
120 | } |
||
121 | |||
122 | void set_screen() |
||
123 | { |
||
124 | |||
125 | printf_xy(20,0,WHITE," Advanced Timer Demo "); |
||
126 | printf_xy(20,1,WHITE,"Giacomo Guidi <giacomo@gandalf.sssup.it>"); |
||
127 | printf_xy(20,2,WHITE," Press Alt + c to exit "); |
||
128 | |||
129 | } |
||
130 | |||
131 | |||
132 | int main(int argc, char **argv) |
||
133 | { |
||
134 | |||
135 | HARD_TASK_MODEL mp; //Show current setting |
||
136 | PID update; |
||
137 | KEY_EVT k; |
||
1172 | giacomo | 138 | |
1151 | giacomo | 139 | k.flag = ALTL_BIT; |
140 | k.scan = KEY_C; |
||
141 | k.ascii = 'c'; |
||
142 | keyb_hook(k,program_key_end); |
||
143 | |||
144 | clear(); |
||
145 | |||
146 | set_screen(); |
||
1172 | giacomo | 147 | |
1151 | giacomo | 148 | hard_task_default_model(mp); |
149 | hard_task_def_ctrl_jet(mp); |
||
150 | hard_task_def_group(mp, 1); |
||
151 | hard_task_def_wcet(mp,UPDATE_WCET); |
||
152 | hard_task_def_mit(mp,UPDATE_PERIOD); |
||
153 | hard_task_def_usemath(mp); |
||
154 | update = task_create("Update", Update, &mp, NULL); |
||
155 | if (update != NIL) task_activate(update); |
||
156 | |||
157 | return 0; |
||
158 | |||
159 | } |