Xenomai  3.0-rc6
tsc.h
1 /*
2  * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _LIB_COBALT_SH_TSC_H
19 #define _LIB_COBALT_SH_TSC_H
20 
21 #include <endian.h>
22 
23 struct xnarch_tsc_area {
24  struct {
25 #if __BYTE_ORDER == __BIG_ENDIAN
26  unsigned long high;
27  unsigned long low;
28 #else /* __LITTLE_ENDIAN */
29  unsigned long low;
30  unsigned long high;
31 #endif /* __LITTLE_ENDIAN */
32  } tsc;
33  unsigned long counter_pa;
34 };
35 
36 extern volatile struct xnarch_tsc_area *__cobalt_sh_tsc;
37 
38 extern volatile unsigned long *__cobalt_sh_tcnt;
39 
40 static inline unsigned long long cobalt_read_tsc(void)
41 {
42  unsigned long long tsc;
43  unsigned long low;
44 
45  tsc = __cobalt_sh_tsc->tsc.high;
46  low = *__cobalt_sh_tcnt ^ 0xffffffffUL;
47  if (low < __cobalt_sh_tsc->tsc.low)
48  tsc++;
49  tsc = (tsc << 32)|low;
50 
51  return tsc;
52 }
53 
54 #endif /* !_LIB_COBALT_SH_TSC_H */