Esempio n. 1
0
/**
 *  hibernate - LLWU is used to handle interrupts that wake. USB regulator is disabled and 3.3V output pin can only supply limited current and voltage drops to ~2.7V.
 *
 *  @param configuration SnoozeBlock class config.
 *  @param mode          |LLS|VLLS3|VLLS2|VLLS1|
 *
 *  @return wakeup source
 */
int SnoozeClass::hibernate( SnoozeBlock &configuration, SLEEP_MODE mode ) {
    SnoozeBlock *p = &configuration;
    enable_periph_irq = false;
    sleep_mode = mode;
    cmp_set( &p->cmp_mask );
    digital_set( &p->digital_mask );
    lptmr_set( &p->lptmr_mask );
#ifdef KINETISK
    rtc_alarm_set( &p->rtc_mask );
#endif
#ifdef KINETISL
    pinMode( 17, OUTPUT );
    digitalWriteFast( 17, LOW );
#endif
    tsi_set( &p->tsi_mask );
    llwu_set( &p->llwu_mask );
    enableHibernate( );
    if ( mode == LLS )        { enter_lls( ); }
    else if ( mode == VLLS3 ) { enter_vlls3( ); }
    else if ( mode == VLLS2 ) { enter_vlls2( ); }
    else if ( mode == VLLS1 ) { enter_vlls1( ); }
    else if ( mode == VLLS0 ) { enter_vlls0( ); }
    disableHibernate( );
    llwu_disable( );
    tsi_disable( &p->tsi_mask );
#ifdef KINETISK
    rtc_disable( &p->rtc_mask );
#endif
    lptmr_disable( &p->lptmr_mask );
    cmp_disable( &p->cmp_mask );
    return wakeupSource;
}
Esempio n. 2
0
static INT32S set_next_alarm(void)
{
	INT32U  temp[ALARM_MAX_NUM] = {0};
	//TIME_T  tm;
	INT8U   i,count = 0;
	INT32U  now_time;
	t_rtc   r_time;
	
	for (i=0;i<ALARM_MAX_NUM;i++) {
		if (alarm_event[i].usage) {
			temp[count] = alarm_event[i].alarm_time.tm_sec +
			          alarm_event[i].alarm_time.tm_min * 60 +
			          alarm_event[i].alarm_time.tm_hour * 3600; 
			count++;
		}
	}
	
	if (count == 0) {
		return STATUS_FAIL;
	}
	
	sort((INT32S *)temp,count);
	//cal_get_time(&tm);
	cal_rtc_time_get(&r_time);
	now_time = r_time.rtc_sec + r_time.rtc_min * 60 + r_time.rtc_hour * 3600; 
	
	for (i=0;i<count;i++) {
		if (temp[i] > now_time) {
			break;
		}
	} 
	
	if (i == count) {
		i = 0;
	}

#if 0 
	r_time.rtc_sec = tm.tm_sec;
	r_time.rtc_min = tm.tm_min;
	r_time.rtc_hour = tm.tm_hour;
	cal_rtc_time_set(&r_time);
#endif
	r_time.rtc_sec = (temp[i] % 60);
    temp[i] /= 60;
    r_time.rtc_min = (temp[i] % 60);
    temp[i] /= 60;
    r_time.rtc_hour = (temp[i] % 24);
	rtc_alarm_set(&r_time);
	
	return STATUS_OK;
	 
}
Esempio n. 3
0
/**
 *  sleep - most versatile sleep mode. SnoozeBlock configuration or any interrupt can wake the processor.
 *
 *  @param configuration SnoozeBlock class config.
 *
 *  @return wakeup source
 */
int SnoozeClass::sleep( SnoozeBlock &configuration ) { 
    SnoozeBlock *p = &configuration;
    enable_periph_irq = true;
#ifdef KINETISL
    tsi_set( &p->tsi_mask );
#endif
    cmp_set( &p->cmp_mask );
    lptmr_set( &p->lptmr_mask );
#ifdef KINETISK
    rtc_alarm_set( &p->rtc_mask );
#endif
    digital_set( &p->digital_mask );
#ifdef KINETISL
    pinMode( 17, OUTPUT );
    digitalWriteFast( 17, LOW );
#endif
    if ( mcg_mode( ) == BLPI ) {
        peripheral_disable( &p->setPeripheral.periph_off_mask );
        enter_wait( );
        peripheral_set( &p->setPeripheral.periph_off_mask );
    }
    else if ( mcg_mode( ) == BLPE ) {
        peripheral_set( &p->setPeripheral.periph_off_mask );
        blpe_blpi (   );
        enter_vlpr( 0 );// now safe to enter vlpr
        enter_wait(   );
        exit_vlpr (   );
        blpi_blpe (   );
        peripheral_set( &p->setPeripheral.periph_off_mask );
    }
    else {
        peripheral_set( &p->setPeripheral.periph_off_mask );
        usbDisable(   );
        pee_blpi  (   );
        enter_vlpr( 0 );// now safe to enter vlpr
        enter_wait(   );
        exit_vlpr (   );
        blpi_pee  (   );
        usbEnable (   );
        peripheral_set( &p->setPeripheral.periph_off_mask );
    }
    digital_disable( &p->digital_mask );
#ifdef KINETISK
    rtc_disable( &p->rtc_mask );
#endif
    lptmr_disable( &p->lptmr_mask );
    cmp_disable( &p->cmp_mask );
#ifdef KINETISL
    tsi_disable( &p->tsi_mask );
#endif
    return wakeupSource;
}