|
Arduino-RTC
Real-Time Clock (RTC) library for Arduino
|
#ifndef HARDWARE_AVR_RTC_H
#define HARDWARE_AVR_RTC_H
RTC
{
public:
RTC():
m_millis( 0 ), m_time( 0 )
{}
bool
tick()
{
uint16_t now = millis();
if( now - m_millis < 1000)
return( false );
uint8_t sreg = SREG;
__asm__ __volatile__( "cli" ::: "memory");
m_time += 1;
m_millis = now;
SREG = sreg;
__asm__ __volatile__("" ::: "memory");
return( true );
}
/*F********************************************************************
*
**********************************************************************/
time_t
get_time()
{
uint8_t sreg = SREG;
__asm__ __volatile__("cli" ::: "memory");
time_t res = m_time;
SREG = sreg;
__asm__ __volatile__("" ::: "memory");
return( res );
}
/*F********************************************************************
*
**********************************************************************/
void
set_time( time_t time)
{
uint8_t sreg = SREG;
__asm__ __volatile__("cli" ::: "memory");
m_time = time;
SREG = sreg;
__asm__ __volatile__("" ::: "memory");
}
/*F********************************************************************
*
**********************************************************************/
void
get_time( struct tm& now)
{
time_t time = get_time();
gmtime_r(&time, &now);
}
/*F********************************************************************
*
**********************************************************************/
void
set_time( struct tm& now)
{
extern long __utc_offset;
set_time( mktime( &now ) + __utc_offset);
}
/*F********************************************************************
*
**********************************************************************/
protected:
volatile uint16_t m_millis;
volatile time_t m_time;
};
#endif
__utc_offset int32_t __utc_offset
Definition:
set_zone.cpp:31
RTC::RTCRTC()
Definition:
RTC.h:30
RTC::m_millis volatile uint16_t m_millis
Definition:
RTC.h:97
RTC::get_time