From e783217833d68831211eec30879203e4803e0c1a Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Tue, 8 Nov 2016 19:02:14 +0000 Subject: [PATCH] Tidy fc_tasks.c --- src/main/fc/fc_tasks.c | 97 +++++----------------------------------- src/main/rx/rx.c | 4 +- src/main/rx/rx.h | 2 +- src/main/sensors/sonar.c | 9 ++-- src/main/sensors/sonar.h | 2 +- 5 files changed, 20 insertions(+), 94 deletions(-) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 2ffbdc91ec..2b26675277 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -85,11 +85,6 @@ static void taskUpdateAccelerometer(uint32_t currentTime) imuUpdateAccelerometer(&masterConfig.accelerometerTrims); } -static void taskUpdateAttitude(uint32_t currentTime) -{ - imuUpdateAttitude(currentTime); -} - static void taskHandleSerial(uint32_t currentTime) { UNUSED(currentTime); @@ -103,13 +98,6 @@ static void taskHandleSerial(uint32_t currentTime) mspSerialProcess(ARMING_FLAG(ARMED) ? MSP_SKIP_NON_MSP_DATA : MSP_EVALUATE_NON_MSP_DATA, mspFcProcessCommand); } -#ifdef BEEPER -static void taskUpdateBeeper(uint32_t currentTime) -{ - beeperUpdate(currentTime); //call periodic beeper handler -} -#endif - static void taskUpdateBattery(uint32_t currentTime) { #ifdef USE_ADC @@ -133,12 +121,6 @@ static void taskUpdateBattery(uint32_t currentTime) } } -static bool taskUpdateRxCheck(uint32_t currentTime, uint32_t currentDeltaTime) -{ - UNUSED(currentDeltaTime); - return rxUpdate(currentTime); -} - static void taskUpdateRxMain(uint32_t currentTime) { processRx(currentTime); @@ -163,18 +145,6 @@ static void taskUpdateRxMain(uint32_t currentTime) #endif } -#ifdef GPS -static void taskProcessGPS(uint32_t currentTime) -{ - // if GPS feature is enabled, gpsThread() will be called at some intervals to check for stuck - // hardware, wrong baud rates, init GPS if needed, etc. Don't use SENSOR_GPS here as gpsUdate() can and will - // change this based on available hardware - if (feature(FEATURE_GPS)) { - gpsUpdate(currentTime); - } -} -#endif - #ifdef MAG static void taskUpdateCompass(uint32_t currentTime) { @@ -198,17 +168,6 @@ static void taskUpdateBaro(uint32_t currentTime) } #endif -#ifdef SONAR -static void taskUpdateSonar(uint32_t currentTime) -{ - UNUSED(currentTime); - - if (sensors(SENSOR_SONAR)) { - sonarUpdate(); - } -} -#endif - #if defined(BARO) || defined(SONAR) static void taskCalculateAltitude(uint32_t currentTime) { @@ -224,15 +183,6 @@ static void taskCalculateAltitude(uint32_t currentTime) }} #endif -#ifdef USE_DASHBOARD -static void taskUpdateDashboard(uint32_t currentTime) -{ - if (feature(FEATURE_DASHBOARD)) { - dashboardUpdate(currentTime); - } -} -#endif - #ifdef TELEMETRY static void taskTelemetry(uint32_t currentTime) { @@ -244,33 +194,6 @@ static void taskTelemetry(uint32_t currentTime) } #endif -#ifdef LED_STRIP -static void taskLedStrip(uint32_t currentTime) -{ - if (feature(FEATURE_LED_STRIP)) { - ledStripUpdate(currentTime); - } -} -#endif - -#ifdef TRANSPONDER -static void taskTransponder(uint32_t currentTime) -{ - if (feature(FEATURE_TRANSPONDER)) { - transponderUpdate(currentTime); - } -} -#endif - -#ifdef OSD -static void taskUpdateOsd(uint32_t currentTime) -{ - if (feature(FEATURE_OSD)) { - osdUpdate(currentTime); - } -} -#endif - void fcTasksInit(void) { schedulerInit(); @@ -365,14 +288,14 @@ cfTask_t cfTasks[TASK_COUNT] = { [TASK_ATTITUDE] = { .taskName = "ATTITUDE", - .taskFunc = taskUpdateAttitude, + .taskFunc = imuUpdateAttitude, .desiredPeriod = 1000000 / 100, .staticPriority = TASK_PRIORITY_MEDIUM, }, [TASK_RX] = { .taskName = "RX", - .checkFunc = taskUpdateRxCheck, + .checkFunc = rxUpdateCheck, .taskFunc = taskUpdateRxMain, .desiredPeriod = 1000000 / 50, // If event-based scheduling doesn't work, fallback to periodic scheduling .staticPriority = TASK_PRIORITY_HIGH, @@ -395,7 +318,7 @@ cfTask_t cfTasks[TASK_COUNT] = { #ifdef BEEPER [TASK_BEEPER] = { .taskName = "BEEPER", - .taskFunc = taskUpdateBeeper, + .taskFunc = beeperUpdate, .desiredPeriod = 1000000 / 100, // 100 Hz .staticPriority = TASK_PRIORITY_LOW, }, @@ -404,7 +327,7 @@ cfTask_t cfTasks[TASK_COUNT] = { #ifdef GPS [TASK_GPS] = { .taskName = "GPS", - .taskFunc = taskProcessGPS, + .taskFunc = gpsUpdate, .desiredPeriod = 1000000 / 10, // GPS usually don't go raster than 10Hz .staticPriority = TASK_PRIORITY_MEDIUM, }, @@ -431,8 +354,8 @@ cfTask_t cfTasks[TASK_COUNT] = { #ifdef SONAR [TASK_SONAR] = { .taskName = "SONAR", - .taskFunc = taskUpdateSonar, - .desiredPeriod = 1000000 / 20, + .taskFunc = sonarUpdate, + .desiredPeriod = 70000, // 70ms required so that SONAR pulses do not interfer with each other .staticPriority = TASK_PRIORITY_LOW, }, #endif @@ -449,7 +372,7 @@ cfTask_t cfTasks[TASK_COUNT] = { #ifdef TRANSPONDER [TASK_TRANSPONDER] = { .taskName = "TRANSPONDER", - .taskFunc = taskTransponder, + .taskFunc = transponderUpdate, .desiredPeriod = 1000000 / 250, // 250 Hz .staticPriority = TASK_PRIORITY_LOW, }, @@ -458,7 +381,7 @@ cfTask_t cfTasks[TASK_COUNT] = { #ifdef USE_DASHBOARD [TASK_DASHBOARD] = { .taskName = "DASHBOARD", - .taskFunc = taskUpdateDashboard, + .taskFunc = dashboardUpdate, .desiredPeriod = 1000000 / 10, .staticPriority = TASK_PRIORITY_LOW, }, @@ -466,7 +389,7 @@ cfTask_t cfTasks[TASK_COUNT] = { #ifdef OSD [TASK_OSD] = { .taskName = "OSD", - .taskFunc = taskUpdateOsd, + .taskFunc = osdUpdate, .desiredPeriod = 1000000 / 60, // 60 Hz .staticPriority = TASK_PRIORITY_LOW, }, @@ -483,7 +406,7 @@ cfTask_t cfTasks[TASK_COUNT] = { #ifdef LED_STRIP [TASK_LEDSTRIP] = { .taskName = "LEDSTRIP", - .taskFunc = taskLedStrip, + .taskFunc = ledStripUpdate, .desiredPeriod = 1000000 / 100, // 100 Hz .staticPriority = TASK_PRIORITY_LOW, }, diff --git a/src/main/rx/rx.c b/src/main/rx/rx.c index 318c85e7e9..6ae0df55eb 100644 --- a/src/main/rx/rx.c +++ b/src/main/rx/rx.c @@ -325,8 +325,10 @@ void resumeRxSignal(void) failsafeOnRxResume(); } -bool rxUpdate(uint32_t currentTime) +bool rxUpdateCheck(uint32_t currentTime, uint32_t currentDeltaTime) { + UNUSED(currentDeltaTime); + resetRxSignalReceivedFlagIfNeeded(currentTime); if (isRxDataDriven()) { diff --git a/src/main/rx/rx.h b/src/main/rx/rx.h index bbbc2db3b7..ecea20120d 100644 --- a/src/main/rx/rx.h +++ b/src/main/rx/rx.h @@ -157,7 +157,7 @@ extern rxRuntimeConfig_t rxRuntimeConfig; //!!TODO remove this extern, only need struct modeActivationCondition_s; void rxInit(const rxConfig_t *rxConfig, const struct modeActivationCondition_s *modeActivationConditions); void useRxConfig(const rxConfig_t *rxConfigToUse); -bool rxUpdate(uint32_t currentTime); +bool rxUpdateCheck(uint32_t currentTime, uint32_t currentDeltaTime); bool rxIsReceivingSignal(void); bool rxAreFlightChannelsValid(void); void calculateRxChannelsAndUpdateFailsafe(uint32_t currentTime); diff --git a/src/main/sensors/sonar.c b/src/main/sensors/sonar.c index b463a399f5..d9b82932dd 100644 --- a/src/main/sensors/sonar.c +++ b/src/main/sensors/sonar.c @@ -26,12 +26,12 @@ #include "build/build_config.h" #include "common/maths.h" -#include "common/axis.h" - -#include "fc/runtime_config.h" +#include "common/utils.h" #include "config/feature.h" +#include "fc/runtime_config.h" + #include "sensors/sensors.h" #include "sensors/battery.h" #include "sensors/sonar.h" @@ -88,8 +88,9 @@ static int32_t applySonarMedianFilter(int32_t newSonarReading) return newSonarReading; } -void sonarUpdate(void) +void sonarUpdate(uint32_t currentTime) { + UNUSED(currentTime); hcsr04_start_reading(); } diff --git a/src/main/sensors/sonar.h b/src/main/sensors/sonar.h index 536bc2d0d8..f86feb04b4 100644 --- a/src/main/sensors/sonar.h +++ b/src/main/sensors/sonar.h @@ -27,7 +27,7 @@ extern int16_t sonarCfAltCm; extern int16_t sonarMaxAltWithTiltCm; void sonarInit(const sonarConfig_t *sonarConfig); -void sonarUpdate(void); +void sonarUpdate(uint32_t currentTime); int32_t sonarRead(void); int32_t sonarCalculateAltitude(int32_t sonarDistance, float cosTiltAngle); int32_t sonarGetLatestAltitude(void);