File: rtl_time.h

package info (click to toggle)
rtlinux 3.1pre3-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 4,896 kB
  • ctags: 4,228
  • sloc: ansic: 26,204; sh: 2,069; makefile: 1,414; perl: 855; tcl: 489; asm: 380; cpp: 42
file content (141 lines) | stat: -rw-r--r-- 3,107 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * rtl_time.h
 *
 * RTLinux architecture-independent clock support
 *
 * Copyright (C) 1999 Michael Barabanov
 *
 */

#ifndef __RTL_TIME__
#define __RTL_TIME__



#define NSECS_PER_SEC 1000000000
#define HRTIME_INFINITY 0x7fffFfffFfffFfffLL

#ifdef __KERNEL__

#include <asm/ptrace.h>
#include <rtl_conf.h>

extern int *(*__errno_location)(void);
#define errno (*(*__errno_location)())

/* for timespec */
#include <linux/posix_types.h>
#include <linux/time.h>
#endif

#include <arch/rtl_time.h>

#define HRT_FROM_NS(x) (x)
#define HRTICKS_PER_SEC 1000000000

#ifndef HRT_FROM_8254
#define HRT_FROM_8254(x) ((x) * 838)
#endif

#ifndef HRT_TO_8254
#define HRT_TO_8254(x) ((x) / 838)
#endif

#ifdef __KERNEL__

#include <rtl_spinlock.h>

typedef void (* clock_irq_handler_t)(struct pt_regs *r);

enum { RTL_CLOCK_MODE_UNINITIALIZED = 1, RTL_CLOCK_MODE_ONESHOT,
RTL_CLOCK_MODE_PERIODIC};

struct rtl_clock {
	int (*init) (struct rtl_clock *);
	void (*uninit) (struct rtl_clock *);
	hrtime_t (*gethrtime)(struct rtl_clock *);
	int (*sethrtime)(struct rtl_clock *, hrtime_t t);

	int (*settimer)(struct rtl_clock *, hrtime_t interval);
	int (*settimermode)(struct rtl_clock *, int mode);
	clock_irq_handler_t handler;
	int mode;
	hrtime_t resolution;
	hrtime_t value;
	hrtime_t delta;
	pthread_spinlock_t lock;
	struct rtl_clock_arch arch;
};

typedef struct rtl_clock *clockid_t;

extern struct rtl_clock RTL_CLOCK_DEFAULTS;

extern int rtl_setclockhandler (clockid_t h, clock_irq_handler_t fn);
extern int rtl_unsetclockhandler (clockid_t h);

extern int rtl_clockadjust (clockid_t clock_id, hrtime_t delta);

/* scheduler interface */
static inline hrtime_t clock_gethrtime (clockid_t clock_id)
{
	return clock_id->gethrtime (clock_id);
}

extern clockid_t rtl_getbestclock (unsigned int cpu);


/* end of scheduler interface */


extern int rtl_init_standard_clocks(void);
extern void rtl_cleanup_standard_clocks(void);

#ifdef CONFIG_RTL_CLOCK_GPOS
extern clockid_t CLOCK_GPOS;
#endif

#endif /* __KERNEL__ */

/* convenience functions */
#define timespec_normalize(t) {\
	if ((t)->tv_nsec >= NSECS_PER_SEC) { \
		(t)->tv_nsec -= NSECS_PER_SEC; \
		(t)->tv_sec++; \
	} else if ((t)->tv_nsec < 0) { \
		(t)->tv_nsec += NSECS_PER_SEC; \
		(t)->tv_sec--; \
	} \
}

#define timespec_add(t1, t2) do { \
	(t1)->tv_nsec += (t2)->tv_nsec;  \
	(t1)->tv_sec += (t2)->tv_sec; \
	timespec_normalize(t1);\
} while (0)

#define timespec_sub(t1, t2) do { \
	(t1)->tv_nsec -= (t2)->tv_nsec;  \
	(t1)->tv_sec -= (t2)->tv_sec; \
	timespec_normalize(t1);\
} while (0)

#define timespec_add_ns(t,n) do { \
	(t)->tv_nsec += n;  \
	timespec_normalize(t); \
        } while (0)
	
#define timespec_nz(t) ((t)->tv_sec != 0 || (t)->tv_nsec != 0)

#define timespec_lt(t1, t2) ((t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && (t1)->tv_nsec < (t2)->tv_nsec))

#define timespec_gt(t1, t2) (timespec_lt(t2, t1))

#define timespec_ge(t1, t2) (!timespec_lt(t1, t2))

#define timespec_le(t1, t2) (!timespec_gt(t1, t2))

#define timespec_eq(t1, t2) ((t1)->tv_sec == (t2)->tv_sec && (t1)->tv_nsec == (t2)->tv_nsec)

#endif