cc430: lpc2387: switch to new periph/rtc interface
Removes the old interface.
This commit is contained in:
parent
ed54a5765a
commit
498edb1854
@ -45,6 +45,11 @@ extern "C" {
|
|||||||
#define PWM_0_CH2_PIN (4)
|
#define PWM_0_CH2_PIN (4)
|
||||||
#define PWM_0_FUNC (1)
|
#define PWM_0_FUNC (1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Real Time Clock configuration
|
||||||
|
*/
|
||||||
|
#define RTC_NUMOF (1)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -23,6 +23,9 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Real Time Clock configuration
|
||||||
|
*/
|
||||||
#define RTC_NUMOF (1)
|
#define RTC_NUMOF (1)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@ -46,6 +46,11 @@ extern "C" {
|
|||||||
#define PWM_0_CH2_PIN (4)
|
#define PWM_0_CH2_PIN (4)
|
||||||
#define PWM_0_FUNC (1)
|
#define PWM_0_FUNC (1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Real Time Clock configuration
|
||||||
|
*/
|
||||||
|
#define RTC_NUMOF (1)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
#include "kernel_types.h"
|
#include "kernel_types.h"
|
||||||
|
|
||||||
#if defined MODULE_RTC
|
#if defined MODULE_RTC
|
||||||
# include "rtc.h"
|
# include "periph/rtc.h"
|
||||||
#elif defined MODULE_VTIMER
|
#elif defined MODULE_VTIMER
|
||||||
# include "vtimer.h"
|
# include "vtimer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#if defined MODULE_RTC
|
#if defined MODULE_RTC
|
||||||
#include "rtc.h"
|
#include "periph/rtc.h"
|
||||||
#elif defined MODULE_VTIMER
|
#elif defined MODULE_VTIMER
|
||||||
#include "vtimer.h"
|
#include "vtimer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -20,51 +20,45 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "cc430-rtc.h"
|
#include "cc430-rtc.h"
|
||||||
|
|
||||||
//static volatile time_t epoch;
|
/* Alarm callback */
|
||||||
|
static rtc_alarm_cb_t _cb;
|
||||||
|
|
||||||
|
/* Argument to alarm callback */
|
||||||
|
static void *_cb_arg;
|
||||||
|
|
||||||
static struct tm time_to_set;
|
static struct tm time_to_set;
|
||||||
static int set_time = 0;
|
static int set_time = 0;
|
||||||
kernel_pid_t rtc_second_pid = KERNEL_PID_UNDEF;
|
kernel_pid_t rtc_second_pid = KERNEL_PID_UNDEF;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void rtc_init(void)
|
void rtc_init(void)
|
||||||
{
|
{
|
||||||
/* Set to calendar mode */
|
/* Set to calendar mode */
|
||||||
RTCCTL1 |= RTCMODE_H;
|
RTCCTL1 |= RTCMODE_H;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
void rtc_poweron(void)
|
||||||
void rtc_enable(void)
|
|
||||||
{
|
{
|
||||||
/* Set RTC operational */
|
/* Set RTC operational */
|
||||||
RTCCTL1 &= ~RTCHOLD_H;
|
RTCCTL1 &= ~RTCHOLD_H;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
void rtc_poweroff(void)
|
||||||
void rtc_disable(void)
|
|
||||||
{
|
{
|
||||||
/* Stop RTC */
|
/* Stop RTC */
|
||||||
RTCCTL1 |= RTCHOLD_H;
|
RTCCTL1 |= RTCHOLD_H;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void rtc_set_localtime(struct tm *localt)
|
int rtc_set_time(struct tm *localt)
|
||||||
{
|
{
|
||||||
if (localt == NULL) {
|
if (localt == NULL) {
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy time to be set */
|
/* copy time to be set */
|
||||||
memcpy(&time_to_set, localt, sizeof(struct tm));
|
memcpy(&time_to_set, localt, sizeof(struct tm));
|
||||||
set_time = 1;
|
set_time = 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
|
||||||
void rtc_set(time_t time) {
|
|
||||||
struct tm* localt;
|
|
||||||
localt = localtime(&time); // convert seconds to broken-down time
|
|
||||||
rtc_set_localtime(localt);
|
|
||||||
epoch = time - localt->tm_sec - localt->tm_min * 60;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
time_t rtc_time(void) {
|
time_t rtc_time(void) {
|
||||||
time_t sec;
|
time_t sec;
|
||||||
@ -74,15 +68,15 @@ time_t rtc_time(void) {
|
|||||||
return sec;
|
return sec;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void rtc_get_localtime(struct tm *localt)
|
int rtc_get_time(struct tm *localt)
|
||||||
{
|
{
|
||||||
uint8_t success = 0;
|
uint8_t success = 0;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint16_t tmpyear;
|
uint16_t tmpyear;
|
||||||
|
|
||||||
if (localt == NULL) {
|
if (localt == NULL) {
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!success) {
|
while (!success) {
|
||||||
@ -129,36 +123,53 @@ void rtc_get_localtime(struct tm *localt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
int rtc_set_alarm(struct tm *localt, rtc_alarm_cb_t cb, void *arg)
|
||||||
void rtc_set_alarm(struct tm *localt, rtc_alarm_mask_t mask)
|
|
||||||
{
|
{
|
||||||
if (mask & RTC_ALARM_MIN) {
|
if (localt != NULL) {
|
||||||
RTCAMIN = localt->tm_min;
|
RTCAMIN = localt->tm_min;
|
||||||
RTCAMIN |= BIT7;
|
RTCAMIN |= BIT7;
|
||||||
}
|
|
||||||
|
|
||||||
if (mask & RTC_ALARM_HOUR) {
|
|
||||||
RTCAHOUR = localt->tm_hour;
|
RTCAHOUR = localt->tm_hour;
|
||||||
RTCAHOUR |= BIT7;
|
RTCAHOUR |= BIT7;
|
||||||
}
|
|
||||||
|
|
||||||
if (mask & RTC_ALARM_DOW) {
|
|
||||||
RTCADOW = localt->tm_wday;
|
RTCADOW = localt->tm_wday;
|
||||||
RTCADOW |= BIT7;
|
RTCADOW |= BIT7;
|
||||||
}
|
|
||||||
|
|
||||||
if (mask & RTC_ALARM_DOM) {
|
|
||||||
RTCADAY = localt->tm_mday;
|
RTCADAY = localt->tm_mday;
|
||||||
RTCADAY |= BIT7;
|
RTCADAY |= BIT7;
|
||||||
}
|
|
||||||
|
|
||||||
RTCCTL0 |= RTCAIE;
|
RTCCTL0 |= RTCAIE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (cb == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
int rtc_get_alarm(struct tm *localt)
|
||||||
void rtc_remove_alarm(void)
|
{
|
||||||
|
if (localt != NULL) {
|
||||||
|
localt->tm_sec = -1;
|
||||||
|
localt->tm_min = RTCAMIN;
|
||||||
|
localt->tm_hour = RTCAHOUR;
|
||||||
|
localt->tm_mday = -1;
|
||||||
|
localt->tm_wday = RTCADOW;
|
||||||
|
localt->tm_yday = -1;
|
||||||
|
localt->tm_mon = - 1;
|
||||||
|
localt->tm_year = -1;
|
||||||
|
localt->tm_isdst = -1; /* not available */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rtc_clear_alarm(void)
|
||||||
{
|
{
|
||||||
/* reset all AE bits */
|
/* reset all AE bits */
|
||||||
RTCAHOUR &= ~BIT7;
|
RTCAHOUR &= ~BIT7;
|
||||||
@ -169,7 +180,7 @@ void rtc_remove_alarm(void)
|
|||||||
/* reset alarm interrupt enable */
|
/* reset alarm interrupt enable */
|
||||||
RTCCTL0 &= ~RTCAIE;
|
RTCCTL0 &= ~RTCAIE;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
interrupt(RTC_VECTOR) __attribute__((naked)) rtc_isr(void)
|
interrupt(RTC_VECTOR) __attribute__((naked)) rtc_isr(void)
|
||||||
{
|
{
|
||||||
__enter_isr();
|
__enter_isr();
|
||||||
@ -194,12 +205,15 @@ interrupt(RTC_VECTOR) __attribute__((naked)) rtc_isr(void)
|
|||||||
|
|
||||||
if (rtc_second_pid != KERNEL_PID_UNDEF) {
|
if (rtc_second_pid != KERNEL_PID_UNDEF) {
|
||||||
static msg_t m;
|
static msg_t m;
|
||||||
m.type = RTC_SECOND;
|
m.type = RTCSEC;
|
||||||
msg_send_int(&m, rtc_second_pid);
|
msg_send_int(&m, rtc_second_pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* RTC alarm */
|
/* RTC alarm */
|
||||||
else if (RTCIV == RTC_RTCAIFG) {
|
else if (RTCIV == RTC_RTCAIFG) {
|
||||||
|
if (_cb) {
|
||||||
|
_cb(_cb_arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__exit_isr();
|
__exit_isr();
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#ifndef CC430_RTC_H
|
#ifndef CC430_RTC_H
|
||||||
#define CC430_RTC_H
|
#define CC430_RTC_H
|
||||||
#include "rtc.h"
|
#include "periph/rtc.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -39,18 +39,6 @@ typedef enum {
|
|||||||
RTC_ALARM_DOM = 0x08 ///< Alarm mask for Day of Month
|
RTC_ALARM_DOM = 0x08 ///< Alarm mask for Day of Month
|
||||||
} rtc_alarm_mask_t;
|
} rtc_alarm_mask_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the alarm
|
|
||||||
* @internal
|
|
||||||
* @param[in] localt Alarm time
|
|
||||||
* @param[in] mask Sets the registers to poll for the alarm
|
|
||||||
*
|
|
||||||
* To disable the alarm set mask to RTC_ALARM_DISABLED.
|
|
||||||
*
|
|
||||||
* @see ::rtc_alarm_mask
|
|
||||||
*/
|
|
||||||
void rtc_set_alarm(struct tm *localti, rtc_alarm_mask_t mask);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resets any set alarm
|
* @brief Resets any set alarm
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include "rtc.h"
|
#include "periph/rtc.h"
|
||||||
#include "lpc2387.h"
|
#include "lpc2387.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -95,7 +95,6 @@ void rtc_set(time_t time);
|
|||||||
*
|
*
|
||||||
* @see ::rtc_alarm_mask
|
* @see ::rtc_alarm_mask
|
||||||
*/
|
*/
|
||||||
void rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the current alarm setting
|
* @brief Gets the current alarm setting
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
#include "kernel_types.h"
|
#include "kernel_types.h"
|
||||||
|
|
||||||
/* cpu */
|
/* cpu */
|
||||||
|
#include "periph/rtc.h"
|
||||||
#include "VIC.h"
|
#include "VIC.h"
|
||||||
#include "lpc2387.h"
|
#include "lpc2387.h"
|
||||||
#include "lpc2387-rtc.h"
|
#include "lpc2387-rtc.h"
|
||||||
@ -35,21 +36,25 @@
|
|||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
/* Alarm callback */
|
||||||
|
static rtc_alarm_cb_t _cb;
|
||||||
|
|
||||||
|
/* Argument to alarm callback */
|
||||||
|
static void *_cb_arg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief epoch time in hour granularity
|
* @brief epoch time in hour granularity
|
||||||
*/
|
*/
|
||||||
static volatile time_t epoch;
|
static volatile time_t epoch;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the current time in broken down format directly from to RTC
|
* @brief Sets the current time in broken down format directly from to RTC
|
||||||
* @param[in] localt Pointer to structure with time to set
|
* @param[in] localt Pointer to structure with time to set
|
||||||
*/
|
*/
|
||||||
void
|
int rtc_set_time(struct tm *localt)
|
||||||
rtc_set_localtime(struct tm *localt)
|
|
||||||
{
|
{
|
||||||
if (localt == NULL) {
|
if (localt == NULL) {
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set clock */
|
/* set clock */
|
||||||
@ -61,25 +66,26 @@ rtc_set_localtime(struct tm *localt)
|
|||||||
RTC_DOY = localt->tm_yday;
|
RTC_DOY = localt->tm_yday;
|
||||||
RTC_MONTH = localt->tm_mon + 1;
|
RTC_MONTH = localt->tm_mon + 1;
|
||||||
RTC_YEAR = localt->tm_year;
|
RTC_YEAR = localt->tm_year;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void rtc_set(time_t time)
|
void rtc_set(time_t time)
|
||||||
{
|
{
|
||||||
struct tm *localt;
|
struct tm *localt;
|
||||||
localt = localtime(&time); /* convert seconds to broken-down time */
|
localt = localtime(&time); /* convert seconds to broken-down time */
|
||||||
rtc_set_localtime(localt);
|
rtc_set_time(localt);
|
||||||
epoch = time - localt->tm_sec - localt->tm_min * 60;
|
epoch = time - localt->tm_sec - localt->tm_min * 60;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
//* set clock to start of unix epoch */
|
/* set clock to start of unix epoch */
|
||||||
void rtc_reset(void)
|
void rtc_reset(void)
|
||||||
{
|
{
|
||||||
rtc_set(0);
|
rtc_set(0);
|
||||||
epoch = 0;
|
epoch = 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void
|
int rtc_set_alarm(struct tm *localt, rtc_alarm_cb_t cb, void *arg)
|
||||||
rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask)
|
|
||||||
{
|
{
|
||||||
if (localt != NULL) {
|
if (localt != NULL) {
|
||||||
RTC_ALSEC = localt->tm_sec;
|
RTC_ALSEC = localt->tm_sec;
|
||||||
@ -90,17 +96,22 @@ rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask)
|
|||||||
RTC_ALDOY = localt->tm_yday;
|
RTC_ALDOY = localt->tm_yday;
|
||||||
RTC_ALMON = localt->tm_mon + 1;
|
RTC_ALMON = localt->tm_mon + 1;
|
||||||
RTC_ALYEAR = localt->tm_year;
|
RTC_ALYEAR = localt->tm_year;
|
||||||
RTC_AMR = ~mask; /* set wich alarm fields to check */
|
RTC_AMR = 0; /* set wich alarm fields to check */
|
||||||
DEBUG("alarm set %2lu.%2lu.%4lu %2lu:%2lu:%2lu\n",
|
DEBUG("alarm set %2lu.%2lu.%4lu %2lu:%2lu:%2lu\n",
|
||||||
RTC_ALDOM, RTC_ALMON, RTC_ALYEAR, RTC_ALHOUR, RTC_ALMIN, RTC_ALSEC);
|
RTC_ALDOM, RTC_ALMON, RTC_ALYEAR, RTC_ALHOUR, RTC_ALMIN, RTC_ALSEC);
|
||||||
|
|
||||||
|
_cb = cb;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else if (cb == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
RTC_AMR = 0xff;
|
RTC_AMR = 0xff;
|
||||||
}
|
return -2;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
enum rtc_alarm_mask
|
int rtc_get_alarm(struct tm *localt)
|
||||||
rtc_get_alarm(struct tm *localt)
|
|
||||||
{
|
{
|
||||||
if (localt != NULL) {
|
if (localt != NULL) {
|
||||||
localt->tm_sec = RTC_ALSEC;
|
localt->tm_sec = RTC_ALSEC;
|
||||||
@ -112,12 +123,20 @@ rtc_get_alarm(struct tm *localt)
|
|||||||
localt->tm_mon = RTC_ALMON - 1;
|
localt->tm_mon = RTC_ALMON - 1;
|
||||||
localt->tm_year = RTC_ALYEAR;
|
localt->tm_year = RTC_ALYEAR;
|
||||||
localt->tm_isdst = -1; /* not available */
|
localt->tm_isdst = -1; /* not available */
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (~RTC_AMR) & 0xff; /* return which alarm fields are checked */
|
return -1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
void rtc_clear_alarm(void)
|
||||||
|
{
|
||||||
|
RTC_AMR = 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
void RTC_IRQHandler(void) __attribute__((interrupt("IRQ")));
|
void RTC_IRQHandler(void) __attribute__((interrupt("IRQ")));
|
||||||
|
|
||||||
void RTC_IRQHandler(void)
|
void RTC_IRQHandler(void)
|
||||||
{
|
{
|
||||||
lpm_begin_awake();
|
lpm_begin_awake();
|
||||||
@ -135,6 +154,9 @@ void RTC_IRQHandler(void)
|
|||||||
else if (RTC_ILR & ILR_RTCALF) {
|
else if (RTC_ILR & ILR_RTCALF) {
|
||||||
RTC_ILR |= ILR_RTCALF;
|
RTC_ILR |= ILR_RTCALF;
|
||||||
RTC_AMR = 0xff; /* disable alarm irq */
|
RTC_AMR = 0xff; /* disable alarm irq */
|
||||||
|
if (_cb) {
|
||||||
|
_cb(_cb_arg);
|
||||||
|
}
|
||||||
DEBUG("Ring\n");
|
DEBUG("Ring\n");
|
||||||
lpm_end_awake();
|
lpm_end_awake();
|
||||||
}
|
}
|
||||||
@ -142,9 +164,9 @@ void RTC_IRQHandler(void)
|
|||||||
VICVectAddr = 0; /* Acknowledge Interrupt */
|
VICVectAddr = 0; /* Acknowledge Interrupt */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void rtc_enable(void)
|
void rtc_enable(void)
|
||||||
{
|
{
|
||||||
|
PCONP |= BIT9;
|
||||||
RTC_ILR = (ILR_RTSSF | ILR_RTCCIF | ILR_RTCALF); /* clear interrupt flags */
|
RTC_ILR = (ILR_RTSSF | ILR_RTCCIF | ILR_RTCALF); /* clear interrupt flags */
|
||||||
RTC_CCR |= CCR_CLKEN; /* enable clock */
|
RTC_CCR |= CCR_CLKEN; /* enable clock */
|
||||||
install_irq(RTC_INT, &RTC_IRQHandler, IRQP_RTC); /* install interrupt handler */
|
install_irq(RTC_INT, &RTC_IRQHandler, IRQP_RTC); /* install interrupt handler */
|
||||||
@ -152,7 +174,7 @@ void rtc_enable(void)
|
|||||||
time_t now = rtc_time(NULL);
|
time_t now = rtc_time(NULL);
|
||||||
epoch = now - (now % 3600);
|
epoch = now - (now % 3600);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void rtc_init(void)
|
void rtc_init(void)
|
||||||
{
|
{
|
||||||
PCONP |= BIT9;
|
PCONP |= BIT9;
|
||||||
@ -174,7 +196,7 @@ void rtc_init(void)
|
|||||||
RTC_DOM, RTC_MONTH, RTC_YEAR, RTC_HOUR, RTC_MIN, RTC_SEC,
|
RTC_DOM, RTC_MONTH, RTC_YEAR, RTC_HOUR, RTC_MIN, RTC_SEC,
|
||||||
epoch);
|
epoch);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
time_t rtc_time(struct timeval *time)
|
time_t rtc_time(struct timeval *time)
|
||||||
{
|
{
|
||||||
uint32_t sec;
|
uint32_t sec;
|
||||||
@ -203,16 +225,16 @@ time_t rtc_time(struct timeval *time)
|
|||||||
|
|
||||||
return sec;
|
return sec;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void rtc_disable(void)
|
void rtc_poweroff(void)
|
||||||
{
|
{
|
||||||
RTC_CCR &= ~CCR_CLKEN; /* disable clock */
|
RTC_CCR &= ~CCR_CLKEN; /* disable clock */
|
||||||
install_irq(RTC_INT, NULL, 0);
|
install_irq(RTC_INT, NULL, 0);
|
||||||
RTC_ILR = 0;
|
RTC_ILR = 0;
|
||||||
|
PCONP &= ~BIT9;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void
|
int rtc_get_time(struct tm *localt)
|
||||||
rtc_get_localtime(struct tm *localt)
|
|
||||||
{
|
{
|
||||||
if (localt != NULL) {
|
if (localt != NULL) {
|
||||||
localt->tm_sec = RTC_SEC;
|
localt->tm_sec = RTC_SEC;
|
||||||
@ -224,9 +246,11 @@ rtc_get_localtime(struct tm *localt)
|
|||||||
localt->tm_mon = RTC_MONTH - 1;
|
localt->tm_mon = RTC_MONTH - 1;
|
||||||
localt->tm_year = RTC_YEAR;
|
localt->tm_year = RTC_YEAR;
|
||||||
localt->tm_isdst = -1; /* not available */
|
localt->tm_isdst = -1; /* not available */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone *ptimezone)
|
void gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone *ptimezone)
|
||||||
{
|
{
|
||||||
(void) ptimezone; /* unused */
|
(void) ptimezone; /* unused */
|
||||||
|
|||||||
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010, Freie Universitaet Berlin (FUB). All rights reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup rtc Realtime Clock
|
|
||||||
* @ingroup drivers
|
|
||||||
* @brief Generic real time clock driver interface
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RTC_H
|
|
||||||
#define RTC_H
|
|
||||||
|
|
||||||
#define RTC_SECOND 10001U
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include "kernel_types.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initializes the RTC for calendar mode
|
|
||||||
*/
|
|
||||||
void rtc_init(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Starts the RTC
|
|
||||||
*/
|
|
||||||
void rtc_enable(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stops the RTC
|
|
||||||
*/
|
|
||||||
void rtc_disable(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the current time in broken down format directly from to RTC
|
|
||||||
* @param[in] localt Pointer to structure with time to set
|
|
||||||
*/
|
|
||||||
void rtc_set_localtime(struct tm *localt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the current time in broken down format directly from the RTC
|
|
||||||
* @param[out] localt Pointer to structure to receive time
|
|
||||||
*/
|
|
||||||
void rtc_get_localtime(struct tm *localt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the current time as a struct timeval
|
|
||||||
* @param[out] time Pointer to structure to receive time
|
|
||||||
*/
|
|
||||||
time_t rtc_time(struct timeval *time);
|
|
||||||
|
|
||||||
extern kernel_pid_t rtc_second_pid;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @} */
|
|
||||||
#endif
|
|
||||||
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// riot
|
// riot
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "rtc.h"
|
#include "periph/rtc.h"
|
||||||
|
|
||||||
// ccn
|
// ccn
|
||||||
#include "ccn_lite/ccnl-riot.h"
|
#include "ccn_lite/ccnl-riot.h"
|
||||||
|
|||||||
@ -52,7 +52,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_RTC
|
#ifdef MODULE_RTC
|
||||||
#include "rtc.h"
|
#include "periph/rtc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_SIXLOWPAN
|
#ifdef MODULE_SIXLOWPAN
|
||||||
@ -214,7 +214,6 @@ void auto_init(void)
|
|||||||
#ifdef MODULE_RTC
|
#ifdef MODULE_RTC
|
||||||
DEBUG("Auto init rtc module.\n");
|
DEBUG("Auto init rtc module.\n");
|
||||||
rtc_init();
|
rtc_init();
|
||||||
rtc_enable();
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_SHT11
|
#ifdef MODULE_SHT11
|
||||||
DEBUG("Auto init SHT11 module.\n");
|
DEBUG("Auto init SHT11 module.\n");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user