implemented basics of rtc module

This commit is contained in:
Stefan Rupp 2014-03-02 08:01:37 +01:00
parent de56b05700
commit 069f3c54d9
2 changed files with 17 additions and 13 deletions

28
rtc.c
View File

@ -8,7 +8,6 @@
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
#if 0
#include <avr/io.h> #include <avr/io.h>
#include "rtc.h" #include "rtc.h"
@ -16,24 +15,29 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
static volatile uint32_t rtc_time; static volatile uint32_t _rtc_time;
ISR(TIMER2_COMP_vect) { ISR(TIMER2_OVF_vect) {
++rtc_time; ++_rtc_time;
return; return;
} }
void rtc_init(void) void rtc_init(uint32_t rtc_time)
{ {
// Stop all interrupts // Stop all interrupts
cli(); cli();
TCCR2B = 0;
TCCR2A = 0;
TCNT2 = 0;
// Reset timer to zero // Reset timer to zero
rtc_time = 0; _rtc_time = rtc_time;
// ... ASSR = (1<<AS2); // set to asynchronous operation
// ... TCCR2A = 0;
// ... TCCR2B = (1<<CS22)|(1<<CS20);
TIMSK2 = (1<<TOIE2); // enable overflow interrupt
sei(); sei();
} }
@ -49,7 +53,7 @@ inline uint32_t rtc_get(void)
sreg = SREG; sreg = SREG;
cli(); cli();
t = rtc_time; t = _rtc_time;
SREG = sreg; SREG = sreg;
return t; return t;
} }
@ -66,7 +70,7 @@ inline uint32_t rtc_get(void)
* \param seconds will be filled in to contain the seconds after return * \param seconds will be filled in to contain the seconds after return
* \param ms be filled in to contain the microseconds after return * \param ms be filled in to contain the microseconds after return
*/ */
void rtc_decode(uint32_t time, uint16_t days, uint8_t *hours, uint8_t *minutes, uint8_t *seconds) void rtc_decode(uint32_t time, uint16_t *days, uint8_t *hours, uint8_t *minutes, uint8_t *seconds)
{ {
if (seconds != NULL) { if (seconds != NULL) {
*seconds = time % 60; *seconds = time % 60;
@ -131,5 +135,5 @@ void timer_validate(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint16_t
*/ */
#endif #endif
#endif

2
rtc.h
View File

@ -5,6 +5,6 @@
uint32_t rtc_get(void); uint32_t rtc_get(void);
void rtc_init(void); void rtc_init(uint32_t rtc_time);
#endif // RTC_H #endif // RTC_H