Subversion Repositories shark

Rev

Rev 1185 | Rev 1360 | 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
#include "ll/i386/advtimer.h"
44
 
45
#include "drivers/keyb.h"
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
 
53
void program_key_end(KEY_EVT *k)
54
{
55
 
56
  sys_end();
57
 
58
}
59
 
60
TASK Update(void *arg)
61
{  
62
  struct timespec actual_timer;
63
 
64
  long nsec,sec,min,hrs,day;
65
  long mean_delay,tot_delay,num_delay;
66
 
67
  signed long long start,end,res;
68
  struct timespec s_test,startts,endts;
69
 
70
  task_nopreempt();
71
 
72
  num_delay = tot_delay = mean_delay = 0;
73
 
74
  while (1) {
75
 
76
        if (clk_per_msec != 0) {
77
 
78
          rdtscll(start);
79
          sys_gettime(&actual_timer);
80
          rdtscll(end);
81
          res = end - start;
82
          rdtscll(start);
83
          rdtscll(end);
84
          res -= (end - start);
85
          s_test.tv_nsec = res * 1000000 / clk_per_msec;
86
 
87
 
88
        } else {
89
 
90
          sys_gettime(&startts);
91
          sys_gettime(&actual_timer);
92
          sys_gettime(&endts);
93
          SUBTIMESPEC(&endts,&startts,&s_test);
94
          sys_gettime(&startts);
95
          sys_gettime(&endts);
96
          SUBTIMESPEC(&endts,&startts,&endts);
97
          SUBTIMESPEC(&s_test,&endts,&s_test);
98
 
99
        }
100
 
101
        if (tot_delay < 1000000000) {
102
          tot_delay += s_test.tv_nsec;
103
          num_delay ++;
104
          mean_delay = tot_delay / num_delay;
105
        }
106
 
107
        nsec = actual_timer.tv_nsec;
108
        sec = actual_timer.tv_sec;
109
        min = sec / 60;
110
        sec %= 60;
111
        hrs = min / 60;
112
        min %= 60;
113
        day = hrs / 24;
114
        hrs %= 24;
115
 
1211 giacomo 116
        printf_xy(0,5,WHITE,"Actual CPU Clk/msec:  %12d",clk_per_msec);
117
        printf_xy(0,6,WHITE,"Actual APIC Clk/msec: %12d",apic_clk_per_msec);  
118
        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 119
 
1211 giacomo 120
        printf_xy(0,9,WHITE,"Timer Access Delay: %12ld ns",mean_delay);
1173 giacomo 121
 
122
        task_endcycle();
123
 
124
  }
125
 
126
  sys_end();
127
 
128
}
129
 
130
void set_screen()
131
{
132
 
133
        printf_xy(20,0,WHITE,"          Advanced Timer Demo           ");
134
        printf_xy(20,1,WHITE,"Giacomo Guidi <giacomo@gandalf.sssup.it>");
135
        printf_xy(20,2,WHITE,"         Press Alt + c to exit          ");
136
 
137
}
138
 
139
 
140
int main(int argc, char **argv)
141
{
142
 
143
  HARD_TASK_MODEL   mp; //Show current setting
144
  PID               update;
145
  KEY_EVT           k;
146
 
147
  k.flag = ALTL_BIT;
148
  k.scan = KEY_C;
149
  k.ascii = 'c';
150
  keyb_hook(k,program_key_end);
151
 
152
  set_screen();
153
 
154
  hard_task_default_model(mp);
155
  hard_task_def_ctrl_jet(mp);
156
  hard_task_def_group(mp, 1);
157
  hard_task_def_wcet(mp,UPDATE_WCET);
158
  hard_task_def_mit(mp,UPDATE_PERIOD);
159
  hard_task_def_usemath(mp);
160
  update = task_create("Update", Update, &mp, NULL);
161
  if (update != NIL) task_activate(update);
162
 
163
  return 0;
164
 
165
}