Xmega Application Note


rtc32_driver.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00054 #include "avr_compiler.h"
00055 #include "rtc32_driver.h"
00056 
00057 
00058 
00059 
00060 
00070 void RTC32_Initialize( uint32_t period,
00071                        uint32_t count,
00072                        uint32_t compareValue )
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 }
00087 
00088 
00093 void RTC32_SetOverflowIntLevel( RTC32_OVFINTLVL_t intLevel )
00094 {
00095         RTC32.INTCTRL = ( RTC32.INTCTRL & ~RTC32_OVFINTLVL_gm ) | intLevel;
00096 }
00097 
00098 
00103 void RTC32_SetCompareIntLevel( RTC32_COMPINTLVL_t intLevel )
00104 {
00105         RTC32.INTCTRL = ( RTC32.INTCTRL & ~RTC32_COMPINTLVL_gm ) | intLevel;
00106 }
00107 
00108 
00115 void RTC32_SetIntLevels( RTC32_OVFINTLVL_t ovfIntLevel,
00116                          RTC32_COMPINTLVL_t compIntLevel )
00117 {
00118         RTC32.INTCTRL = ( RTC32.INTCTRL &
00119                         ~( RTC32_COMPINTLVL_gm | RTC32_OVFINTLVL_gm ) ) |
00120                         ovfIntLevel |
00121                         compIntLevel;
00122 }
00123 
00139 void RTC32_SetAlarm( uint32_t alarmTimeout )
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 }
00158 
00168 void RTC32_SetCount( uint32_t count )
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 }
00177 
00185 uint32_t RTC32_GetCount( void )
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 }
00193 
00201 void RTC32_SetPeriod( uint32_t period )
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 }
@DOC_TITLE@
Generated on Thu Jun 24 16:35:07 2010 for AVR1321: Using the XMEGA 32bit RTC by doxygen 1.6.1