Пример #1
0
/**
 * \brief Interrupt handler for the RTC. Refresh the display.
 */
void RTC_Handler(void)
{
	uint32_t ul_status = rtc_get_status(RTC);

	/* Second increment interrupt */
	if ((ul_status & RTC_SR_SEC) == RTC_SR_SEC) {
		/* Disable RTC interrupt */
		rtc_disable_interrupt(RTC, RTC_IDR_SECDIS);

		refresh_display();

		rtc_clear_status(RTC, RTC_SCCR_SECCLR);

		rtc_enable_interrupt(RTC, RTC_IER_SECEN);
	} else {
		/* Time or date alarm */
		if ((ul_status & RTC_SR_ALARM) == RTC_SR_ALARM) {
			/* Disable RTC interrupt */
			rtc_disable_interrupt(RTC, RTC_IDR_ALRDIS);

			gs_ul_alarm_triggered = 1;
			refresh_display();
			/* Show additional menu item for clear notification */
			gs_ul_menu_shown = 0;
			rtc_clear_status(RTC, RTC_SCCR_ALRCLR);
			rtc_enable_interrupt(RTC, RTC_IER_ALREN);
		}
	}
}
Пример #2
0
void terminate(const char *s)
{
	rtc_disable_interrupt(RTC, RTC_IDR_ALRDIS);//disabilito interrupt RTC
	rtt_disable_interrupt(RTT, RTT_MR_RTTINCIEN);//disabilito interrupt RTT
	afec_disable(AFEC0);//disabilito convertitore A/D
	dacc_disable_channel(DACC_BASE, DACC_CHANNEL);//disabilito convertitore D/A
	write_record_syslog(s);
	write_record_syslog("Programma terminato!");
	close_logfile_SD(); //chiudo logfile
	f_close(&syslog_file_object); //chiudo file syslog
	dac_out=0;//azzero tensione in uscita
	ioport_set_pin_level(LED_SD_USE, IOPORT_PIN_LEVEL_HIGH); //spengo led SD_USE
	ioport_set_pin_level(LED_SYSTEM_READY, IOPORT_PIN_LEVEL_HIGH); //spengo led SD_PRESENT
	ioport_set_pin_level(LED_ERROR, IOPORT_PIN_LEVEL_LOW); //accendo led ERROR
	exit(EXIT_SUCCESS);
}
Пример #3
0
static void ui_display_disable_rtc(void)
{
	rtc_disable_interrupt(&AVR32_RTC);

	rtc_disable(&AVR32_RTC);
}
void rtc_init_counter_mode() {
	NVIC_InitTypeDef NVIC_InitStructure;
	EXTI_InitTypeDef EXTI_InitStructure;
	RTC_InitTypeDef RTC_InitStructure;
	/* Enable the PWR clock */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

	/* Allow access to RTC */
    PWR_RTCAccessCmd(ENABLE);

	  /* Reset RTC Domain */
	  RCC_RTCResetCmd(ENABLE);
	  RCC_RTCResetCmd(DISABLE);

	/* Enable the LSE OSC */
	RCC_LSEConfig(RCC_LSE_ON );

	/* Wait till LSE is ready */
	while (RCC_GetFlagStatus(RCC_FLAG_LSERDY ) == RESET) {
	}

	/* Select the RTC Clock Source */
	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE );
	/* Set the RTC time base to 1s */
	RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
	RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
	RTC_InitStructure.RTC_SynchPrediv = 0x00FF;
	RTC_Init(&RTC_InitStructure);

	/* Enable the RTC Clock */
	RCC_RTCCLKCmd(ENABLE);
	/* Wait for RTC APB registers synchronization */
	RTC_WaitForSynchro();

	/* EXTI configuration *******************************************************/
	EXTI_ClearITPendingBit(EXTI_Line20 );
	EXTI_InitStructure.EXTI_Line = EXTI_Line20;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);

	/* Enable the RTC Wakeup Interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	/* Configure the RTC WakeUp Clock source: CK_SPRE (1Hz) */
	RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits );
	RTC_SetWakeUpCounter(0x0);

	/* Enable the RTC Wakeup Interrupt */
	RTC_ITConfig(RTC_IT_WUT, ENABLE);

	rtc_disable_interrupt();
	/* Enable Wakeup Counter */
	RTC_WakeUpCmd(ENABLE);

}
int main(void)
{
	system_init();
    rtc_init_counter_mode();
    rtc_start();

	//test_fec_encoding();
	//test_fec_decoding();

	button_enable_interrupts();


	phy_init();
	phy_set_rx_callback(rx_callback);

	while(1) {
        if (INTERRUPT_BUTTON1 & interrupt_flags) {
        	interrupt_flags &= ~INTERRUPT_BUTTON1;
//        	led_toggle(1);

        	start_tx();

        	button_clear_interrupt_flag();
        	button_enable_interrupts();
        }

        if (INTERRUPT_BUTTON3 & interrupt_flags) {
			interrupt_flags &= ~INTERRUPT_BUTTON3;

			if (rtcEnabled) {
				rtcEnabled = 0;
				rtc_disable_interrupt();
			} else {
				rtcEnabled = 1;
				rtc_enable_interrupt();
			}

			button_clear_interrupt_flag();
			button_enable_interrupts();
        }

        if (INTERRUPT_RTC & interrupt_flags) {
        	interrupt_flags &= ~INTERRUPT_RTC;
        	led_toggle(0);

        	start_tx();
        }

        if (!phy_is_rx_in_progress() && !phy_is_tx_in_progress()) {
        	start_rx();
        }

        if (phy_is_rx_in_progress())
        {
        	led_on(2);
        } else {
        	led_off(2);
        }

        if (phy_is_tx_in_progress())
        {
        	led_on(3);
        } else {
        	led_off(3);
        }


//		system_lowpower_mode(4,1);
	}
	return 0;
}