Commit from zer0 on branch b_zer0 (2007-08-20 21:08 CEST) ---------------------------------
Replace macros by static inline. aversive modules/devices/control_system/control_system_manager/control_system_manager.c 1.7.4.2 aversive modules/devices/robot/robot_system/robot_system.c 1.6.4.4 --------------------------------------------------------------------------------------- aversive/modules/devices/control_system/control_system_manager/control_system_manager.c (1.7.4.1 -> 1.7.4.2) --------------------------------------------------------------------------------------- *************** *** 15,21 **** * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ! * Revision : $Id: control_system_manager.c,v 1.7.4.1 2006-11-26 21:06:03 zer0 Exp $ * */ #include <stdio.h> --- 15,21 ---- * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ! * Revision : $Id: control_system_manager.c,v 1.7.4.2 2007-08-20 19:08:31 zer0 Exp $ * */ #include <stdio.h> *************** *** 36,55 **** * - if pointer is null, return the IN value * - else apply filter */ ! #define SAFE_FILTER( f, param, value ) ({ \ ! int32_t (*__f)(void *, int32_t); \ ! int32_t __tmp = value; \ ! void * __param ; \ ! uint8_t __flags; \ ! IRQ_LOCK(__flags); \ ! __f = f; \ ! __param = param; \ ! IRQ_UNLOCK(__flags); \ ! if ( __f ) { \ ! __tmp = __f(__param, value); \ ! } \ ! __tmp; \ ! }) /** Call a processout() pointer : * - lock the interrupts --- 36,56 ---- * - if pointer is null, return the IN value * - else apply filter */ ! static inline uint32_t ! safe_filter(int32_t (*f)(void *, int32_t), void * param, int32_t value) ! { ! int32_t (*f_tmp)(void *, int32_t); ! void * param_tmp; ! uint8_t flags; ! IRQ_LOCK(flags); ! f_tmp = f; ! param_tmp = param; ! IRQ_UNLOCK(flags); ! if (f_tmp) { ! return f_tmp(param_tmp, value); ! } ! return value; ! } /** Call a processout() pointer : * - lock the interrupts *************** *** 58,77 **** * - if pointer is null, return 0 * - else return the value processed by the function */ ! #define SAFE_GETPROCESSOUT( f, param ) ({ \ ! int32_t (*__f)(void *); \ ! int32_t __tmp = 0; \ ! void * __param ; \ ! uint8_t __flags; \ ! IRQ_LOCK(__flags); \ ! __f = f; \ ! __param = param; \ ! IRQ_UNLOCK(__flags); \ ! if ( __f ) { \ ! __tmp = __f(__param); \ ! } \ ! __tmp; \ ! }) /** Call a processin() pointer : * - lock the interrupts --- 59,79 ---- * - if pointer is null, return 0 * - else return the value processed by the function */ ! static inline uint32_t ! safe_getprocessout(int32_t (*f)(void *), void * param) ! { ! int32_t (*f_tmp)(void *); ! void * param_tmp; ! uint8_t flags; ! IRQ_LOCK(flags); ! f_tmp = f; ! param_tmp = param; ! IRQ_UNLOCK(flags); ! if (f_tmp) { ! return f_tmp(param_tmp); ! } ! return 0; ! } /** Call a processin() pointer : * - lock the interrupts *************** *** 80,97 **** * - if pointer is null, don't do anything * - else call the processin with the parameters */ ! #define SAFE_SETPROCESSIN( f, param, value ) do { \ ! void (*__f)(void *, int32_t); \ ! void * __param ; \ ! uint8_t __flags; \ ! IRQ_LOCK(__flags); \ ! __f = f; \ ! __param = param; \ ! IRQ_UNLOCK(__flags); \ ! if ( __f ) { \ ! __f(__param, value); \ ! } \ ! } while(0) /**********************************************/ --- 82,101 ---- * - if pointer is null, don't do anything * - else call the processin with the parameters */ ! static inline void ! safe_setprocessin(void (*f)(void *, int32_t), void * param, int32_t value) ! { ! void (*f_tmp)(void *, int32_t); ! void * param_tmp; ! uint8_t flags; ! IRQ_LOCK(flags); ! f_tmp = f; ! param_tmp = param; ! IRQ_UNLOCK(flags); ! if (f_tmp) { ! f_tmp(param_tmp, value); ! } ! } /**********************************************/ *************** *** 189,205 **** debug_printf("%d %ld ", i++, consign); /* if the consign filter exist */ ! cs->filtered_consign_value = consign = SAFE_FILTER(cs->consign_filter, cs->consign_filter_params, consign); debug_printf("%ld ", cs->filtered_consign_value); /* read the process out if defined */ ! process_out_value = SAFE_GETPROCESSOUT(cs->process_out, cs->process_out_params); debug_printf("%ld ", process_out_value); /* apply the feedback filter if defined */ ! process_out_value = SAFE_FILTER(cs->feedback_filter, cs->feedback_filter_params, process_out_value); debug_printf("%ld ", process_out_value); --- 193,209 ---- debug_printf("%d %ld ", i++, consign); /* if the consign filter exist */ ! cs->filtered_consign_value = consign = safe_filter(cs->consign_filter, cs->consign_filter_params, consign); debug_printf("%ld ", cs->filtered_consign_value); /* read the process out if defined */ ! process_out_value = safe_getprocessout(cs->process_out, cs->process_out_params); debug_printf("%ld ", process_out_value); /* apply the feedback filter if defined */ ! process_out_value = safe_filter(cs->feedback_filter, cs->feedback_filter_params, process_out_value); debug_printf("%ld ", process_out_value); *************** *** 209,220 **** debug_printf("%ld ", cs->error_value); /* apply the correct filter to error_value and put it into out_value */ ! cs->out_value = SAFE_FILTER(cs->correct_filter, cs->correct_filter_params, cs->error_value); debug_printf("%ld\n", cs->out_value); /* send out_value to process in*/ ! SAFE_SETPROCESSIN (cs->process_in, cs->process_in_params, cs->out_value); /* return the out value */ return (cs->out_value); --- 213,224 ---- debug_printf("%ld ", cs->error_value); /* apply the correct filter to error_value and put it into out_value */ ! cs->out_value = safe_filter(cs->correct_filter, cs->correct_filter_params, cs->error_value); debug_printf("%ld\n", cs->out_value); /* send out_value to process in*/ ! safe_setprocessin (cs->process_in, cs->process_in_params, cs->out_value); /* return the out value */ return (cs->out_value); ---------------------------------------------------------- aversive/modules/devices/robot/robot_system/robot_system.c (1.6.4.3 -> 1.6.4.4) ---------------------------------------------------------- *************** *** 15,21 **** * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ! * Revision : $Id: robot_system.c,v 1.6.4.3 2007-06-17 21:23:40 zer0 Exp $ * */ --- 15,21 ---- * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ! * Revision : $Id: robot_system.c,v 1.6.4.4 2007-08-20 19:08:31 zer0 Exp $ * */ *************** *** 45,62 **** * - if pointer is null, don't do anything * - else call the pwm with the parameters */ ! #define SAFE_SETPWM( f, param, value ) do { \ ! void (*__f)(void *, int32_t); \ ! void * __param ; \ ! uint8_t __flags; \ ! IRQ_LOCK(__flags); \ ! __f = f; \ ! __param = param; \ ! IRQ_UNLOCK(__flags); \ ! if ( __f ) { \ ! __f(__param, value); \ ! } \ ! } while(0) /** Call a encoder() pointer : * - lock the interrupts --- 45,64 ---- * - if pointer is null, don't do anything * - else call the pwm with the parameters */ ! static inline void ! safe_setpwm(void (*f)(void *, int32_t), void * param, int32_t value) ! { ! void (*f_tmp)(void *, int32_t); ! void * param_tmp; ! uint8_t flags; ! IRQ_LOCK(flags); ! f_tmp = f; ! param_tmp = param; ! IRQ_UNLOCK(flags); ! if (f_tmp) { ! f_tmp(param_tmp, value); ! } ! } /** Call a encoder() pointer : * - lock the interrupts *************** *** 65,84 **** * - if pointer is null, return 0 * - else return the value processed by the function */ ! #define SAFE_GETENCODER( f, param ) ({ \ ! int32_t (*__f)(void *); \ ! int32_t __tmp = 0; \ ! void * __param ; \ ! uint8_t __flags; \ ! IRQ_LOCK(__flags); \ ! __f = f; \ ! __param = param; \ ! IRQ_UNLOCK(__flags); \ ! if ( __f ) { \ ! __tmp = __f(__param); \ ! } \ ! __tmp; \ ! }) /** Set the structure to 0 */ void rs_init( struct robot_system * rs) --- 67,87 ---- * - if pointer is null, return 0 * - else return the value processed by the function */ ! static inline uint32_t ! safe_getencoder(int32_t (*f)(void *), void * param) ! { ! int32_t (*f_tmp)(void *); ! void * param_tmp; ! uint8_t flags; ! IRQ_LOCK(flags); ! f_tmp = f; ! param_tmp = param; ! IRQ_UNLOCK(flags); ! if (f_tmp) { ! return f_tmp(param_tmp); ! } ! return 0; ! } /** Set the structure to 0 */ void rs_init( struct robot_system * rs) *************** *** 222,229 **** p.angle = angle; rs_get_wheels_from_polar(&w, &p); ! SAFE_SETPWM(rs->left_pwm, rs->left_pwm_param, w.left); ! SAFE_SETPWM(rs->right_pwm, rs->right_pwm_param, w.right); } /** --- 225,232 ---- p.angle = angle; rs_get_wheels_from_polar(&w, &p); ! safe_setpwm(rs->left_pwm, rs->left_pwm_param, w.left); ! safe_setpwm(rs->right_pwm, rs->right_pwm_param, w.right); } /** *************** *** 245,252 **** p.distance = distance; rs_get_wheels_from_polar(&w, &p); ! SAFE_SETPWM(rs->left_pwm, rs->left_pwm_param, w.left); ! SAFE_SETPWM(rs->right_pwm, rs->right_pwm_param, w.right); } /** --- 248,255 ---- p.distance = distance; rs_get_wheels_from_polar(&w, &p); ! safe_setpwm(rs->left_pwm, rs->left_pwm_param, w.left); ! safe_setpwm(rs->right_pwm, rs->right_pwm_param, w.right); } /** *************** *** 444,454 **** double ratio; /* read encoders */ ! wext.left = SAFE_GETENCODER(rs->left_ext_encoder, rs->left_ext_encoder_param); ! wext.right = SAFE_GETENCODER(rs->right_ext_encoder, rs->right_ext_encoder_param); ! wmot.left = SAFE_GETENCODER(rs->left_mot_encoder, rs->left_mot_encoder_param); ! wmot.right = SAFE_GETENCODER(rs->right_mot_encoder, rs->right_mot_encoder_param); DEBUG(E_ROBOT_SYSTEM, "ENCODERS : %ld %ld %ld %ld", wmot.left, wmot.right, wext.left, wext.right); --- 447,457 ---- double ratio; /* read encoders */ ! wext.left = safe_getencoder(rs->left_ext_encoder, rs->left_ext_encoder_param); ! wext.right = safe_getencoder(rs->right_ext_encoder, rs->right_ext_encoder_param); ! wmot.left = safe_getencoder(rs->left_mot_encoder, rs->left_mot_encoder_param); ! wmot.right = safe_getencoder(rs->right_mot_encoder, rs->right_mot_encoder_param); DEBUG(E_ROBOT_SYSTEM, "ENCODERS : %ld %ld %ld %ld", wmot.left, wmot.right, wext.left, wext.right); _______________________________________________ Avr-list mailing list Avr-list@droids-corp.org CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive WIKI : http://wiki.droids-corp.org/index.php/Aversive DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/ BUGZILLA : http://bugzilla.droids-corp.org COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog