Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
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 #include "generated/radio.h"
50 #define RADIO_CONTROL_NB_CHANNEL RADIO_CTL_NB
51 #endif
52 
54 struct fbw_state {
55 #if defined RADIO_CONTROL || RADIO_CONTROL_AUTO1
57  uint8_t ppm_cpt;
58 #endif
60  uint8_t nb_err;
63 };
64 
65 struct ap_state {
66  pprz_t commands[COMMANDS_NB];
70 };
71 
72 // Status bits from FBW to AUTOPILOT
73 #define STATUS_RADIO_OK 0
74 #define STATUS_RADIO_REALLY_LOST 1
75 #define STATUS_MODE_AUTO 2
76 #define STATUS_MODE_FAILSAFE 3
77 #define AVERAGED_CHANNELS_SENT 4
78 #define MASK_FBW_CHANGED 0xf
79 
80 
81 extern struct fbw_state* fbw_state;
82 extern struct ap_state* ap_state;
83 
84 extern volatile bool_t inter_mcu_received_fbw;
85 extern volatile bool_t inter_mcu_received_ap;
86 
87 
88 #ifdef FBW
89 
90 extern uint8_t time_since_last_ap;
91 extern bool_t ap_ok;
92 
93 #define AP_STALLED_TIME 30 // 500ms with a 60Hz timer
94 
95 
96 static inline void inter_mcu_init(void) {
97  fbw_state->status = 0;
98  fbw_state->nb_err = 0;
99 
100  ap_ok = FALSE;
101 }
102 
103 
104 /* Prepare data to be sent to mcu0 */
105 static inline void inter_mcu_fill_fbw_state (void) {
106  uint8_t status = 0;
107 
108 #ifdef RADIO_CONTROL
109  uint8_t i;
110  for(i = 0; i < RADIO_CONTROL_NB_CHANNEL; i++)
111  fbw_state->channels[i] = radio_control.values[i];
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) : 0); // Any valid frame contains averaged channels
118 #endif // RADIO_CONTROL
119 
120  status |= (fbw_mode == FBW_MODE_AUTO ? _BV(STATUS_MODE_AUTO) : 0);
121  status |= (fbw_mode == FBW_MODE_FAILSAFE ? _BV(STATUS_MODE_FAILSAFE) : 0);
122  fbw_state->status = status;
123 
124  fbw_state->vsupply = electrical.vsupply;
125  fbw_state->current = electrical.current;
126 #if defined SINGLE_MCU
127 
129 #endif
130 }
131 
133 static inline void inter_mcu_event_task( void) {
134  time_since_last_ap = 0;
135  ap_ok = TRUE;
136 }
137 
139 static inline void inter_mcu_periodic_task(void) {
140  if (time_since_last_ap >= AP_STALLED_TIME) {
141  ap_ok = FALSE;
142 #ifdef SINGLE_MCU
143  // Keep filling the buffer even if no AP commands are received
144  inter_mcu_fill_fbw_state();
145 #endif
146 
147  } else
148  time_since_last_ap++;
149 }
150 
151 #endif /* FBW */
152 
153 #endif /* INTER_MCU */
154 
155 #endif /* INTER_MCU_H */
FBW ( FlyByWire ) process API.
unsigned short uint16_t
Definition: types.h:16
status
Definition: anemotaxis.c:10
static int32_t current
Supply current in milliAmpere.
Definition: main_ap.c:155
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:41
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:64
int16_t pprz_t
Definition: paparazzi.h:6
volatile bool_t inter_mcu_received_fbw
Definition: inter_mcu.c:36
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:8
struct fbw_state * fbw_state
Definition: inter_mcu.c:32
#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:56
#define FBW_MODE_AUTO
Definition: main_fbw.h:36
pprz_t command_pitch_trim
Definition: main_fbw.c:65
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:9
#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:66
#define FBW_MODE_FAILSAFE
Definition: main_fbw.h:37
struct Electrical electrical