From f9ac3a3de231643e59bf38fb526204556656e83b Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Tue, 21 Jan 2014 22:43:41 +0100 Subject: [PATCH 1/3] OP-1188 Optimize stack utilization for multipid bank selection in Stabilization module +review OPReview --- flight/modules/Stabilization/stabilization.c | 22 ++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/flight/modules/Stabilization/stabilization.c b/flight/modules/Stabilization/stabilization.c index 9bc5d1957..186c10739 100644 --- a/flight/modules/Stabilization/stabilization.c +++ b/flight/modules/Stabilization/stabilization.c @@ -757,13 +757,17 @@ static float stab_powf(float x, uint8_t p) static void SettingsBankUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { - StabilizationBankData bank, oldBank; - - StabilizationBankGet(&oldBank); - if (cur_flight_mode < 0 || cur_flight_mode >= NUM_FMS_POSITIONS) { return; } + if ((settings.FlightModeMap[cur_flight_mode] == 0 && ev->obj != StabilizationSettingsBank1Handle()) || + (settings.FlightModeMap[cur_flight_mode] == 1 && ev->obj != StabilizationSettingsBank2Handle()) || + (settings.FlightModeMap[cur_flight_mode] == 2 && ev->obj != StabilizationSettingsBank3Handle()) || + settings.FlightModeMap[cur_flight_mode] > 2) { + return; + } + + StabilizationBankData bank; switch (settings.FlightModeMap[cur_flight_mode]) { case 0: @@ -777,16 +781,8 @@ static void SettingsBankUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) case 2: StabilizationSettingsBank3Get((StabilizationSettingsBank3Data *)&bank); break; - - default: - memset(&bank, 0, sizeof(StabilizationBankDataPacked)); -// return; //bank number is invalid. All we can do is ignore it. - } - - // Need to do this to prevent an infinite loop - if (memcmp(&oldBank, &bank, sizeof(StabilizationBankDataPacked)) != 0) { - StabilizationBankSet(&bank); } + StabilizationBankSet(&bank); } static void BankUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) From c1f810f1cef6a3774127149c1e3505b92dd3e05c Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Wed, 22 Jan 2014 00:01:38 +0100 Subject: [PATCH 2/3] OP-1188 fix an issue that is preventing bank initialization at startup --- flight/modules/Stabilization/stabilization.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/flight/modules/Stabilization/stabilization.c b/flight/modules/Stabilization/stabilization.c index 186c10739..65462ae0c 100644 --- a/flight/modules/Stabilization/stabilization.c +++ b/flight/modules/Stabilization/stabilization.c @@ -194,7 +194,6 @@ MODULE_INITCALL(StabilizationInitialize, StabilizationStart); static void stabilizationTask(__attribute__((unused)) void *parameters) { UAVObjEvent ev; - uint32_t timeval = PIOS_DELAY_GetRaw(); ActuatorDesiredData actuatorDesired; @@ -760,10 +759,10 @@ static void SettingsBankUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) if (cur_flight_mode < 0 || cur_flight_mode >= NUM_FMS_POSITIONS) { return; } - if ((settings.FlightModeMap[cur_flight_mode] == 0 && ev->obj != StabilizationSettingsBank1Handle()) || - (settings.FlightModeMap[cur_flight_mode] == 1 && ev->obj != StabilizationSettingsBank2Handle()) || - (settings.FlightModeMap[cur_flight_mode] == 2 && ev->obj != StabilizationSettingsBank3Handle()) || - settings.FlightModeMap[cur_flight_mode] > 2) { + if ((ev) && ((settings.FlightModeMap[cur_flight_mode] == 0 && ev->obj != StabilizationSettingsBank1Handle()) || + (settings.FlightModeMap[cur_flight_mode] == 1 && ev->obj != StabilizationSettingsBank2Handle()) || + (settings.FlightModeMap[cur_flight_mode] == 2 && ev->obj != StabilizationSettingsBank3Handle()) || + settings.FlightModeMap[cur_flight_mode] > 2)) { return; } From 3ef980aa89bfd26f2fbd25e62d9c9b81daecc4e1 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Wed, 22 Jan 2014 00:01:58 +0100 Subject: [PATCH 3/3] OP-1188 fix stack for coptercontrol --- flight/targets/boards/coptercontrol/firmware/inc/pios_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h index bb491920c..ea94abb02 100644 --- a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h +++ b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h @@ -162,7 +162,7 @@ #endif #define PIOS_STABILIZATION_STACK_SIZE 790 #define PIOS_TELEM_STACK_SIZE 540 -#define PIOS_EVENTDISPATCHER_STACK_SIZE 150 +#define PIOS_EVENTDISPATCHER_STACK_SIZE 160 /* This can't be too high to stop eventdispatcher thread overflowing */ #define PIOS_EVENTDISAPTCHER_QUEUE 10