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