1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cc430: lpc2387: switch to new periph/rtc interface

Removes the old interface.
This commit is contained in:
Oleg Hahm 2014-11-20 17:55:28 +01:00
parent ed54a5765a
commit 498edb1854
12 changed files with 125 additions and 157 deletions

View File

@ -45,6 +45,11 @@ extern "C" {
#define PWM_0_CH2_PIN (4)
#define PWM_0_FUNC (1)
/**
* @brief Real Time Clock configuration
*/
#define RTC_NUMOF (1)
#ifdef __cplusplus
}
#endif

View File

@ -23,6 +23,9 @@
extern "C" {
#endif
/**
* @brief Real Time Clock configuration
*/
#define RTC_NUMOF (1)
#ifdef __cplusplus

View File

@ -46,6 +46,11 @@ extern "C" {
#define PWM_0_CH2_PIN (4)
#define PWM_0_FUNC (1)
/**
* @brief Real Time Clock configuration
*/
#define RTC_NUMOF (1)
#ifdef __cplusplus
}
#endif

View File

@ -19,7 +19,7 @@
#include "kernel_types.h"
#if defined MODULE_RTC
# include "rtc.h"
# include "periph/rtc.h"
#elif defined MODULE_VTIMER
# include "vtimer.h"
#endif

View File

@ -31,7 +31,7 @@
#include "kernel.h"
#include "irq.h"
#if defined MODULE_RTC
#include "rtc.h"
#include "periph/rtc.h"
#elif defined MODULE_VTIMER
#include "vtimer.h"
#endif

View File

@ -20,51 +20,45 @@
#include "cpu.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 int set_time = 0;
kernel_pid_t rtc_second_pid = KERNEL_PID_UNDEF;
/*---------------------------------------------------------------------------*/
void rtc_init(void)
{
/* Set to calendar mode */
RTCCTL1 |= RTCMODE_H;
}
/*---------------------------------------------------------------------------*/
void rtc_enable(void)
void rtc_poweron(void)
{
/* Set RTC operational */
RTCCTL1 &= ~RTCHOLD_H;
}
/*---------------------------------------------------------------------------*/
void rtc_disable(void)
void rtc_poweroff(void)
{
/* Stop RTC */
RTCCTL1 |= RTCHOLD_H;
}
/*---------------------------------------------------------------------------*/
void rtc_set_localtime(struct tm *localt)
int rtc_set_time(struct tm *localt)
{
if (localt == NULL) {
return;
return -1;
}
/* copy time to be set */
memcpy(&time_to_set, localt, sizeof(struct tm));
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 sec;
@ -74,15 +68,15 @@ time_t rtc_time(void) {
return sec;
}
*/
/*---------------------------------------------------------------------------*/
void rtc_get_localtime(struct tm *localt)
int rtc_get_time(struct tm *localt)
{
uint8_t success = 0;
uint8_t i;
uint16_t tmpyear;
if (localt == NULL) {
return;
return -1;
}
while (!success) {
@ -129,36 +123,53 @@ void rtc_get_localtime(struct tm *localt)
}
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
void rtc_set_alarm(struct tm *localt, rtc_alarm_mask_t mask)
int rtc_set_alarm(struct tm *localt, rtc_alarm_cb_t cb, void *arg)
{
if (mask & RTC_ALARM_MIN) {
if (localt != NULL) {
RTCAMIN = localt->tm_min;
RTCAMIN |= BIT7;
}
if (mask & RTC_ALARM_HOUR) {
RTCAHOUR = localt->tm_hour;
RTCAHOUR |= BIT7;
}
if (mask & RTC_ALARM_DOW) {
RTCADOW = localt->tm_wday;
RTCADOW |= BIT7;
}
if (mask & RTC_ALARM_DOM) {
RTCADAY = localt->tm_mday;
RTCADAY |= BIT7;
RTCCTL0 |= RTCAIE;
return 0;
}
RTCCTL0 |= RTCAIE;
else if (cb == NULL) {
return -1;
}
return -2;
}
/*---------------------------------------------------------------------------*/
void rtc_remove_alarm(void)
int rtc_get_alarm(struct tm *localt)
{
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 */
RTCAHOUR &= ~BIT7;
@ -169,7 +180,7 @@ void rtc_remove_alarm(void)
/* reset alarm interrupt enable */
RTCCTL0 &= ~RTCAIE;
}
/*---------------------------------------------------------------------------*/
interrupt(RTC_VECTOR) __attribute__((naked)) rtc_isr(void)
{
__enter_isr();
@ -194,12 +205,15 @@ interrupt(RTC_VECTOR) __attribute__((naked)) rtc_isr(void)
if (rtc_second_pid != KERNEL_PID_UNDEF) {
static msg_t m;
m.type = RTC_SECOND;
m.type = RTCSEC;
msg_send_int(&m, rtc_second_pid);
}
}
/* RTC alarm */
else if (RTCIV == RTC_RTCAIFG) {
if (_cb) {
_cb(_cb_arg);
}
}
__exit_isr();

View File

@ -8,7 +8,7 @@
#ifndef CC430_RTC_H
#define CC430_RTC_H
#include "rtc.h"
#include "periph/rtc.h"
#include "time.h"
#ifdef __cplusplus
@ -39,18 +39,6 @@ typedef enum {
RTC_ALARM_DOM = 0x08 ///< Alarm mask for Day of Month
} 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
*/

View File

@ -32,7 +32,7 @@
#include <time.h>
#include <sys/time.h>
#include "rtc.h"
#include "periph/rtc.h"
#include "lpc2387.h"
#ifdef __cplusplus
@ -95,7 +95,6 @@ void rtc_set(time_t time);
*
* @see ::rtc_alarm_mask
*/
void rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask);
/**
* @brief Gets the current alarm setting

View File

@ -24,6 +24,7 @@
#include "kernel_types.h"
/* cpu */
#include "periph/rtc.h"
#include "VIC.h"
#include "lpc2387.h"
#include "lpc2387-rtc.h"
@ -35,21 +36,25 @@
#define ENABLE_DEBUG (0)
#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
*/
static volatile time_t epoch;
/*---------------------------------------------------------------------------*/
/**
* @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)
int rtc_set_time(struct tm *localt)
{
if (localt == NULL) {
return;
return -1;
}
/* set clock */
@ -61,25 +66,26 @@ rtc_set_localtime(struct tm *localt)
RTC_DOY = localt->tm_yday;
RTC_MONTH = localt->tm_mon + 1;
RTC_YEAR = localt->tm_year;
return 0;
}
/*---------------------------------------------------------------------------*/
void rtc_set(time_t time)
{
struct tm *localt;
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;
}
/*---------------------------------------------------------------------------*/
//* set clock to start of unix epoch */
/* set clock to start of unix epoch */
void rtc_reset(void)
{
rtc_set(0);
epoch = 0;
}
/*---------------------------------------------------------------------------*/
void
rtc_set_alarm(struct tm *localt, enum rtc_alarm_mask mask)
int rtc_set_alarm(struct tm *localt, rtc_alarm_cb_t cb, void *arg)
{
if (localt != NULL) {
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_ALMON = localt->tm_mon + 1;
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",
RTC_ALDOM, RTC_ALMON, RTC_ALYEAR, RTC_ALHOUR, RTC_ALMIN, RTC_ALSEC);
_cb = cb;
return 0;
}
else {
RTC_AMR = 0xff;
else if (cb == NULL) {
return -1;
}
RTC_AMR = 0xff;
return -2;
}
/*---------------------------------------------------------------------------*/
enum rtc_alarm_mask
rtc_get_alarm(struct tm *localt)
int rtc_get_alarm(struct tm *localt)
{
if (localt != NULL) {
localt->tm_sec = RTC_ALSEC;
@ -112,12 +123,20 @@ rtc_get_alarm(struct tm *localt)
localt->tm_mon = RTC_ALMON - 1;
localt->tm_year = RTC_ALYEAR;
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)
{
lpm_begin_awake();
@ -135,6 +154,9 @@ void RTC_IRQHandler(void)
else if (RTC_ILR & ILR_RTCALF) {
RTC_ILR |= ILR_RTCALF;
RTC_AMR = 0xff; /* disable alarm irq */
if (_cb) {
_cb(_cb_arg);
}
DEBUG("Ring\n");
lpm_end_awake();
}
@ -142,9 +164,9 @@ void RTC_IRQHandler(void)
VICVectAddr = 0; /* Acknowledge Interrupt */
}
/*---------------------------------------------------------------------------*/
void rtc_enable(void)
{
PCONP |= BIT9;
RTC_ILR = (ILR_RTSSF | ILR_RTCCIF | ILR_RTCALF); /* clear interrupt flags */
RTC_CCR |= CCR_CLKEN; /* enable clock */
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);
epoch = now - (now % 3600);
}
/*---------------------------------------------------------------------------*/
void rtc_init(void)
{
PCONP |= BIT9;
@ -174,7 +196,7 @@ void rtc_init(void)
RTC_DOM, RTC_MONTH, RTC_YEAR, RTC_HOUR, RTC_MIN, RTC_SEC,
epoch);
}
/*---------------------------------------------------------------------------*/
time_t rtc_time(struct timeval *time)
{
uint32_t sec;
@ -191,8 +213,8 @@ time_t rtc_time(struct timeval *time)
min = RTC_MIN;
}
sec += min * 60; /* add number of minutes */
sec += epoch; /* add precalculated epoch in hour granularity */
sec += min * 60; /* add number of minutes */
sec += epoch; /* add precalculated epoch in hour granularity */
if (time != NULL) {
usec = usec * 15625;
@ -203,16 +225,16 @@ time_t rtc_time(struct timeval *time)
return sec;
}
/*---------------------------------------------------------------------------*/
void rtc_disable(void)
void rtc_poweroff(void)
{
RTC_CCR &= ~CCR_CLKEN; /* disable clock */
install_irq(RTC_INT, NULL, 0);
RTC_ILR = 0;
PCONP &= ~BIT9;
}
/*---------------------------------------------------------------------------*/
void
rtc_get_localtime(struct tm *localt)
int rtc_get_time(struct tm *localt)
{
if (localt != NULL) {
localt->tm_sec = RTC_SEC;
@ -224,9 +246,11 @@ rtc_get_localtime(struct tm *localt)
localt->tm_mon = RTC_MONTH - 1;
localt->tm_year = RTC_YEAR;
localt->tm_isdst = -1; /* not available */
return 0;
}
return -1;
}
/*---------------------------------------------------------------------------*/
void gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone *ptimezone)
{
(void) ptimezone; /* unused */

View File

@ -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

View File

@ -26,7 +26,7 @@
// riot
#include "thread.h"
#include "rtc.h"
#include "periph/rtc.h"
// ccn
#include "ccn_lite/ccnl-riot.h"

View File

@ -52,7 +52,7 @@
#endif
#ifdef MODULE_RTC
#include "rtc.h"
#include "periph/rtc.h"
#endif
#ifdef MODULE_SIXLOWPAN
@ -214,7 +214,6 @@ void auto_init(void)
#ifdef MODULE_RTC
DEBUG("Auto init rtc module.\n");
rtc_init();
rtc_enable();
#endif
#ifdef MODULE_SHT11
DEBUG("Auto init SHT11 module.\n");