00001
00041 #ifndef ARCH_TIMEOUT_H_INCLUDED
00042 #define ARCH_TIMEOUT_H_INCLUDED
00043
00044 #include <arch/sysreg.h>
00045 #include <chip/clk.h>
00046
00047 struct timeout {
00048 uint32_t base;
00049 uint32_t delta;
00050 };
00051
00052 static inline void timeout_init_us(struct timeout *timeout, unsigned int us)
00053 {
00054 timeout->base = sysreg_read(COUNT);
00055 timeout->delta = ((get_cpu_clock_rate() / 10000) * us) / 100;
00056 }
00057
00058 static inline bool timeout_has_expired(const struct timeout *timeout)
00059 {
00060 uint32_t now;
00061
00062 now = sysreg_read(COUNT);
00063 if ((now - timeout->base) > timeout->delta)
00064 return true;
00065 else
00066 return false;
00067 }
00068
00069 #endif