2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
5 * @addtogroup FaultModule Fault Module
6 * @brief Insert various fault conditions for testing
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
11 * @brief Fault module, inserts faults for testing
12 * @see The GNU Public License (GPL) Version 3
14 *****************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "openpilot.h"
35 #include "hwsettings.h"
36 #include "faultsettings.h"
38 static bool module_enabled
;
39 static uint8_t active_fault
;
41 static int32_t fault_initialize(void)
43 #ifdef MODULE_FAULT_BUILTIN
44 module_enabled
= true;
46 HwSettingsInitialize();
47 uint8_t optionalModules
[HWSETTINGS_OPTIONALMODULES_NUMELEM
];
49 HwSettingsOptionalModulesGet(optionalModules
);
51 if (optionalModules
[HWSETTINGS_OPTIONALMODULES_FAULT
] == HWSETTINGS_OPTIONALMODULES_ENABLED
) {
52 module_enabled
= true;
54 module_enabled
= false;
58 /* Do this outside the module_enabled test so that it
59 * can be changed even when the module has been disabled.
60 * This is important so we can remove faults even when
61 * we've booted in BootFault recovery mode with all optional
64 FaultSettingsInitialize();
67 FaultSettingsActivateFaultGet(&active_fault
);
69 switch (active_fault
) {
70 case FAULTSETTINGS_ACTIVATEFAULT_MODULEINITASSERT
:
71 /* Simulate an assert during module init */
74 case FAULTSETTINGS_ACTIVATEFAULT_INITOUTOFMEMORY
:
75 /* Leak all available memory */
76 while (pios_malloc(10)) {
80 case FAULTSETTINGS_ACTIVATEFAULT_INITBUSERROR
:
82 /* Force a bad access */
83 uint32_t *bad_ptr
= (uint32_t *)0xFFFFFFFF;
84 *bad_ptr
= 0xAA55AA55;
93 static void fault_task(void *parameters
);
95 static int32_t fault_start(void)
97 xTaskHandle fault_task_handle
;
100 switch (active_fault
) {
101 case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK
:
102 case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY
:
103 xTaskCreate(fault_task
,
104 (signed char *)"Fault",
105 configMINIMAL_STACK_SIZE
,
107 configMAX_PRIORITIES
- 1,
116 MODULE_INITCALL(fault_initialize
, fault_start
);
118 static void fault_task(__attribute__((unused
)) void *parameters
)
120 switch (active_fault
) {
121 case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK
:
122 /* Consume all realtime, not letting the systemtask run */
127 case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY
:
128 /* Leak all available memory and then sleep */
129 while (pios_malloc(10)) {