From 895d215265683f1c8a590d6f871e7e47c9f7fa66 Mon Sep 17 00:00:00 2001 From: Ben Hitchcock Date: Thu, 4 Dec 2014 06:59:27 +0800 Subject: [PATCH] Tightening up code inside atomic block, and whitespace changes (tabs to spaces) --- src/main/drivers/pwm_output.c | 57 +++++++++++++++++------------------ src/main/drivers/pwm_rx.c | 8 ++--- src/main/drivers/timer.c | 15 ++++----- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 9d4162cb..21286cc1 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -131,7 +131,7 @@ static void pwmWriteBrushed(uint8_t index, uint16_t value) static void pwmWriteStandard(uint8_t index, uint16_t value) { - *motors[index]->ccr = value; + *motors[index]->ccr = value; } void pwmWriteMotor(uint8_t index, uint16_t value) @@ -142,28 +142,28 @@ void pwmWriteMotor(uint8_t index, uint16_t value) void pwmFinishedWritingMotors(uint8_t numberMotors) { - uint8_t index; - volatile TIM_TypeDef *lastTimerPtr = NULL; + uint8_t index; + volatile TIM_TypeDef *lastTimerPtr = NULL; - if(feature(FEATURE_ONESHOT125)){ + if(feature(FEATURE_ONESHOT125)){ - for(index = 0; index < numberMotors; index++){ + for(index = 0; index < numberMotors; index++){ - // Force the timer to overflow if it's the first motor to output, or if we change timers - if(motors[index]->tim != lastTimerPtr){ - lastTimerPtr = motors[index]->tim; + // Force the timer to overflow if it's the first motor to output, or if we change timers + if(motors[index]->tim != lastTimerPtr){ + lastTimerPtr = motors[index]->tim; - timerForceOverflow(motors[index]->tim); - } - } + timerForceOverflow(motors[index]->tim); + } + } - // Set the compare register to 0, which stops the output pulsing if the timer overflows before the main loop completes again. - // This compare register will be set to the output value on the next main loop. - for(index = 0; index < numberMotors; index++){ - *motors[index]->ccr = 0; - } - } + // Set the compare register to 0, which stops the output pulsing if the timer overflows before the main loop completes again. + // This compare register will be set to the output value on the next main loop. + for(index = 0; index < numberMotors; index++){ + *motors[index]->ccr = 0; + } + } } void pwmWriteServo(uint8_t index, uint16_t value) @@ -175,26 +175,25 @@ void pwmWriteServo(uint8_t index, uint16_t value) void pwmBrushedMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse) { - uint32_t hz = PWM_BRUSHED_TIMER_MHZ * 1000000; - motors[motorIndex] = pwmOutConfig(timerHardware, PWM_BRUSHED_TIMER_MHZ, hz / motorPwmRate, idlePulse); - motors[motorIndex]->pwmWritePtr = pwmWriteBrushed; - + uint32_t hz = PWM_BRUSHED_TIMER_MHZ * 1000000; + motors[motorIndex] = pwmOutConfig(timerHardware, PWM_BRUSHED_TIMER_MHZ, hz / motorPwmRate, idlePulse); + motors[motorIndex]->pwmWritePtr = pwmWriteBrushed; } void pwmBrushlessMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse) { - uint32_t hz = PWM_TIMER_MHZ * 1000000; + uint32_t hz = PWM_TIMER_MHZ * 1000000; - if(feature(FEATURE_ONESHOT125)){ - motors[motorIndex] = pwmOutConfig(timerHardware, ONESHOT125_TIMER_MHZ, 0xFFFF, idlePulse); - } else { - motors[motorIndex] = pwmOutConfig(timerHardware, PWM_TIMER_MHZ, hz / motorPwmRate, idlePulse); - } + if(feature(FEATURE_ONESHOT125)){ + motors[motorIndex] = pwmOutConfig(timerHardware, ONESHOT125_TIMER_MHZ, 0xFFFF, idlePulse); + } else { + motors[motorIndex] = pwmOutConfig(timerHardware, PWM_TIMER_MHZ, hz / motorPwmRate, idlePulse); + } - motors[motorIndex]->pwmWritePtr = pwmWriteStandard; + motors[motorIndex]->pwmWritePtr = pwmWriteStandard; } void pwmServoConfig(const timerHardware_t *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse) { - servos[servoIndex] = pwmOutConfig(timerHardware, PWM_TIMER_MHZ, 1000000 / servoPwmRate, servoCenterPulse); + servos[servoIndex] = pwmOutConfig(timerHardware, PWM_TIMER_MHZ, 1000000 / servoPwmRate, servoCenterPulse); } diff --git a/src/main/drivers/pwm_rx.c b/src/main/drivers/pwm_rx.c index 6aa977f3..9757e69d 100644 --- a/src/main/drivers/pwm_rx.c +++ b/src/main/drivers/pwm_rx.c @@ -161,7 +161,7 @@ static void ppmEdgeCallback(timerCCHandlerRec_t* cbRec, captureCompare_t capture ppmDev.currentTime += ppmDev.largeCounter; // Divide by 8 if Oneshot125 is active and this is a CC3D board - ppmDev.currentTime = ppmDev.currentTime >> ppmCountShift; + ppmDev.currentTime = ppmDev.currentTime >> ppmCountShift; /* Capture computation */ ppmDev.deltaTime = ppmDev.currentTime - ppmDev.previousTime; @@ -331,9 +331,9 @@ void ppmInConfig(const timerHardware_t *timerHardwarePtr) timerConfigure(timerHardwarePtr, (uint16_t)PPM_TIMER_PERIOD, PWM_TIMER_MHZ); - if((timerHardwarePtr->tim == TIM4) && (feature(FEATURE_ONESHOT125))){ - ppmCountShift = 3; // Divide by 8 if the timer is running at 8 MHz - } + if((timerHardwarePtr->tim == TIM4) && (feature(FEATURE_ONESHOT125))){ + ppmCountShift = 3; // Divide by 8 if the timer is running at 8 MHz + } timerChCCHandlerInit(&self->edgeCb, ppmEdgeCallback); diff --git a/src/main/drivers/timer.c b/src/main/drivers/timer.c index 078c925d..5e59da31 100644 --- a/src/main/drivers/timer.c +++ b/src/main/drivers/timer.c @@ -806,12 +806,13 @@ void timerStart(void) **/ void timerForceOverflow(volatile TIM_TypeDef *tim) { - ATOMIC_BLOCK(NVIC_PRIO_TIMER) { - // Save the current count so that PPM reading will work on the same timer that was forced to overflow - uint8_t timerIndex = lookupTimerIndex((const TIM_TypeDef *)tim); - timerConfig[timerIndex].forcedOverflowTimerValue = tim->CNT + 1; + uint8_t timerIndex = lookupTimerIndex((const TIM_TypeDef *)tim); - // Force an overflow by setting the UG bit - tim->EGR |= TIM_EGR_UG; - } + ATOMIC_BLOCK(NVIC_PRIO_TIMER) { + // Save the current count so that PPM reading will work on the same timer that was forced to overflow + timerConfig[timerIndex].forcedOverflowTimerValue = tim->CNT + 1; + + // Force an overflow by setting the UG bit + tim->EGR |= TIM_EGR_UG; + } } \ No newline at end of file