NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
failsafe.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include "system_calls.h"
21 #include "../config/failsafe.h"
22 
23 #define FAILSAFE_POWER_ON_DELAY_US (1000 * 1000 * 5)
24 #define MILLIS_PER_TENTH_SECOND 100
25 #define MILLIS_PER_SECOND 1000
26 #define PERIOD_OF_1_SECONDS 1 * MILLIS_PER_SECOND
27 #define PERIOD_OF_3_SECONDS 3 * MILLIS_PER_SECOND
28 #define PERIOD_OF_30_SECONDS 30 * MILLIS_PER_SECOND
29 #define PERIOD_RXDATA_FAILURE 200 // millis
30 #define PERIOD_RXDATA_RECOVERY 200 // millis
31 
32 typedef enum {
40 
41 typedef enum {
45 
46 struct failsafe {
47  int16_t events;
48  bool monitoring;
49  bool active;
53  sys_millis_t throttleLowPeriod; // throttle stick must have been below 'min_check' for this period
55  sys_millis_t receivingRxDataPeriod; // period for the required period of valid rxData
56  sys_millis_t receivingRxDataPeriodPreset; // preset for the required period of valid rxData
59 
60  struct ninja *ninja;
61  const struct config *config;
62 };
63 
64 void failsafe_init(struct failsafe *self, struct ninja *ninja, const struct config *config);
65 
66 void failsafe_start_monitoring(struct failsafe *self);
67 void failsafe_update(struct failsafe *self);
68 
69 void failsafe_reset(struct failsafe *self);
71 bool failsafe_is_monitoring(struct failsafe *self);
72 bool failsafe_is_active(struct failsafe *self);
73 bool failsafe_is_receiving_rx(struct failsafe *self);
74 void failsafe_on_rx_suspend(struct failsafe *self, uint32_t suspendPeriod);
75 void failsafe_on_rx_resume(struct failsafe *self);
76 
77 void failsafe_on_valid_data_received(struct failsafe *self);
78 void failsafe_on_valid_data_failed(struct failsafe *self);
Definition: config.h:81
Definition: ninja.h:40
bool failsafe_is_monitoring(struct failsafe *self)
Definition: failsafe.c:66
failsafeRxLinkState_e rxLinkState
Definition: failsafe.h:58
sys_millis_t landingShouldBeFinishedAt
Definition: failsafe.h:54
Definition: failsafe.h:46
uint32_t validRxDataFailedAt
Definition: failsafe.h:52
void failsafe_reset(struct failsafe *self)
Definition: failsafe.c:41
void failsafe_on_rx_resume(struct failsafe *self)
Definition: failsafe.c:109
int16_t events
Definition: failsafe.h:47
sys_millis_t receivingRxDataPeriod
Definition: failsafe.h:55
Definition: failsafe.h:37
int32_t sys_millis_t
Definition: system_calls.h:6
sys_millis_t receivingRxDataPeriodPreset
Definition: failsafe.h:56
Definition: failsafe.h:43
bool active
Definition: failsafe.h:49
void failsafe_on_valid_data_received(struct failsafe *self)
Definition: failsafe.c:114
void failsafe_init(struct failsafe *self, struct ninja *ninja, const struct config *config)
bool failsafe_is_active(struct failsafe *self)
Definition: failsafe.c:70
Definition: failsafe.h:36
failsafePhase_e phase
Definition: failsafe.h:57
Definition: failsafe.h:38
void failsafe_start_monitoring(struct failsafe *self)
Definition: failsafe.c:74
bool failsafe_is_receiving_rx(struct failsafe *self)
Definition: failsafe.c:101
failsafePhase_e failsafe_get_state(struct failsafe *self)
Definition: failsafe.c:62
Definition: failsafe.h:34
void failsafe_update(struct failsafe *self)
Definition: failsafe.c:128
uint32_t validRxDataReceivedAt
Definition: failsafe.h:51
void failsafe_on_valid_data_failed(struct failsafe *self)
Definition: failsafe.c:121
bool monitoring
Definition: failsafe.h:48
Definition: failsafe.h:33
uint32_t rxDataFailurePeriod
Definition: failsafe.h:50
const struct config * config
Definition: failsafe.h:61
sys_millis_t throttleLowPeriod
Definition: failsafe.h:53
struct ninja * ninja
Definition: failsafe.h:60
failsafePhase_e
Definition: failsafe.h:32
failsafeRxLinkState_e
Definition: failsafe.h:41
Definition: failsafe.h:42
void failsafe_on_rx_suspend(struct failsafe *self, uint32_t suspendPeriod)
Definition: failsafe.c:105
Definition: failsafe.h:35