[tuxdroid-svn] r404 - in firmware: tuxcore/trunk tuxdefs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-06-19 16:27:57
|
Author: jaguarondi Date: 2007-06-19 18:27:52 +0200 (Tue, 19 Jun 2007) New Revision: 404 Modified: firmware/tuxcore/trunk/Makefile firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/standalone.c firmware/tuxdefs/commands.h firmware/tuxdefs/config.h Log: * Added the AVR sleep functions so that it now really enters sleep mode. The head button interrupt is used to exit from sleep. The status of the leds is saved and restored but it doesn't work all the time probably because of bug #9. I'll check this later on. * Added config.h dependency for the .eep taget in the Makefile. * The CLOSE_EYES_CMD was missing from commands.h. * Added the standalone sequences for the pre and post sleep events. Modified: firmware/tuxcore/trunk/Makefile =================================================================== --- firmware/tuxcore/trunk/Makefile 2007-06-19 11:48:44 UTC (rev 403) +++ firmware/tuxcore/trunk/Makefile 2007-06-19 16:27:52 UTC (rev 404) @@ -125,7 +125,7 @@ %.hex: %.elf avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ -%.eep: %.elf +%.eep: %.elf common/config.h avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ %.lss: %.elf Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-06-19 11:48:44 UTC (rev 403) +++ firmware/tuxcore/trunk/main.c 2007-06-19 16:27:52 UTC (rev 404) @@ -22,6 +22,7 @@ #include <avr/interrupt.h> #include <avr/io.h> #include <avr/pgmspace.h> +#include <avr/sleep.h> #include "global.h" #include "sensors.h" @@ -313,6 +314,7 @@ /* set external I/O as pull-up */ EXIO_PT |= EXIO_MK; + PCIFR = _BV(PCIE0) | _BV(PCIE1) | _BV(PCIE2); /* clear pending interrupts */ sei(); /* enable global interrupts */ } @@ -324,11 +326,12 @@ void closeIO(void) { PCICR = 0; - EICRA = 0; + EIMSK = 0; ADCSRA = 0; turnLedsOff(); turnIrOff(); } + /* * timer 2 intitialisation * @@ -414,6 +417,7 @@ uint8_t PRR_bak; /* Set power savings configuration. */ + cli(); led_bak = readLeds(); closeIO(); closePosSwitches(); @@ -421,14 +425,20 @@ stopMouth(); stopWings(); PRR_bak = PRR; - PRR = _BV(PRTTWI) | _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRADC); + PRR = _BV(PRTWI) | _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRADC); /* 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 */ - } + /* Set pin change interrupt on head button */ + PCMSK0 = SW_HD_MK; + PCIFR = _BV(PCIE0); + PCICR |= _BV(PCIE0); + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + sleep_enable(); + sei(); + sleep_cpu(); + sleep_disable(); + /* Re-configure in normal mode. */ PRR = PRR_bak; setLeds(led_bak); /* restore leds status */ @@ -438,5 +448,7 @@ /* 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 otherwise position switches signals are wrong */ + /* Wait 200ms for the pull-up to rise before next standalone behavior + * otherwise position switches signals are wrong */ + event_timer = 2; } Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-06-19 11:48:44 UTC (rev 403) +++ firmware/tuxcore/trunk/standalone.c 2007-06-19 16:27:52 UTC (rev 404) @@ -128,7 +128,7 @@ launchActions((const uint8_t *)&unplug_e); } - /* Entering sleep mode. */ + /* Before entering sleep mode. */ else if (cond_flags.sleep == COND_PRE_SLEEP) { cond_flags.sleep = COND_SLEEP; Modified: firmware/tuxdefs/commands.h =================================================================== --- firmware/tuxdefs/commands.h 2007-06-19 11:48:44 UTC (rev 403) +++ firmware/tuxdefs/commands.h 2007-06-19 16:27:52 UTC (rev 404) @@ -152,16 +152,20 @@ /* 1st parameter: number of movements before the eyes will stop */ #define STOP_EYES_CMD 0x32 /* stop the eyes motor */ #define OPEN_EYES_CMD 0x33 /* open the eyes if they are closed */ +#define CLOSE_EYES_CMD 0x38 /* open the eyes if they are closed */ + #define MOVE_MOUTH_CMD 0x41 /* move the mouth */ /* 1st parameter: number of movements before the mouth will stop */ #define OPEN_MOUTH_CMD 0x34 /* open the mouth if it is closed */ #define CLOSE_MOUTH_CMD 0x35 /* close the mouth if it is open */ #define STOP_MOUTH_CMD 0x36 /* stop the mouth motor */ + #define WAVE_WINGS_CMD 0x80 /* move the wings up and down */ /* 1st parameter: number of movements before the wings will stop */ /* 2nd parameter: pwm value between 1 (slow) and 5 (fast) */ #define STOP_WINGS_CMD 0x30 /* stop the wings motor */ #define RESET_WINGS_CMD 0x31 /* reset the wings in the low position */ + #define SPIN_LEFT_CMD 0x82 /* spin left of a given angle */ /* 1st parameter: angle to turn, the unit is approximately 1/8th of a turn */ /* 2nd parameter: pwm value between 1 (slow) and 5 (fast) */ Modified: firmware/tuxdefs/config.h =================================================================== --- firmware/tuxdefs/config.h 2007-06-19 11:48:44 UTC (rev 403) +++ firmware/tuxdefs/config.h 2007-06-19 16:27:52 UTC (rev 404) @@ -18,8 +18,9 @@ * Standalone events */ -#define SHORT_EVENT 16 -#define LONG_EVENT 31 +#define TINY_EVENT 6 +#define SHORT_EVENT 16 +#define LONG_EVENT 31 #define END_OF_ACTIONS 0xFF /* action time that indicates the end of commands */ /* Startup event */ @@ -65,6 +66,20 @@ END_OF_ACTIONS\ } +/* Entering sleep event */ +#define SLEEP_ENTER_E_SEQ {\ + 10, CLOSE_EYES_CMD, PLAY_SOUND_CMD, 1, 0, /* */\ + /* the delay (first byte) is necessary for the movement to complete before + * sleep is entered */\ + END_OF_ACTIONS\ +} + +/* Exiting sleep event */ +#define SLEEP_EXIT_E_SEQ {\ + 0, OPEN_EYES_CMD, PLAY_SOUND_CMD, 5, 0, /* */\ + END_OF_ACTIONS\ +} + /* RF connection event */ #define RF_CONN_E_SEQ {\ 0, LED_ON_CMD, 0, 0, 0, /* tun on the leds */\ |