diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 7b4fb96f2..a6136a416 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -70,6 +70,10 @@ ifeq ($(USE_GPS), YES) OPTMODULES += GPS endif +ifeq ($(TEST_FAULTS), YES) +OPTMODULES += Fault +endif + MODULES = Attitude Stabilization Actuator ManualControl FirmwareIAP # Telemetry must be last to grab the optional modules (why?) MODULES += Telemetry @@ -151,6 +155,7 @@ SRC += $(OPUAVSYNTHDIR)/accessorydesired.c SRC += $(OPUAVSYNTHDIR)/objectpersistence.c SRC += $(OPUAVSYNTHDIR)/gcstelemetrystats.c SRC += $(OPUAVSYNTHDIR)/flighttelemetrystats.c +SRC += $(OPUAVSYNTHDIR)/faultsettings.c SRC += $(OPUAVSYNTHDIR)/flightstatus.c SRC += $(OPUAVSYNTHDIR)/systemstats.c SRC += $(OPUAVSYNTHDIR)/systemalarms.c diff --git a/flight/Modules/Fault/Fault.c b/flight/Modules/Fault/Fault.c new file mode 100644 index 000000000..a76ebb4ec --- /dev/null +++ b/flight/Modules/Fault/Fault.c @@ -0,0 +1,131 @@ +/** + ****************************************************************************** + * @addtogroup OpenPilotModules OpenPilot Modules + * @{ + * @addtogroup FaultModule Fault Module + * @brief Insert various fault conditions for testing + * @{ + * + * @file FaultInsertion.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Fault module, inserts faults for testing + * @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 +#include "hwsettings.h" +#include "faultsettings.h" + +static bool module_enabled; +static uint8_t active_fault; + +static int32_t fault_initialize(void) +{ + HwSettingsInitialize(); + uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; + + HwSettingsOptionalModulesGet(optionalModules); + + if (optionalModules[HWSETTINGS_OPTIONALMODULES_FAULT] == HWSETTINGS_OPTIONALMODULES_ENABLED) { + module_enabled = true; + } else { + module_enabled = false; + } + + /* Do this outside the module_enabled test so that it + * can be changed even when the module has been disabled. + * This is important so we can remove faults even when + * we've booted in BootFault recovery mode with all optional + * modules disabled. + */ + FaultSettingsInitialize(); + + if (module_enabled) { + FaultSettingsActivateFaultGet(&active_fault); + + switch (active_fault) { + case FAULTSETTINGS_ACTIVATEFAULT_MODULEINITASSERT: + /* Simulate an assert during module init */ + PIOS_Assert(0); + break; + case FAULTSETTINGS_ACTIVATEFAULT_INITOUTOFMEMORY: + /* Leak all available memory */ + while (pvPortMalloc(10)) ; + break; + case FAULTSETTINGS_ACTIVATEFAULT_INITBUSERROR: + { + /* Force a bad access */ + uint32_t * bad_ptr = (uint32_t *)0xFFFFFFFF; + *bad_ptr = 0xAA55AA55; + } + break; + } + } + + return 0; +} + +static void fault_task(void *parameters); + +static int32_t fault_start(void) +{ + xTaskHandle fault_task_handle; + + if (module_enabled) { + switch (active_fault) { + case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK: + case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY: + xTaskCreate(fault_task, + (signed char *)"Fault", + configMINIMAL_STACK_SIZE, + NULL, + configMAX_PRIORITIES-1, + &fault_task_handle); + return 0; + break; + } + } + return -1; +} +MODULE_INITCALL(fault_initialize, fault_start) + +static void fault_task(void *parameters) +{ + switch (active_fault) { + case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK: + /* Consume all realtime, not letting the systemtask run */ + while(1); + break; + case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY: + /* Leak all available memory and then sleep */ + while (pvPortMalloc(10)) ; + while (1) { + vTaskDelay(1000); + } + break; + } +} + +/** + * @} + * @} + */ diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro index 511253626..0b17a6755 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro @@ -72,7 +72,8 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \ $$UAVOBJECT_SYNTHETICS/gcsreceiver.h \ $$UAVOBJECT_SYNTHETICS/receiveractivity.h \ $$UAVOBJECT_SYNTHETICS/attitudesettings.h \ - $$UAVOBJECT_SYNTHETICS/cameradesired.h + $$UAVOBJECT_SYNTHETICS/cameradesired.h \ + $$UAVOBJECT_SYNTHETICS/faultsettings.h SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \ $$UAVOBJECT_SYNTHETICS/ahrsstatus.cpp \ @@ -124,4 +125,5 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \ $$UAVOBJECT_SYNTHETICS/gcsreceiver.cpp \ $$UAVOBJECT_SYNTHETICS/receiveractivity.cpp \ $$UAVOBJECT_SYNTHETICS/attitudesettings.cpp \ - $$UAVOBJECT_SYNTHETICS/cameradesired.cpp + $$UAVOBJECT_SYNTHETICS/cameradesired.cpp \ + $$UAVOBJECT_SYNTHETICS/faultsettings.cpp diff --git a/shared/uavobjectdefinition/faultsettings.xml b/shared/uavobjectdefinition/faultsettings.xml new file mode 100644 index 000000000..8d02f0d78 --- /dev/null +++ b/shared/uavobjectdefinition/faultsettings.xml @@ -0,0 +1,12 @@ + + + Allows testers to simulate various fault scenarios. + + + + + + + + + diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 263d5f279..1e34e0808 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -15,7 +15,7 @@ - +