| Xmega Application Note | |||||
XMEGA 32-bit Real Time Counter (RTC) example source code. More...
#include "avr_compiler.h"#include "rtc32_driver.h"#include "vbat.h"
Go to the source code of this file.
Functions | |
| void | chip_init (void) |
| int | main (void) |
| __interrupt void | rtc32_comp (void) |
| void | vbat_init (void) |
XMEGA 32-bit Real Time Counter (RTC) example source code.
This file contains an example application that demonstrates the 32-bit RTC driver. It shows how to set up the 32-bit RTC together with battery backup module. It uses the compare match interrupt of 32-bit RTC module to wake up MCU from power save mode. This example can be used to demonstrate how low power consumption xmega can be.
Definition in file rtc32_example1.c.
| void chip_init | ( | void | ) |
Definition at line 65 of file rtc32_example1.c.
References ENTER_CRITICAL_REGION, and LEAVE_CRITICAL_REGION.
Referenced by main().
00066 { 00067 /* 00068 * Disable all modules except the 32-bit RTC to minimise power 00069 * consumption 00070 */ 00071 PR.PRGEN = PR_AES_bm | PR_EBI_bm | PR_EVSYS_bm | PR_DMA_bm; 00072 PR.PRPA = PR_ADC_bm | PR_AC_bm; 00073 PR.PRPB = PR_DAC_bm | PR_ADC_bm | PR_AC_bm; 00074 PR.PRPC = PR_TWI_bm | PR_USART0_bm | PR_USART1_bm | PR_SPI_bm 00075 | PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; 00076 PR.PRPD = PR_USART0_bm | PR_USART1_bm | PR_SPI_bm | PR_HIRES_bm 00077 | PR_TC0_bm | PR_TC1_bm; 00078 PR.PRPE = PR_TWI_bm | PR_USART0_bm | PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; 00079 PR.PRPF = PR_USART0_bm | PR_HIRES_bm | PR_TC0_bm; 00080 00081 PORTA.DIR = 0x02; 00082 PORTA.OUTCLR = 0x02; 00083 00084 /* Configure system clock to use 32 MHz internal RC oscillator */ 00085 OSC.CTRL |= OSC_RC32MEN_bm; 00086 ENTER_CRITICAL_REGION( ); 00087 CCP = 0xD8; 00088 CLK.PSCTRL = (uint8_t)CLK_PSADIV_1_gc | (uint8_t)CLK_PSBCDIV_1_1_gc; 00089 while ( (OSC.STATUS & OSC_RC32MRDY_bm) == 0 ); 00090 CCP = 0xD8; 00091 CLK.CTRL = CLK_SCLKSEL_RC32M_gc; 00092 LEAVE_CRITICAL_REGION(); 00093 00094 /* Configure the interrupt system */ 00095 PMIC.CTRL |= PMIC_LOLVLEN_bm; 00096 00097 }
| int main | ( | void | ) |
Definition at line 107 of file rtc32_example1.c.
References chip_init(), RTC32_SetAlarm(), RTC32_SetCompareIntLevel(), vbat_init(), VBAT_STATUS_BBBOD, VBAT_STATUS_BBPOR, VBAT_STATUS_NO_POWER, VBAT_STATUS_OK, VBAT_STATUS_XOSCFAIL, and vbat_system_check().
00108 { 00109 uint8_t vbat_status; 00110 00111 chip_init(); 00112 vbat_status = vbat_system_check(true); 00113 00114 /* 00115 * Depending on the VBAT system check appropriate actions need to 00116 * be taken. 00117 * In this example we re-initialize the VBAT system in all 00118 * error cases. 00119 */ 00120 switch (vbat_status) 00121 { 00122 case VBAT_STATUS_OK: 00123 // Interrupts must be re-enabled 00124 RTC32_SetCompareIntLevel(RTC32_COMPINTLVL_LO_gc); 00125 break; 00126 case VBAT_STATUS_NO_POWER: // fall through 00127 case VBAT_STATUS_BBPOR: // fall through 00128 case VBAT_STATUS_BBBOD: // fall through 00129 case VBAT_STATUS_XOSCFAIL: // fall through 00130 default: 00131 vbat_init(); 00132 break; 00133 } 00134 00135 sei(); 00136 00137 while (true) { 00138 RTC32_SetAlarm(2); 00139 PORTA.OUTTGL = 0x02; 00140 SLEEP.CTRL = SLEEP_SMODE_PSAVE_gc | SLEEP_SEN_bm; 00141 cpu_sleep(); 00142 } 00143 }

| __interrupt void rtc32_comp | ( | void | ) |
Definition at line 146 of file rtc32_example1.c.
| void vbat_init | ( | void | ) |
Definition at line 99 of file rtc32_example1.c.
References RTC32_Initialize(), RTC32_SetCompareIntLevel(), vbat_enable_xosc(), and vbat_reset().
Referenced by main().
00100 { 00101 vbat_reset(); 00102 vbat_enable_xosc(0); 00103 RTC32_Initialize(0xffffffff, 0, 2 ); 00104 RTC32_SetCompareIntLevel(RTC32_COMPINTLVL_LO_gc); 00105 }

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