Skip to content

Commit

Permalink
syscalls: Updated xenon_gettimeofday
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Jul 30, 2012
1 parent 53b9a8c commit 66bba17
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions libxenon/drivers/newlib/xenon_syscalls.c
Expand Up @@ -53,22 +53,30 @@ __syscalls_t __syscalls = {


// 22 nov 2005
#define RTC_BASE 1132614024UL//1005782400UL
#define RTC_BASE 1005782400UL//1132614024UL

static int xenon_gettimeofday(struct _reent *ptr, struct timeval *tp, struct timezone *tz) {
unsigned char msg[16] = {0x04};
unsigned long long msec;
unsigned long sec;
union{
uint8_t u8[8];
uint64_t t;
} time;
time.t = 0;
uint64_t msec = 0;

xenon_smc_send_message(msg);
xenon_smc_receive_response(msg);

msec = msg[1] | (msg[2] << 8) | (msg[3] << 16) | (msg[4] << 24) | ((unsigned long long) msg[5] << 32);
time.u8[3] = msg[5];
time.u8[4] = msg[4];
time.u8[5] = msg[3];
time.u8[6] = msg[2];
time.u8[7] = msg[1];

sec = msec / 1000;
tp->tv_sec = sec + RTC_BASE;
msec -= sec * 1000;
tp->tv_usec = msec * 1000;
msec = (time.t / 1000) + RTC_BASE;

tp->tv_sec = (time.t / 1000) + RTC_BASE;
tp->tv_usec = (time.t % 1000) * 1000;

return 0;
}
Expand Down

0 comments on commit 66bba17

Please sign in to comment.