LP-500 HoTT Telemetry added device definitions
[librepilot.git] / flight / modules / Fault / Fault.c
blob42faa781f329dfea2f2e30c07599494615805848
1 /**
2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
4 * @{
5 * @addtogroup FaultModule Fault Module
6 * @brief Insert various fault conditions for testing
7 * @{
9 * @file Fault.c
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
24 * for more details.
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
31 // ****************
33 #include "openpilot.h"
34 #include <stdbool.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;
45 #else
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;
53 } else {
54 module_enabled = false;
56 #endif
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
62 * modules disabled.
64 FaultSettingsInitialize();
66 if (module_enabled) {
67 FaultSettingsActivateFaultGet(&active_fault);
69 switch (active_fault) {
70 case FAULTSETTINGS_ACTIVATEFAULT_MODULEINITASSERT:
71 /* Simulate an assert during module init */
72 PIOS_Assert(0);
73 break;
74 case FAULTSETTINGS_ACTIVATEFAULT_INITOUTOFMEMORY:
75 /* Leak all available memory */
76 while (pios_malloc(10)) {
79 break;
80 case FAULTSETTINGS_ACTIVATEFAULT_INITBUSERROR:
82 /* Force a bad access */
83 uint32_t *bad_ptr = (uint32_t *)0xFFFFFFFF;
84 *bad_ptr = 0xAA55AA55;
86 break;
90 return 0;
93 static void fault_task(void *parameters);
95 static int32_t fault_start(void)
97 xTaskHandle fault_task_handle;
99 if (module_enabled) {
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,
106 NULL,
107 configMAX_PRIORITIES - 1,
108 &fault_task_handle);
109 return 0;
111 break;
114 return -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 */
123 while (1) {
126 break;
127 case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY:
128 /* Leak all available memory and then sleep */
129 while (pios_malloc(10)) {
132 while (1) {
133 vTaskDelay(1000);
135 break;
140 * @}
141 * @}