Xmega Application Note


vbat.c File Reference

#include "avr_compiler.h"
#include "vbat.h"
Include dependency graph for vbat.c:

Go to the source code of this file.

Functions

void vbat_enable_xosc (bool use1khz)
 This function starts the crystal oscillator with 1 or 1024 Hz clock output.
void vbat_reset (void)
 This function resets the battery backup module.
uint8_t vbat_system_check (bool first_time_startup)
 Check battery backup system status.

Function Documentation

void vbat_enable_xosc ( bool  use1khz  ) 

This function starts the crystal oscillator with 1 or 1024 Hz clock output.

Parameters:
use1khz Boolean for selecting 1 kHz or 1 Hz RTC clock rate.

Definition at line 27 of file vbat.c.

Referenced by vbat_init().

00028 {
00029         // Enable the failure detection.
00030         VBAT.CTRL |= VBAT_XOSCFDEN_bm;
00031 
00032         /* A delay is needed to give the voltage in the backup system some time
00033          * to stabilise.
00034          */
00035         delay_us(200);
00036 
00037         // Enable oscillator, with 1 kHz or 1 Hz output.
00038         if (use1khz)
00039                 VBAT.CTRL |= VBAT_XOSCEN_bm | VBAT_XOSCSEL_bm;
00040         else
00041                 VBAT.CTRL |= VBAT_XOSCEN_bm;
00042 }

void vbat_reset ( void   ) 

This function resets the battery backup module.

This function will set the access enable bit for the control register.

Definition at line 9 of file vbat.c.

References ENTER_CRITICAL_REGION, and LEAVE_CRITICAL_REGION.

Referenced by vbat_init().

00010 {
00011         // Enable R/W access to the battery backup module.
00012         VBAT.CTRL = VBAT_ACCEN_bm;
00013 
00014         // Reset the module. (Reset bit is protected by CCP.)
00015         ENTER_CRITICAL_REGION();
00016         CCP = 0xD8;
00017         VBAT.CTRL = VBAT_RESET_bm;
00018         LEAVE_CRITICAL_REGION();
00019 }

uint8_t vbat_system_check ( bool  first_time_init  ) 

Check battery backup system status.

Parameters:
first_time_startup When this is the first time the system starts then this is false otherwise true.
Returns:
Backup system status.

Definition at line 44 of file vbat.c.

References VBAT_STATUS_BBBOD, VBAT_STATUS_BBPOR, VBAT_STATUS_INIT, VBAT_STATUS_NO_POWER, VBAT_STATUS_OK, and VBAT_STATUS_XOSCFAIL.

Referenced by main().

00045 {
00046         uint8_t vbat_status;
00047         /*
00048          * Check if sufficient power was detected on the VBAT input. The brown-
00049          * out detector (BBBOD) will be sampled once when the device starts up
00050          * and the result is visible as the BBPWR flag.
00051          */
00052         if (VBAT.STATUS & VBAT_BBPWR_bm)
00053                 vbat_status = VBAT_STATUS_NO_POWER;
00054         else {
00055                 /*
00056                  * We hav sufficient power, now we check if a power-on-reset
00057                  * (BBPOR) was detected on VBAT. This is visible from the BBPORF
00058                  * flag which is also only updated once when the device starts.
00059                  */
00060                 if (VBAT.STATUS & VBAT_BBPORF_bm) {
00061                         if (first_time_startup)
00062                                 vbat_status = VBAT_STATUS_INIT;
00063                         else
00064                                 vbat_status = VBAT_STATUS_BBPOR;
00065                 }
00066                 else if (VBAT.STATUS & VBAT_BBBORF_bm)
00067                         vbat_status = VBAT_STATUS_BBBOD;
00068                 else {
00069                         VBAT.CTRL = VBAT_ACCEN_bm;
00070                         if (VBAT.STATUS & VBAT_XOSCFAIL_bm)
00071                                 vbat_status = VBAT_STATUS_XOSCFAIL;
00072                         else
00073                                 vbat_status = VBAT_STATUS_OK;
00074                 }
00075         }
00076         return vbat_status;
00077 }

@DOC_TITLE@
Generated on Thu Jun 24 16:35:07 2010 for AVR1321: Using the XMEGA 32bit RTC by doxygen 1.6.1