From 709cd9f8df5d6ddd84ddb2c1b0df6cc6a5fd4433 Mon Sep 17 00:00:00 2001 From: Hydra Date: Sat, 18 Mar 2017 17:31:54 +0000 Subject: [PATCH] CF/BF - reduce code size by changing dependencies in battery.c and removing two functions from fc_tasks.c I don't like the dependency changes, but I'm not overly concerned by them. --- src/main/fc/fc_tasks.c | 17 ++--------------- src/main/sensors/battery.c | 14 +++++++++++--- src/main/sensors/battery.h | 5 +++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 6f185a796..4ceb6a555 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -109,19 +109,6 @@ static void taskHandleSerial(timeUs_t currentTimeUs) mspSerialProcess(ARMING_FLAG(ARMED) ? MSP_SKIP_NON_MSP_DATA : MSP_EVALUATE_NON_MSP_DATA, mspFcProcessCommand); } - -void taskBatteryVoltage(timeUs_t currentTimeUs) -{ - UNUSED(currentTimeUs); - batteryUpdateVoltage(); -} - -void taskBatteryCurrent(timeUs_t currentTimeUs) -{ - UNUSED(currentTimeUs); - batteryUpdateCurrentMeter(getTaskDeltaTime(TASK_SELF), ARMING_FLAG(ARMED)); -} - void taskBatteryAlerts(timeUs_t currentTimeUs) { UNUSED(currentTimeUs); @@ -381,13 +368,13 @@ cfTask_t cfTasks[TASK_COUNT] = { [TASK_BATTERY_VOLTAGE] = { .taskName = "BATTERY_VOLTAGE", - .taskFunc = taskBatteryVoltage, + .taskFunc = batteryUpdateVoltage, .desiredPeriod = TASK_PERIOD_HZ(50), .staticPriority = TASK_PRIORITY_MEDIUM, }, [TASK_BATTERY_CURRENT] = { .taskName = "BATTERY_CURRENT", - .taskFunc = taskBatteryCurrent, + .taskFunc = batteryUpdateCurrentMeter, .desiredPeriod = TASK_PERIOD_HZ(50), .staticPriority = TASK_PRIORITY_MEDIUM, }, diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index b27025693..0b056a7ca 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -26,6 +26,8 @@ #include "common/maths.h" #include "common/utils.h" +#include "scheduler/scheduler.h" + #include "config/feature.h" #include "config/parameter_group.h" #include "config/parameter_group_ids.h" @@ -33,6 +35,7 @@ #include "drivers/adc.h" #include "drivers/system.h" +#include "fc/runtime_config.h" #include "fc/config.h" #include "fc/rc_controls.h" @@ -102,8 +105,10 @@ PG_RESET_TEMPLATE(batteryConfig_t, batteryConfig, .vbathysteresis = 1 ); -void batteryUpdateVoltage(void) +void batteryUpdateVoltage(timeUs_t currentTimeUs) { + UNUSED(currentTimeUs); + switch(batteryConfig()->voltageMeterSource) { #ifdef USE_ESC_SENSOR case VOLTAGE_METER_ESC: @@ -315,13 +320,16 @@ static void batteryUpdateConsumptionState(void) } } -void batteryUpdateCurrentMeter(int32_t lastUpdateAt, bool armed) +void batteryUpdateCurrentMeter(timeUs_t currentTimeUs) { + UNUSED(currentTimeUs); if (batteryCellCount == 0) { currentMeterReset(¤tMeter); return; } + int32_t lastUpdateAt = getTaskDeltaTime(TASK_SELF); + switch(batteryConfig()->currentMeterSource) { case CURRENT_METER_ADC: currentMeterADCRefresh(lastUpdateAt); @@ -333,7 +341,7 @@ void batteryUpdateCurrentMeter(int32_t lastUpdateAt, bool armed) bool throttleLowAndMotorStop = (throttleStatus == THROTTLE_LOW && feature(FEATURE_MOTOR_STOP)); int32_t throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000; - currentMeterVirtualRefresh(lastUpdateAt, armed, throttleLowAndMotorStop, throttleOffset); + currentMeterVirtualRefresh(lastUpdateAt, ARMING_FLAG(ARMED), throttleLowAndMotorStop, throttleOffset); currentMeterVirtualRead(¤tMeter); break; } diff --git a/src/main/sensors/battery.h b/src/main/sensors/battery.h index 20d317fed..799e5318c 100644 --- a/src/main/sensors/battery.h +++ b/src/main/sensors/battery.h @@ -20,6 +20,7 @@ #include "config/parameter_group.h" #include "common/filter.h" +#include "common/time.h" #include "sensors/current.h" #include "sensors/voltage.h" @@ -53,7 +54,7 @@ typedef enum { } batteryState_e; void batteryInit(void); -void batteryUpdateVoltage(void); +void batteryUpdateVoltage(timeUs_t currentTimeUs); void batteryUpdatePresence(void); batteryState_e getBatteryState(void); @@ -74,4 +75,4 @@ int32_t getAmperage(void); int32_t getAmperageLatest(void); int32_t getMAhDrawn(void); -void batteryUpdateCurrentMeter(int32_t lastUpdateAt, bool armed); +void batteryUpdateCurrentMeter(timeUs_t currentTimeUs);