Xmega Application Note


rtc_driver.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00060 #include "rtc_driver.h"
00061 
00062 
00075 void RTC_Initialize( uint16_t period,
00076                      uint16_t count,
00077                      uint16_t compareValue,
00078                      RTC_PRESCALER_t prescaler )
00079 {
00080         RTC.PER = period - 1;
00081         RTC.CNT = count;
00082         RTC.COMP = compareValue;
00083         RTC.CTRL = ( RTC.CTRL & ~RTC_PRESCALER_gm ) | prescaler;
00084 }
00085 
00086 
00091 void RTC_SetOverflowIntLevel( RTC_OVFINTLVL_t intLevel )
00092 {
00093         RTC.INTCTRL = ( RTC.INTCTRL & ~RTC_OVFINTLVL_gm ) | intLevel;
00094 }
00095 
00096 
00101 void RTC_SetCompareIntLevel( RTC_COMPINTLVL_t intLevel )
00102 {
00103         RTC.INTCTRL = ( RTC.INTCTRL & ~RTC_COMPINTLVL_gm ) | intLevel;
00104 }
00105 
00106 
00113 void RTC_SetIntLevels( RTC_OVFINTLVL_t ovfIntLevel,
00114                        RTC_COMPINTLVL_t compIntLevel )
00115 {
00116         RTC.INTCTRL = ( RTC.INTCTRL &
00117                       ~( RTC_COMPINTLVL_gm | RTC_OVFINTLVL_gm ) ) |
00118                       ovfIntLevel |
00119                       compIntLevel;
00120 }
00121 
00122 
00138 void RTC_SetAlarm( uint16_t alarmTimeout )
00139 {
00140         /* Calculate compare time. */
00141         uint16_t compareValue = RTC.CNT + alarmTimeout;
00142 
00143         /* Wrap on period. */
00144         if (compareValue > RTC.PER){
00145                 compareValue -= RTC.PER;
00146         }
00147 
00148         /* Add the timeout value to get the absolute time of the alarm. */
00149         RTC.COMP = compareValue;
00150 }
00151 
00152 
00160 void RTC_SetPrescaler( RTC_PRESCALER_t prescaler )
00161 {
00162         RTC.CTRL = ( RTC.CTRL & ~RTC_PRESCALER_gm ) | prescaler;
00163 }
@DOC_TITLE@
Generated on Wed Apr 23 08:25:23 2008 for AVR1314 Using the Xmega Real Time Counter by doxygen 1.5.5