2009-11-24 09:25:03 +00:00
|
|
|
#include <types.h>
|
2009-11-21 17:22:18 +00:00
|
|
|
|
2007-07-05 16:01:15 +00:00
|
|
|
#ifndef CLOCK_H
|
|
|
|
#define CLOCK_H
|
2007-07-05 16:01:15 +00:00
|
|
|
|
2012-06-28 18:32:32 +00:00
|
|
|
#include <linux/time.h>
|
|
|
|
|
2010-11-26 19:56:26 +00:00
|
|
|
#define CLOCKSOURCE_MASK(bits) (uint64_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
|
|
|
|
|
2007-07-05 16:01:15 +00:00
|
|
|
struct clocksource {
|
|
|
|
uint32_t shift;
|
|
|
|
uint32_t mult;
|
|
|
|
uint64_t (*read)(void);
|
|
|
|
uint64_t cycle_last;
|
|
|
|
uint64_t mask;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-07-05 16:01:15 +00:00
|
|
|
static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles)
|
2007-07-05 16:01:15 +00:00
|
|
|
{
|
|
|
|
uint64_t ret = cycles;
|
|
|
|
ret = (ret * cs->mult) >> cs->shift;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int init_clock(struct clocksource *);
|
|
|
|
|
|
|
|
uint64_t get_time_ns(void);
|
|
|
|
|
2011-06-21 18:56:53 +00:00
|
|
|
void clocks_calc_mult_shift(uint32_t *mult, uint32_t *shift, uint32_t from, uint32_t to, uint32_t maxsec);
|
|
|
|
|
2007-07-05 16:01:15 +00:00
|
|
|
uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant);
|
|
|
|
|
|
|
|
int is_timeout(uint64_t start_ns, uint64_t time_offset_ns);
|
2012-10-29 13:02:35 +00:00
|
|
|
int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns);
|
2007-07-05 16:01:15 +00:00
|
|
|
|
|
|
|
// void udelay(unsigned long usecs);
|
|
|
|
|
2008-08-11 07:52:39 +00:00
|
|
|
void ndelay(unsigned long nsecs);
|
2007-07-05 16:01:15 +00:00
|
|
|
void mdelay(unsigned long msecs);
|
|
|
|
|
2007-07-05 16:01:15 +00:00
|
|
|
#define SECOND ((uint64_t)(1000 * 1000 * 1000))
|
|
|
|
#define MSECOND ((uint64_t)(1000 * 1000))
|
|
|
|
#define USECOND ((uint64_t)(1000))
|
|
|
|
|
2014-09-30 06:25:55 +00:00
|
|
|
extern uint64_t time_beginning;
|
|
|
|
|
2012-02-08 09:22:52 +00:00
|
|
|
/*
|
|
|
|
* Convenience wrapper to implement a typical polling loop with
|
|
|
|
* timeout. returns 0 if the condition became true within the
|
|
|
|
* timeout or -ETIMEDOUT otherwise
|
|
|
|
*/
|
|
|
|
#define wait_on_timeout(timeout, condition) \
|
|
|
|
({ \
|
|
|
|
int __ret = 0; \
|
|
|
|
uint64_t __to_start = get_time_ns(); \
|
|
|
|
\
|
|
|
|
while (!(condition)) { \
|
|
|
|
if (is_timeout(__to_start, (timeout))) { \
|
|
|
|
__ret = -ETIMEDOUT; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2007-07-05 16:01:15 +00:00
|
|
|
#endif /* CLOCK_H */
|