65 NO_INIT
volatile classb_preinit_teststate_t classb_wdt_teststate;
69 NO_INIT
volatile uint16_t classb_rtc_count;
111 register uint16_t counter;
117 if ( RST.STATUS & (RST_PORF_bm | RST_EXTRF_bm | RST_PDIRF_bm) ) {
120 RST.STATUS = (RST_PORF_bm | RST_EXTRF_bm | RST_PDIRF_bm);
122 classb_wdt_teststate = TEST_WDT_1;
134 OSC.CTRL |= OSC_RC32KEN_bm;
135 while (!(OSC.STATUS & OSC_RC32KRDY_bm));
136 CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;
139 RTC_TEST.PER = CLASSB_WDT_RTC_PER;
141 while( rtc_is_busy() );
143 RTC_TEST.CTRL = RTC_TEST_START_bm;
158 classb_rtc_count = 0;
159 counter = CLASSB_WDT_MAX / (CLASSB_WDT_RTC_PER+1);
162 while( !(RTC_TEST.INTFLAGS & RTC_TEST_OVFIF_bm) );
163 RTC_TEST.INTFLAGS = RTC_TEST_OVFIF_bm;
168 classb_wdt_teststate = FAULT_WDT;
172 else if ( RST.STATUS & RST_WDRF_bm ) {
175 RST.STATUS = RST_WDRF_bm;
178 switch (classb_wdt_teststate) {
185 classb_wdt_teststate = FAULT_WDT;
188 if( classb_rtc_count >= CLASSB_WDT_MIN / (CLASSB_WDT_RTC_PER+1) ){
197 CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;
200 RTC_TEST.PER = CLASSB_WDT_RTC_PER;
202 while( rtc_is_busy() );
204 RTC_TEST.CTRL = RTC_TEST_START_bm;
217 counter = classb_rtc_count;
218 counter += (classb_rtc_count >> 1);
221 while( !(RTC_TEST.INTFLAGS & RTC_TEST_OVFIF_bm) );
222 RTC_TEST.INTFLAGS = RTC_TEST_OVFIF_bm;
226 counter = classb_rtc_count;
227 counter += (classb_rtc_count >> 1);
230 while( !(RTC_TEST.INTFLAGS & RTC_TEST_OVFIF_bm) );
231 RTC_TEST.INTFLAGS = RTC_TEST_OVFIF_bm;
240 classb_wdt_teststate = TEST_WDT_2;
242 counter = (classb_rtc_count >> 1);
244 while( !(RTC_TEST.INTFLAGS & RTC_TEST_OVFIF_bm) );
245 RTC_TEST.INTFLAGS = RTC_TEST_OVFIF_bm;
249 classb_wdt_teststate = FAULT_WDT;
257 classb_wdt_teststate = FAULT_WDT;
266 CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;
269 RTC_TEST.PER = CLASSB_WDT_RTC_PER;
271 while( rtc_is_busy() );
273 RTC_TEST.CTRL = RTC_TEST_START_bm;
280 while( WDT.STATUS & WDT_SYNCBUSY_bm );
285 while( WDT.STATUS & WDT_SYNCBUSY_bm );
289 classb_wdt_teststate = TEST_WDT_3;
295 counter = classb_rtc_count >> 2;
297 while( !(RTC_TEST.INTFLAGS & RTC_TEST_OVFIF_bm) );
298 RTC_TEST.INTFLAGS = RTC_TEST_OVFIF_bm;
301 classb_wdt_teststate = FAULT_WDT;
310 while( WDT.STATUS & WDT_SYNCBUSY_bm );
315 while( WDT.STATUS & WDT_SYNCBUSY_bm );
319 classb_wdt_teststate = TEST_WDT_OK;
333 classb_wdt_teststate = FAULT_WDT;
349 if (classb_wdt_teststate == FAULT_WDT)
356 #if defined(__ICCAVR__)