From 45b0e787a4cc409ae1d2daa5a96bdcb924e11b26 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 30 Mar 2013 19:57:16 +0100 Subject: [PATCH 1/9] OP-886 Improvements to sanitychecks Added an Extensions to Alarm for detailed status/substatus reporting. Extended Alarms are the first in the Alarm structure and have corresponding fields in Status and Substatus structures. Also added a filter to the HWsettings update to prevent to block arming when actual settings have not changed. +review OPReview --- .../System => Libraries}/alarms.c | 42 +++- .../System => Libraries}/inc/alarms.h | 1 + flight/Libraries/inc/sanitycheck.h | 13 +- flight/Libraries/sanitycheck.c | 64 +++--- flight/Modules/System/systemmod.c | 17 +- flight/targets/CopterControl/Makefile | 2 +- .../targets/CopterControl/System/inc/alarms.h | 50 ---- flight/targets/OSD/Makefile | 2 +- flight/targets/OSD/System/alarms.c | 210 ----------------- flight/targets/OSD/System/inc/alarms.h | 50 ---- flight/targets/PipXtreme/System/alarms.c | 214 ------------------ flight/targets/RevoMini/Makefile | 2 +- flight/targets/RevoMini/System/alarms.c | 210 ----------------- flight/targets/RevoMini/System/inc/alarms.h | 50 ---- flight/targets/Revolution/Makefile | 2 +- flight/targets/Revolution/System/alarms.c | 210 ----------------- flight/targets/Revolution/System/inc/alarms.h | 50 ---- flight/targets/SimPosix/Makefile | 2 +- flight/targets/SimPosix/System/alarms.c | 210 ----------------- flight/targets/SimPosix/System/inc/alarms.h | 50 ---- shared/uavobjectdefinition/systemalarms.xml | 18 +- 21 files changed, 123 insertions(+), 1346 deletions(-) rename flight/{targets/CopterControl/System => Libraries}/alarms.c (76%) rename flight/{targets/PipXtreme/System => Libraries}/inc/alarms.h (91%) mode change 100755 => 100644 delete mode 100644 flight/targets/CopterControl/System/inc/alarms.h delete mode 100644 flight/targets/OSD/System/alarms.c delete mode 100644 flight/targets/OSD/System/inc/alarms.h delete mode 100755 flight/targets/PipXtreme/System/alarms.c delete mode 100644 flight/targets/RevoMini/System/alarms.c delete mode 100644 flight/targets/RevoMini/System/inc/alarms.h delete mode 100644 flight/targets/Revolution/System/alarms.c delete mode 100644 flight/targets/Revolution/System/inc/alarms.h delete mode 100644 flight/targets/SimPosix/System/alarms.c delete mode 100644 flight/targets/SimPosix/System/inc/alarms.h diff --git a/flight/targets/CopterControl/System/alarms.c b/flight/Libraries/alarms.c similarity index 76% rename from flight/targets/CopterControl/System/alarms.c rename to flight/Libraries/alarms.c index 01d79a1e5..6f5d53d8b 100644 --- a/flight/targets/CopterControl/System/alarms.c +++ b/flight/Libraries/alarms.c @@ -87,6 +87,42 @@ int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity } +/** + * Set an Extended Alarm + * @param alarm The system alarm to be modified + * @param severity The alarm severity + * @param status: the Extended alarm status field + * @param subStatus: the Extended alarm substatus field + * @return 0 if success, -1 if an error + */ +int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity, uint8_t status, uint8_t subStatus) +{ + SystemAlarmsData alarms; + + // Check that this is a valid alarm + if (alarm >= SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM) + { + return -1; + } + + // Lock + xSemaphoreTakeRecursive(lock, portMAX_DELAY); + + // Read alarm and update its severity only if it was changed + SystemAlarmsGet(&alarms); + if ( alarms.Alarm[alarm] != severity ) + { + alarms.ExtendedAlarmStatus[alarm] = status; + alarms.ExtendedAlarmSubStatus[alarm] = subStatus; + alarms.Alarm[alarm] = severity; + SystemAlarmsSet(&alarms); + } + + // Release lock + xSemaphoreGiveRecursive(lock); + return 0; +} + /** * Get an alarm * @param alarm The system alarm to be read @@ -136,7 +172,11 @@ void AlarmsDefaultAll() */ int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) { - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); + if (alarm < SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM){ + return ExtendedAlarmsSet(alarm, SYSTEMALARMS_ALARM_OK, 0, 0); + } else { + return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); + } } /** diff --git a/flight/targets/PipXtreme/System/inc/alarms.h b/flight/Libraries/inc/alarms.h old mode 100755 new mode 100644 similarity index 91% rename from flight/targets/PipXtreme/System/inc/alarms.h rename to flight/Libraries/inc/alarms.h index 9fb047dca..ad2522273 --- a/flight/targets/PipXtreme/System/inc/alarms.h +++ b/flight/Libraries/inc/alarms.h @@ -33,6 +33,7 @@ int32_t AlarmsInitialize(void); int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity); +int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity, uint8_t status, uint8_t subStatus); SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm); int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm); void AlarmsDefaultAll(); diff --git a/flight/Libraries/inc/sanitycheck.h b/flight/Libraries/inc/sanitycheck.h index 2f201da22..9ee72f3c5 100644 --- a/flight/Libraries/inc/sanitycheck.h +++ b/flight/Libraries/inc/sanitycheck.h @@ -29,6 +29,17 @@ #ifndef SANITYCHECK_H #define SANITYCHECK_H +#define SANITYCHECK_STATUS_ERROR_NONE 0 +#define SANITYCHECK_STATUS_ERROR_FLIGHTMODE 1 + +#define BOOTFAULT_STATUS_ERROR_NONE 0 +#define BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT 1 + +#if (SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM != SYSTEMALARMS_EXTENDEDALARMSUBSTATUS_NUMELEM) || \ + (SYSTEMALARMS_EXTENDEDALARMSUBSTATUS_NUMELEM > SYSTEMALARMS_ALARM_NUMELEM) +#error incongruent SystemAlarms. Please revise the UAVO definition in SystemAlarm.xml +#endif + extern int32_t configuration_check(); -#endif /* SANITYCHECK_H */ \ No newline at end of file +#endif /* SANITYCHECK_H */ diff --git a/flight/Libraries/sanitycheck.c b/flight/Libraries/sanitycheck.c index ab5cab3bf..18c73ea00 100644 --- a/flight/Libraries/sanitycheck.c +++ b/flight/Libraries/sanitycheck.c @@ -49,8 +49,9 @@ static int32_t check_stabilization_settings(int index, bool multirotor); */ int32_t configuration_check() { - int32_t status = SYSTEMALARMS_ALARM_OK; - + int32_t severity = SYSTEMALARMS_ALARM_OK; + uint8_t alarmstatus = SANITYCHECK_STATUS_ERROR_NONE; + uint8_t alarmsubstatus = 0; // Get board type const struct pios_board_info * bdinfo = &pios_board_info_blob; bool coptercontrol = bdinfo->board_type == 0x04; @@ -85,58 +86,61 @@ int32_t configuration_check() for(uint32_t i = 0; i < num_modes; i++) { switch(modes[i]) { case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_MANUAL: - if (multirotor) - status = SYSTEMALARMS_ALARM_ERROR; + if (multirotor) { + severity = SYSTEMALARMS_ALARM_ERROR; + } break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED1: - status = (status == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(1, multirotor) : status; + severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(1, multirotor) : severity; break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED2: - status = (status == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(2, multirotor) : status; + severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(2, multirotor) : severity; break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED3: - status = (status == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(3, multirotor) : status; + severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(3, multirotor) : severity; break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_AUTOTUNE: - if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_AUTOTUNE)) - status = SYSTEMALARMS_ALARM_ERROR; + if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_AUTOTUNE)) { + severity = SYSTEMALARMS_ALARM_ERROR; + } break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ALTITUDEHOLD: - if (coptercontrol) - status = SYSTEMALARMS_ALARM_ERROR; - else { - // Revo supports altitude hold - if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_ALTITUDEHOLD)) - status = SYSTEMALARMS_ALARM_ERROR; + if (coptercontrol) { + severity = SYSTEMALARMS_ALARM_ERROR; + } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_ALTITUDEHOLD)) { // Revo supports altitude hold + severity = SYSTEMALARMS_ALARM_ERROR; } break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_VELOCITYCONTROL: - if (coptercontrol) - status = SYSTEMALARMS_ALARM_ERROR; - else { - // Revo supports altitude hold - if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) - status = SYSTEMALARMS_ALARM_ERROR; + if (coptercontrol) { + severity = SYSTEMALARMS_ALARM_ERROR; + } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold + severity = SYSTEMALARMS_ALARM_ERROR; } break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_POSITIONHOLD: - if (coptercontrol) - status = SYSTEMALARMS_ALARM_ERROR; - else { - // Revo supports altitude hold - if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) - status = SYSTEMALARMS_ALARM_ERROR; + if (coptercontrol){ + severity = SYSTEMALARMS_ALARM_ERROR; + } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold + severity = SYSTEMALARMS_ALARM_ERROR; } break; default: // Uncovered modes are automatically an error - status = SYSTEMALARMS_ALARM_ERROR; + severity = SYSTEMALARMS_ALARM_ERROR; } + // mark the first encountered erroneous setting in status and substatus + if(severity != SYSTEMALARMS_ALARM_OK && alarmstatus == SANITYCHECK_STATUS_ERROR_NONE) + { + alarmstatus = SANITYCHECK_STATUS_ERROR_FLIGHTMODE; + alarmsubstatus = i; + } + } // TODO: Check on a multirotor no axis supports "None" - if(status != SYSTEMALARMS_ALARM_OK) - AlarmsSet(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION, status); + if(severity != SYSTEMALARMS_ALARM_OK) + ExtendedAlarmsSet(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION, severity, alarmstatus, alarmsubstatus); else AlarmsClear(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION); diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 8d6e88508..b857baeac 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -49,6 +49,8 @@ #include "watchdogstatus.h" #include "taskmonitor.h" #include "hwsettings.h" +#include + //#define DEBUG_THIS_FILE @@ -85,6 +87,7 @@ static xTaskHandle systemTaskHandle; static xQueueHandle objectPersistenceQueue; static bool stackOverflow; static bool mallocFailed; +static HwSettingsData bootHwSettings; // Private functions static void objectUpdatedCb(UAVObjEvent * ev); @@ -171,6 +174,8 @@ static void systemTask(void *parameters) // Listen for SettingPersistance object updates, connect a callback function ObjectPersistenceConnectQueue(objectPersistenceQueue); + // Load a copy of HwSetting active at boot time + HwSettingsGet(&bootHwSettings); // Whenever the configuration changes, make sure it is safe to fly HwSettingsConnectCallback(hwSettingsUpdatedCb); @@ -303,9 +308,10 @@ static void objectUpdatedCb(UAVObjEvent * ev) retval = UAVObjDeleteMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_FULLERASE) { - retval = -1; #if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) retval = PIOS_FLASHFS_Format(0); +#else + retval = -1; #endif } switch(retval) { @@ -328,7 +334,14 @@ static void objectUpdatedCb(UAVObjEvent * ev) */ static void hwSettingsUpdatedCb(UAVObjEvent * ev) { - AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT,SYSTEMALARMS_ALARM_ERROR); + HwSettingsData currentHwSettings; + HwSettingsGet(¤tHwSettings); + // check whether the Hw Configuration has changed from the one used at boot time + if(!memcmp(&bootHwSettings,¤tHwSettings,sizeof(HwSettingsData))){ + return; + } + + ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT,SYSTEMALARMS_ALARM_ERROR,BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT, 0); } /** diff --git a/flight/targets/CopterControl/Makefile b/flight/targets/CopterControl/Makefile index 1db667a81..2867232a4 100644 --- a/flight/targets/CopterControl/Makefile +++ b/flight/targets/CopterControl/Makefile @@ -62,7 +62,7 @@ ifndef TESTAPP SRC += $(OPSYSTEM)/coptercontrol.c SRC += $(OPSYSTEM)/pios_board.c SRC += $(OPSYSTEM)/pios_usb_board_data.c - SRC += $(OPSYSTEM)/alarms.c + SRC += $(FLIGHTLIB)/alarms.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c diff --git a/flight/targets/CopterControl/System/inc/alarms.h b/flight/targets/CopterControl/System/inc/alarms.h deleted file mode 100644 index 9fb047dca..000000000 --- a/flight/targets/CopterControl/System/inc/alarms.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @{ - * @file alarms.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include file of the alarm library - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef ALARMS_H -#define ALARMS_H - -#include "systemalarms.h" -#define SYSTEMALARMS_ALARM_DEFAULT SYSTEMALARMS_ALARM_UNINITIALISED - -int32_t AlarmsInitialize(void); -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity); -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm); -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm); -void AlarmsDefaultAll(); -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm); -void AlarmsClearAll(); -int32_t AlarmsHasWarnings(); -int32_t AlarmsHasErrors(); -int32_t AlarmsHasCritical(); - -#endif // ALARMS_H - -/** - * @} - * @} - */ diff --git a/flight/targets/OSD/Makefile b/flight/targets/OSD/Makefile index 9ff2df65d..31fe6ee57 100644 --- a/flight/targets/OSD/Makefile +++ b/flight/targets/OSD/Makefile @@ -48,7 +48,7 @@ ifndef TESTAPP SRC += $(OPSYSTEM)/osd.c SRC += $(OPSYSTEM)/pios_board.c SRC += $(OPSYSTEM)/pios_usb_board_data.c - SRC += $(OPSYSTEM)/alarms.c + SRC += $(FLIGHTLIB)/alarms.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c diff --git a/flight/targets/OSD/System/alarms.c b/flight/targets/OSD/System/alarms.c deleted file mode 100644 index e61c7c1ea..000000000 --- a/flight/targets/OSD/System/alarms.c +++ /dev/null @@ -1,210 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @brief OpenPilot System libraries are available to all OP modules. - * @{ - * @file alarms.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Library for setting and clearing system alarms - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "openpilot.h" -#include "alarms.h" - -// Private constants - -// Private types - -// Private variables -static xSemaphoreHandle lock; - -// Private functions -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity); - -/** - * Initialize the alarms library - */ -int32_t AlarmsInitialize(void) -{ - SystemAlarmsInitialize(); - lock = xSemaphoreCreateRecursiveMutex(); - return 0; -} - -/** - * Set an alarm - * @param alarm The system alarm to be modified - * @param severity The alarm severity - * @return 0 if success, -1 if an error - */ -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return -1; - } - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarm and update its severity only if it was changed - SystemAlarmsGet(&alarms); - if ( alarms.Alarm[alarm] != severity ) - { - alarms.Alarm[alarm] = severity; - SystemAlarmsSet(&alarms); - } - - // Release lock - xSemaphoreGiveRecursive(lock); - return 0; - -} - -/** - * Get an alarm - * @param alarm The system alarm to be read - * @return Alarm severity - */ -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return 0; - } - - // Read alarm - SystemAlarmsGet(&alarms); - return alarms.Alarm[alarm]; -} - -/** - * Set an alarm to it's default value - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_DEFAULT); -} - -/** - * Default all alarms - */ -void AlarmsDefaultAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsDefault(n); - } -} - -/** - * Clear an alarm - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); -} - -/** - * Clear all alarms - */ -void AlarmsClearAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsClear(n); - } -} - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasWarnings() -{ - return hasSeverity(SYSTEMALARMS_ALARM_WARNING); -} - -/** - * Check if there are any alarms with error or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasErrors() -{ - return hasSeverity(SYSTEMALARMS_ALARM_ERROR); -}; - -/** - * Check if there are any alarms with critical or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasCritical() -{ - return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); -}; - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - uint32_t n; - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarms - SystemAlarmsGet(&alarms); - - // Go through alarms and check if any are of the given severity or higher - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - if ( alarms.Alarm[n] >= severity) - { - xSemaphoreGiveRecursive(lock); - return 1; - } - } - - // If this point is reached then no alarms found - xSemaphoreGiveRecursive(lock); - return 0; -} -/** - * @} - * @} - */ - diff --git a/flight/targets/OSD/System/inc/alarms.h b/flight/targets/OSD/System/inc/alarms.h deleted file mode 100644 index b62bc531b..000000000 --- a/flight/targets/OSD/System/inc/alarms.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @{ - * @file alarms.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include file of the alarm library - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef ALARMS_H -#define ALARMS_H - -#include "systemalarms.h" -#define SYSTEMALARMS_ALARM_DEFAULT SYSTEMALARMS_ALARM_UNINITIALISED - -int32_t AlarmsInitialize(void); -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity); -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm); -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm); -void AlarmsDefaultAll(); -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm); -void AlarmsClearAll(); -int32_t AlarmsHasWarnings(); -int32_t AlarmsHasErrors(); -int32_t AlarmsHasCritical(); - -#endif // ALARMS_H - -/** - * @} - * @} - */ diff --git a/flight/targets/PipXtreme/System/alarms.c b/flight/targets/PipXtreme/System/alarms.c deleted file mode 100755 index 01d79a1e5..000000000 --- a/flight/targets/PipXtreme/System/alarms.c +++ /dev/null @@ -1,214 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @brief OpenPilot System libraries are available to all OP modules. - * @{ - * @file alarms.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Library for setting and clearing system alarms - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "openpilot.h" -#include "alarms.h" - -// Private constants - -// Private types - -// Private variables -static xSemaphoreHandle lock; - -// Private functions -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity); - -/** - * Initialize the alarms library - */ -int32_t AlarmsInitialize(void) -{ - SystemAlarmsInitialize(); - - lock = xSemaphoreCreateRecursiveMutex(); - //do not change the default states of the alarms, let the init code generated by the uavobjectgenerator handle that - //AlarmsClearAll(); - //AlarmsDefaultAll(); - return 0; -} - -/** - * Set an alarm - * @param alarm The system alarm to be modified - * @param severity The alarm severity - * @return 0 if success, -1 if an error - */ -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return -1; - } - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarm and update its severity only if it was changed - SystemAlarmsGet(&alarms); - if ( alarms.Alarm[alarm] != severity ) - { - alarms.Alarm[alarm] = severity; - SystemAlarmsSet(&alarms); - } - - // Release lock - xSemaphoreGiveRecursive(lock); - return 0; - -} - -/** - * Get an alarm - * @param alarm The system alarm to be read - * @return Alarm severity - */ -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return 0; - } - - // Read alarm - SystemAlarmsGet(&alarms); - return alarms.Alarm[alarm]; -} - -/** - * Set an alarm to it's default value - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_DEFAULT); -} - -/** - * Default all alarms - */ -void AlarmsDefaultAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsDefault(n); - } -} - -/** - * Clear an alarm - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); -} - -/** - * Clear all alarms - */ -void AlarmsClearAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsClear(n); - } -} - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasWarnings() -{ - return hasSeverity(SYSTEMALARMS_ALARM_WARNING); -} - -/** - * Check if there are any alarms with error or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasErrors() -{ - return hasSeverity(SYSTEMALARMS_ALARM_ERROR); -}; - -/** - * Check if there are any alarms with critical or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasCritical() -{ - return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); -}; - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - uint32_t n; - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarms - SystemAlarmsGet(&alarms); - - // Go through alarms and check if any are of the given severity or higher - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - if ( alarms.Alarm[n] >= severity) - { - xSemaphoreGiveRecursive(lock); - return 1; - } - } - - // If this point is reached then no alarms found - xSemaphoreGiveRecursive(lock); - return 0; -} -/** - * @} - * @} - */ - diff --git a/flight/targets/RevoMini/Makefile b/flight/targets/RevoMini/Makefile index f432a535a..316853ad9 100644 --- a/flight/targets/RevoMini/Makefile +++ b/flight/targets/RevoMini/Makefile @@ -66,7 +66,7 @@ ifndef TESTAPP SRC += $(OPSYSTEM)/revolution.c SRC += $(OPSYSTEM)/pios_board.c SRC += $(OPSYSTEM)/pios_usb_board_data.c - SRC += $(OPSYSTEM)/alarms.c + SRC += $(FLIGHTLIB)/alarms.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c diff --git a/flight/targets/RevoMini/System/alarms.c b/flight/targets/RevoMini/System/alarms.c deleted file mode 100644 index e61c7c1ea..000000000 --- a/flight/targets/RevoMini/System/alarms.c +++ /dev/null @@ -1,210 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @brief OpenPilot System libraries are available to all OP modules. - * @{ - * @file alarms.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Library for setting and clearing system alarms - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "openpilot.h" -#include "alarms.h" - -// Private constants - -// Private types - -// Private variables -static xSemaphoreHandle lock; - -// Private functions -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity); - -/** - * Initialize the alarms library - */ -int32_t AlarmsInitialize(void) -{ - SystemAlarmsInitialize(); - lock = xSemaphoreCreateRecursiveMutex(); - return 0; -} - -/** - * Set an alarm - * @param alarm The system alarm to be modified - * @param severity The alarm severity - * @return 0 if success, -1 if an error - */ -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return -1; - } - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarm and update its severity only if it was changed - SystemAlarmsGet(&alarms); - if ( alarms.Alarm[alarm] != severity ) - { - alarms.Alarm[alarm] = severity; - SystemAlarmsSet(&alarms); - } - - // Release lock - xSemaphoreGiveRecursive(lock); - return 0; - -} - -/** - * Get an alarm - * @param alarm The system alarm to be read - * @return Alarm severity - */ -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return 0; - } - - // Read alarm - SystemAlarmsGet(&alarms); - return alarms.Alarm[alarm]; -} - -/** - * Set an alarm to it's default value - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_DEFAULT); -} - -/** - * Default all alarms - */ -void AlarmsDefaultAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsDefault(n); - } -} - -/** - * Clear an alarm - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); -} - -/** - * Clear all alarms - */ -void AlarmsClearAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsClear(n); - } -} - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasWarnings() -{ - return hasSeverity(SYSTEMALARMS_ALARM_WARNING); -} - -/** - * Check if there are any alarms with error or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasErrors() -{ - return hasSeverity(SYSTEMALARMS_ALARM_ERROR); -}; - -/** - * Check if there are any alarms with critical or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasCritical() -{ - return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); -}; - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - uint32_t n; - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarms - SystemAlarmsGet(&alarms); - - // Go through alarms and check if any are of the given severity or higher - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - if ( alarms.Alarm[n] >= severity) - { - xSemaphoreGiveRecursive(lock); - return 1; - } - } - - // If this point is reached then no alarms found - xSemaphoreGiveRecursive(lock); - return 0; -} -/** - * @} - * @} - */ - diff --git a/flight/targets/RevoMini/System/inc/alarms.h b/flight/targets/RevoMini/System/inc/alarms.h deleted file mode 100644 index 9fb047dca..000000000 --- a/flight/targets/RevoMini/System/inc/alarms.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @{ - * @file alarms.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include file of the alarm library - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef ALARMS_H -#define ALARMS_H - -#include "systemalarms.h" -#define SYSTEMALARMS_ALARM_DEFAULT SYSTEMALARMS_ALARM_UNINITIALISED - -int32_t AlarmsInitialize(void); -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity); -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm); -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm); -void AlarmsDefaultAll(); -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm); -void AlarmsClearAll(); -int32_t AlarmsHasWarnings(); -int32_t AlarmsHasErrors(); -int32_t AlarmsHasCritical(); - -#endif // ALARMS_H - -/** - * @} - * @} - */ diff --git a/flight/targets/Revolution/Makefile b/flight/targets/Revolution/Makefile index 60ae27377..da79a2e86 100644 --- a/flight/targets/Revolution/Makefile +++ b/flight/targets/Revolution/Makefile @@ -66,7 +66,7 @@ ifndef TESTAPP SRC += $(OPSYSTEM)/revolution.c SRC += $(OPSYSTEM)/pios_board.c SRC += $(OPSYSTEM)/pios_usb_board_data.c - SRC += $(OPSYSTEM)/alarms.c + SRC += $(FLIGHTLIB)/alarms.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c diff --git a/flight/targets/Revolution/System/alarms.c b/flight/targets/Revolution/System/alarms.c deleted file mode 100644 index e61c7c1ea..000000000 --- a/flight/targets/Revolution/System/alarms.c +++ /dev/null @@ -1,210 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @brief OpenPilot System libraries are available to all OP modules. - * @{ - * @file alarms.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Library for setting and clearing system alarms - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "openpilot.h" -#include "alarms.h" - -// Private constants - -// Private types - -// Private variables -static xSemaphoreHandle lock; - -// Private functions -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity); - -/** - * Initialize the alarms library - */ -int32_t AlarmsInitialize(void) -{ - SystemAlarmsInitialize(); - lock = xSemaphoreCreateRecursiveMutex(); - return 0; -} - -/** - * Set an alarm - * @param alarm The system alarm to be modified - * @param severity The alarm severity - * @return 0 if success, -1 if an error - */ -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return -1; - } - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarm and update its severity only if it was changed - SystemAlarmsGet(&alarms); - if ( alarms.Alarm[alarm] != severity ) - { - alarms.Alarm[alarm] = severity; - SystemAlarmsSet(&alarms); - } - - // Release lock - xSemaphoreGiveRecursive(lock); - return 0; - -} - -/** - * Get an alarm - * @param alarm The system alarm to be read - * @return Alarm severity - */ -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return 0; - } - - // Read alarm - SystemAlarmsGet(&alarms); - return alarms.Alarm[alarm]; -} - -/** - * Set an alarm to it's default value - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_DEFAULT); -} - -/** - * Default all alarms - */ -void AlarmsDefaultAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsDefault(n); - } -} - -/** - * Clear an alarm - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); -} - -/** - * Clear all alarms - */ -void AlarmsClearAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsClear(n); - } -} - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasWarnings() -{ - return hasSeverity(SYSTEMALARMS_ALARM_WARNING); -} - -/** - * Check if there are any alarms with error or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasErrors() -{ - return hasSeverity(SYSTEMALARMS_ALARM_ERROR); -}; - -/** - * Check if there are any alarms with critical or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasCritical() -{ - return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); -}; - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - uint32_t n; - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarms - SystemAlarmsGet(&alarms); - - // Go through alarms and check if any are of the given severity or higher - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - if ( alarms.Alarm[n] >= severity) - { - xSemaphoreGiveRecursive(lock); - return 1; - } - } - - // If this point is reached then no alarms found - xSemaphoreGiveRecursive(lock); - return 0; -} -/** - * @} - * @} - */ - diff --git a/flight/targets/Revolution/System/inc/alarms.h b/flight/targets/Revolution/System/inc/alarms.h deleted file mode 100644 index 9fb047dca..000000000 --- a/flight/targets/Revolution/System/inc/alarms.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @{ - * @file alarms.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include file of the alarm library - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef ALARMS_H -#define ALARMS_H - -#include "systemalarms.h" -#define SYSTEMALARMS_ALARM_DEFAULT SYSTEMALARMS_ALARM_UNINITIALISED - -int32_t AlarmsInitialize(void); -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity); -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm); -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm); -void AlarmsDefaultAll(); -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm); -void AlarmsClearAll(); -int32_t AlarmsHasWarnings(); -int32_t AlarmsHasErrors(); -int32_t AlarmsHasCritical(); - -#endif // ALARMS_H - -/** - * @} - * @} - */ diff --git a/flight/targets/SimPosix/Makefile b/flight/targets/SimPosix/Makefile index 47b90c6ec..6b948a6fd 100644 --- a/flight/targets/SimPosix/Makefile +++ b/flight/targets/SimPosix/Makefile @@ -78,7 +78,7 @@ SRC += ${OUTDIR}/InitMods.c SRC += ${OPMODULEDIR}/System/systemmod.c SRC += $(OPSYSTEM)/simposix.c SRC += $(OPSYSTEM)/pios_board.c -SRC += $(OPSYSTEM)/alarms.c +SRC += $(FLIGHTLIB)/alarms.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c diff --git a/flight/targets/SimPosix/System/alarms.c b/flight/targets/SimPosix/System/alarms.c deleted file mode 100644 index 6ccd5fb62..000000000 --- a/flight/targets/SimPosix/System/alarms.c +++ /dev/null @@ -1,210 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @brief OpenPilot System libraries are available to all OP modules. - * @{ - * @file alarms.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Library for setting and clearing system alarms - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "openpilot.h" -#include "alarms.h" - -// Private constants - -// Private types - -// Private variables -static xSemaphoreHandle lock; - -// Private functions -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity); - -/** - * Initialize the alarms library - */ -int32_t AlarmsInitialize(void) -{ - SystemAlarmsInitialize(); - lock = xSemaphoreCreateRecursiveMutex(); - return 0; -} - -/** - * Set an alarm - * @param alarm The system alarm to be modified - * @param severity The alarm severity - * @return 0 if success, -1 if an error - */ -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return -1; - } - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarm and update its severity only if it was changed - SystemAlarmsGet(&alarms); - if ( alarms.Alarm[alarm] != severity ) - { - alarms.Alarm[alarm] = severity; - SystemAlarmsSet(&alarms); - } - - // Release lock - xSemaphoreGiveRecursive(lock); - return 0; - -} - -/** - * Get an alarm - * @param alarm The system alarm to be read - * @return Alarm severity - */ -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) -{ - SystemAlarmsData alarms; - - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return 0; - } - - // Read alarm - SystemAlarmsGet(&alarms); - return alarms.Alarm[alarm]; -} - -/** - * Set an alarm to it's default value - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_DEFAULT); -} - -/** - * Default all alarms - */ -void AlarmsDefaultAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsDefault(n); - } -} - -/** - * Clear an alarm - * @param alarm The system alarm to be modified - * @return 0 if success, -1 if an error - */ -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) -{ - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); -} - -/** - * Clear all alarms - */ -void AlarmsClearAll() -{ - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsClear(n); - } -} - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasWarnings() -{ - return hasSeverity(SYSTEMALARMS_ALARM_WARNING); -} - -/** - * Check if there are any alarms with error or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasErrors() -{ - return hasSeverity(SYSTEMALARMS_ALARM_ERROR); -}; - -/** - * Check if there are any alarms with critical or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -int32_t AlarmsHasCritical() -{ - return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); -}; - -/** - * Check if there are any alarms with the given or higher severity - * @return 0 if no alarms are found, 1 if at least one alarm is found - */ -static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) -{ - SystemAlarmsData alarms; - uint32_t n; - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - - // Read alarms - SystemAlarmsGet(&alarms); - - // Go through alarms and check if any are of the given severity or higher - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - if ( alarms.Alarm[n] >= severity) - { - xSemaphoreGiveRecursive(lock); - return 1; - } - } - - // If this point is reached then no alarms found - xSemaphoreGiveRecursive(lock); - return 0; -} -/** - * @} - * @} - */ - diff --git a/flight/targets/SimPosix/System/inc/alarms.h b/flight/targets/SimPosix/System/inc/alarms.h deleted file mode 100644 index 0f0faeb8f..000000000 --- a/flight/targets/SimPosix/System/inc/alarms.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @{ - * @file alarms.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include file of the alarm library - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef ALARMS_H -#define ALARMS_H - -#include "systemalarms.h" -#define SYSTEMALARMS_ALARM_DEFAULT SYSTEMALARMS_ALARM_UNINITIALISED - -int32_t AlarmsInitialize(void); -int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity); -SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm); -int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm); -void AlarmsDefaultAll(); -int32_t AlarmsClear(SystemAlarmsAlarmElem alarm); -void AlarmsClearAll(); -int32_t AlarmsHasWarnings(); -int32_t AlarmsHasErrors(); -int32_t AlarmsHasCritical(); - -#endif // ALARMS_H - -/** - * @} - * @} - */ diff --git a/shared/uavobjectdefinition/systemalarms.xml b/shared/uavobjectdefinition/systemalarms.xml index 82da544e2..8780d031d 100644 --- a/shared/uavobjectdefinition/systemalarms.xml +++ b/shared/uavobjectdefinition/systemalarms.xml @@ -1,12 +1,13 @@ - Alarms from OpenPilot to indicate failure conditions or warnings. Set by various modules. + Alarms from OpenPilot to indicate failure conditions or warnings. Set by various modules.Some modules may have a module defined Status and Substatus fields that details its condition + SystemConfiguration + BootFault OutOfMemory StackOverflow CPUOverload - SystemConfiguration EventSystem Telemetry ManualControl @@ -19,10 +20,21 @@ FlightTime I2C GPS - BootFault Power + + + SystemConfiguration + BootFault + + + + + SystemConfiguration + BootFault + + From 23c0c3585c395e932049724d64a65cc83833515a Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Mon, 1 Apr 2013 16:41:12 +0200 Subject: [PATCH 2/9] OP-886 Fixes to styles and includes +review OPReview-430 --- flight/Libraries/alarms.c | 47 +++++++++++++++++-------------- flight/Libraries/sanitycheck.c | 16 +++++++---- flight/Modules/System/systemmod.c | 31 ++++++++++---------- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/flight/Libraries/alarms.c b/flight/Libraries/alarms.c index 6f5d53d8b..2e79a156a 100644 --- a/flight/Libraries/alarms.c +++ b/flight/Libraries/alarms.c @@ -28,7 +28,7 @@ */ #include "openpilot.h" -#include "alarms.h" +#include "inc/alarms.h" // Private constants @@ -71,7 +71,10 @@ int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity } // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); + if(xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0){ + return -1; + } + // Read alarm and update its severity only if it was changed SystemAlarmsGet(&alarms); @@ -99,28 +102,30 @@ int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions { SystemAlarmsData alarms; - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM) - { - return -1; - } + // Check that this is a valid alarm + if (alarm >= SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM) + { + return -1; + } - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); + // Lock + if(xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0){ + return -1; + } - // Read alarm and update its severity only if it was changed - SystemAlarmsGet(&alarms); - if ( alarms.Alarm[alarm] != severity ) - { - alarms.ExtendedAlarmStatus[alarm] = status; - alarms.ExtendedAlarmSubStatus[alarm] = subStatus; - alarms.Alarm[alarm] = severity; - SystemAlarmsSet(&alarms); - } + // Read alarm and update its severity only if it was changed + SystemAlarmsGet(&alarms); + if (alarms.Alarm[alarm] != severity) + { + alarms.ExtendedAlarmStatus[alarm] = status; + alarms.ExtendedAlarmSubStatus[alarm] = subStatus; + alarms.Alarm[alarm] = severity; + SystemAlarmsSet(&alarms); + } - // Release lock - xSemaphoreGiveRecursive(lock); - return 0; + // Release lock + xSemaphoreGiveRecursive(lock); + return 0; } /** diff --git a/flight/Libraries/sanitycheck.c b/flight/Libraries/sanitycheck.c index 18c73ea00..b14fe30e6 100644 --- a/flight/Libraries/sanitycheck.c +++ b/flight/Libraries/sanitycheck.c @@ -26,13 +26,17 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" -#include "taskmonitor.h" +#include #include -#include "sanitycheck.h" -#include "manualcontrolsettings.h" -#include "systemalarms.h" -#include "systemsettings.h" + +// Private includes +#include "inc/taskmonitor.h" +#include "inc/sanitycheck.h" + +// UAVOs +#include +#include +#include /**************************** * Current checks: diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index b857baeac..5e5769b8a 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -38,17 +38,20 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" -#include "systemmod.h" -#include "objectpersistence.h" -#include "flightstatus.h" -#include "systemstats.h" -#include "systemsettings.h" -#include "i2cstats.h" -#include "taskinfo.h" -#include "watchdogstatus.h" -#include "taskmonitor.h" -#include "hwsettings.h" +#include +// private includes +#include "inc/systemmod.h" +// UAVOs +#include +#include +#include +#include +#include +#include +#include +#include +#include +// Flight Libraries #include @@ -337,11 +340,9 @@ static void hwSettingsUpdatedCb(UAVObjEvent * ev) HwSettingsData currentHwSettings; HwSettingsGet(¤tHwSettings); // check whether the Hw Configuration has changed from the one used at boot time - if(!memcmp(&bootHwSettings,¤tHwSettings,sizeof(HwSettingsData))){ - return; + if(memcmp(&bootHwSettings, ¤tHwSettings, sizeof(HwSettingsData)) != 0){ + ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT,SYSTEMALARMS_ALARM_ERROR,BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT, 0); } - - ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT,SYSTEMALARMS_ALARM_ERROR,BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT, 0); } /** From 13dd1178a8c48e4a9181c971534fd761e1e1006f Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Wed, 3 Apr 2013 19:26:25 +0200 Subject: [PATCH 3/9] OP-886 Fixes to styles: testing style settings for Eclipse +review OPReview-430 --- flight/Libraries/alarms.c | 102 +++++++------- flight/Libraries/sanitycheck.c | 240 ++++++++++++++++----------------- 2 files changed, 167 insertions(+), 175 deletions(-) diff --git a/flight/Libraries/alarms.c b/flight/Libraries/alarms.c index 2e79a156a..a2840004d 100644 --- a/flight/Libraries/alarms.c +++ b/flight/Libraries/alarms.c @@ -46,12 +46,12 @@ static int32_t hasSeverity(SystemAlarmsAlarmOptions severity); int32_t AlarmsInitialize(void) { SystemAlarmsInitialize(); - - lock = xSemaphoreCreateRecursiveMutex(); - //do not change the default states of the alarms, let the init code generated by the uavobjectgenerator handle that - //AlarmsClearAll(); - //AlarmsDefaultAll(); - return 0; + + lock = xSemaphoreCreateRecursiveMutex(); + //do not change the default states of the alarms, let the init code generated by the uavobjectgenerator handle that + //AlarmsClearAll(); + //AlarmsDefaultAll(); + return 0; } /** @@ -62,26 +62,23 @@ int32_t AlarmsInitialize(void) */ int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity) { - SystemAlarmsData alarms; + SystemAlarmsData alarms; - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return -1; - } - - // Lock - if(xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0){ + // Check that this is a valid alarm + if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) { return -1; } + // Lock + if (xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0) { + return -1; + } // Read alarm and update its severity only if it was changed SystemAlarmsGet(&alarms); - if ( alarms.Alarm[alarm] != severity ) - { - alarms.Alarm[alarm] = severity; - SystemAlarmsSet(&alarms); + if (alarms.Alarm[alarm] != severity) { + alarms.Alarm[alarm] = severity; + SystemAlarmsSet(&alarms); } // Release lock @@ -103,20 +100,18 @@ int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions SystemAlarmsData alarms; // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM) - { + if (alarm >= SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM) { return -1; } // Lock - if(xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0){ + if (xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0) { return -1; } // Read alarm and update its severity only if it was changed SystemAlarmsGet(&alarms); - if (alarms.Alarm[alarm] != severity) - { + if (alarms.Alarm[alarm] != severity) { alarms.ExtendedAlarmStatus[alarm] = status; alarms.ExtendedAlarmSubStatus[alarm] = subStatus; alarms.Alarm[alarm] = severity; @@ -135,13 +130,12 @@ int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions */ SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) { - SystemAlarmsData alarms; + SystemAlarmsData alarms; - // Check that this is a valid alarm - if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) - { - return 0; - } + // Check that this is a valid alarm + if (alarm >= SYSTEMALARMS_ALARM_NUMELEM) { + return 0; + } // Read alarm SystemAlarmsGet(&alarms); @@ -155,7 +149,7 @@ SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm) */ int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) { - return AlarmsSet(alarm, SYSTEMALARMS_ALARM_DEFAULT); + return AlarmsSet(alarm, SYSTEMALARMS_ALARM_DEFAULT); } /** @@ -163,10 +157,9 @@ int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) */ void AlarmsDefaultAll() { - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsDefault(n); + uint32_t n; + for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { + AlarmsDefault(n); } } @@ -177,7 +170,7 @@ void AlarmsDefaultAll() */ int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) { - if (alarm < SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM){ + if (alarm < SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM) { return ExtendedAlarmsSet(alarm, SYSTEMALARMS_ALARM_OK, 0, 0); } else { return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); @@ -189,10 +182,9 @@ int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) */ void AlarmsClearAll() { - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - AlarmsClear(n); + uint32_t n; + for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { + AlarmsClear(n); } } @@ -202,7 +194,7 @@ void AlarmsClearAll() */ int32_t AlarmsHasWarnings() { - return hasSeverity(SYSTEMALARMS_ALARM_WARNING); + return hasSeverity(SYSTEMALARMS_ALARM_WARNING); } /** @@ -211,8 +203,9 @@ int32_t AlarmsHasWarnings() */ int32_t AlarmsHasErrors() { - return hasSeverity(SYSTEMALARMS_ALARM_ERROR); -}; + return hasSeverity(SYSTEMALARMS_ALARM_ERROR); +} +; /** * Check if there are any alarms with critical or higher severity @@ -220,8 +213,9 @@ int32_t AlarmsHasErrors() */ int32_t AlarmsHasCritical() { - return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); -}; + return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); +} +; /** * Check if there are any alarms with the given or higher severity @@ -229,23 +223,21 @@ int32_t AlarmsHasCritical() */ static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) { - SystemAlarmsData alarms; - uint32_t n; + SystemAlarmsData alarms; + uint32_t n; - // Lock + // Lock xSemaphoreTakeRecursive(lock, portMAX_DELAY); // Read alarms SystemAlarmsGet(&alarms); // Go through alarms and check if any are of the given severity or higher - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) - { - if ( alarms.Alarm[n] >= severity) - { - xSemaphoreGiveRecursive(lock); - return 1; - } + for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { + if (alarms.Alarm[n] >= severity) { + xSemaphoreGiveRecursive(lock); + return 1; + } } // If this point is reached then no alarms found diff --git a/flight/Libraries/sanitycheck.c b/flight/Libraries/sanitycheck.c index b14fe30e6..c98369597 100644 --- a/flight/Libraries/sanitycheck.c +++ b/flight/Libraries/sanitycheck.c @@ -53,102 +53,102 @@ static int32_t check_stabilization_settings(int index, bool multirotor); */ int32_t configuration_check() { - int32_t severity = SYSTEMALARMS_ALARM_OK; - uint8_t alarmstatus = SANITYCHECK_STATUS_ERROR_NONE; - uint8_t alarmsubstatus = 0; - // Get board type - const struct pios_board_info * bdinfo = &pios_board_info_blob; - bool coptercontrol = bdinfo->board_type == 0x04; + int32_t severity = SYSTEMALARMS_ALARM_OK; + uint8_t alarmstatus = SANITYCHECK_STATUS_ERROR_NONE; + uint8_t alarmsubstatus = 0; + // Get board type + const struct pios_board_info * bdinfo = &pios_board_info_blob; + bool coptercontrol = bdinfo->board_type == 0x04; - // Classify airframe type - bool multirotor = true; - uint8_t airframe_type; - SystemSettingsAirframeTypeGet(&airframe_type); - switch(airframe_type) { - case SYSTEMSETTINGS_AIRFRAMETYPE_QUADX: - case SYSTEMSETTINGS_AIRFRAMETYPE_QUADP: - case SYSTEMSETTINGS_AIRFRAMETYPE_HEXA: - case SYSTEMSETTINGS_AIRFRAMETYPE_OCTO: - case SYSTEMSETTINGS_AIRFRAMETYPE_HEXAX: - case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOV: - case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOCOAXP: - case SYSTEMSETTINGS_AIRFRAMETYPE_HEXACOAX: - case SYSTEMSETTINGS_AIRFRAMETYPE_TRI: - multirotor = true; - break; - default: - multirotor = false; - } + // Classify airframe type + bool multirotor = true; + uint8_t airframe_type; + SystemSettingsAirframeTypeGet(&airframe_type); + switch(airframe_type) { + case SYSTEMSETTINGS_AIRFRAMETYPE_QUADX: + case SYSTEMSETTINGS_AIRFRAMETYPE_QUADP: + case SYSTEMSETTINGS_AIRFRAMETYPE_HEXA: + case SYSTEMSETTINGS_AIRFRAMETYPE_OCTO: + case SYSTEMSETTINGS_AIRFRAMETYPE_HEXAX: + case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOV: + case SYSTEMSETTINGS_AIRFRAMETYPE_OCTOCOAXP: + case SYSTEMSETTINGS_AIRFRAMETYPE_HEXACOAX: + case SYSTEMSETTINGS_AIRFRAMETYPE_TRI: + multirotor = true; + break; + default: + multirotor = false; + } - // For each available flight mode position sanity check the available - // modes - uint8_t num_modes; - uint8_t modes[MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_NUMELEM]; - ManualControlSettingsFlightModeNumberGet(&num_modes); - ManualControlSettingsFlightModePositionGet(modes); + // For each available flight mode position sanity check the available + // modes + uint8_t num_modes; + uint8_t modes[MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_NUMELEM]; + ManualControlSettingsFlightModeNumberGet(&num_modes); + ManualControlSettingsFlightModePositionGet(modes); - for(uint32_t i = 0; i < num_modes; i++) { - switch(modes[i]) { - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_MANUAL: - if (multirotor) { - severity = SYSTEMALARMS_ALARM_ERROR; - } - break; - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED1: - severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(1, multirotor) : severity; - break; - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED2: - severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(2, multirotor) : severity; - break; - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED3: - severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(3, multirotor) : severity; - break; - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_AUTOTUNE: - if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_AUTOTUNE)) { - severity = SYSTEMALARMS_ALARM_ERROR; - } - break; - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ALTITUDEHOLD: - if (coptercontrol) { - severity = SYSTEMALARMS_ALARM_ERROR; - } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_ALTITUDEHOLD)) { // Revo supports altitude hold - severity = SYSTEMALARMS_ALARM_ERROR; - } - break; - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_VELOCITYCONTROL: - if (coptercontrol) { - severity = SYSTEMALARMS_ALARM_ERROR; - } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold - severity = SYSTEMALARMS_ALARM_ERROR; - } - break; - case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_POSITIONHOLD: - if (coptercontrol){ - severity = SYSTEMALARMS_ALARM_ERROR; - } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold - severity = SYSTEMALARMS_ALARM_ERROR; - } - break; - default: - // Uncovered modes are automatically an error - severity = SYSTEMALARMS_ALARM_ERROR; - } - // mark the first encountered erroneous setting in status and substatus - if(severity != SYSTEMALARMS_ALARM_OK && alarmstatus == SANITYCHECK_STATUS_ERROR_NONE) - { - alarmstatus = SANITYCHECK_STATUS_ERROR_FLIGHTMODE; - alarmsubstatus = i; - } + for(uint32_t i = 0; i < num_modes; i++) { + switch(modes[i]) { + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_MANUAL: + if (multirotor) { + severity = SYSTEMALARMS_ALARM_ERROR; + } + break; + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED1: + severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(1, multirotor) : severity; + break; + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED2: + severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(2, multirotor) : severity; + break; + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED3: + severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(3, multirotor) : severity; + break; + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_AUTOTUNE: + if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_AUTOTUNE)) { + severity = SYSTEMALARMS_ALARM_ERROR; + } + break; + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ALTITUDEHOLD: + if (coptercontrol) { + severity = SYSTEMALARMS_ALARM_ERROR; + } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_ALTITUDEHOLD)) { // Revo supports altitude hold + severity = SYSTEMALARMS_ALARM_ERROR; + } + break; + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_VELOCITYCONTROL: + if (coptercontrol) { + severity = SYSTEMALARMS_ALARM_ERROR; + } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold + severity = SYSTEMALARMS_ALARM_ERROR; + } + break; + case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_POSITIONHOLD: + if (coptercontrol){ + severity = SYSTEMALARMS_ALARM_ERROR; + } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold + severity = SYSTEMALARMS_ALARM_ERROR; + } + break; + default: + // Uncovered modes are automatically an error + severity = SYSTEMALARMS_ALARM_ERROR; + } + // mark the first encountered erroneous setting in status and substatus + if(severity != SYSTEMALARMS_ALARM_OK && alarmstatus == SANITYCHECK_STATUS_ERROR_NONE) + { + alarmstatus = SANITYCHECK_STATUS_ERROR_FLIGHTMODE; + alarmsubstatus = i; + } - } + } - // TODO: Check on a multirotor no axis supports "None" - if(severity != SYSTEMALARMS_ALARM_OK) - ExtendedAlarmsSet(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION, severity, alarmstatus, alarmsubstatus); - else - AlarmsClear(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION); + // TODO: Check on a multirotor no axis supports "None" + if(severity != SYSTEMALARMS_ALARM_OK) + ExtendedAlarmsSet(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION, severity, alarmstatus, alarmsubstatus); + else + AlarmsClear(SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION); - return 0; + return 0; } /** @@ -159,39 +159,39 @@ int32_t configuration_check() */ static int32_t check_stabilization_settings(int index, bool multirotor) { - // Make sure the modes have identical sizes - if (MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM != MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_NUMELEM || - MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM != MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_NUMELEM) - return SYSTEMALARMS_ALARM_ERROR; + // Make sure the modes have identical sizes + if (MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM != MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_NUMELEM || + MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM != MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_NUMELEM) + return SYSTEMALARMS_ALARM_ERROR; - uint8_t modes[MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM]; + uint8_t modes[MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NUMELEM]; - // Get the different axis modes for this switch position - switch(index) { - case 1: - ManualControlSettingsStabilization1SettingsGet(modes); - break; - case 2: - ManualControlSettingsStabilization2SettingsGet(modes); - break; - case 3: - ManualControlSettingsStabilization3SettingsGet(modes); - break; - default: - return SYSTEMALARMS_ALARM_ERROR; - } + // Get the different axis modes for this switch position + switch(index) { + case 1: + ManualControlSettingsStabilization1SettingsGet(modes); + break; + case 2: + ManualControlSettingsStabilization2SettingsGet(modes); + break; + case 3: + ManualControlSettingsStabilization3SettingsGet(modes); + break; + default: + return SYSTEMALARMS_ALARM_ERROR; + } - // For multirotors verify that nothing is set to "none" - if (multirotor) { - for(uint32_t i = 0; i < NELEMENTS(modes); i++) { - if (modes[i] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NONE) - return SYSTEMALARMS_ALARM_ERROR; - } - } + // For multirotors verify that nothing is set to "none" + if (multirotor) { + for(uint32_t i = 0; i < NELEMENTS(modes); i++) { + if (modes[i] == MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NONE) + return SYSTEMALARMS_ALARM_ERROR; + } + } - // Warning: This assumes that certain conditions in the XML file are met. That - // MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NONE has the same numeric value for each channel - // and is the same for STABILIZATIONDESIRED_STABILIZATIONMODE_NONE + // Warning: This assumes that certain conditions in the XML file are met. That + // MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_NONE has the same numeric value for each channel + // and is the same for STABILIZATIONDESIRED_STABILIZATIONMODE_NONE - return SYSTEMALARMS_ALARM_OK; + return SYSTEMALARMS_ALARM_OK; } From f30692836a4971a78a848d0bd06ce26c712a1765 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Thu, 4 Apr 2013 20:11:57 +0200 Subject: [PATCH 4/9] OP-886 Fixes to styles +review OPReview-430 --- flight/Libraries/alarms.c | 4 ++-- flight/Modules/System/systemmod.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/flight/Libraries/alarms.c b/flight/Libraries/alarms.c index a2840004d..c9cddee6d 100644 --- a/flight/Libraries/alarms.c +++ b/flight/Libraries/alarms.c @@ -205,7 +205,7 @@ int32_t AlarmsHasErrors() { return hasSeverity(SYSTEMALARMS_ALARM_ERROR); } -; + /** * Check if there are any alarms with critical or higher severity @@ -215,7 +215,7 @@ int32_t AlarmsHasCritical() { return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL); } -; + /** * Check if there are any alarms with the given or higher severity diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 5e5769b8a..5de110488 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -340,8 +340,8 @@ static void hwSettingsUpdatedCb(UAVObjEvent * ev) HwSettingsData currentHwSettings; HwSettingsGet(¤tHwSettings); // check whether the Hw Configuration has changed from the one used at boot time - if(memcmp(&bootHwSettings, ¤tHwSettings, sizeof(HwSettingsData)) != 0){ - ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT,SYSTEMALARMS_ALARM_ERROR,BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT, 0); + if (memcmp(&bootHwSettings, ¤tHwSettings, sizeof(HwSettingsData)) != 0) { + ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_ERROR, BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT, 0); } } From 72a2d1a50e8123735199404c676f0659d8734baa Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Fri, 19 Apr 2013 18:47:56 +0300 Subject: [PATCH 5/9] style: use 2 spaces and full stop for UAVO comments (as used in other objects) +review OPReview-430 --- shared/uavobjectdefinition/systemalarms.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/uavobjectdefinition/systemalarms.xml b/shared/uavobjectdefinition/systemalarms.xml index 8780d031d..e3d12baa6 100644 --- a/shared/uavobjectdefinition/systemalarms.xml +++ b/shared/uavobjectdefinition/systemalarms.xml @@ -1,6 +1,6 @@ - Alarms from OpenPilot to indicate failure conditions or warnings. Set by various modules.Some modules may have a module defined Status and Substatus fields that details its condition + Alarms from OpenPilot to indicate failure conditions or warnings. Set by various modules. Some modules may have a module defined Status and Substatus fields that details its condition. SystemConfiguration From 343a4b9015f8fa577987bc12691ae6de10f8f939 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Sat, 20 Apr 2013 00:56:45 +0300 Subject: [PATCH 6/9] OP-886: cosmetic style and spacing fixes --- flight/Libraries/alarms.c | 11 ++++------- flight/Modules/System/systemmod.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/flight/Libraries/alarms.c b/flight/Libraries/alarms.c index 94a1006ef..e0da51185 100644 --- a/flight/Libraries/alarms.c +++ b/flight/Libraries/alarms.c @@ -157,8 +157,7 @@ int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm) */ void AlarmsDefaultAll() { - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { + for (uint32_t n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { AlarmsDefault(n); } } @@ -182,8 +181,7 @@ int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) */ void AlarmsClearAll() { - uint32_t n; - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { + for (uint32_t n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { AlarmsClear(n); } } @@ -224,7 +222,6 @@ int32_t AlarmsHasCritical() static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) { SystemAlarmsData alarms; - uint32_t n; // Lock xSemaphoreTakeRecursive(lock, portMAX_DELAY); @@ -233,7 +230,7 @@ static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) SystemAlarmsGet(&alarms); // Go through alarms and check if any are of the given severity or higher - for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { + for (uint32_t n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n) { if (alarms.Alarm[n] >= severity) { xSemaphoreGiveRecursive(lock); return 1; @@ -244,8 +241,8 @@ static int32_t hasSeverity(SystemAlarmsAlarmOptions severity) xSemaphoreGiveRecursive(lock); return 0; } + /** * @} * @} */ - diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 5de110488..4b8cc6772 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -39,8 +39,10 @@ */ #include + // private includes #include "inc/systemmod.h" + // UAVOs #include #include @@ -51,6 +53,7 @@ #include #include #include + // Flight Libraries #include @@ -69,8 +72,8 @@ #ifndef IDLE_COUNTS_PER_SEC_AT_NO_LOAD #define IDLE_COUNTS_PER_SEC_AT_NO_LOAD 995998 // calibrated by running tests/test_cpuload.c - // must be updated if the FreeRTOS or compiler - // optimisation options are changed. + // must be updated if the FreeRTOS or compiler + // optimisation options are changed. #endif #if defined(PIOS_SYSTEM_STACK_SIZE) @@ -177,8 +180,8 @@ static void systemTask(void *parameters) // Listen for SettingPersistance object updates, connect a callback function ObjectPersistenceConnectQueue(objectPersistenceQueue); - // Load a copy of HwSetting active at boot time - HwSettingsGet(&bootHwSettings); + // Load a copy of HwSetting active at boot time + HwSettingsGet(&bootHwSettings); // Whenever the configuration changes, make sure it is safe to fly HwSettingsConnectCallback(hwSettingsUpdatedCb); @@ -314,7 +317,7 @@ static void objectUpdatedCb(UAVObjEvent * ev) #if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) retval = PIOS_FLASHFS_Format(0); #else - retval = -1; + retval = -1; #endif } switch(retval) { From 220b4b504256341512a5ec90a47e9059a45036ce Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Sat, 20 Apr 2013 02:10:40 +0300 Subject: [PATCH 7/9] OP-886: use enum for extended alarm status field See also: http://reviews.openpilot.org/cru/OPReview-430 http://progress.openpilot.org/browse/OP-915 --- flight/Libraries/alarms.c | 11 +++++++---- flight/Libraries/inc/alarms.h | 5 ++++- flight/Libraries/inc/sanitycheck.h | 8 +------- flight/Libraries/sanitycheck.c | 7 +++---- flight/Modules/System/systemmod.c | 2 +- shared/uavobjectdefinition/systemalarms.xml | 7 ++++++- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/flight/Libraries/alarms.c b/flight/Libraries/alarms.c index e0da51185..b3706ba24 100644 --- a/flight/Libraries/alarms.c +++ b/flight/Libraries/alarms.c @@ -91,11 +91,14 @@ int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity * Set an Extended Alarm * @param alarm The system alarm to be modified * @param severity The alarm severity - * @param status: the Extended alarm status field - * @param subStatus: the Extended alarm substatus field + * @param status The Extended alarm status field + * @param subStatus The Extended alarm substatus field * @return 0 if success, -1 if an error */ -int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity, uint8_t status, uint8_t subStatus) +int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, + SystemAlarmsAlarmOptions severity, + SystemAlarmsExtendedAlarmStatusOptions status, + uint8_t subStatus) { SystemAlarmsData alarms; @@ -170,7 +173,7 @@ void AlarmsDefaultAll() int32_t AlarmsClear(SystemAlarmsAlarmElem alarm) { if (alarm < SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM) { - return ExtendedAlarmsSet(alarm, SYSTEMALARMS_ALARM_OK, 0, 0); + return ExtendedAlarmsSet(alarm, SYSTEMALARMS_ALARM_OK, SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE, 0); } else { return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK); } diff --git a/flight/Libraries/inc/alarms.h b/flight/Libraries/inc/alarms.h index dc785015e..e91a3be55 100644 --- a/flight/Libraries/inc/alarms.h +++ b/flight/Libraries/inc/alarms.h @@ -33,7 +33,10 @@ int32_t AlarmsInitialize(void); int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity); -int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity, uint8_t status, uint8_t subStatus); +int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, + SystemAlarmsAlarmOptions severity, + SystemAlarmsExtendedAlarmStatusOptions status, + uint8_t subStatus); SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm); int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm); void AlarmsDefaultAll(); diff --git a/flight/Libraries/inc/sanitycheck.h b/flight/Libraries/inc/sanitycheck.h index 9ee72f3c5..b7fd74ca3 100644 --- a/flight/Libraries/inc/sanitycheck.h +++ b/flight/Libraries/inc/sanitycheck.h @@ -29,15 +29,9 @@ #ifndef SANITYCHECK_H #define SANITYCHECK_H -#define SANITYCHECK_STATUS_ERROR_NONE 0 -#define SANITYCHECK_STATUS_ERROR_FLIGHTMODE 1 - -#define BOOTFAULT_STATUS_ERROR_NONE 0 -#define BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT 1 - #if (SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM != SYSTEMALARMS_EXTENDEDALARMSUBSTATUS_NUMELEM) || \ (SYSTEMALARMS_EXTENDEDALARMSUBSTATUS_NUMELEM > SYSTEMALARMS_ALARM_NUMELEM) -#error incongruent SystemAlarms. Please revise the UAVO definition in SystemAlarm.xml +#error Incongruent SystemAlarms. Please revise the UAVO definition in systemalarms.xml #endif extern int32_t configuration_check(); diff --git a/flight/Libraries/sanitycheck.c b/flight/Libraries/sanitycheck.c index c98369597..07940d764 100644 --- a/flight/Libraries/sanitycheck.c +++ b/flight/Libraries/sanitycheck.c @@ -54,7 +54,7 @@ static int32_t check_stabilization_settings(int index, bool multirotor); int32_t configuration_check() { int32_t severity = SYSTEMALARMS_ALARM_OK; - uint8_t alarmstatus = SANITYCHECK_STATUS_ERROR_NONE; + SystemAlarmsExtendedAlarmStatusOptions alarmstatus = SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE; uint8_t alarmsubstatus = 0; // Get board type const struct pios_board_info * bdinfo = &pios_board_info_blob; @@ -134,9 +134,8 @@ int32_t configuration_check() severity = SYSTEMALARMS_ALARM_ERROR; } // mark the first encountered erroneous setting in status and substatus - if(severity != SYSTEMALARMS_ALARM_OK && alarmstatus == SANITYCHECK_STATUS_ERROR_NONE) - { - alarmstatus = SANITYCHECK_STATUS_ERROR_FLIGHTMODE; + if ((severity != SYSTEMALARMS_ALARM_OK) && (alarmstatus == SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE)) { + alarmstatus = SYSTEMALARMS_EXTENDEDALARMSTATUS_FLIGHTMODE; alarmsubstatus = i; } diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 4b8cc6772..b3f5f6db8 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -344,7 +344,7 @@ static void hwSettingsUpdatedCb(UAVObjEvent * ev) HwSettingsGet(¤tHwSettings); // check whether the Hw Configuration has changed from the one used at boot time if (memcmp(&bootHwSettings, ¤tHwSettings, sizeof(HwSettingsData)) != 0) { - ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_ERROR, BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT, 0); + ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_ERROR, SYSTEMALARMS_EXTENDEDALARMSTATUS_REBOOTREQUIRED, 0); } } diff --git a/shared/uavobjectdefinition/systemalarms.xml b/shared/uavobjectdefinition/systemalarms.xml index b34bd1612..fedeef14a 100644 --- a/shared/uavobjectdefinition/systemalarms.xml +++ b/shared/uavobjectdefinition/systemalarms.xml @@ -23,11 +23,16 @@ Power - + SystemConfiguration BootFault + + + + + From dd37c31a0713ccdf82a8566d267192a8f16550dd Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 20 Apr 2013 13:59:25 +0200 Subject: [PATCH 8/9] OP-886 Fixes to styles, used enum for ExtendedAlarmStatus Conflicts: flight/Libraries/inc/sanitycheck.h shared/uavobjectdefinition/systemalarms.xml --- flight/Libraries/inc/sanitycheck.h | 8 ++++++++ flight/Libraries/sanitycheck.c | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/flight/Libraries/inc/sanitycheck.h b/flight/Libraries/inc/sanitycheck.h index b7fd74ca3..214b50cfc 100644 --- a/flight/Libraries/inc/sanitycheck.h +++ b/flight/Libraries/inc/sanitycheck.h @@ -26,9 +26,17 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #ifndef SANITYCHECK_H #define SANITYCHECK_H +#define SANITYCHECK_STATUS_ERROR_NONE SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE +#define SANITYCHECK_STATUS_ERROR_FLIGHTMODE SYSTEMALARMS_EXTENDEDALARMSTATUS_FLIGHTMODE + +#define BOOTFAULT_STATUS_ERROR_NONE SYSTEMALARMS_EXTENDEDALARMSTATUS_NONE +#define BOOTFAULT_STATUS_ERROR_REQUIRE_REBOOT SYSTEMALARMS_EXTENDEDALARMSTATUS_REBOOTREQUIRED + #if (SYSTEMALARMS_EXTENDEDALARMSTATUS_NUMELEM != SYSTEMALARMS_EXTENDEDALARMSUBSTATUS_NUMELEM) || \ (SYSTEMALARMS_EXTENDEDALARMSUBSTATUS_NUMELEM > SYSTEMALARMS_ALARM_NUMELEM) #error Incongruent SystemAlarms. Please revise the UAVO definition in systemalarms.xml diff --git a/flight/Libraries/sanitycheck.c b/flight/Libraries/sanitycheck.c index 07940d764..75c1fd6b2 100644 --- a/flight/Libraries/sanitycheck.c +++ b/flight/Libraries/sanitycheck.c @@ -35,7 +35,6 @@ // UAVOs #include -#include #include /**************************** From 8011a9476d26f3dada48778d14d3906ddf1d22fa Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 20 Apr 2013 15:24:12 +0200 Subject: [PATCH 9/9] OP-886 fixed a bug caused by wrong check for xSemaphoreTakeRecursive return code Conflicts: flight/Libraries/alarms.c --- flight/Libraries/alarms.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/flight/Libraries/alarms.c b/flight/Libraries/alarms.c index b3706ba24..78238a3bf 100644 --- a/flight/Libraries/alarms.c +++ b/flight/Libraries/alarms.c @@ -70,9 +70,7 @@ int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity } // Lock - if (xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0) { - return -1; - } + xSemaphoreTakeRecursive(lock, portMAX_DELAY); // Read alarm and update its severity only if it was changed SystemAlarmsGet(&alarms); @@ -108,9 +106,7 @@ int32_t ExtendedAlarmsSet(SystemAlarmsAlarmElem alarm, } // Lock - if (xSemaphoreTakeRecursive(lock, portMAX_DELAY) != 0) { - return -1; - } + xSemaphoreTakeRecursive(lock, portMAX_DELAY); // Read alarm and update its severity only if it was changed SystemAlarmsGet(&alarms);