From: asterix Date: Fri, 6 Jun 2008 14:02:37 +0000 (+0000) Subject: Use log module. Reformat. X-Git-Tag: 2.0.0~508 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=57b276690a570cd37b2f2448249e1558cafbd369;p=bertos.git Use log module. Reformat. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1426 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/cfg_stepper.h b/bertos/cfg/cfg_stepper.h index b884bfc3..1efeef26 100644 --- a/bertos/cfg/cfg_stepper.h +++ b/bertos/cfg/cfg_stepper.h @@ -40,11 +40,28 @@ #ifndef CFG_STEPPER_H #define CFG_STEPPER_H +/** + * Logging level definition. + * + * Use 0 to log only the error messages + * Use 1 to log the error and warning messages + * Use 2 to log all messages + */ +#define STEPPER_LOG_LEVEL 2 + +/** + * Set logging verbosity. + * + * If verbosity is zero print short log messages. + */ +#define STEPPER_LOG_VERBOSITY 0 + + /// Max number of the stepper motor. -#define CONFIG_NUM_STEPPER_MOTORS 1 +#define CONFIG_NUM_STEPPER_MOTORS 6 /// Max number of the timer usable on target to drive stepper motor. -#define CONFIG_TC_STEPPER_MAX_NUM 6 +#define CONFIG_TC_STEPPER_MAX_NUM 6 #endif /* CFG_STEPPER_H */ diff --git a/bertos/drv/stepper.c b/bertos/drv/stepper.c index 3e4fc7b9..57ac7fc4 100644 --- a/bertos/drv/stepper.c +++ b/bertos/drv/stepper.c @@ -24,6 +24,11 @@ #include "cfg/cfg_stepper.h" #include +// Define logging setting (for cfg/log.h module). +#define LOG_LEVEL STEPPER_LOG_LEVEL +#define LOG_VERBOSITY STEPPER_LOG_VERBOSITY +#include + #include #include @@ -131,10 +136,8 @@ INLINE void FAST_FUNC stepper_schedule_irq(struct Stepper* motor, stepper_time_t static void stepper_accel(struct Stepper *motor) { -#ifdef _DEBUG - uint16_t old_val = motor->rampValue; - uint32_t old_clock = motor->rampClock; -#endif + DB(uint16_t old_val = motor->rampValue;) + DB(uint32_t old_clock = motor->rampClock;) const struct Ramp *ramp = &motor->cfg->ramp; @@ -144,13 +147,12 @@ static void stepper_accel(struct Stepper *motor) motor->rampClock += motor->rampValue; motor->rampStep++; -#ifdef _DEBUG - if (old_val && motor->rampValue > old_val) + DB(if (old_val && motor->rampValue > old_val) { - kprintf("Runtime ramp error: (max=%x, min=%x)\n", ramp->clocksMaxWL, ramp->clocksMinWL); - kprintf(" %04x @ %lu --> %04x @ %lu\n", old_val, old_clock, motor->rampValue, motor->rampClock); - } -#endif + LOG_ERR("Runtime ramp error: (max=%x, min=%x)\n", ramp->clocksMaxWL, ramp->clocksMinWL); + LOG_ERR(" %04x @ %lu --> %04x @ %lu\n", old_val, old_clock, motor->rampValue, motor->rampClock); + }) + } static void stepper_decel(struct Stepper *motor) @@ -269,7 +271,7 @@ static void stepper_checkLevelSensor(struct Stepper* motor) // record current position, disable check and stop motor motor->stepsDeaf = DEAFSTEPS_DEFAULT; motor->stepsLevel = motor->step; -// motor->stepToReach = motor->step + motor->rampStep * motor->dir; + //motor->stepToReach = motor->step + motor->rampStep * motor->dir; motor->stepToReach = motor->step; motor->rampClock = motor->cfg->ramp.clocksMaxWL; @@ -305,11 +307,11 @@ static enum StepperState FAST_FUNC FSM_run(struct Stepper *motor) if (distance == 0) // Position reached - stop motor - // motor->speed = SPEED_STOPPED; + //motor->speed = SPEED_STOPPED; motor->rampStep = -1; - // motor->rampClock = motor->ramp->clocksMaxWL; - // motor->rampValue = 0; - // motor->rampClock = motor->rampValue = motor->ramp->clocksMaxWL; + //motor->rampClock = motor->ramp->clocksMaxWL; + //motor->rampValue = 0; + //motor->rampClock = motor->rampValue = motor->ramp->clocksMaxWL; else if (distance <= motor->rampStep) stepper_decel(motor); @@ -500,7 +502,7 @@ static enum StepperState FSM_init(struct Stepper* motor) * That will be our absolute zero. */ - motor->step = motor->cfg->stepsInHome - 1; // start counting down steps in home + motor->step = motor->cfg->stepsInHome - 1; // start counting down steps in home motor->stepToReach = 0; stepper_schedule_irq(motor, motor->cfg->clocksHome, true); @@ -510,7 +512,7 @@ static enum StepperState FSM_init(struct Stepper* motor) static enum StepperState FSM_entering(struct Stepper* motor) { // We must be in home -// ASSERT(stepper_readHome(motor)); + //ASSERT(stepper_readHome(motor)); // if while entering the sensor we are no more in home we reset the steps // counter (optical sensor) @@ -557,7 +559,7 @@ static enum StepperState FSM_outhome(struct Stepper* motor) // We must be out of home: once we are no more in home // we just need to move away, even if not very precide (optical sensor) - // ASSERT(!stepper_readHome(motor)); + // ASSERT(!stepper_readHome(motor)); if(motor->step >= motor->cfg->stepsOutHome) { @@ -783,7 +785,7 @@ int16_t stepper_get_stepCircular(struct Stepper *motor) return motor->stepCircular; } -int16_t stepper_scaleSteps(struct Stepper *motor, int16_t dir) +int16_t stepper_scaleSteps(struct Stepper *motor, int16_t dir) { int16_t steps; @@ -808,14 +810,14 @@ int16_t stepper_scaleSteps(struct Stepper *motor, int16_t dir) static void stepper_enableCheckHome(struct Stepper *motor, bool bDirPositive) { - enum MotorHomeSensorCheck value = MOTOR_HOMESENSOR_NOCHECK; // default + enum MotorHomeSensorCheck value = MOTOR_HOMESENSOR_NOCHECK; // default motor->stepsTollMin = 0; - if( (motor->stepToReach != STEPS_INFINITE_POSITIVE) && + if((motor->stepToReach != STEPS_INFINITE_POSITIVE) && (motor->stepToReach != STEPS_INFINITE_NEGATIVE) ) { - if(bDirPositive) // else if(motor->dir == DIR_POSITIVE) + if(bDirPositive) // else if(motor->dir == DIR_POSITIVE) { /* if the direction is positive (movement from 0 position), * if the starting position is inside home and the target position @@ -857,8 +859,8 @@ static void stepper_enableCheckHome(struct Stepper *motor, bool bDirPositive) /** * Move motor to absolute position at specified speed * - * \arg steps position to reach in steps - * \arg speed speed in timer ticks (use TIME2CLOCKS() to convert) + * \arg steps position to reach in steps + * \arg speed speed in timer ticks (use TIME2CLOCKS() to convert) */ int16_t stepper_move(struct Stepper *motor, int16_t steps, uint16_t speed, int16_t deafstep) {