int up_rtc_initialize(void) { int ret; rtc_dumpregs("On reset"); /* Attach the RTC interrupt handler */ #ifdef CONFIG_RTC_ALARM ret = irq_attach(LPC17_IRQ_RTC, rtc_interrupt); if (ret == OK) { up_enable_irq(LPC17_IRQ_RTC); } #endif /* CONFIG_RTC_ALARM */ /* Perform the one-time setup of the RTC */ ret = rtc_setup(); /* Configure RTC interrupt to catch alarm interrupts. All RTC interrupts are * connected to the EXTI controller. To enable the RTC Alarm interrupt, the * following sequence is required: * * 1. Configure and enable the EXTI Line 17 in interrupt mode and select the * rising edge sensitivity. * 2. Configure and enable the RTC_Alarm IRQ channel in the NVIC. * 3. Configure the RTC to generate RTC alarms (Alarm A or Alarm B). */ g_rtc_enabled = true; rtc_dumpregs("After Initialization"); return OK; }
/****************************************************************************** * @brief Main function *****************************************************************************/ int main(void) { /* Initialize chip */ CHIP_Init(); /* Enable code view */ setupSWO(); /* Initialize LCD */ SegmentLCD_Init(false); /* Enable the HFPER clock */ CMU_ClockEnable(cmuClock_HFPER, true); /* Configure RTC and GPIO */ rtc_setup(); gpio_setup(); /* Stay in this loop forever */ while (1) { /* Wait for Push Button 1 to be pressed */ while (GPIO_PinInGet(PB0_PORT, PB0_PIN)) ; /* and released, so that we do not exit the while loop below immediately */ while (!GPIO_PinInGet(PB0_PORT, PB0_PIN)) ; /* Reset time */ time = 0; /* Disable LCD */ LCD_Enable(true); /* Update time until Push Button 1 is pressed again */ while (1) { if (RTC_CounterGet() == 0) { SegmentLCD_Number(++time); } if (!GPIO_PinInGet(PB0_PORT, PB0_PIN)) break; } /* Delay while showing the result on the LCD */ for (uint32_t delay = 0; delay < 30; delay++) { /* Wait for the RTC to overflow once */ while (RTC_CounterGet() != 0) ; while (RTC_CounterGet() == 0) ; } /* Disable LCD */ LCD_Enable(false); } }
int main(void) { rtc_setup(); board_setup(); mch_net_init(); testapp_init(); while (1) { mch_net_poll(); sys_check_timeouts(); } }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // disable WDT BCSCTL1 = CALBC1_16MHZ; // 16MHz clock DCOCTL = CALDCO_16MHZ; init_cal(); Setup_PWM_Timers(); TOUCH_SETUP(); rtc_setup(); Setup_LCD(); reset_idle_timer(); OVEN_SETUP; OVEN_OFF; Start_OS(); // while(1); }
void setup() { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); WWDG_DeInit(); time_setup(); debug_setup(); rtc_setup(); spi_setup(); sdcard_setupGpio(); cc3000_setupGpio(); button_setup(); if (!sdcard_setup()) { printf("Failed to setup SDCard\n"); } else { if (!sdcard_fat_setup()) { printf("Failed to setup SDCard Fat\n"); } } if (config_read()) { printf("read config success\n"); } else { printf("read config FAILED\n"); while (1); } network_setup(); uint32_t ntpTime = ntp_getTime(); printf("ntp time %lu\n", ntpTime); if (ntpTime > 0) { rtc_setTime(ntpTime); } }
int main(void) { uint16_t counter; char c; uint8_t stop = TRUE; usart_init(); sonar_init(); rtc_setup(); counter = 0; usart_resume(0); strcpy_P(usart->tx0_buffer, PSTR("\nTsunami Simulator ")); strcat_P(usart->tx0_buffer, PSTR(GITREL)); strcat_P(usart->tx0_buffer, PSTR("\n\nConnected!\n")); usart_printstr(0, NULL); rtc_start(); while (1) { /* Restart the counter */ rtc_clear(); c = usart_getchar(0, FALSE); switch (c) { case '0': stop = TRUE; break; case '1': stop = FALSE; break; default: break; } if (stop) { /* stop the code */ while(usart_getchar(0, FALSE) != '1'); stop = FALSE; rtc_clear(); } /* send the trigger */ sonar_trigger(); /* clear all the data */ sonar_clear(); /* * Wait 40mS maximum and collect all the * data during the period. */ while (rtc_us < 4000) sonar_set(); /* * speed = ((i * SCALEuS)/1000000) * 340 / 2 * where: * i * SCALEuS is the duration in uS of the signal. * (i * SCALEuS)/1000000 is the same in seconds. * 340 is the speed of the sound and * /2 we need only half of the way. * The simplyfied formula in cm. * 340 mm/msec = 34cm/msec = 0.029 msec/cm = 29 uS/cm * dist (cm) = T (uS) / 29 /2. */ usart->tx0_buffer = utoa(counter, usart->tx0_buffer, 10); usart_printstr(0, NULL); usart_printstr(0, " "); counter++; sonar_print(); /* if the counter has already reach 50mS, * then this cycle takes too long. */ if (rtc_us > 5000) usart_printstr(0, "Warning! Time overrun.\n"); /* Wait up to 50mS before restart */ while (rtc_us < 5000); } return(0); }
/**************************************************************************//** * @brief RTC Setup * Produce an interrupt every second *****************************************************************************/ void rtc_setup(void) { /* Starting LFXO and waiting until it is stable */ CMU_OscillatorEnable(cmuOsc_LFXO, true, true); /* Routing the LFXO clock to the RTC */ CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO); CMU_ClockEnable(cmuClock_RTC, true); /* Enabling clock to the interface of the low energy modules */ CMU_ClockEnable(cmuClock_CORELE, true); const RTC_Init_TypeDef rtcInit = { .enable = true, .debugRun = false, .comp0Top = true, }; RTC_Init(&rtcInit); /* Produce interrupt every second */ RTC_CompareSet(0, 32768); /* Enable interrupt for compare register 0 */ RTC_IntEnable(RTC_IFC_COMP0); /* Enabling interrupt from RTC */ NVIC_EnableIRQ(RTC_IRQn); } /**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { /* Initialize chip */ CHIP_Init(); /* Enable code view */ setupSWO(); /* Configure peripherals */ rtc_setup(); BSP_LedsInit(); while (1) { switch (STATE) { case EM0: break; case EM1: EMU_EnterEM1(); break; case EM2: EMU_EnterEM2(true); break; } } }