/** * 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; }
/** * 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; }
int timer_set(tim_t dev, int channel, unsigned int timeout) { if (channel != 0) { /* only one channel is supported */ return -1; } if ((unsigned int)dev >= TIMER_NUMOF) { /* invalid timer */ return -1; } /* demultiplex to handle two types of hardware timers */ switch (_timer_variant(dev)) { case TIMER_PIT: return pit_set(_pit_index(dev), timeout); case TIMER_LPTMR: return lptmr_set(_lptmr_index(dev), timeout); default: return -1; } }