![]() |
Energy Micro IEC60355 Library Example Project 1.0 (internal use only!) GCC-Version
Example project demonstrating POST and BIST library functions
|
The interrupt test checks functionality of a Timer
.
More...
|
Defines | |
| #define | SyncRTC() (RTC->SYNCBUSY & 1) |
| #define | SyncCMU() (CMU->OSCENCMD & 0x80) |
| #define | GetIRQRTC() (RTC->IF & RTC_IF_COMP0) |
Functions | |
| void | IEC60335_resetClockTest (uint32_t ratio, uint32_t tolerance) |
| internal function to reset all test structures | |
| void | IEC60335_ClassB_initClockTest (uint32_t ratio, uint32_t tolerance) |
| This function initializes the IEC60335 Class B clock test for BIST usage all test structures are reset to defined values. | |
| testResult_t | IEC60335_ClassB_Clocktest_PollHandler (void) |
This function represents the part of the IEC60335 Class B clock test which has to be executed within the main loop. It checks several thing:
| |
| void | IEC60335_ClassB_Clocktest_RTCHandler (void) |
| This function is intended to be called once inside the custom RTC interrupt service handler. | |
| static __INLINE void | IEC60335_ClassB_Clocktest_TimerHandler (void) |
| This function is intended to use as timer interrupt service handler or to be called once inside the timer interrupt service handler. | |
Variables | |
| ClockTest_t | ClockTest |
| ClockTest_t | ClockTest |
The interrupt test checks functionality of a Timer
.
RTC is checked against the selected timer device by running both with a specified
number of counts with tolerance during a defined period of the RTC
| #define GetIRQRTC | ( | ) | (RTC->IF & RTC_IF_COMP0) |
Definition at line 49 of file iec60335_class_b_timer_rtc_test.c.
Referenced by IEC60335_ClassB_Clocktest_PollHandler().
| #define SyncCMU | ( | ) | (CMU->OSCENCMD & 0x80) |
Definition at line 48 of file iec60335_class_b_timer_rtc_test.c.
Referenced by IEC60335_ClassB_initClockTest().
| #define SyncRTC | ( | ) | (RTC->SYNCBUSY & 1) |
Definition at line 47 of file iec60335_class_b_timer_rtc_test.c.
Referenced by IEC60335_ClassB_initClockTest().
| testResult_t IEC60335_ClassB_Clocktest_PollHandler | ( | void | ) |
This function represents the part of the IEC60335 Class B clock test which has to be executed within the main loop. It checks several thing:
This function represents the part of the IEC60335 Class B clock test which has to be executed within the main loop. It checks several thing:
This function must be called once inside the main loop.
Definition at line 180 of file iec60335_class_b_timer_rtc_test.c.
References ClkTest_struct::baseTicks, GetIRQRTC, IEC60335_resetClockTest(), IEC60335_testFailed, IEC60335_testInProgress, IEC60335_testPassed, ClkTest_struct::Ratio, ClkTest_struct::result, ClkTest_struct::timerCounter, and ClkTest_struct::Tolerance.
Referenced by main().
{
testResult_t result = IEC60335_testFailed;
uint32_t absolutUP, absolutLOW, intermediate;
ClockTest.result = IEC60335_testInProgress;
/* wait on RTC flag if running */
if (RTC->CTRL & RTC_CTRL_EN)
{
while (0 == (GetIRQRTC())) ;
RTC->IFC = RTC_IFC_COMP0;
ClockTest.baseTicks++;
}
else /* else quit here */
{
return(result);
}
/* calculate tolerance band extremes */
intermediate = ClockTest.Ratio * ClockTest.Tolerance / 100;
#if TESSY
intermediate = TS_TessyDummyIntermediate(intermediate);
#endif
if (intermediate > (0x80000000 - 1))
{
ClockTest.result = IEC60335_testFailed;
return(result);
}
else
{
/* absolutLOW must not be negative */
if (ClockTest.Ratio >= intermediate)
{
absolutLOW = ClockTest.Ratio - intermediate;
}
else
{
absolutLOW = 0;
}
absolutUP = intermediate + ClockTest.Ratio;
}
/* calculate average counter/baseTicks */
intermediate = ClockTest.timerCounter / ClockTest.baseTicks;
if ((intermediate > absolutLOW) && (intermediate < absolutUP))
{
result = IEC60335_testPassed;
/* reset the counters */
IEC60335_resetClockTest(0, 0);
/* stop Interrupts */
#if (USE_SYSTICK == 1)
/* Disable SysTick IRQ and SysTick Timer */
SysTick->CTRL &= ~(SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk);
#elif (USE_TIMER0)
if (TIMER0->CMD != TIMER_CMD_START)
{
ClockTest.result = IEC60335_testFailed;
return(IEC60335_testFailed);
}
ClockTest.result = IEC60335_testPassed;
/* disable interrupt */
NVIC->ICER[((uint32_t)(TIMER0_IRQn) >> 5)] = (1 << ((uint32_t)(TIMER0_IRQn) & 0x1F));
/* Clear pending interrupt */
NVIC->ICPR[((uint32_t)(TIMER0_IRQn) >> 5)] = (1 << ((uint32_t)(TIMER0_IRQn) & 0x1F));
TIMER0->IFC = TIMER_IEN_OF;
TIMER0->IEN &= ~TIMER_IEN_OF;
#elif (USE_TIMER1)
/* TODO : implement timer1 stop here */
#endif
}
return(result);
}


