Mercurial > sarpn
changeset 5:a4d737f03f88
import TOD code
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Wed, 09 Mar 2011 18:39:54 -0500 |
parents | e2b1d6184703 |
children | d3c54eb7510b |
files | include/tod.h |
diffstat | 1 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/tod.h Wed Mar 09 18:39:54 2011 -0500 @@ -0,0 +1,45 @@ +#ifndef __TOD_H +#define __TOD_H + +/* + * The Time Of Day (TOD) hardware adds 1 to the 51st bit every microsecond + * The timer hardware subtracts 1 from the 51st bit every microsecond + */ +#define TOD_MICROSEC 0x0000000000001000UL +#define TOD_SEC 0x0000000f4240000ULL +#define TOD_MIN 0x000003938700000ULL +#define TOD_HOUR 0x0000d693a400000ULL +#define TOD_DAY 0x00141dd76000000ULL +#define TOD_YEAR 0x1cae8c13e000000ULL /* not leap */ +#define TOD_FOURYEARS 0x72ce4e26e000000ULL + +/* + * Stores (if possible) the current TOD value. + * + * Returns: + * 0 on success, *tod contains current time & date + * *tod == 0 is midnight, Jan 1, 1900 + * 1 on success, *tod contains uptime + * *tod == 0 is the instant the system powered on + * 2 or 3 on failure, value of *tod is unpredictable + */ +static inline int get_tod(u64 *tod) +{ + int cc; + + asm volatile( + "stck %0\n" + "ipm %1\n" + "srl %1,28\n" + : /* output */ + "=m" (*tod), + "=d" (cc) + : /* input */ + : /* clobber */ + "cc" + ); + + return cc; +} + +#endif