Subversion Repositories shark

Rev

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