Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
inter_mcu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2005 Pascal Brisset, Antoine Drouin
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
32 #ifndef INTER_MCU_H
33 #define INTER_MCU_H
34 
35 
36 #ifdef INTER_MCU
37 
38 #include <inttypes.h>
39 
40 #include "std.h"
41 
42 #include "paparazzi.h"
43 #include "generated/airframe.h"
45 #include "subsystems/electrical.h"
47 
48 
50 struct fbw_state {
51 #if defined RADIO_CONTROL || RADIO_CONTROL_AUTO1
53  uint8_t ppm_cpt;
54 #endif
56  uint8_t nb_err;
59  float energy;
60 };
61 
62 struct ap_state {
63  pprz_t commands[COMMANDS_NB];
67 };
68 
69 // Status bits from FBW to AUTOPILOT
70 #define STATUS_RADIO_OK 0
71 #define STATUS_RADIO_REALLY_LOST 1
72 #define STATUS_MODE_AUTO 2
73 #define STATUS_MODE_FAILSAFE 3
74 #define AVERAGED_CHANNELS_SENT 4
75 #define MASK_FBW_CHANGED 0xf
76 
77 
78 extern struct fbw_state *fbw_state;
79 extern struct ap_state *ap_state;
80 
81 extern volatile bool_t inter_mcu_received_fbw;
82 extern volatile bool_t inter_mcu_received_ap;
83 
84 
85 #ifdef FBW
86 
87 extern uint8_t time_since_last_ap;
88 extern bool_t ap_ok;
89 
90 #define AP_STALLED_TIME 30 // 500ms with a 60Hz timer
91 
92 
93 static inline void inter_mcu_init(void)
94 {
95  fbw_state->status = 0;
96  fbw_state->nb_err = 0;
97 
98  ap_ok = FALSE;
99 }
100 
101 
102 /* Prepare data to be sent to mcu0 */
103 static inline void inter_mcu_fill_fbw_state(void)
104 {
105  uint8_t status = 0;
106 
107 #ifdef RADIO_CONTROL
108  uint8_t i;
109  for (i = 0; i < RADIO_CONTROL_NB_CHANNEL; i++) {
110  fbw_state->channels[i] = radio_control.values[i];
111  }
112 
113  fbw_state->ppm_cpt = radio_control.frame_rate;
114 
115  status = (radio_control.status == RC_OK ? _BV(STATUS_RADIO_OK) : 0);
116  status |= (radio_control.status == RC_REALLY_LOST ? _BV(STATUS_RADIO_REALLY_LOST) : 0);
117  status |= (radio_control.status == RC_OK ? _BV(AVERAGED_CHANNELS_SENT) :
118  0); // Any valid frame contains averaged channels
119 #endif // RADIO_CONTROL
120 
121  status |= (fbw_mode == FBW_MODE_AUTO ? _BV(STATUS_MODE_AUTO) : 0);
122  status |= (fbw_mode == FBW_MODE_FAILSAFE ? _BV(STATUS_MODE_FAILSAFE) : 0);
123  fbw_state->status = status;
124 
125  fbw_state->vsupply = electrical.vsupply;
126  fbw_state->current = electrical.current;
127  fbw_state->energy = electrical.energy;
128 #if defined SINGLE_MCU
129 
131 #endif
132 }
133 
135 static inline void inter_mcu_event_task(void)
136 {
137  time_since_last_ap = 0;
138  ap_ok = TRUE;
139 }
140 
142 static inline void inter_mcu_periodic_task(void)
143 {
144  if (time_since_last_ap >= AP_STALLED_TIME) {
145  ap_ok = FALSE;
146 #ifdef SINGLE_MCU
147  // Keep filling the buffer even if no AP commands are received
148  inter_mcu_fill_fbw_state();
149 #endif
150 
151  } else {
152  time_since_last_ap++;
153  }
154 }
155 
156 #endif /* FBW */
157 
158 #endif /* INTER_MCU */
159 
160 #endif /* INTER_MCU_H */
int32_t current
current in milliamps
Definition: electrical.h:49
unsigned short uint16_t
Definition: types.h:16
status
Definition: anemotaxis.c:10
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:52
pprz_t command_pitch_trim
Definition: main_fbw.c:69
uint8_t status
Definition: radio_control.h:53
volatile bool_t inter_mcu_received_ap
Definition: inter_mcu.c:41
int16_t pprz_t
Definition: paparazzi.h:6
volatile bool_t inter_mcu_received_fbw
Definition: inter_mcu.c:40
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:58
struct fbw_state * fbw_state
Definition: inter_mcu.c:36
int32_t current
Supply current in milliAmpere.
Definition: autopilot.c:53
#define FALSE
Definition: std.h:5
struct ap_state * ap_state
Definition: inter_mcu.c:37
#define TRUE
Definition: std.h:4
Interface for electrical status: supply voltage, current, battery status, etc.
pprz_t command_roll_trim
Trim commands for roll, pitch and yaw.
Definition: main_fbw.c:68
struct RadioControl radio_control
Definition: radio_control.c:30
pprz_t command_yaw_trim
Definition: main_fbw.c:70
signed long int32_t
Definition: types.h:19
#define RC_REALLY_LOST
Definition: radio_control.h:50
#define RADIO_CONTROL_NB_CHANNEL
Definition: spektrum_arch.h:34
#define RC_OK
Definition: radio_control.h:48
uint8_t fbw_mode
Definition: main_fbw.c:56
float energy
Energy consumption (mAh) This is the ap copy of the measurement from fbw.
Definition: autopilot.c:54
unsigned char uint8_t
Definition: types.h:14
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
Definition: commands.c:30
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
float energy
consumed energy in mAh
Definition: electrical.h:51
struct Electrical electrical
Definition: electrical.c:65
FBW ( FlyByWire ) process API.
uint8_t frame_rate
Definition: radio_control.h:56