/******************************************************************************* * Name: powerStandby * Description: Putting microcontroller into power standby state. * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control. Turning off the ADC module is * basically removing the purpose of this low power mode. * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. bod Brown Out Detector (BOD) module disable control: * (a) BOD_OFF - Turn off BOD module * (b) BOD_ON - Leave BOD module in its default state * *******************************************************************************/ void Low_Power::power_standby(Period_t period, ADC_t adc, BOD_t bod) { if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } if (bod == BOD_OFF) { #if defined __AVR_ATmega328P__ lowPowerBodOff(SLEEP_MODE_STANDBY); #else lowPowerBodOn(SLEEP_MODE_STANDBY); #endif } else { lowPowerBodOn(SLEEP_MODE_STANDBY); } if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); }
/******************************************************************************* * Name: powerDown * Description: Putting microcontroller into power down state. This is * the lowest current consumption state. Use this together with * external pin interrupt to wake up through external event * triggering (example: RTC clockout pin, SD card detect pin). * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control. Turning off the ADC module is * basically removing the purpose of this low power mode. * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. bod Brown Out Detector (BOD) module disable control: * (a) BOD_OFF - Turn off BOD module * (b) BOD_ON - Leave BOD module in its default state * *******************************************************************************/ void LowPowerClass::powerDown(period_t period, adc_t adc, bod_t bod) { if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); if (period != SLEEP_FOREVER) { wdt_enable(period); #if defined(__AVR_ATtiny85__) WDTCR |= (1 << WDIE); #else WDTCSR |= (1 << WDIE); #endif } if (bod == BOD_OFF) { #if defined __AVR_ATmega328P__ lowPowerBodOff(SLEEP_MODE_PWR_DOWN); #else lowPowerBodOn(SLEEP_MODE_PWR_DOWN); #endif } else { lowPowerBodOn(SLEEP_MODE_PWR_DOWN); } if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); }
/******************************************************************************* * Name: powerSave * Description: Putting microcontroller into power save state. This is * the lowest current consumption state after power down. * Use this state together with an external 32.768 kHz crystal (but * 8/16 MHz crystal/resonator need to be removed) to provide an * asynchronous clock source to Timer 2. Please take note that * Timer 2 is also used by the Arduino core for PWM operation. * Please refer to wiring.c for explanation. Removal of the external * 8/16 MHz crystal/resonator requires the microcontroller to run * on its internal RC oscillator which is not so accurate for time * critical operation. * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control. Turning off the ADC module is * basically removing the purpose of this low power mode. * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. bod Brown Out Detector (BOD) module disable control: * (a) BOD_OFF - Turn off BOD module * (b) BOD_ON - Leave BOD module in its default state * * 4. timer2 Timer 2 module disable control: * (a) TIMER2_OFF - Turn off Timer 2 module * (b) TIMER2_ON - Leave Timer 2 module in its default state * *******************************************************************************/ void LowPowerClass::powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) { // Temporary clock source variable unsigned char clockSource = 0; #if !defined(__AVR_ATmega32U4__) && !defined(__AVR_ATtiny85__) if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); if (TCCR2B & CS21) clockSource |= (1 << CS21); if (TCCR2B & CS20) clockSource |= (1 << CS20); // Remove the clock source to shutdown Timer2 TCCR2B &= ~(1 << CS22); TCCR2B &= ~(1 << CS21); TCCR2B &= ~(1 << CS20); } #endif if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); if (period != SLEEP_FOREVER) { wdt_enable(period); #if defined(__AVR_ATtiny85__) WDTCR |= (1 << WDIE); #else WDTCSR |= (1 << WDIE); #endif } if (bod == BOD_OFF) { #if defined __AVR_ATmega328P__ lowPowerBodOff(SLEEP_MODE_PWR_SAVE); #else lowPowerBodOn(SLEEP_MODE_PWR_SAVE); #endif } else { lowPowerBodOn(SLEEP_MODE_PWR_SAVE); } if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); #if !defined(__AVR_ATmega32U4__) && !defined(__AVR_ATtiny85__) if (timer2 == TIMER2_OFF) { if (clockSource & CS22) TCCR2B |= (1 << CS22); if (clockSource & CS21) TCCR2B |= (1 << CS21); if (clockSource & CS20) TCCR2B |= (1 << CS20); } #endif }
/******************************************************************************* * Name: powerExtStandby * Description: Putting microcontroller into power extended standby state. This * is different from the power standby state as it has the * capability to run Timer 2 asynchronously. * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control. * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. bod Brown Out Detector (BOD) module disable control: * (a) BOD_OFF - Turn off BOD module * (b) BOD_ON - Leave BOD module in its default state * * 4. timer2 Timer 2 module disable control: * (a) TIMER2_OFF - Turn off Timer 2 module * (b) TIMER2_ON - Leave Timer 2 module in its default state * *******************************************************************************/ void Low_Power::power_ext_standby(Period_t period, ADC_t adc, BOD_t bod, Timer2_t timer2) { // Temporary clock source variable unsigned char clockSource = 0; #if !defined(__AVR_ATmega32U4__) if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); if (TCCR2B & CS21) clockSource |= (1 << CS21); if (TCCR2B & CS20) clockSource |= (1 << CS20); // Remove the clock source to shutdown Timer2 TCCR2B &= ~(1 << CS22); TCCR2B &= ~(1 << CS21); TCCR2B &= ~(1 << CS20); } #endif if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } if (bod == BOD_OFF) { #if defined __AVR_ATmega328P__ lowPowerBodOff(SLEEP_MODE_EXT_STANDBY); #else lowPowerBodOn(SLEEP_MODE_EXT_STANDBY); #endif } else { lowPowerBodOn(SLEEP_MODE_EXT_STANDBY); } if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); #if !defined(__AVR_ATmega32U4__) if (timer2 == TIMER2_OFF) { if (clockSource & CS22) TCCR2B |= (1 << CS22); if (clockSource & CS21) TCCR2B |= (1 << CS21); if (clockSource & CS20) TCCR2B |= (1 << CS20); } #endif }
void LowPowerClass::idle(period_t period, adc_t adc, timer1_t timer1, timer0_t timer0) { if (adc == ADC_OFF) { ADCSRA &= ~(1 << ADEN); power_adc_disable(); } if (timer1 == TIMER1_OFF) power_timer1_disable(); if (timer0 == TIMER0_OFF) power_timer0_disable(); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCR |= (1 << WDIE); } lowPowerBodOn(SLEEP_MODE_IDLE); if (adc == ADC_OFF) { power_adc_enable(); ADCSRA |= (1 << ADEN); } if (timer1 == TIMER1_OFF) power_timer1_enable(); if (timer0 == TIMER0_OFF) power_timer0_enable(); }
/******************************************************************************* * Name: powerSave * Description: Putting microcontroller into power save state. This is * the lowest current consumption state after power down. * Use this state together with an external 32.768 kHz crystal (but * 8/16 MHz crystal/resonator need to be removed) to provide an * asynchronous clock source to Timer 2. Please take note that * Timer 2 is also used by the Arduino core for PWM operation. * Please refer to wiring.c for explanation. Removal of the external * 8/16 MHz crystal/resonator requires the microcontroller to run * on its internal RC oscillator which is not so accurate for time * critical operation. * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control. Turning off the ADC module is * basically removing the purpose of this low power mode. * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. bod Brown Out Detector (BOD) module disable control: * (a) BOD_OFF - Turn off BOD module * (b) BOD_ON - Leave BOD module in its default state * * 4. timer2 Timer 2 module disable control: * (a) TIMER2_OFF - Turn off Timer 2 module * (b) TIMER2_ON - Leave Timer 2 module in its default state * *******************************************************************************/ void LowPowerClass::powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) { // Temporary clock source variable unsigned char clockSource = 0; if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); if (TCCR2B & CS21) clockSource |= (1 << CS21); if (TCCR2B & CS20) clockSource |= (1 << CS20); // Remove the clock source to shutdown Timer2 TCCR2B &= ~(1 << CS22); TCCR2B &= ~(1 << CS21); TCCR2B &= ~(1 << CS20); } if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } if (bod == BOD_OFF) { lowPowerBodOff(SLEEP_MODE_PWR_SAVE); } else { lowPowerBodOn(SLEEP_MODE_PWR_SAVE); } if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); if (timer2 == TIMER2_OFF) { if (clockSource & CS22) TCCR2B |= (1 << CS22); if (clockSource & CS21) TCCR2B |= (1 << CS21); if (clockSource & CS20) TCCR2B |= (1 << CS20); } }
void Low_Power::idle(Period_t period, ADC_t adc, Timer4_t timer4, Timer3_t timer3, Timer1_t timer1, Timer0_t timer0, SPI_t spi, USART1_t usart1, TWI_t twi, usb_t usb) { if (adc == ADC_OFF) { ADCSRA &= ~(1 << ADEN); power_adc_disable(); } if (timer4 == TIMER4_OFF) power_timer4_disable(); if (timer3 == TIMER3_OFF) power_timer3_disable(); if (timer1 == TIMER1_OFF) power_timer1_disable(); if (timer0 == TIMER0_OFF) power_timer0_disable(); if (spi == SPI_OFF) power_spi_disable(); if (usart1 == USART1_OFF) power_usart1_disable(); if (twi == TWI_OFF) power_twi_disable(); if (usb == USB_OFF) power_usb_disable(); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } lowPowerBodOn(SLEEP_MODE_IDLE); if (adc == ADC_OFF) { power_adc_enable(); ADCSRA |= (1 << ADEN); } if (timer4 == TIMER4_OFF) power_timer4_enable(); if (timer3 == TIMER3_OFF) power_timer3_enable(); if (timer1 == TIMER1_OFF) power_timer1_enable(); if (timer0 == TIMER0_OFF) power_timer0_enable(); if (spi == SPI_OFF) power_spi_enable(); if (usart1 == USART1_OFF) power_usart1_enable(); if (twi == TWI_OFF) power_twi_enable(); if (usb == USB_OFF) power_usb_enable(); }
/******************************************************************************* * Name: adcNoiseReduction * Description: Putting microcontroller into ADC noise reduction state. This is * a very useful state when using the ADC to achieve best and low * noise signal. * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control. Turning off the ADC module is * basically removing the purpose of this low power mode. * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. timer2 Timer 2 module disable control: * (a) TIMER2_OFF - Turn off Timer 2 module * (b) TIMER2_ON - Leave Timer 2 module in its default state * *******************************************************************************/ void Low_Power::adc_noise_reduction(Period_t period, ADC_t adc, Timer2_t timer2) { // Temporary clock source variable unsigned char clockSource = 0; #if !defined(__AVR_ATmega32U4__) if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); if (TCCR2B & CS21) clockSource |= (1 << CS21); if (TCCR2B & CS20) clockSource |= (1 << CS20); // Remove the clock source to shutdown Timer2 TCCR2B &= ~(1 << CS22); TCCR2B &= ~(1 << CS21); TCCR2B &= ~(1 << CS20); } #endif if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } lowPowerBodOn(SLEEP_MODE_ADC); if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); #if !defined(__AVR_ATmega32U4__) if (timer2 == TIMER2_OFF) { if (clockSource & CS22) TCCR2B |= (1 << CS22); if (clockSource & CS21) TCCR2B |= (1 << CS21); if (clockSource & CS20) TCCR2B |= (1 << CS20); } #endif }
/******************************************************************************* * Name: powerDown * Description: Putting microcontroller into power down state. This is * the lowest current consumption state. Use this together with * external pin interrupt to wake up through external event * triggering (example: RTC clockout pin, SD card detect pin). * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control. Turning off the ADC module is * basically removing the purpose of this low power mode. * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. bod Brown Out Detector (BOD) module disable control: * (a) BOD_OFF - Turn off BOD module * (b) BOD_ON - Leave BOD module in its default state * *******************************************************************************/ void LowPowerClass::powerDown(period_t period, adc_t adc, bod_t bod) { if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } if (bod == BOD_OFF) { lowPowerBodOff(SLEEP_MODE_PWR_DOWN); } else { lowPowerBodOn(SLEEP_MODE_PWR_DOWN); } if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); }
void Low_Power::idle(Period_t period, ADC_t adc, Timer5_t timer5, Timer4_t timer4, Timer3_t timer3, Timer2_t timer2, Timer1_t timer1, Timer0_t timer0, SPI_t spi, USART3_t usart3, USART2_t usart2, USART1_t usart1, USART0_t usart0, TWI_t twi) { // Temporary clock source variable unsigned char clockSource = 0; if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); if (TCCR2B & CS21) clockSource |= (1 << CS21); if (TCCR2B & CS20) clockSource |= (1 << CS20); // Remove the clock source to shutdown Timer2 TCCR2B &= ~(1 << CS22); TCCR2B &= ~(1 << CS21); TCCR2B &= ~(1 << CS20); power_timer2_disable(); } if (adc == ADC_OFF) { ADCSRA &= ~(1 << ADEN); power_adc_disable(); } if (timer5 == TIMER5_OFF) power_timer5_disable(); if (timer4 == TIMER4_OFF) power_timer4_disable(); if (timer3 == TIMER3_OFF) power_timer3_disable(); if (timer1 == TIMER1_OFF) power_timer1_disable(); if (timer0 == TIMER0_OFF) power_timer0_disable(); if (spi == SPI_OFF) power_spi_disable(); if (usart3 == USART3_OFF) power_usart3_disable(); if (usart2 == USART2_OFF) power_usart2_disable(); if (usart1 == USART1_OFF) power_usart1_disable(); if (usart0 == USART0_OFF) power_usart0_disable(); if (twi == TWI_OFF) power_twi_disable(); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } lowPowerBodOn(SLEEP_MODE_IDLE); if (adc == ADC_OFF) { power_adc_enable(); ADCSRA |= (1 << ADEN); } if (timer2 == TIMER2_OFF) { if (clockSource & CS22) TCCR2B |= (1 << CS22); if (clockSource & CS21) TCCR2B |= (1 << CS21); if (clockSource & CS20) TCCR2B |= (1 << CS20); power_timer2_enable(); } if (timer5 == TIMER5_OFF) power_timer5_enable(); if (timer4 == TIMER4_OFF) power_timer4_enable(); if (timer3 == TIMER3_OFF) power_timer3_enable(); if (timer1 == TIMER1_OFF) power_timer1_enable(); if (timer0 == TIMER0_OFF) power_timer0_enable(); if (spi == SPI_OFF) power_spi_enable(); if (usart3 == USART3_OFF) power_usart3_enable(); if (usart2 == USART2_OFF) power_usart2_enable(); if (usart1 == USART1_OFF) power_usart1_enable(); if (usart0 == USART0_OFF) power_usart0_enable(); if (twi == TWI_OFF) power_twi_enable(); }
/******************************************************************************* * Name: idle * Description: Putting microcontroller into idle state. Please make sure you * understand the implication and result of disabling module. * * Argument Description * ========= =========== * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake * up resource: * (a) SLEEP_15MS - 15 ms sleep * (b) SLEEP_30MS - 30 ms sleep * (c) SLEEP_60MS - 60 ms sleep * (d) SLEEP_120MS - 120 ms sleep * (e) SLEEP_250MS - 250 ms sleep * (f) SLEEP_500MS - 500 ms sleep * (g) SLEEP_1S - 1 s sleep * (h) SLEEP_2S - 2 s sleep * (i) SLEEP_4S - 4 s sleep * (j) SLEEP_8S - 8 s sleep * (k) SLEEP_FOREVER - Sleep without waking up through WDT * * 2. adc ADC module disable control: * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 3. timer2 Timer 2 module disable control: * (a) TIMER2_OFF - Turn off Timer 2 module * (b) TIMER2_ON - Leave Timer 2 module in its default state * * 4. timer1 Timer 1 module disable control: * (a) TIMER1_OFF - Turn off Timer 1 module * (b) TIMER1_ON - Leave Timer 1 module in its default state * * 5. timer0 Timer 0 module disable control: * (a) TIMER0_OFF - Turn off Timer 0 module * (b) TIMER0_ON - Leave Timer 0 module in its default state * * 6. spi SPI module disable control: * (a) ADC_OFF - Turn off ADC module * (b) ADC_ON - Leave ADC module in its default state * * 7. usart0 USART0 module disable control: * (a) USART0_OFF - Turn off USART0 module * (b) USART0_ON - Leave USART0 module in its default state * * 8. twi TWI module disable control: * (a) TWI_OFF - Turn off TWI module * (b) TWI_ON - Leave TWI module in its default state * *******************************************************************************/ void LowPowerClass::idle(period_t period, adc_t adc, timer2_t timer2, timer1_t timer1, timer0_t timer0, spi_t spi, usart0_t usart0, twi_t twi) { // Temporary clock source variable unsigned char clockSource = 0; if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); if (TCCR2B & CS21) clockSource |= (1 << CS21); if (TCCR2B & CS20) clockSource |= (1 << CS20); // Remove the clock source to shutdown Timer2 TCCR2B &= ~(1 << CS22); TCCR2B &= ~(1 << CS21); TCCR2B &= ~(1 << CS20); power_timer2_disable(); } if (adc == ADC_OFF) { ADCSRA &= ~(1 << ADEN); power_adc_disable(); } if (timer1 == TIMER1_OFF) power_timer1_disable(); if (timer0 == TIMER0_OFF) power_timer0_disable(); if (spi == SPI_OFF) power_spi_disable(); if (usart0 == USART0_OFF) power_usart0_disable(); if (twi == TWI_OFF) power_twi_disable(); if (period != SLEEP_FOREVER) { wdt_enable(period); WDTCSR |= (1 << WDIE); } lowPowerBodOn(SLEEP_MODE_IDLE); if (adc == ADC_OFF) { power_adc_enable(); ADCSRA |= (1 << ADEN); } if (timer2 == TIMER2_OFF) { if (clockSource & CS22) TCCR2B |= (1 << CS22); if (clockSource & CS21) TCCR2B |= (1 << CS21); if (clockSource & CS20) TCCR2B |= (1 << CS20); power_timer2_enable(); } if (timer1 == TIMER1_OFF) power_timer1_enable(); if (timer0 == TIMER0_OFF) power_timer0_enable(); if (spi == SPI_OFF) power_spi_enable(); if (usart0 == USART0_OFF) power_usart0_enable(); if (twi == TWI_OFF) power_twi_enable(); }