/**************************************************************************//** * @brief Register a callback function at the given frequency. * * @param[in] pFunction Pointer to function that should be called at the * given frequency. * @param[in] argument Argument to be given to the function. * @param[in] frequency Frequency at which to call function at. * * @return 0 for successful or * -1 if the requested frequency does not match the RTC frequency. *****************************************************************************/ int rtcIntCallbackRegister(void (*pFunction)(void*), void* argument, unsigned int frequency) { RTCDRV_TimerID_t timerId; rtcCallback = pFunction; rtcCallbackArg = argument; RTCDRV_AllocateTimer(&timerId); RTCDRV_StartTimer(timerId, rtcdrvTimerTypePeriodic, 1000 / frequency, memLcdCallback, NULL); return 0; }
/***************************************************************************//** * @brief * Delay ms function * * @param[in] ms * 32bit Time in ms for delay * *******************************************************************************/ void delay(uint32_t ms) { uint32_t ticks; ticks = MSEC_TO_TICKS(ms); delay_done = false; if (ECODE_EMDRV_RTCDRV_OK != RTCDRV_StartTimer(delay_timer, rtcdrvTimerTypeOneshot, ticks, delay_callback, 0)) fatal("can't initialize delay timer"); while (! delay_done) EMU_EnterEM2(true); }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { uint8_t prod_rev; char string[8]; int i; uint32_t temp; uint32_t temp_offset; /* Chip errata */ CHIP_Init(); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); /* Enable peripheral clocks */ CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(cmuClock_ADC0, true); /* Initialize RTC timer. */ RTCDRV_Init(); RTCDRV_AllocateTimer( &xTimerForWakeUp); /* Initialize LCD controller without boost */ SegmentLCD_Init(false); SegmentLCD_AllOff(); /* This is a work around for Chip Rev.D Errata, Revision 0.6. */ /* Check for product revision 16 and 17 and set the offset */ /* for ADC0_TEMP_0_READ_1V25. */ prod_rev = (DEVINFO->PART & _DEVINFO_PART_PROD_REV_MASK) >> _DEVINFO_PART_PROD_REV_SHIFT; if( (prod_rev == 16) || (prod_rev == 17) ) { temp_offset = 112; } else { temp_offset = 0; } /* Enable board control interrupts */ gpioSetup(); /* Setup ADC for sampling internal temperature sensor. */ setupSensor(); /* Main loop - just read temperature and update LCD */ while (1) { /* Start one ADC sample */ ADC_Start(ADC0, adcStartSingle); /* Wait in EM1 for ADC to complete */ EMU_EnterEM1(); /* Read sensor value */ /* According to rev. D errata ADC0_TEMP_0_READ_1V25 should be decreased */ /* by the offset but it is the same if ADC reading is increased - */ /* reference manual 28.3.4.2. */ temp = ADC_DataSingleGet(ADC0) + temp_offset; /* Convert ADC sample to Fahrenheit / Celsius and print string to display */ if (showFahrenheit) { /* Show Fahrenheit on alphanumeric part of display */ i = (int)(convertToFahrenheit(temp) * 10); snprintf(string, 8, "%2d,%1d%%F", (i/10), abs(i%10)); /* Show Celsius on numeric part of display */ i = (int)(convertToCelsius(temp) * 10); SegmentLCD_Number(i*10); SegmentLCD_Symbol(LCD_SYMBOL_DP10, 1); SegmentLCD_Symbol(LCD_SYMBOL_DEGC, 1); SegmentLCD_Symbol(LCD_SYMBOL_DEGF, 0); } else { /* Show Celsius on alphanumeric part of display */ i = (int)(convertToCelsius(temp) * 10); snprintf(string, 8, "%2d,%1d%%C", (i/10), abs(i%10)); /* Show Fahrenheit on numeric part of display */ i = (int)(convertToFahrenheit(temp) * 10); SegmentLCD_Number(i*10); SegmentLCD_Symbol(LCD_SYMBOL_DP10, 1); SegmentLCD_Symbol(LCD_SYMBOL_DEGC, 0); SegmentLCD_Symbol(LCD_SYMBOL_DEGF, 1); } SegmentLCD_Write(string); /* Sleep for 2 seconds in EM 2 */ RTCDRV_StartTimer( xTimerForWakeUp, rtcdrvTimerTypeOneshot, 2000, NULL, NULL); EMU_EnterEM2(true); } }