| Xmega Application Note | |||||
XMEGA 32-bit RTC driver header file. More...
#include "avr_compiler.h"

Go to the source code of this file.
Defines | |
| #define | RTC32_GetCompareFlag() ( RTC32.INTFLAGS & RTC32_COMPIF_bm ) |
| This macro returns the status of the RTC compare flag. | |
| #define | RTC32_GetCompareValue() ( RTC32.COMP ) |
| This macro returns the current RTC compare value. | |
| #define | RTC32_GetOverflowFlag() ( RTC32.INTFLAGS & RTC32_OVFIF_bm ) |
| This macro returns the status of the RTC overflow flag. | |
| #define | RTC32_GetPeriod() ( RTC32.PER ) |
| This macro returns the current RTC period value. | |
| #define | RTC32_SetCompareValue(_cmpVal) ( RTC32.COMP = (_cmpVal) ) |
| This macro sets a new RTC compare value. | |
| #define | RTC32_SyncBusy() ( RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm ) |
| This macro returns the RTC32 CNT/CTRL write synchronization flag. | |
| #define | RTC32_SyncCnt() ( RTC32.SYNCCTRL |= RTC32_SYNCCNT_bm ) |
| This macro initiates read synchronization of the RTC32 CNT register. | |
| #define | RTC32_SyncCntBusy() ( RTC32.SYNCCTRL & RTC32_SYNCCNT_bm ) |
| This macro returns the RTC32 CNT read synchronization flag. | |
| #define | RTC32_ToscBusy() !( VBAT.STATUS & VBAT_XOSCRDY_bm ) |
| This macro returns the XOSC/TOSC ready flag. | |
Functions | |
| uint32_t | RTC32_GetCount (void) |
| This function returns the current RTC count value. | |
| void | RTC32_Initialize (uint32_t period, uint32_t count, uint32_t compareValue) |
| This function initializes the RTC with period, initial count and compare value. | |
| void | RTC32_Reset (void) |
| void | RTC32_SetAlarm (uint32_t alarmTimeout) |
| This function sets a timeout alarm. | |
| void | RTC32_SetCompareIntLevel (RTC32_COMPINTLVL_t intLevel) |
| This function sets the RTC compare interrupt level. | |
| void | RTC32_SetCount (uint32_t count) |
| This function sets a new RTC count value. | |
| void | RTC32_SetIntLevels (RTC32_OVFINTLVL_t ovfIntLevel, RTC32_COMPINTLVL_t compIntLevel) |
| This function sets both compare and overflow interrupt levels in one go. | |
| void | RTC32_SetOverflowIntLevel (RTC32_OVFINTLVL_t intLevel) |
| This function sets the RTC overflow interrupt level. | |
| void | RTC32_SetPeriod (uint32_t period) |
| This function sets a new RTC period. | |
| void | RTC32_ToscEnable (bool use1khz) |
XMEGA 32-bit RTC driver header file.
This file contains the function prototypes and enumerator definitions for various configuration parameters for the XMEGA 32-bit RTC driver.
Copyright (c) 2008, Atmel Corporation All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file rtc32_driver.h.
| #define RTC32_GetCompareFlag | ( | ) | ( RTC32.INTFLAGS & RTC32_COMPIF_bm ) |
This macro returns the status of the RTC compare flag.
Definition at line 93 of file rtc32_driver.h.
| #define RTC32_GetCompareValue | ( | ) | ( RTC32.COMP ) |
This macro returns the current RTC compare value.
This is the compare value of the RTC, which will be compared to the count sequence. The compare value must be less than or equal to PER.
Definition at line 119 of file rtc32_driver.h.
| #define RTC32_GetOverflowFlag | ( | ) | ( RTC32.INTFLAGS & RTC32_OVFIF_bm ) |
This macro returns the status of the RTC overflow flag.
Definition at line 87 of file rtc32_driver.h.
| #define RTC32_GetPeriod | ( | ) | ( RTC32.PER ) |
This macro returns the current RTC period value.
This is the period value of the RTC, which is the top of the count sequence.
Definition at line 101 of file rtc32_driver.h.
| #define RTC32_SetCompareValue | ( | _cmpVal | ) | ( RTC32.COMP = (_cmpVal) ) |
This macro sets a new RTC compare value.
This is the compare value of the RTC, which will be compared to the count sequence. The compare value must be less than the RTC period.
| _cmpVal | The new compare value. |
Definition at line 110 of file rtc32_driver.h.
| #define RTC32_SyncBusy | ( | ) | ( RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm ) |
This macro returns the RTC32 CNT/CTRL write synchronization flag.
Definition at line 62 of file rtc32_driver.h.
Referenced by RTC32_Initialize(), RTC32_SetCount(), and RTC32_SetPeriod().
| #define RTC32_SyncCnt | ( | ) | ( RTC32.SYNCCTRL |= RTC32_SYNCCNT_bm ) |
This macro initiates read synchronization of the RTC32 CNT register.
Initiates synchronization of CNT register from RTC to system clock domain.
Definition at line 74 of file rtc32_driver.h.
Referenced by RTC32_GetCount(), and RTC32_SetAlarm().
| #define RTC32_SyncCntBusy | ( | ) | ( RTC32.SYNCCTRL & RTC32_SYNCCNT_bm ) |
This macro returns the RTC32 CNT read synchronization flag.
Definition at line 81 of file rtc32_driver.h.
Referenced by RTC32_GetCount(), and RTC32_SetAlarm().
| #define RTC32_ToscBusy | ( | ) | !( VBAT.STATUS & VBAT_XOSCRDY_bm ) |
This macro returns the XOSC/TOSC ready flag.
Definition at line 68 of file rtc32_driver.h.
| uint32_t RTC32_GetCount | ( | void | ) |
This function returns the current RTC count value.
This function synchronizes the RTC32 module's CNT value to the system clock domain, then returns its value.
Definition at line 185 of file rtc32_driver.c.
References RTC32_SyncCnt, and RTC32_SyncCntBusy.
00186 { 00187 /* Synchronize the RTC module's CNT value to the system clock domain. */ 00188 RTC32_SyncCnt(); 00189 do { } while ( RTC32_SyncCntBusy() ); 00190 00191 return RTC32.CNT; 00192 }
| void RTC32_Initialize | ( | uint32_t | period, | |
| uint32_t | count, | |||
| uint32_t | compareValue | |||
| ) |
This function initializes the RTC with period, initial count and compare value.
All the synchronized registers are written at the same time to save time.
| period | RTC period. Topvalue = Period - 1. | |
| count | Initial RTC count. | |
| compareValue | Compare value. |
Definition at line 70 of file rtc32_driver.c.
References RTC32_SyncBusy.
Referenced by vbat_init().
00073 { 00074 /* Disable the RTC32 module before writing to it. Wait for synch. */ 00075 RTC32.CTRL &= ~RTC32_ENABLE_bm; 00076 do { } while ( RTC32_SyncBusy() ); 00077 00078 /* Write PER, COMP and CNT. */ 00079 RTC32.PER = period - 1; 00080 RTC32.COMP = compareValue; 00081 RTC32.CNT = count; 00082 00083 /* Re-enable the RTC32 module, synchronize before returning. */ 00084 RTC32.CTRL |= RTC32_ENABLE_bm; 00085 do { } while ( RTC32_SyncBusy() ); 00086 }
| void RTC32_Reset | ( | void | ) |
| void RTC32_SetAlarm | ( | uint32_t | alarmTimeout | ) |
This function sets a timeout alarm.
This function sets a timeout alarm by adding the timeout to the current count value. If the resulting alarm value is larger than the RTC period value, it will wrap around. An RTC compare interrupt will be triggered¨ after the specified timeout.
| alarmTimeout | Timeout time in RTC clock cycles (scaled). |
Definition at line 139 of file rtc32_driver.c.
References RTC32_SyncCnt, and RTC32_SyncCntBusy.
Referenced by main().
00140 { 00141 uint32_t compareValue; 00142 00143 /* Synchronize CNT from RTC to system clock domain. */ 00144 RTC32_SyncCnt(); 00145 do { } while ( RTC32_SyncCntBusy() ); 00146 00147 /* Calculate compare time. */ 00148 compareValue = RTC32.CNT + alarmTimeout; 00149 00150 /* Wrap on period. */ 00151 if (compareValue > RTC32.PER){ 00152 compareValue -= RTC32.PER; 00153 } 00154 00155 /* Add the timeout value to get the absolute time of the alarm. */ 00156 RTC32.COMP = compareValue; 00157 }
| void RTC32_SetCompareIntLevel | ( | RTC32_COMPINTLVL_t | intLevel | ) |
This function sets the RTC compare interrupt level.
| intLevel | The compare interrupt level. |
Definition at line 103 of file rtc32_driver.c.
Referenced by main(), and vbat_init().
| void RTC32_SetCount | ( | uint32_t | count | ) |
This function sets a new RTC count value.
This function waits for the RTC32 module to finish synchronizing the CNT and CTRL registers before writing the new count.
The function does not return until the CNT register has synchronized from the system to RTC clock domain.
| count | The new RTC count value. |
Definition at line 168 of file rtc32_driver.c.
References RTC32_SyncBusy.
00169 { 00170 /* Make sure that CNT is not currently synchronizing, or write will fail. */ 00171 do { } while ( RTC32_SyncBusy() ); 00172 00173 /* Write new count value and wait for synchronization before returning. */ 00174 RTC32.CNT = count; 00175 do { } while ( RTC32_SyncBusy() ); 00176 }
| void RTC32_SetIntLevels | ( | RTC32_OVFINTLVL_t | ovfIntLevel, | |
| RTC32_COMPINTLVL_t | compIntLevel | |||
| ) |
This function sets both compare and overflow interrupt levels in one go.
| ovfIntLevel | The overflow interrupt level. | |
| compIntLevel | The compare interrupt level. |
Definition at line 115 of file rtc32_driver.c.
| void RTC32_SetOverflowIntLevel | ( | RTC32_OVFINTLVL_t | intLevel | ) |
This function sets the RTC overflow interrupt level.
| intLevel | The overflow interrupt level. |
Definition at line 93 of file rtc32_driver.c.
| void RTC32_SetPeriod | ( | uint32_t | period | ) |
This function sets a new RTC period.
This function disables the RTC32 module, writes the new period to its PER register, then re-enables the module.
| period | The new RTC period. |
Definition at line 201 of file rtc32_driver.c.
References RTC32_SyncBusy.
00202 { 00203 /* Disable the RTC32 module before writing to it. Wait for synch. */ 00204 RTC32.CTRL &= ~RTC32_ENABLE_bm; 00205 do { } while ( RTC32_SyncBusy() ); 00206 00207 RTC32.PER = period; 00208 00209 /* Enable the RTC32 module. Wait for synch. */ 00210 RTC32.CTRL |= RTC32_ENABLE_bm; 00211 do { } while ( RTC32_SyncBusy() ); 00212 }
| void RTC32_ToscEnable | ( | bool | use1khz | ) |
Generated on Thu Jun 24 16:35:07 2010 for AVR1321: Using the XMEGA 32bit RTC by 1.6.1
|