[tuxdroid-svn] r328 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-05-30 12:36:31
|
Author: jaguarondi Date: 2007-05-30 14:36:27 +0200 (Wed, 30 May 2007) New Revision: 328 Modified: firmware/tuxcore/trunk/Makefile firmware/tuxcore/trunk/config.c firmware/tuxcore/trunk/config.h firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: - ADD: events for entering and exiting sleep mode. - ADD: closePosSwitches to minimize power during sleep mode. - ADD: closeEyes command. Modified: firmware/tuxcore/trunk/Makefile =================================================================== Modified: firmware/tuxcore/trunk/config.c =================================================================== --- firmware/tuxcore/trunk/config.c 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/config.c 2007-05-30 12:36:27 UTC (rev 328) @@ -40,6 +40,11 @@ /* Unplug event */ uint8_t unplug_e[SHORT_EVENT] EEMEM = UNPLUG_E_SEQ; +/* Entering sleep event */ +uint8_t sleep_enter_e[SHORT_EVENT] EEMEM = SLEEP_ENTER_E_SEQ; +/* Exiting sleep event */ +uint8_t sleep_exit_e[SHORT_EVENT] EEMEM = SLEEP_EXIT_E_SEQ; + /* RF connection event */ uint8_t rf_conn_e[SHORT_EVENT] EEMEM = RF_CONN_E_SEQ; Modified: firmware/tuxcore/trunk/config.h =================================================================== --- firmware/tuxcore/trunk/config.h 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/config.h 2007-05-30 12:36:27 UTC (rev 328) @@ -44,6 +44,11 @@ /* Unplug event */ extern uint8_t unplug_e[]; +/* Entering sleep event */ +extern uint8_t sleep_enter_e[]; +/* Exiting sleep event */ +extern uint8_t sleep_exit_e[]; + /* RF connection event */ extern uint8_t rf_conn_e[]; Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/global.h 2007-05-30 12:36:27 UTC (rev 328) @@ -332,6 +332,18 @@ extern uint8_t led_backup; /* + * Sleep modes + */ + +typedef enum +{ + COND_NO_SLEEP = 0, + COND_PRE_SLEEP, + COND_SLEEP, + COND_POST_SLEEP, +} sleep_modes_t; + +/* * Condition flags * * TODO merge flags by categories in bitfields or bytes and masks @@ -349,7 +361,7 @@ uint8_t unplug; uint8_t tux_recog_cnt; uint8_t tux_recog; - uint8_t sleep; + sleep_modes_t sleep; /* flags not reset by the COND_RESET_CMD */ uint8_t eyes_closed; uint8_t rf_conn; Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/main.c 2007-05-30 12:36:27 UTC (rev 328) @@ -237,8 +237,8 @@ standalone_behavior(); /* standalone behavior manager */ - /* Entering sleep mode */ - if (cond_flags.sleep) + /* Entering sleep mode. */ + if ((cond_flags.sleep == COND_SLEEP) && !event_timer) /* wait for standalone actions to be done */ sleep(); /* @@ -392,11 +392,19 @@ void sleep(void) { - turnLeftLedOff(); + /* Set power savings configuration. */ + closePosSwitches(); + + /* Sleep. */ while(SW_HD_PIN & SW_HD_MK) /* exit sleep if head is pushed */ { /* XXX Enter sleep mode here, either wakeup regularly to check the head button or better configure an interrupt on the head button to wake-up the CPU */ } - turnLeftLedOn(); - cond_flags.sleep = 0; + + /* Re-configure in normal mode. */ + initPosSwitches(); + + /* Set 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 */ } Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/motors.c 2007-05-30 12:36:27 UTC (rev 328) @@ -201,7 +201,7 @@ void initPosSwitches(void) { - /* wings switch */ + /* flipper switch */ PSW_WINGS_DDR &= ~PSW_WINGS_MK; PSW_WINGS_PT |= PSW_WINGS_MK; /* eyes switches */ @@ -215,6 +215,28 @@ PSW_SPIN_PT |= PSW_SPIN_MK; } +/* + * Set position switches for minimal power consumption. + * + * All pins have internal pull-up and the switch shorts the pin low so to avoid + * undefined states, we must set all pins as strong low. + */ +void closePosSwitches(void) +{ + /* flipper switch */ + PSW_WINGS_PT &= ~PSW_WINGS_MK; + PSW_WINGS_DDR |= PSW_WINGS_MK; + /* eyes switches */ + PSW_EYES_PT &= ~PSW_EYES_MK; + PSW_EYES_DDR |= PSW_EYES_MK; + /* mouth switches */ + PSW_MOUTH_PT &= ~PSW_MOUTH_MK; + PSW_MOUTH_DDR |= PSW_MOUTH_MK; + /* spin switch */ + PSW_SPIN_PT &= ~PSW_SPIN_MK; + PSW_SPIN_DDR |= PSW_SPIN_MK; +} + uint8_t getPosSwitches(void) { // return (PINB & PSW_MK); Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/motors.h 2007-05-30 12:36:27 UTC (rev 328) @@ -50,6 +50,7 @@ * Init as pull-up input */ void initPosSwitches(void); +void closePosSwitches(void); uint8_t getPosSwitches(void); /* Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/parser.c 2007-05-30 12:36:27 UTC (rev 328) @@ -80,6 +80,10 @@ { openEyes(); } + else if (command[0] == CLOSE_EYES_CMD) + { + closeEyes(); + } else if (command[0] == MOVE_MOUTH_CMD) { moveMouth(command[1]); @@ -178,7 +182,7 @@ for (i = 0; i < 3; i++) /* forward the command to the audio CPU */ audioIntBuf[i] = command[i]; audioIntBufIdx = 3; - cond_flags.sleep = 1; + cond_flags.sleep = COND_PRE_SLEEP; return; } Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-05-29 17:54:51 UTC (rev 327) +++ firmware/tuxcore/trunk/standalone.c 2007-05-30 12:36:27 UTC (rev 328) @@ -65,7 +65,9 @@ { while ((event_timer <= action.time) && (action.time != END_OF_ACTIONS)) { + /* Execute the pre-loaded action */ split_command_parser(action.command, MAX_COMMAND_SIZE); + /* then load the next action for execution at action.time. */ loadAction(); } event_manager_flag = 0; @@ -126,6 +128,20 @@ launchActions((const uint8_t *)&unplug_e); } + /* Entering sleep mode. */ + if (cond_flags.sleep == COND_PRE_SLEEP) + { + cond_flags.sleep = COND_SLEEP; + launchActions((const uint8_t *)&sleep_enter_e); + } + + /* Exiting sleep mode. */ + if (cond_flags.sleep == COND_POST_SLEEP) + { + launchActions((const uint8_t *)&sleep_exit_e); + cond_flags.sleep = COND_NO_SLEEP; + } + /* RF connection */ if (cond_flags.rf_conn) { |