From c0c6450e613219d7c200b12ff76b7246bc90b014 Mon Sep 17 00:00:00 2001 From: Hydra Date: Sat, 18 Mar 2017 16:44:46 +0000 Subject: [PATCH] CF/BF - use one task for each battery sensor. --- src/main/fc/fc_tasks.c | 56 ++++++++++++++-------------------- src/main/scheduler/scheduler.h | 3 +- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 9180e6c336..6f185a7961 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -89,12 +89,6 @@ void taskBstMasterProcess(timeUs_t currentTimeUs); #define TASK_PERIOD_MS(ms) ((ms) * 1000) #define TASK_PERIOD_US(us) (us) -/* VBAT monitoring interval (in microseconds) - 1s*/ -#define VBATINTERVAL (6 * 3500) -/* IBat monitoring interval (in microseconds) - 6 default looptimes */ -#define IBATINTERVAL (6 * 3500) - - static void taskUpdateAccelerometer(timeUs_t currentTimeUs) { UNUSED(currentTimeUs); @@ -116,28 +110,16 @@ static void taskHandleSerial(timeUs_t currentTimeUs) } -void taskBatterySensors(timeUs_t currentTimeUs) +void taskBatteryVoltage(timeUs_t currentTimeUs) { - static uint32_t vbatLastServiced = 0; + UNUSED(currentTimeUs); + batteryUpdateVoltage(); +} - if (batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE) { - if (cmp32(currentTimeUs, vbatLastServiced) >= VBATINTERVAL) { - vbatLastServiced = currentTimeUs; - - batteryUpdateVoltage(); - } - } - - if (batteryConfig()->currentMeterSource != CURRENT_METER_NONE) { - - static uint32_t ibatLastServiced = 0; - const int32_t ibatTimeSinceLastServiced = cmp32(currentTimeUs, ibatLastServiced); - - if (ibatTimeSinceLastServiced >= IBATINTERVAL) { - ibatLastServiced = currentTimeUs; - batteryUpdateCurrentMeter(ibatTimeSinceLastServiced, ARMING_FLAG(ARMED)); - } - } +void taskBatteryCurrent(timeUs_t currentTimeUs) +{ + UNUSED(currentTimeUs); + batteryUpdateCurrentMeter(getTaskDeltaTime(TASK_SELF), ARMING_FLAG(ARMED)); } void taskBatteryAlerts(timeUs_t currentTimeUs) @@ -254,11 +236,13 @@ void fcTasksInit(void) setTaskEnabled(TASK_SERIAL, true); rescheduleTask(TASK_SERIAL, TASK_PERIOD_HZ(serialConfig()->serial_update_rate_hz)); - bool useBatterySensors = batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE || batteryConfig()->currentMeterSource != CURRENT_METER_NONE; - setTaskEnabled(TASK_BATTERY_SENSORS, useBatterySensors); + bool useBatteryVoltage = batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE; + setTaskEnabled(TASK_BATTERY_VOLTAGE, useBatteryVoltage); + bool useBatteryCurrent = batteryConfig()->currentMeterSource != CURRENT_METER_NONE; + setTaskEnabled(TASK_BATTERY_CURRENT, useBatteryCurrent); bool useBatteryAlerts = batteryConfig()->useVBatAlerts || batteryConfig()->useConsumptionAlerts || feature(FEATURE_OSD); - setTaskEnabled(TASK_BATTERY_ALERTS, useBatterySensors && useBatteryAlerts); + setTaskEnabled(TASK_BATTERY_ALERTS, (useBatteryVoltage || useBatteryCurrent) && useBatteryAlerts); setTaskEnabled(TASK_RX, true); @@ -395,10 +379,16 @@ cfTask_t cfTasks[TASK_COUNT] = { .staticPriority = TASK_PRIORITY_MEDIUM, }, - [TASK_BATTERY_SENSORS] = { - .taskName = "BATTERY_SENSORS", - .taskFunc = taskBatterySensors, - .desiredPeriod = TASK_PERIOD_HZ(50), // 50 Hz + [TASK_BATTERY_VOLTAGE] = { + .taskName = "BATTERY_VOLTAGE", + .taskFunc = taskBatteryVoltage, + .desiredPeriod = TASK_PERIOD_HZ(50), + .staticPriority = TASK_PRIORITY_MEDIUM, + }, + [TASK_BATTERY_CURRENT] = { + .taskName = "BATTERY_CURRENT", + .taskFunc = taskBatteryCurrent, + .desiredPeriod = TASK_PERIOD_HZ(50), .staticPriority = TASK_PRIORITY_MEDIUM, }, #ifdef BEEPER diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index d8044fa22d..96fc785689 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -56,7 +56,8 @@ typedef enum { TASK_RX, TASK_SERIAL, TASK_DISPATCH, - TASK_BATTERY_SENSORS, + TASK_BATTERY_VOLTAGE, + TASK_BATTERY_CURRENT, TASK_BATTERY_ALERTS, #ifdef BEEPER TASK_BEEPER,