* added a general RTC header
* added RTC support to chronos
dev/timer
Oliver Hahm 13 years ago
parent c083928983
commit ddcbd10a03

@ -28,5 +28,6 @@
SubDir TOP cpu cc430 ;
Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ;
Module rtc : cc430-rtc.c ;
SubInclude TOP cpu msp430-common ;

@ -0,0 +1,184 @@
/******************************************************************************
Copyright 2010, Freie Universitaet Berlin (FUB). All rights reserved.
These sources were developed at the Freie Universitaet Berlin, Computer Systems
and Telematics group (http://cst.mi.fu-berlin.de).
-------------------------------------------------------------------------------
This file is part of µkleos.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
FeuerWare is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://scatterweb.mi.fu-berlin.de
and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
#include <string.h>
#include <signal.h>
#include <irq.h>
#include <cpu.h>
#include <cc430x613x.h>
#include <cc430-rtc.h>
//static volatile time_t epoch;
static struct tm time_to_set;
/*---------------------------------------------------------------------------*/
void rtc_init(void) {
/* Set to calendar mode */
RTCCTL1 |= RTCMODE_H;
}
/*---------------------------------------------------------------------------*/
void rtc_enable(void) {
/* Set RTC operational */
RTCCTL1 &= ~RTCHOLD_H;
}
/*---------------------------------------------------------------------------*/
void rtc_disable(void) {
/* Stop RTC */
RTCCTL1 |= RTCHOLD_H;
}
/*---------------------------------------------------------------------------*/
void rtc_set_localtime(struct tm* localt) {
if(localt == NULL) {
return;
}
/* copy time to be set */
memcpy(&time_to_set, localt, sizeof(struct tm));
/* set interrupt to set this time after the next transition */
RTCCTL0 |= RTCRDYIE;
}
/*---------------------------------------------------------------------------
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;
struct tm t;
rtc_get_localtime(&t);
sec = mktime(&t);
return sec;
}
*/
/*---------------------------------------------------------------------------*/
void rtc_get_localtime(struct tm* localt) {
uint8_t success = 0;
uint8_t i;
uint16_t tmpyear;
if( localt == NULL ) {
return;
}
while (!success) {
for (i = 0; i < 8; i++) {
/* try again when RTC is in transition */
if (!(RTCCTL1 & RTCRDY_H)) {
break;
}
switch (i) {
case 0:
localt->tm_sec = RTCSEC;
break;
case 1:
localt->tm_min = RTCMIN;
break;
case 2:
localt->tm_hour = RTCHOUR;
break;
case 3:
localt->tm_mday = RTCDAY;
break;
case 4:
localt->tm_wday = RTCDOW;
break;
case 5:
localt->tm_mon = RTCMON - 1;
break;
case 6:
tmpyear = RTCYEARL;
tmpyear |= (RTCYEARH << 0x08);
localt->tm_year = tmpyear - 1900;
break;
default:
success = 1;
break;
}
}
}
}
/*---------------------------------------------------------------------------*/
void rtc_set_alarm(struct tm* localt, rtc_alarm_mask_t mask) {
if (mask & RTC_ALARM_MIN) {
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;
}
/*---------------------------------------------------------------------------*/
void rtc_remove_alarm(void) {
/* reset all AE bits */
RTCAHOUR &= ~BIT7;
RTCAMIN &= ~BIT7;
RTCADAY &= ~BIT7;
RTCADOW &= ~BIT7;
/* reset alarm interrupt enable */
RTCCTL0 &= ~RTCAIE;
}
/*---------------------------------------------------------------------------*/
interrupt(RTC_VECTOR) __attribute__ ((naked)) rtc_isr(void) {
__enter_isr();
/* RTC is save to write for up to one second now */
if (RTCIV == RTC_RTCRDYIFG) {
/* disable interrupt */
RTCCTL0 &= ~RTCRDYIE;
/* set previous set time and reset it */
RTCSEC = time_to_set.tm_sec;
RTCMIN = time_to_set.tm_min;
RTCHOUR = time_to_set.tm_hour;
RTCDAY = time_to_set.tm_mday;
RTCDOW = time_to_set.tm_wday;
RTCMON = time_to_set.tm_mon + 1;
RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF;
RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08;
}
/* RTC alarm */
else if (RTCIV == RTC_RTCAIFG) {
}
__exit_isr();
}

@ -0,0 +1,75 @@
/******************************************************************************
Copyright 2010, Freie Universitaet Berlin (FUB). All rights reserved.
These sources were developed at the Freie Universitaet Berlin, Computer Systems
and Telematics group (http://cst.mi.fu-berlin.de).
-------------------------------------------------------------------------------
This file is part of µkleos.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
FeuerWare is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://scatterweb.mi.fu-berlin.de
and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
#ifndef CC430_RTC_H
#define CC430_RTC_H
#include <rtc.h>
#include <time.h>
/**
* @defgroup cc430_rtc CC430 Real Time Clock
* @ingroup cc430
*/
/**
* @file cc430-rtc.h
* @brief CC430 Real Time Clock
*
* @author Freie Universität Berlin, Computer Systems & Telematics, µkleos
* @version $Revision $
*/
/**
* @brief Mask for RTC alarms
* @see ::rtc_set_alarm
*/
typedef enum {
RTC_ALARM_DISABLED = 0x00, ///< Alarm disables
RTC_ALARM_MIN = 0x01, ///< Alarm mask for Minutes
RTC_ALARM_HOUR = 0x02, ///< Alarm mask for Hours
RTC_ALARM_DOW = 0x04, ///< Alarm mask for Day of Week
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
*/
void rtc_remove_alarm(void);
#endif

@ -24,8 +24,8 @@ and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
#ifndef __RTC_H
#define __RTC_H
#ifndef LPC2387_RTC_H
#define LPC2387_RTC_H
/**
* @defgroup lpc2387_rtc LPC2387 Real-Time-Clock
@ -48,9 +48,10 @@ and the mailinglist (subscription via web site)
* @note $Id: lpc2387-rtc.h 1998 2010-03-16 13:05:41Z baar $
*/
#include <rtc.h>
#include <time.h>
#include <sys/time.h>
#include "lpc2387.h"
#include <lpc2387.h>
/* ------------------------------------------------------------------------- */
/**
@ -76,13 +77,6 @@ enum rtc_alarm_mask {
RTC_AMR_YEAR= AMRYEAR, ///< Alarm mask for Year
};
/**
* @brief Initializes the RTC
* @internal
* During reboots only alarms are reset.
*/
void rtc_init(void);
void rtc_reset(void);
/**
@ -91,12 +85,6 @@ void rtc_reset(void);
*/
time_t rtc_get_compile_time(void) __attribute__((noinline));
/**
* @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 clock time
* @param[out] time optional return value
@ -111,22 +99,6 @@ time_t rtc_time(struct timeval* time);
*/
void rtc_set(time_t time);
/**
* @brief Enables the RTC
*/
void rtc_enable(void);
/**
* @brief Disables the RTC
*/
void rtc_disable(void);
/**
* @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 Sets the alarm
* @internal

@ -0,0 +1,15 @@
#ifndef MSPGCC_TIME_H
#define MSPGCC_TIME_H
struct tm
{
int tm_sec; // Seconds after the minute [0, 59]
int tm_min; // Minutes after the hour [0, 59]
int tm_hour; // Hours since midnight [0, 23]
int tm_mday; // Day of the month [1, 31]
int tm_mon; // Months since January [0, 11]
int tm_year; // Years since 1900
int tm_wday; // Days since Sunday [0, 6]
};
#endif

@ -0,0 +1,59 @@
/******************************************************************************
Copyright 2010, Freie Universitaet Berlin (FUB). All rights reserved.
These sources were developed at the Freie Universitaet Berlin, Computer Systems
and Telematics group (http://cst.mi.fu-berlin.de).
-------------------------------------------------------------------------------
This file is part of µkleos.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
FeuerWare is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://scatterweb.mi.fu-berlin.de
and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
#ifndef RTC_H
#define RTC_H
#include <time.h>
/**
* @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);
#endif

@ -44,6 +44,7 @@ and the mailinglist (subscription via web site)
#include <mutex.h>
#include <sht11.h>
#include <sht11-board.h>
#include <bitarithm.h>
//#define ENABLE_DEBUG (1)
#include <debug.h>

@ -1,9 +1,7 @@
#include <stdint.h>
#include <stdio.h>
#include <board_uart0.h>
#ifdef MODULE_RTC
#include <lpc2387-rtc.h>
#endif
#include <rtc.h>
#include <auto_init.h>
#define ENABLE_DEBUG

@ -12,8 +12,8 @@ void _id_handler(char *id) {
}
else {
printf("Setting new id %lu\n", newid);
sysconfig.id = newid;
#ifdef MODULE_CONFIG
sysconfig.id = newid;
if (!config_save()) {
puts("ERROR setting new id");
}

@ -3,8 +3,7 @@
#include <string.h>
#ifdef MODULE_RTC
#include <lpc2387-rtc.h>
#include <sys/time.h>
#include <rtc.h>
void _gettime_handler(void) {
struct tm now;
@ -36,8 +35,7 @@ void _settime_handler(char* c) {
now.tm_year = epoch_year - 1900;
now.tm_mon = month - 1;
time_t t = mktime(&now);
rtc_set(t);
rtc_set_localtime(&now);
}
void _date_handler(char* c) {

Loading…
Cancel
Save