1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 21:05:35 +03:00

Tightening up code inside atomic block, and whitespace changes (tabs to spaces)

This commit is contained in:
Ben Hitchcock 2014-12-04 06:59:27 +08:00
parent 8a9e51c779
commit 895d215265
3 changed files with 40 additions and 40 deletions

View file

@ -131,7 +131,7 @@ static void pwmWriteBrushed(uint8_t index, uint16_t value)
static void pwmWriteStandard(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) 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) void pwmFinishedWritingMotors(uint8_t numberMotors)
{ {
uint8_t index; uint8_t index;
volatile TIM_TypeDef *lastTimerPtr = NULL; 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 // Force the timer to overflow if it's the first motor to output, or if we change timers
if(motors[index]->tim != lastTimerPtr){ if(motors[index]->tim != lastTimerPtr){
lastTimerPtr = motors[index]->tim; 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. // 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. // This compare register will be set to the output value on the next main loop.
for(index = 0; index < numberMotors; index++){ for(index = 0; index < numberMotors; index++){
*motors[index]->ccr = 0; *motors[index]->ccr = 0;
} }
} }
} }
void pwmWriteServo(uint8_t index, uint16_t value) 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) void pwmBrushedMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse)
{ {
uint32_t hz = PWM_BRUSHED_TIMER_MHZ * 1000000; uint32_t hz = PWM_BRUSHED_TIMER_MHZ * 1000000;
motors[motorIndex] = pwmOutConfig(timerHardware, PWM_BRUSHED_TIMER_MHZ, hz / motorPwmRate, idlePulse); motors[motorIndex] = pwmOutConfig(timerHardware, PWM_BRUSHED_TIMER_MHZ, hz / motorPwmRate, idlePulse);
motors[motorIndex]->pwmWritePtr = pwmWriteBrushed; motors[motorIndex]->pwmWritePtr = pwmWriteBrushed;
} }
void pwmBrushlessMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse) 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)){ if(feature(FEATURE_ONESHOT125)){
motors[motorIndex] = pwmOutConfig(timerHardware, ONESHOT125_TIMER_MHZ, 0xFFFF, idlePulse); motors[motorIndex] = pwmOutConfig(timerHardware, ONESHOT125_TIMER_MHZ, 0xFFFF, idlePulse);
} else { } else {
motors[motorIndex] = pwmOutConfig(timerHardware, PWM_TIMER_MHZ, hz / motorPwmRate, idlePulse); 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) 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);
} }

View file

@ -161,7 +161,7 @@ static void ppmEdgeCallback(timerCCHandlerRec_t* cbRec, captureCompare_t capture
ppmDev.currentTime += ppmDev.largeCounter; ppmDev.currentTime += ppmDev.largeCounter;
// Divide by 8 if Oneshot125 is active and this is a CC3D board // 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 */ /* Capture computation */
ppmDev.deltaTime = ppmDev.currentTime - ppmDev.previousTime; 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); timerConfigure(timerHardwarePtr, (uint16_t)PPM_TIMER_PERIOD, PWM_TIMER_MHZ);
if((timerHardwarePtr->tim == TIM4) && (feature(FEATURE_ONESHOT125))){ if((timerHardwarePtr->tim == TIM4) && (feature(FEATURE_ONESHOT125))){
ppmCountShift = 3; // Divide by 8 if the timer is running at 8 MHz ppmCountShift = 3; // Divide by 8 if the timer is running at 8 MHz
} }
timerChCCHandlerInit(&self->edgeCb, ppmEdgeCallback); timerChCCHandlerInit(&self->edgeCb, ppmEdgeCallback);

View file

@ -806,12 +806,13 @@ void timerStart(void)
**/ **/
void timerForceOverflow(volatile TIM_TypeDef *tim) void timerForceOverflow(volatile TIM_TypeDef *tim)
{ {
ATOMIC_BLOCK(NVIC_PRIO_TIMER) { uint8_t timerIndex = lookupTimerIndex((const TIM_TypeDef *)tim);
// 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;
// Force an overflow by setting the UG bit ATOMIC_BLOCK(NVIC_PRIO_TIMER) {
tim->EGR |= TIM_EGR_UG; // 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;
}
} }