Xmega Application Note


vbat.h File Reference

XMEGA VBAT system driver. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

Battery backup system status macros



#define VBAT_STATUS_BBBOD   4
 A brown-out was detected on the VBAT input.
#define VBAT_STATUS_BBPOR   3
 A POR was detected on the VBAT input.
#define VBAT_STATUS_INIT   2
 The backup system must be initialized.
#define VBAT_STATUS_NO_POWER   1
 No power detected on VBAT.
#define VBAT_STATUS_OK   0
 Everything works as expected.
#define VBAT_STATUS_XOSCFAIL   5
 A failure was detected on the oscillator.

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_init)
 Check battery backup system status.

Detailed Description

XMEGA VBAT system driver.

Application note:
AVR1321: Using the XMEGA 32-bit RTC and battery backup system
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
112
Date
2009-11-18 14:31:39 +0800 (WED, 18 Nov 2009)


Definition in file vbat.h.


Define Documentation

#define VBAT_STATUS_BBBOD   4

A brown-out was detected on the VBAT input.

The backup system is in a unkown state and must be reset.

Definition at line 94 of file vbat.h.

Referenced by main(), and vbat_system_check().

#define VBAT_STATUS_BBPOR   3

A POR was detected on the VBAT input.

This means the backup system is in an unkonw state.

Definition at line 87 of file vbat.h.

Referenced by main(), and vbat_system_check().

#define VBAT_STATUS_INIT   2

The backup system must be initialized.

A POR was detected on VBAT input which indicates that a supply was connected to the backup system. Since this is also the first start-up of the device we then need to initialize the backup system.

Definition at line 80 of file vbat.h.

Referenced by vbat_system_check().

#define VBAT_STATUS_NO_POWER   1

No power detected on VBAT.

The backup system is not operational and all data within the backup system will be lost when main power is lost.

Definition at line 71 of file vbat.h.

Referenced by main(), and vbat_system_check().

#define VBAT_STATUS_OK   0

Everything works as expected.

The backup system is configured and had no issues while main power was lost. Because of that all data stored in the backup domain is valid.

Definition at line 63 of file vbat.h.

Referenced by main(), and vbat_system_check().

#define VBAT_STATUS_XOSCFAIL   5

A failure was detected on the oscillator.

The oscillator stopped for at least TBD period of time and because of that we can not rely on the RTC time any more.

Definition at line 101 of file vbat.h.

Referenced by main(), and vbat_system_check().


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 also set the access enable bit for the control register.

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