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
int test_digital_pin(int pin)
{
   // Set as INPUT_PULLUP and make sure it reads as a DIGITAL_HIGH
   delayMs(1);
   digital_mode(pin, INPUT_PULLUP);
   delayMs(1);
   if (digital_get(pin) != DIGITAL_HIGH)
      return 1;
      
   // Set as INPUT_PULLDOWN and make sure it reads as a DIGITAL_LOW
   delayMs(1);
   digital_mode(pin, INPUT_PULLDOWN);
   delayMs(1);
   if (digital_get(pin) != DIGITAL_LOW)
      return 2;
      
   // Test outputting LOW then changing to input
   // and checking that the pin reads as a LOW
   digital_mode(pin, INPUT);
   delayMs(50);
   digital_mode(pin, OUTPUT);
   digital_set(pin, DIGITAL_HIGH);
   delayMs(1);
   digital_mode(pin, INPUT);
   if (digital_get(pin) != DIGITAL_HIGH)
      return 3;
      
   // Test outputting HIGH then changing to input
   // and checking that the pin reads as a HIGH
   digital_mode(pin, INPUT);
   delayMs(50);
   digital_mode(pin, OUTPUT);
   digital_set(pin, DIGITAL_LOW);
   delayMs(1);
   digital_mode(pin, INPUT);
   if (digital_get(pin) != DIGITAL_LOW)
      return 4;
      
   return 0;
}
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;
}