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 uint8_t optionalModules
[HWSETTINGS_OPTIONALMODULES_NUMELEM
];
48 HwSettingsOptionalModulesGet(optionalModules
);
50 if (optionalModules
[HWSETTINGS_OPTIONALMODULES_FAULT
] == HWSETTINGS_OPTIONALMODULES_ENABLED
) {
51 module_enabled
= true;
53 module_enabled
= false;
57 /* Do this outside the module_enabled test so that it
58 * can be changed even when the module has been disabled.
59 * This is important so we can remove faults even when
60 * we've booted in BootFault recovery mode with all optional
65 FaultSettingsActivateFaultGet(&active_fault
);
67 switch (active_fault
) {
68 case FAULTSETTINGS_ACTIVATEFAULT_MODULEINITASSERT
:
69 /* Simulate an assert during module init */
72 case FAULTSETTINGS_ACTIVATEFAULT_INITOUTOFMEMORY
:
73 /* Leak all available memory */
74 while (pios_malloc(10)) {
78 case FAULTSETTINGS_ACTIVATEFAULT_INITBUSERROR
:
80 /* Force a bad access */
81 uint32_t *bad_ptr
= (uint32_t *)0xFFFFFFFF;
82 *bad_ptr
= 0xAA55AA55;
91 static void fault_task(void *parameters
);
93 static int32_t fault_start(void)
95 xTaskHandle fault_task_handle
;
98 switch (active_fault
) {
99 case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK
:
100 case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY
:
101 xTaskCreate(fault_task
,
102 (signed char *)"Fault",
103 configMINIMAL_STACK_SIZE
,
105 configMAX_PRIORITIES
- 1,
114 MODULE_INITCALL(fault_initialize
, fault_start
);
116 static void fault_task(__attribute__((unused
)) void *parameters
)
118 switch (active_fault
) {
119 case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK
:
120 /* Consume all realtime, not letting the systemtask run */
125 case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY
:
126 /* Leak all available memory and then sleep */
127 while (pios_malloc(10)) {