Merge pull request #782 from OlegHahm/syscall_gettimeofday

sys: vtimer: added gettimeofday syscall
This commit is contained in:
Christian Mehlis 2014-02-26 15:56:53 +01:00
commit af87308e2a
5 changed files with 57 additions and 0 deletions

View File

@ -26,12 +26,18 @@
#include <sys/stat.h>
#include <sys/unistd.h>
#include <stdint.h>
#include <sys/time.h>
#include "arm_cpu.h"
// core
#include "kernel.h"
#include "irq.h"
#include "io.h"
#if defined MODULE_RTC
#include "rtc.h"
#elif defined MODULE_VTIMER
#include "vtimer.h"
#endif
/* When using the HAL standard in and out are handled by HAL
devices. */
@ -271,5 +277,17 @@ int _kill_r(struct _reent *r, int pid, int sig)
return -1;
}
/*---------------------------------------------------------------------------*/
int _gettimeofday(struct timeval *tp, void *restrict tzp) {
(void) tzp;
#if defined MODULE_RTC
rtc_time(tp);
#elif defined MODULE_VTIMER
vtimer_gettimeofday(tp);
#else
#warning gettimeofday syscall is not implemented without vtimer or rtc module
#endif
return 0;
}
void _init(void) {}
void _fini(void) {}

View File

@ -21,8 +21,12 @@
#include <sys/stat.h>
#include <sys/unistd.h>
#include <stdint.h>
#include <sys/time.h>
#include "kernel.h"
#include "irq.h"
#ifdef MODULE_VTIMER
#include "vtimer.h"
#endif
/**
* @name Heaps (defined in linker script)
@ -227,5 +231,13 @@ int _kill_r(struct _reent *r, int pid, int sig)
return -1;
}
/*---------------------------------------------------------------------------*/
#ifdef MODULE_VTIMER
int _gettimeofday(struct timeval *tp, void *restrict tzp) {
(void) tzp;
vtimer_gettimeofday(tp);
return 0;
}
#endif
void _init(void){}
void _fini(void){}

View File

@ -30,9 +30,13 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#ifdef MODULE_VTIMER
#include <sys/time.h>
#endif
#include "cpu.h"
#include "irq.h"
#include "vtimer.h"
#include "native_internal.h"
@ -297,3 +301,11 @@ void errx(int eval, const char *fmt, ...)
va_start(argp, fmt);
verrx(eval, fmt, argp);
}
#ifdef MODULE_VTIMER
int _gettimeofday(struct timeval *tp, void *restrict tzp) {
(void) tzp;
vtimer_gettimeofday(tp);
return 0;
}
#endif

View File

@ -19,6 +19,7 @@
#define __VTIMER_H
#include <time.h>
#include <sys/time.h>
#include "queue.h"
#include "timex.h"
@ -47,6 +48,12 @@ typedef struct vtimer_t {
*/
void vtimer_now(timex_t *out);
/**
* @brief Get the current time in seconds and microseconds since system start
* @param[in] tp Uptime will be stored in the timeval structure pointed to by tp
*/
void vtimer_gettimeofday(struct timeval *tp);
/**
* @brief Returns the current time in broken down format
* @param[out] localt Pointer to structure to receive time

View File

@ -266,6 +266,14 @@ void vtimer_now(timex_t *out)
out->microseconds = us % (1000 * 1000);
}
void vtimer_gettimeofday(struct timeval *tp) {
timex_t now;
vtimer_now(&now);
tp->tv_sec = now.seconds;
tp->tv_usec = now.microseconds;
}
void vtimer_get_localtime(struct tm *localt)
{
timex_t now;