| void IEC60335_ClassB_Clocktest_RTCHandler | ( | void | ) |
This function is intended to be called once inside the custom RTC interrupt service handler.
This function is intended to be called once inside the custom RTC interrupt service handler. It can be used as service handler by itself. The result can be evaluated by checking the counters values are reseted after this.
This function tests the timer time frame and in this case the CPU frequency. Also, this function checks if the main loop function was called. (DO_NOT_INCLUDE_WITH_DOXYGEN)
This function tests the timer time frame and in this case the CPU frequency.
Also, this function checks if the main loop function was called.
Definition at line 275 of file iec60335_class_b_timer_rtc_test.c.
References ClkTest_struct::baseTicks, IEC60335_resetClockTest(), IEC60335_testFailed, IEC60335_testInProgress, IEC60335_testPassed, ClkTest_struct::Ratio, ClkTest_struct::result, ClkTest_struct::timerCounter, and ClkTest_struct::Tolerance.
{
uint32_t absolutUP, absolutLOW, intermediate;
ClockTest.result = IEC60335_testInProgress;
/* TODO: call this vector if RTC is used with interrupt */
/* check comp0 interrupt */
if (RTC->IF & RTC_IF_COMP0)
{
ClockTest.baseTicks++;
RTC->IFC = RTC_IFC_COMP0; /* clear the interrupt flag */
/* calculate tolerance band extremes */
intermediate = ClockTest.Ratio * ClockTest.Tolerance / 100;
/* absolutLOW must not be negative */
if (ClockTest.Ratio >= intermediate)
{
absolutLOW = ClockTest.Ratio - intermediate;
}
else
{
absolutLOW = 0;
}
absolutUP = intermediate + ClockTest.Ratio;
/* calculate average counter/baseTicks */
intermediate = ClockTest.timerCounter / ClockTest.baseTicks;
if ((intermediate > absolutLOW) && (intermediate < absolutUP))
{
/* reset the counters */
IEC60335_resetClockTest(0, 0);
/* stop Interrupts */
#if (USE_SYSTICK == 1)
/* Disable SysTick IRQ and SysTick Timer */
SysTick->CTRL &= ~(SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk);
#elif (USE_TIMER0)
if (TIMER0->CMD != TIMER_CMD_START)
{
ClockTest.result = IEC60335_testFailed;
return;
}
ClockTest.result = IEC60335_testPassed;
/* disable interrupt */
NVIC->ICER[((uint32_t)(TIMER0_IRQn) >> 5)] = (1 << ((uint32_t)(TIMER0_IRQn) & 0x1F));
/* Clear pending interrupt */
NVIC->ICPR[((uint32_t)(TIMER0_IRQn) >> 5)] = (1 << ((uint32_t)(TIMER0_IRQn) & 0x1F));
TIMER0->IFC = TIMER_IEN_OF;
TIMER0->IEN &= ~TIMER_IEN_OF;
#elif (USE_TIMER1)
/* TODO : implement timer1 stop here */
#endif
}
}
}

| static __INLINE void IEC60335_ClassB_Clocktest_TimerHandler | ( | void | ) | [static] |
This function is intended to use as timer interrupt service handler or to be called once inside the timer interrupt service handler.
Definition at line 76 of file iec60335_class_b_timer_rtc_test.h.
References ClkTest_struct::timerCounter.
Referenced by SysTick_Handler(), and TIMER0_IRQHandler().
{
/* Increment counter necessary in test*/
ClockTest.timerCounter++;
}

