[tuxdroid-svn] r331 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-05-31 09:02:40
|
Author: jaguarondi Date: 2007-05-31 11:02:10 +0200 (Thu, 31 May 2007) New Revision: 331 Modified: firmware/tuxcore/trunk/main.c Log: - ADD: configure all blocks and pins to minimize power during sleep. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-05-31 07:46:46 UTC (rev 330) +++ firmware/tuxcore/trunk/main.c 2007-05-31 09:02:10 UTC (rev 331) @@ -40,7 +40,8 @@ #define DBG_STACK 0 /* stack overflow detection */ #define TEST_CHARGER 0 /* use eyes LED's to indicate charger status */ -void ioInit(void); +void initIO(void); +void closeIO(void); void timer2Init(void); void updateStatus(void); void sleep(void); @@ -201,7 +202,7 @@ initMotors(); initIR(); timer2Init(); - ioInit(); + initIO(); config_init(); /* I2C communication initialization */ @@ -278,7 +279,7 @@ * I/O initialisation * */ -void ioInit(void) +void initIO(void) { /* Set charger inhibit line as output */ CHARGER_INH_DDR |= CHARGER_INH_MK; @@ -316,6 +317,19 @@ } /* + * Close IO pins to minimize power consumption. + * + * CHARGER_INH and IR stay configured, they're just turned off. + */ +void closeIO(void) +{ + PCICR = 0; + EICRA = 0; + ADCSRA = 0; + turnLedsOff(); + turnIrOff(); +} +/* * timer 2 intitialisation * * Main tick timer every 4ms. A 8 bits software counter @@ -387,13 +401,27 @@ } /* - * Sleep functions + * Sleep function + * + * Configures all blocks and pins to minimize power, + * sleep until a wake-up condition is met, + * restore the configuration to continue normal operation. */ void sleep(void) { + uint8_t led_bak; + uint8_t PRR_bak; + /* Set power savings configuration. */ + led_bak = readLeds(); + closeIO(); closePosSwitches(); + stopSpin(); + stopMouth(); + stopWings(); + PRR_bak = PRR; + PRR = _BV(PRTTWI) | _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRADC); /* Sleep. */ while(SW_HD_PIN & SW_HD_MK) /* exit sleep if head is pushed */ @@ -402,9 +430,13 @@ } /* Re-configure in normal mode. */ + PRR = PRR_bak; + setLeds(led_bak); /* restore leds status */ + i2cCommunicationInit(); initPosSwitches(); + initIO(); - /* Set the post-sleep event */ + /* Trigger the post-sleep event */ cond_flags.sleep = COND_POST_SLEEP; - event_timer = 2; /* wait 200ms for the pull-up to rise before next standalone behavior */ + event_timer = 2; /* wait 200ms for the pull-up to rise before next standalone behavior otherwise position switches signals are wrong */ } |