[tuxdroid-svn] r516 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-12 12:58:53
|
Author: jaguarondi Date: 2007-09-12 14:58:49 +0200 (Wed, 12 Sep 2007) New Revision: 516 Modified: firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h Log: * Deleted mouth_pos as it's not going to be used. * Changed low level functions from defines to static inline and moved them to their corresponding group. * Reordered the configuration functions. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 12:39:37 UTC (rev 515) +++ firmware/tuxcore/trunk/main.c 2007-09-12 12:58:49 UTC (rev 516) @@ -187,8 +187,8 @@ if (t100ms_flag) { t100ms_flag = FALSE; - updateStatusFlag = 1; /* XXX to move */ - if (event_timer) /* XXX to move */ + updateStatusFlag = 1; + if (event_timer) { event_timer--; event_manager_flag = 1; Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 12:39:37 UTC (rev 515) +++ firmware/tuxcore/trunk/motors.c 2007-09-12 12:58:49 UTC (rev 516) @@ -55,6 +55,18 @@ * up to down and from down to up. */ #define FLIPPERS_RESETTIMER_HYST 0x10 +/** Number of periods remaining before stopping the eyes. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +static uint8_t eyes_stop_delay; +/** Number of movements remaining before stopping the flippers. */ +uint8_t eyes_move_counter; +/** Number of periods remaining before stopping the mouth. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +static uint8_t mouth_stop_delay; +/** Number of movements remaining before stopping the mouth. */ +uint8_t mouth_move_counter; /** Number of periods remaining before stopping the flippers. * Normally used when braking, to stop the motor after a short period of * inversion. */ @@ -68,18 +80,6 @@ uint8_t flippers_timer; /** Period taken by the previous movement of the flippers. */ uint8_t flippers_revious_timer; -/** Number of periods remaining before stopping the eyes. - * Normally used when braking, to stop the motor after a short period of - * inversion. */ -static uint8_t eyes_stop_delay; -/** Number of movements remaining before stopping the flippers. */ -uint8_t eyes_move_counter; -/** Number of periods remaining before stopping the mouth. - * Normally used when braking, to stop the motor after a short period of - * inversion. */ -static uint8_t mouth_stop_delay; -/** Number of movements remaining before stopping the mouth. */ -uint8_t mouth_move_counter; /** Number of periods remaining before stopping the rotation. * Normally used when braking, to stop the motor after a short period of * inversion. */ @@ -91,30 +91,88 @@ /** Spinning direction */ static uint8_t spin_direction; -uint8_t mouth_pos; /* XXX delete this */ - /** PWM mask register applied on the port on a regular basis. */ uint8_t portB_PWM_mask; /** - * \name Low level motor control - * These functions access the motor I/O port. + * \name Module configuration + * These functions initialize the motors and switches I/O ports for normal and + * sleep mode. * @{ */ -/** Stop the eyes motor. */ -#define stop_eyes_motor() {MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK);} +/** \ingroup movements */ +/** + \brief Initialize the position switches for normal operation. + Initialize all I/O of the position switches as input with internal pull-up. + */ +void initPosSwitches(void) +{ + PSW_WINGS_DDR &= ~PSW_WINGS_MK; + PSW_WINGS_PT |= PSW_WINGS_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; +} -/** Start the eyes motor. */ -#define run_eyes_motor() {(MOT_EYES_PT &= ~MOT_IEYES_MK); \ - (MOT_EYES_PT |= MOT_EYES_MK);} -/** Invert the eyes motor. */ -#define invert_eyes_motor() {(MOT_EYES_PT &= ~MOT_EYES_MK); \ - (MOT_EYES_PT |= MOT_IEYES_MK);} +/** + \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. + */ +void closePosSwitches(void) +{ + PSW_WINGS_PT &= ~PSW_WINGS_MK; + PSW_WINGS_DDR |= PSW_WINGS_MK; + PSW_EYES_PT &= ~PSW_EYES_MK; + PSW_EYES_DDR |= PSW_EYES_MK; + PSW_MOUTH_PT &= ~PSW_MOUTH_MK; + PSW_MOUTH_DDR |= PSW_MOUTH_MK; + 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_WINGS_FW_DDR |= MOT_WINGS_FW_MK; + MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; + MOT_SPIN_DDR |= MOT_SPIN_MK; +} /*! @} */ /** * \name Eyes functions * @{ */ +/** \brief Low level access to stop the eyes motor. */ +static inline void stop_eyes_motor(void) __attribute__ ((always_inline)); +void stop_eyes_motor(void) +{ + MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK); +} +/** \brief Low level access to start the eyes motor. */ +static inline void run_eyes_motor(void) __attribute__ ((always_inline)); +void run_eyes_motor(void) +{ + (MOT_EYES_PT &= ~MOT_IEYES_MK); + (MOT_EYES_PT |= MOT_EYES_MK); +} + +/** \brief Low level access to invert the eyes motor. */ +static inline void invert_eyes_motor(void) __attribute__ ((always_inline)); +void invert_eyes_motor(void) +{ + (MOT_EYES_PT &= ~MOT_EYES_MK); + (MOT_EYES_PT |= MOT_IEYES_MK); +} + /** \brief Stop the eyes \ingroup eyes @@ -264,12 +322,6 @@ /* We only count when the switch is pushed, not released. */ if (~PSW_MOUTH_PIN & PSW_MOUTH_MK) { - if (~PSW_MOUTH_PIN & PSW_MOUTH_O_MK) - if (mouth_pos == CLOSE) /* XXX can we delete this line? */ - mouth_pos = OPEN; - if (~PSW_MOUTH_PIN & PSW_MOUTH_C_MK) - if (mouth_pos == OPEN) /* XXX can we delete this line? */ - mouth_pos = CLOSE; if (mouth_move_counter) { mouth_move_counter--; @@ -378,62 +430,6 @@ } } -/* - * POSITION SWITCHES - * Init as pull-up input - */ - -void initPosSwitches(void) -{ - /* flipper switch */ - PSW_WINGS_DDR &= ~PSW_WINGS_MK; - PSW_WINGS_PT |= PSW_WINGS_MK; - /* eyes switches */ - PSW_EYES_DDR &= ~PSW_EYES_MK; - PSW_EYES_PT |= PSW_EYES_MK; - /* mouth switches */ - PSW_MOUTH_DDR &= ~PSW_MOUTH_MK; - PSW_MOUTH_PT |= PSW_MOUTH_MK; - /* spin switch */ - PSW_SPIN_DDR &= ~PSW_SPIN_MK; - 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; -} - -/* - * Set motors I/O as output - */ - -void initMotors(void) -{ - MOT_EYES_DDR |= MOT_EYES_MK; - MOT_MOUTH_DDR |= MOT_MOUTH_MK; - MOT_WINGS_FW_DDR |= MOT_WINGS_FW_MK; - MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; - MOT_SPIN_DDR |= MOT_SPIN_MK; -} - /** \brief Start waving the flippers up and down \ingroup flippers \param cnt number of movements before the flippers will stop \param pwm pwm value Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 12:39:37 UTC (rev 515) +++ firmware/tuxcore/trunk/motors.h 2007-09-12 12:58:49 UTC (rev 516) @@ -67,26 +67,27 @@ enum spin_direction { LEFT, RIGHT }; -/* counters to stop eye/mouth and flippers at timer int */ +/** \ingroup eyes */ +extern uint8_t eyes_move_counter; +/** \ingroup mouth */ +extern uint8_t mouth_move_counter; +/** \ingroup flippers */ extern uint8_t flippers_move_counter, flippers_PWM; -extern uint8_t eyes_move_counter; -extern uint8_t mouth_move_counter, mouth_pos; +/** \ingroup spin */ extern uint8_t spin_move_counter, spin_PWM; /* pwm mask registers */ extern uint8_t portB_PWM_mask; -void initMotors(void); - /* - * POSITION SWITCHES - * Init as pull-up input + * Module configuration */ void initPosSwitches(void); void closePosSwitches(void); +void initMotors(void); /* - * Basic movements + * Movements */ extern void stop_eyes(void); extern void blink_eyes(uint8_t cnt); |