mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
native: move rtc to periph
* adapt implementation to new interface * remove now superfluous drivers directory
This commit is contained in:
parent
a10cb114c5
commit
c0ef84bb9f
@ -1,2 +1,3 @@
|
||||
FEATURES_PROVIDED += transceiver periph_cpuid cpp
|
||||
FEATURES_PROVIDED += periph_random
|
||||
FEATURES_PROVIDED += periph_rtc
|
||||
|
@ -1,7 +1,6 @@
|
||||
MODULE = cpu
|
||||
|
||||
DIRS += periph
|
||||
DIRS += drivers
|
||||
ifneq (,$(filter nativenet,$(USEMODULE)))
|
||||
DIRS += net
|
||||
endif
|
||||
|
@ -1,5 +0,0 @@
|
||||
ifneq (,$(filter rtc,$(USEMODULE)))
|
||||
DIRS += rtc
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,3 +0,0 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
INCLUDES = $(NATIVEINCLUDES)
|
@ -1,93 +0,0 @@
|
||||
/**
|
||||
* Native CPU rtc.h implementation
|
||||
*
|
||||
* The native rtc implementation uses POSIX system calls to simulate a
|
||||
* real-time clock.
|
||||
*
|
||||
* Setting the clock will be implemented using a delta variable.
|
||||
*
|
||||
* Copyright (C) 2013 Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
||||
*
|
||||
* @ingroup native_cpu
|
||||
* @ingroup rtc
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "rtc.h"
|
||||
#include "cpu.h"
|
||||
|
||||
#include "native_internal.h"
|
||||
|
||||
static int native_rtc_enabled;
|
||||
static int native_rtc_initialized;
|
||||
|
||||
void rtc_init(void)
|
||||
{
|
||||
native_rtc_enabled = 0;
|
||||
native_rtc_initialized = 1;
|
||||
printf("native rtc initialized\n");
|
||||
}
|
||||
|
||||
void rtc_enable(void)
|
||||
{
|
||||
DEBUG("rtc_enable\n");
|
||||
if (native_rtc_initialized == 1) {
|
||||
native_rtc_enabled = 1;
|
||||
}
|
||||
else {
|
||||
DEBUG("rtc not initialized, not enabling\n");
|
||||
}
|
||||
}
|
||||
|
||||
void rtc_disable(void)
|
||||
{
|
||||
DEBUG("rtc_disable()\n");
|
||||
native_rtc_enabled = 0;
|
||||
}
|
||||
|
||||
void rtc_set_localtime(struct tm *localt)
|
||||
{
|
||||
DEBUG("rtc_set_localtime()\n");
|
||||
|
||||
(void)localt; /* not implemented atm */
|
||||
printf("setting time not supported.");
|
||||
}
|
||||
|
||||
void rtc_get_localtime(struct tm *localt)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
if (native_rtc_enabled == 1) {
|
||||
_native_syscall_enter();
|
||||
t = time(NULL);
|
||||
|
||||
if (localtime_r(&t, localt) == NULL) {
|
||||
err(EXIT_FAILURE, "rtc_get_localtime: localtime_r");
|
||||
}
|
||||
_native_syscall_leave();
|
||||
}
|
||||
}
|
||||
|
||||
time_t rtc_time(struct timeval *time)
|
||||
{
|
||||
if (native_rtc_enabled == 1) {
|
||||
_native_syscall_enter();
|
||||
if (gettimeofday(time, NULL) == -1) {
|
||||
err(EXIT_FAILURE, "rtc_time: gettimeofday");
|
||||
}
|
||||
_native_syscall_leave();
|
||||
}
|
||||
return time->tv_sec;
|
||||
}
|
@ -27,6 +27,13 @@
|
||||
#define RANDOM_NUMOF (1U)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name RealTime Clock configuration
|
||||
* @{
|
||||
*/
|
||||
#define RTC_NUMOF (1)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
111
cpu/native/periph/rtc.c
Normal file
111
cpu/native/periph/rtc.c
Normal file
@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Native CPU periph/rtc.h implementation
|
||||
*
|
||||
* The native rtc implementation uses POSIX system calls to simulate a
|
||||
* real-time clock.
|
||||
*
|
||||
* Setting the clock will be implemented using a delta variable.
|
||||
*
|
||||
* Copyright (C) 2013 Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
||||
*
|
||||
* @ingroup native_cpu
|
||||
* @ingroup rtc
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "periph/rtc.h"
|
||||
#include "cpu.h"
|
||||
|
||||
#include "native_internal.h"
|
||||
|
||||
static int native_rtc_powered;
|
||||
static int native_rtc_initialized;
|
||||
|
||||
void rtc_init(void)
|
||||
{
|
||||
native_rtc_powered = 0;
|
||||
native_rtc_initialized = 1;
|
||||
printf("Native RTC initialized.\n");
|
||||
rtc_poweron();
|
||||
}
|
||||
|
||||
void rtc_poweron(void)
|
||||
{
|
||||
DEBUG("rtc_poweron\n");
|
||||
if (native_rtc_initialized == 1) {
|
||||
native_rtc_powered = 1;
|
||||
}
|
||||
else {
|
||||
DEBUG("rtc not initialized, not powering on\n");
|
||||
}
|
||||
}
|
||||
|
||||
void rtc_poweroff(void)
|
||||
{
|
||||
DEBUG("rtc_poweroff()\n");
|
||||
native_rtc_powered = 0;
|
||||
}
|
||||
|
||||
int rtc_set_time(struct tm *ttime)
|
||||
{
|
||||
DEBUG("rtc_set_time()\n");
|
||||
|
||||
(void)ttime; /* not implemented atm */
|
||||
printf("setting time not supported.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rtc_get_time(struct tm *ttime)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
if (native_rtc_powered == 1) {
|
||||
_native_syscall_enter();
|
||||
t = time(NULL);
|
||||
|
||||
if (localtime_r(&t, ttime) == NULL) {
|
||||
err(EXIT_FAILURE, "rtc_get_time: localtime_r");
|
||||
}
|
||||
_native_syscall_leave();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
||||
{
|
||||
(void) time;
|
||||
(void) cb;
|
||||
(void) arg;
|
||||
|
||||
warnx("rtc_set_alarm: not implemeted");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rtc_get_alarm(struct tm *time)
|
||||
{
|
||||
(void) time;
|
||||
|
||||
warnx("rtc_get_alarm: not implemeted");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void rtc_clear_alarm(void)
|
||||
{
|
||||
warnx("rtc_clear_alarm: not implemeted");
|
||||
}
|
@ -51,7 +51,6 @@ ifneq (,$(filter msba2,$(BOARD)))
|
||||
endif
|
||||
ifneq (,$(filter native,$(BOARD)))
|
||||
USEMODULE += ltc4150
|
||||
USEMODULE += rtc
|
||||
USEMODULE += config
|
||||
USEMODULE += random
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user