[tuxdroid-svn] r520 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-13 06:33:14
|
Author: jaguarondi Date: 2007-09-13 08:32:43 +0200 (Thu, 13 Sep 2007) New Revision: 520 Modified: firmware/tuxcore/trunk/hardware.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h Log: * Merged initialization of position switches, motors and interrupts in the same init function. * Cleanup. Modified: firmware/tuxcore/trunk/hardware.h =================================================================== --- firmware/tuxcore/trunk/hardware.h 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/hardware.h 2007-09-13 06:32:43 UTC (rev 520) @@ -71,13 +71,13 @@ /** Spin switch DDR. */ #define PSW_SPIN_DDR DDRD /** Flippers position switch PIN. */ -#define PSW_WINGS_PIN PINC +#define PSW_FLIPPERS_PIN PINC /** Flippers position switch PORT. */ -#define PSW_WINGS_PT PORTC +#define PSW_FLIPPERS_PT PORTC /** Flippers position switch DDR. */ -#define PSW_WINGS_DDR DDRC +#define PSW_FLIPPERS_DDR DDRC /** Flippers position switch mask. */ -#define PSW_WINGS_MK _BV(PC1) +#define PSW_FLIPPERS_MK _BV(PC1) /** Mouth position switches PIN. */ #define PSW_MOUTH_PIN PINB /** Mouth position switches PORT. */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/main.c 2007-09-13 06:32:43 UTC (rev 520) @@ -140,9 +140,8 @@ */ int main(void) { - /* I/O initialization */ - initPosSwitches(); - initMotors(); + /* Initialization */ + init_movements(); initIR(); main_tick_init(); initIO(); @@ -243,23 +242,6 @@ /* Set output for Led's */ LED_DDR |= LED_MK; - /* Enable 'Pin change interrupt 0' for mouth position switches */ - PCMSK0 = PSW_MOUTH_MK; - PCICR |= _BV(PCIE0); - - /* Enable 'Pin change interrupt 1' for wings position switch */ - PCMSK1 = PSW_WINGS_MK; - PCICR |= _BV(PCIE1); - - /* Enable 'Pin change interrupt 2' for eyes position switches */ - PCMSK2 = PSW_EYES_C_MK; - PCICR |= _BV(PCIE2); - - /* Enable 'INT1 interrupt' for spin position switch in falling edge mode - * and 'INT0 interrupt' for IR receiver in falling edge mode */ - EICRA = _BV(ISC11); // | _BV(ISC01); - EIMSK = _BV(INT1); // | _BV(INT0); - /* Enable ADC, select ADC clock = F_CPU / 128 (i.e. 16 Hz) * Single conversion mode */ @@ -355,7 +337,7 @@ cli(); led_bak = readLeds(); closeIO(); - closePosSwitches(); + powersave_movements(); stopSpin(); stop_mouth(); stop_flippers(); @@ -378,7 +360,7 @@ PRR = PRR_bak; setLeds(led_bak); /* restore leds status */ i2cCommunicationInit(); - initPosSwitches(); + init_movements(); initIO(); /* Trigger the post-sleep event */ Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/motors.c 2007-09-13 06:32:43 UTC (rev 520) @@ -101,30 +101,44 @@ * @{ */ /** \ingroup movements */ /** - \brief Initialize the position switches for normal operation. - Initialize all I/O of the position switches as input with internal pull-up. + \brief Initialize all I/O for normal movement operation. + This function sets all motor I/O as output, initializes all I/O of the + position switches as input with internal pull-up and enables all + corresponding interrupts. */ -void initPosSwitches(void) +void init_movements(void) { - PSW_WINGS_DDR &= ~PSW_WINGS_MK; - PSW_WINGS_PT |= PSW_WINGS_MK; + PSW_FLIPPERS_DDR &= ~PSW_FLIPPERS_MK; + PSW_FLIPPERS_PT |= PSW_FLIPPERS_MK; PSW_EYES_DDR &= ~PSW_EYES_MK; PSW_EYES_PT |= PSW_EYES_MK; PSW_MOUTH_DDR &= ~PSW_MOUTH_MK; PSW_MOUTH_PT |= PSW_MOUTH_MK; PSW_SPIN_DDR &= ~PSW_SPIN_MK; PSW_SPIN_PT |= PSW_SPIN_MK; + /* Enable 'Pin change interrupt 0' for the mouth position switches */ + PCMSK0 = PSW_MOUTH_MK; + PCICR |= _BV(PCIE0); + /* Enable 'Pin change interrupt 1' for the flippers position switch */ + PCMSK1 = PSW_FLIPPERS_MK; + PCICR |= _BV(PCIE1); + /* Enable 'Pin change interrupt 2' for the eyes position switches */ + PCMSK2 = PSW_EYES_C_MK; + PCICR |= _BV(PCIE2); + /* Enable 'INT1 interrupt' for the spin position switch in falling edge mode */ + EICRA |= _BV(ISC11); + EIMSK |= _BV(INT1); } /** \brief Initializes the 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. + In normal mode, all pins have internal pull-up and each switch shorts the + pin low. So in power save mode, we must set all pins as strong low. */ -void closePosSwitches(void) +void powersave_movements(void) { - PSW_WINGS_PT &= ~PSW_WINGS_MK; - PSW_WINGS_DDR |= PSW_WINGS_MK; + PSW_FLIPPERS_PT &= ~PSW_FLIPPERS_MK; + PSW_FLIPPERS_DDR |= PSW_FLIPPERS_MK; PSW_EYES_PT &= ~PSW_EYES_MK; PSW_EYES_DDR |= PSW_EYES_MK; PSW_MOUTH_PT &= ~PSW_MOUTH_MK; @@ -132,19 +146,6 @@ PSW_SPIN_PT &= ~PSW_SPIN_MK; PSW_SPIN_DDR |= PSW_SPIN_MK; } - -/** - \brief Initalizes the motors for normal operation. - This sets all motor I/O as output - */ -void initMotors(void) -{ - MOT_EYES_DDR |= MOT_EYES_MK; - MOT_MOUTH_DDR |= MOT_MOUTH_MK; - MOT_FLIPPERS_FW_DDR |= MOT_FLIPPERS_FW_MK; - MOT_FLIPPERS_BW_DDR |= MOT_FLIPPERS_BW_MK; - MOT_SPIN_DDR |= MOT_SPIN_MK; -} /*! @} */ /** @@ -546,7 +547,7 @@ } /** - \brief Wings position interrupt + \brief Flippers position interrupt This interrupt stops the flippers when the desired number of movements have been executed. In order to stop the flippers quickly and block the motor, we @@ -562,7 +563,7 @@ ISR(SIG_PIN_CHANGE1) { /* We only count when the switch is pushed, not released. */ - if (~PSW_WINGS_PIN & PSW_WINGS_MK) + if (~PSW_FLIPPERS_PIN & PSW_FLIPPERS_MK) { /* This test prevents the toggle when the flippers are pushed. The * flippers motor must be switched on (flippers_PWM <> 0) to toggle the Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/motors.h 2007-09-13 06:32:43 UTC (rev 520) @@ -82,8 +82,8 @@ /* * Module configuration */ -void initPosSwitches(void); -void closePosSwitches(void); +void init_movements(void); +void powersave_movements(void); void initMotors(void); /* |