Atmel Software Framework

rtc32.c File Reference

AVR XMEGA 32-bit Real Time Counter driver.

Copyright (c) 2010-2015 Atmel Corporation. All rights reserved.

#include <compiler.h>
#include <parts.h>
#include <sysclk.h>
#include <delay.h>
#include "rtc32.h"

Data Structures

struct  RTC32_struct2
struct  rtc_data_struct
 Driver private struct. More...


#define RTC32   (*(RTC32_t2 *)0x0420)


typedef struct RTC32_struct2 RTC32_t2


 ISR (RTC32_COMP_vect)
 Compare interrupt used for alarm. More...
bool rtc_alarm_has_triggered (void)
 Check if pending alarm has triggered. More...
static uint32_t rtc_get_counter (void)
 Get counter. More...
uint32_t rtc_get_time (void)
 Get current time. More...
void rtc_init (void)
 Initialize the 32kHz oscillator and RTC32. More...
static __always_inline bool rtc_is_busy (void)
 Check if RTC32 is busy synchronizing. More...
void rtc_set_alarm (uint32_t time)
 Set alarm time. More...
void rtc_set_callback (rtc_callback_t callback)
 Set callback to call on alarm. More...
void rtc_set_time (uint32_t time)
 Set current time. More...
enum vbat_status_code rtc_vbat_system_check (bool first_time_startup)
 Checks battery backup system status. More...
static void vbat_init (void)
 Initialize VBAT and start 32kHz oscillator. More...


struct rtc_data_struct rtc_data
 Driver private data. More...

#define RTC32   (*(RTC32_t2 *)0x0420)

Workaround for missing CNT, PER and COMP in WinAVR header files

Remove when header files are fixed if WinAVR release

Referenced by ISR(), main(), main_init_rtc32(), oven_classb_init_tests(), rtc32_is_busy(), rtc_alarm_has_triggered(), rtc_get_counter(), rtc_init(), rtc_is_busy(), rtc_set_alarm(), and rtc_set_time().


Referenced by vbat_init().


typedef struct RTC32_struct2 RTC32_t2

Workaround for missing CNT, PER and COMP in WinAVR header files

Remove when header files are fixed if WinAVR release

ISR ( RTC32_COMP_vect  )

Compare interrupt used for alarm.

Disables the RTC32 interrupts, then calls the alarm callback function if one has been set.

References rtc_data_struct::callback, RTC32, rtc_data, and rtc_get_time().

static uint32_t rtc_get_counter ( void  )

Get counter.

Counter value

References RTC32.

Referenced by rtc_get_time().

static __always_inline bool rtc_is_busy ( void  )

Check if RTC32 is busy synchronizing.

Return values
trueIs busy
falseIs ready

References RTC32.

static void vbat_init ( void  )

Initialize VBAT and start 32kHz oscillator.

Enables access to the VBAT system, performs a reset, enables the failure detection, and starts the oscillator.

The default clock rate to the RTC32 is 1Hz but this can be changed to 1024Hz by the user in the module configuration by defining CONFIG_RTC32_CLOCK_1024HZ.

References ccp_write_io(), delay_us, and RTC32_CLOCK.

Referenced by rtc_init().

struct rtc_data_struct rtc_data

Driver private data.