Subversion Repositories shark

Rev

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