rtc32_driver.c
Go to the documentation of this file.00001
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
00075 RTC32.CTRL &= ~RTC32_ENABLE_bm;
00076 do { } while ( RTC32_SyncBusy() );
00077
00078
00079 RTC32.PER = period - 1;
00080 RTC32.COMP = compareValue;
00081 RTC32.CNT = count;
00082
00083
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
00144 RTC32_SyncCnt();
00145 do { } while ( RTC32_SyncCntBusy() );
00146
00147
00148 compareValue = RTC32.CNT + alarmTimeout;
00149
00150
00151 if (compareValue > RTC32.PER){
00152 compareValue -= RTC32.PER;
00153 }
00154
00155
00156 RTC32.COMP = compareValue;
00157 }
00158
00168 void RTC32_SetCount( uint32_t count )
00169 {
00170
00171 do { } while ( RTC32_SyncBusy() );
00172
00173
00174 RTC32.CNT = count;
00175 do { } while ( RTC32_SyncBusy() );
00176 }
00177
00185 uint32_t RTC32_GetCount( void )
00186 {
00187
00188 RTC32_SyncCnt();
00189 do { } while ( RTC32_SyncCntBusy() );
00190
00191 return RTC32.CNT;
00192 }
00193
00201 void RTC32_SetPeriod( uint32_t period )
00202 {
00203
00204 RTC32.CTRL &= ~RTC32_ENABLE_bm;
00205 do { } while ( RTC32_SyncBusy() );
00206
00207 RTC32.PER = period;
00208
00209
00210 RTC32.CTRL |= RTC32_ENABLE_bm;
00211 do { } while ( RTC32_SyncBusy() );
00212 }