コード例 #1
0
RTC_SET_TIME(software, r, time, waitime) {
	int ret;
	rtc_lock(r, waitime, -1);
	ret = rtc_setTimeISR(r, time);
	if (ret < 0) {
		rtc_unlock(r, -1);
		return -1;
	}
	rtc_unlock(r, -1);
	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: ChuckM/libopencm3-examples
static int setup_rtc(void)
{
	/* turn on power block to enable unlocking */
	rcc_periph_clock_enable(RCC_PWR);
	pwr_disable_backup_domain_write_protect();

	/* reset rtc */
	RCC_CSR |= RCC_CSR_RTCRST;
	RCC_CSR &= ~RCC_CSR_RTCRST;

	/* We want to use the LSE fitted on the discovery board */
	rcc_osc_on(RCC_LSE);
	rcc_wait_for_osc_ready(RCC_LSE);

	/* Select the LSE as rtc clock */
	rcc_rtc_select_clock(RCC_CSR_RTCSEL_LSE);

	/* ?! Stdperiph examples don't turn this on until _afterwards_ which
	 * simply doesn't work.  It must be on at least to be able to
	 * configure it */
	RCC_CSR |= RCC_CSR_RTCEN;

	rtc_unlock();

	/* enter init mode */
	RTC_ISR |= RTC_ISR_INIT;
	while ((RTC_ISR & RTC_ISR_INITF) == 0);

	/* set synch prescaler, using defaults for 1Hz out */
	uint32_t sync = 255;
	uint32_t async = 127;
	rtc_set_prescaler(sync, async);

	/* load time and date here if desired, and hour format */

	/* exit init mode */
	RTC_ISR &= ~(RTC_ISR_INIT);

	/* and write protect again */
	rtc_lock();

	/* and finally enable the clock */
	RCC_CSR |= RCC_CSR_RTCEN;

	/* And wait for synchro.. */
	rtc_wait_for_synchro();
	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: ChuckM/libopencm3-examples
static int setup_rtc_wakeup(int period)
{
	rtc_unlock();

	/* ensure wakeup timer is off */
	RTC_CR &= ~RTC_CR_WUTE;

	/* Wait until we can write */
	while ((RTC_ISR & RTC_ISR_WUTWF) == 0);

	RTC_WUTR = period - 1;

	/* Use the 1Hz clock as source */
	RTC_CR &= ~(RTC_CR_WUCLKSEL_MASK << RTC_CR_WUCLKSEL_SHIFT);
	RTC_CR |= (RTC_CR_WUCLKSEL_SPRE << RTC_CR_WUCLKSEL_SHIFT);

	/* Restart WakeUp unit */
	RTC_CR |= RTC_CR_WUTE;

	/* interrupt configuration */

	/* also, let's have an interrupt */
	RTC_CR |= RTC_CR_WUTIE;

	/* done with rtc registers, lock them again */
	rtc_lock();

	nvic_enable_irq(NVIC_RTC_WKUP_IRQ);

	/* EXTI configuration */
	/* Configure the EXTI subsystem. */
	/* not needed, this chooses ports
	   exti_select_source(EXTI20, BUTTON_DISCO_USER_PORT);
	*/
	exti_set_trigger(EXTI20, EXTI_TRIGGER_RISING);
	exti_enable_request(EXTI20);
	return 0;
}
コード例 #4
0
ファイル: plc_rtc.c プロジェクト: nucleron/yaplc
void plc_rtc_init( tm* time )
{
    uint32_t tmp=0;
    uint32_t year;
    uint32_t i;

    rcc_periph_clock_enable( RCC_PWR );

    pwr_disable_backup_domain_write_protect();

    PLC_BKP_RTC_IS_OK = 0;

    /* LSE oscillator clock used as the RTC clock */
    RCC_BDCR |= 0x00000100;
    RCC_BDCR |= RCC_BDCR_LSEON;

    rcc_periph_clock_enable( RCC_RTC );

    rtc_unlock();

    RTC_ISR |= RTC_ISR_INIT;
    for(i=0; i<1000000; i++)
    {
        if( RTC_ISR & RTC_ISR_INITF )
        {
            break;
        }
    }

    if( !(RTC_ISR & RTC_ISR_INITF) )
    {
        plc_hw_status |= PLC_HW_ERR_LSE;

        RTC_ISR &= ~RTC_ISR_INIT;
        pwr_enable_backup_domain_write_protect();
        return;
    }

    rtc_set_prescaler( 0x1FF, 0x3F );

    tmp  =  (unsigned long)(time->tm_sec%10 );
    tmp |= ((unsigned long)(time->tm_sec/10 )) <<  4;
    tmp |= ((unsigned long)(time->tm_min%10 )) <<  8;
    tmp |= ((unsigned long)(time->tm_min/10 )) << 12;
    tmp |= ((unsigned long)(time->tm_hour%10)) << 16;
    tmp |= ((unsigned long)(time->tm_hour/10)) << 20;
    RTC_TR = tmp;

    /* Only 2 digits used!!! *time may be const, so use year var. */
    year = time->tm_year % 100;

    tmp  =  (unsigned long)(time->tm_day%10 );
    tmp |= ((unsigned long)(time->tm_day/10 )) <<  4;
    tmp |= ((unsigned long)(time->tm_mon%10 )) <<  8;
    tmp |= ((unsigned long)(time->tm_mon/10 )) << 12;
    tmp |= ((unsigned long)(year%10)) << 16;
    tmp |= ((unsigned long)(year/10)) << 20;
    RTC_DR = tmp;

    /* exit from initialization mode */
    RTC_ISR &= ~RTC_ISR_INIT;

    PLC_BKP_RTC_IS_OK = 1;

    pwr_enable_backup_domain_write_protect();
}
コード例 #5
0
ファイル: kernel.c プロジェクト: HerrSchrader/McBetty
/* Semantik: Event tasks are functions, that need to be called when a signal is set.
  In most cases the signal is set by an IRQ handler and the event task is the bottom half.
  Events therefore have a higher priority than normal tasks. Before a normal task is allowed to run,
  all pending events are handled.
  TODO priority within events is not implemented and fast recurring events are not handled here.
  TODO we could add some functions to attach/detach a handler to/from each signal
*/
static void 
handle_events(){

	if (signal_is_set(SIG_TIMER))
		timer_tick();
#if 0			
	if (signal_is_set(SIG_NEW_TIME))
		NewTimeTask();
#endif		
#if 0		
	if (signal_is_set(SIG_RTC))
		RtcTask();
#endif		
	
#if 0
	if (pending_tasks & (1<<5)){
			RTCget_busy = 0;
			RTCtest(task3_dat);
		};
#endif 
			

	if (signal_is_set(SIG_RX_PACKET)) {
		rfRcvPacket();
	};
#if 0		
		
		if (signal_is_set(SIG_NEW_PACKET)) {
		signal_clr(SIG_NEW_PACKET);
		pkt_cnt++;
		packet[packet_length] = 0;
		process_packet((char *)packet, packet_length);
	};
#endif
				
#if 0
	if (signal_is_set(SIG_TX)){
		do_tx();
	};
	
#endif

#if 0		
	if (signal_is_set(SIG_KEYSCAN)) {
		key_scan();
	};
#endif				

#if 1	
	if (signal_is_set(SIG_KEY_CHG)) {
		key_change();
	};
#endif	
#if 0
	if (signal_is_set(SIG_RTC_INT)) {
		Task30();
	};
#endif
#if 0
	if (signal_is_set(SIG_RTC_UNLOCK)) {
		rtc_unlock();
	};
#endif 
			
#if 1	
	// SIG_NONE is used, when the API needs a signal, but no handler needs to be invoked
	if (signal_is_set(SIG_NONE)) {
		signal_clr(SIG_NONE);
	};
#endif					
}