| void IEC60335_ClassB_initClockTest | ( | uint32_t | ratio, |
| uint32_t | tolerance | ||
| ) |
This function initializes the IEC60335 Class B clock test for BIST usage all test structures are reset to defined values.
(DO_NOT_INCLUDE_WITH_DOXYGEN)
| ratio | setup value for timer test ratio to RTC in counter ticks |
| tolerance | setup value for deviation tolerance in percent |
Definition at line 91 of file iec60335_class_b_timer_rtc_test.c.
References IEC60335_resetClockTest(), SyncCMU, and SyncRTC.
Referenced by main().
{
/* setup parameter */
IEC60335_resetClockTest(ratio, tolerance);
/* start RTC */
if (!RTC->CTRL & RTC_CTRL_EN)
{
/* enable LE clock */
CMU->HFCORECLKEN0 |= 4;
CMU->OSCENCMD = 0x40; /* enable osc LFXO */
while (SyncCMU()) ; /* wait for stabilizing */
CMU->LFCLKSEL |= CMU_LFCLKSEL_LFA_LFXO;
/* enable RTC clock */
CMU->LFACLKEN0 = 1;
CMU->LFAPRESC0 = CMU_LFAPRESC0_RTC_DIV4096;
while (SyncRTC()) ;
RTC->IEN = 0; /* ints off */
RTC->IFC = 7;
/* set compare */
while (SyncRTC()) ;
RTC->COMP0 = 0x666;
while (SyncRTC()) ;
/* run RTC */
RTC->CTRL |= RTC_CTRL_EN | RTC_CTRL_DEBUGRUN | RTC_CTRL_COMP0TOP;
}
#if (USE_SYSTICK == 1)
/* Setup SysTick Timer for 10 msec interrupts */
/* set reload register */
SysTick->LOAD = ((14000000 / 100) & SysTick_LOAD_RELOAD_Msk) - 1;
/* set Priority for Cortex-M3 System Interrupts */
SCB->SHP[((uint32_t)(SysTick_IRQn) & 0xF) - 4] = ((((1 << __NVIC_PRIO_BITS) - 1) << (8 - __NVIC_PRIO_BITS)) & 0xff);
/* Load the SysTick Counter Value */
SysTick->VAL = 0;
/* Enable SysTick IRQ and SysTick Timer */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
#elif (USE_TIMER0)
/* start timer0 */
/* Enable Timer Clock */
CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_TIMER0;
/* Configure TIMER from HFPERCLK */
TIMER0->CTRL = TIMER_CTRL_CLKSEL_PRESCHFPERCLK | TIMER_CTRL_PRESC_DIV32 | \
TIMER_CTRL_FALLA_NONE | TIMER_CTRL_RISEA_NONE | \
(0 << _TIMER_CTRL_DEBUGRUN_SHIFT) | TIMER_CTRL_MODE_UP;
/* 32K ticks interrupts */
TIMER0->TOP = 4 * 1024;
/* Clear pending interrupt */
NVIC->ICPR[((uint32_t)(TIMER0_IRQn) >> 5)] = (1 << ((uint32_t)(TIMER0_IRQn) & 0x1F));
TIMER0->IFC = TIMER_IEN_OF;
TIMER0->IEN = TIMER_IEN_OF;
/* enable interrupt */
NVIC->ISER[((uint32_t)(TIMER0_IRQn) >> 5)] = (1 << ((uint32_t)(TIMER0_IRQn) & 0x1F));
TIMER0->CMD = TIMER_CMD_START;
#elif (USE_TIMER1)
/* start timer1 */
/* TODO : implement timer1 setup here */
#endif
}


| void IEC60335_resetClockTest | ( | uint32_t | ratio, |
| uint32_t | tolerance | ||
| ) |
internal function to reset all test structures
(DO_NOT_INCLUDE_WITH_DOXYGEN)
Definition at line 64 of file iec60335_class_b_timer_rtc_test.c.
References ClkTest_struct::baseTicks, IEC60335_testInProgress, ClkTest_struct::Ratio, ClkTest_struct::result, ClkTest_struct::timerCounter, and ClkTest_struct::Tolerance.
Referenced by IEC60335_ClassB_Clocktest_PollHandler(), IEC60335_ClassB_Clocktest_RTCHandler(), and IEC60335_ClassB_initClockTest().
{
/* reset counter */
if (ratio == 0)
{
ClockTest.timerCounter = 0;
ClockTest.baseTicks = 0;
ClockTest.result = IEC60335_testInProgress + 1;
}
else
{
ClockTest.Ratio = ratio;
ClockTest.Tolerance = tolerance;
ClockTest.timerCounter = 0;
ClockTest.baseTicks = 0;
}
}

RTC/Timer-test structure
Definition at line 52 of file iec60335_class_b_timer_rtc_test.c.
RTC/Timer-test structure
Definition at line 52 of file iec60335_class_b_timer_rtc_test.c.