Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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;
61  uint8_t vsupply; /* 1e-1 V */
62  int32_t current; /* milliAmps */
63 };
64 
65 struct ap_state {
66  pprz_t commands[COMMANDS_NB];
69 };
70 
71 // Status bits from FBW to AUTOPILOT
72 #define STATUS_RADIO_OK 0
73 #define STATUS_RADIO_REALLY_LOST 1
74 #define STATUS_MODE_AUTO 2
75 #define STATUS_MODE_FAILSAFE 3
76 #define AVERAGED_CHANNELS_SENT 4
77 #define MASK_FBW_CHANGED 0xf
78 
79 
80 extern struct fbw_state* fbw_state;
81 extern struct ap_state* ap_state;
82 
83 extern volatile bool_t inter_mcu_received_fbw;
84 extern volatile bool_t inter_mcu_received_ap;
85 
86 
87 #ifdef FBW
88 
89 extern uint8_t time_since_last_ap;
90 extern bool_t ap_ok;
91 
92 #define AP_STALLED_TIME 30 // 500ms with a 60Hz timer
93 
94 
95 static inline void inter_mcu_init(void) {
96  fbw_state->status = 0;
97  fbw_state->nb_err = 0;
98 
99  ap_ok = FALSE;
100 }
101 
102 
103 /* Prepare data to be sent to mcu0 */
104 static inline void inter_mcu_fill_fbw_state (void) {
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  fbw_state->ppm_cpt = radio_control.frame_rate;
113 
114  status = (radio_control.status == RC_OK ? _BV(STATUS_RADIO_OK) : 0);
115  status |= (radio_control.status == RC_REALLY_LOST ? _BV(STATUS_RADIO_REALLY_LOST) : 0);
116  status |= (radio_control.status == RC_OK ? _BV(AVERAGED_CHANNELS_SENT) : 0); // Any valid frame contains averaged channels
117 #endif // RADIO_CONTROL
118 
119  status |= (fbw_mode == FBW_MODE_AUTO ? _BV(STATUS_MODE_AUTO) : 0);
120  status |= (fbw_mode == FBW_MODE_FAILSAFE ? _BV(STATUS_MODE_FAILSAFE) : 0);
121  fbw_state->status = status;
122 
123  fbw_state->vsupply = electrical.vsupply;
124  fbw_state->current = electrical.current;
125 #if defined SINGLE_MCU
126 
128 #endif
129 }
130 
132 static inline void inter_mcu_event_task( void) {
133  time_since_last_ap = 0;
134  ap_ok = TRUE;
135 }
136 
138 static inline void inter_mcu_periodic_task(void) {
139  if (time_since_last_ap >= AP_STALLED_TIME) {
140  ap_ok = FALSE;
141 #ifdef SINGLE_MCU
142  // Keep filling the buffer even if no AP commands are received
143  inter_mcu_fill_fbw_state();
144 #endif
145 
146  } else
147  time_since_last_ap++;
148 }
149 
150 #endif /* FBW */
151 
152 #endif /* INTER_MCU */
153 
154 #endif /* INTER_MCU_H */
FBW ( FlyByWire ) process API.
status
Definition: anemotaxis.c:10
static int32_t current
Supply current in milliAmpere.
Definition: main_ap.c:133
pprz_t command_roll_trim
Definition: commands.c:39
volatile bool_t inter_mcu_received_ap
Definition: inter_mcu.c:39
pprz_t command_pitch_trim
Definition: commands.c:40
int16_t pprz_t
Definition: paparazzi.h:6
volatile bool_t inter_mcu_received_fbw
Definition: inter_mcu.c:38
struct fbw_state * fbw_state
Definition: inter_mcu.c:34
#define FALSE
Definition: imu_chimu.h:141
struct ap_state * ap_state
Definition: inter_mcu.c:35
uint8_t vsupply
Definition: electrical.h:8
uint8_t fbw_mode
Definition: main_fbw.c:52
#define FBW_MODE_AUTO
Definition: main_fbw.h:35
struct RadioControl radio_control
Definition: radio_control.c:27
signed long int32_t
Definition: types.h:19
#define TRUE
Definition: imu_chimu.h:144
int32_t current
Definition: electrical.h:9
#define RADIO_CONTROL_NB_CHANNEL
Definition: spektrum_arch.h:36
unsigned char uint8_t
Definition: types.h:14
pprz_t commands[COMMANDS_NB]
Definition: commands.c:42
#define FBW_MODE_FAILSAFE
Definition: main_fbw.h:36
struct Electrical electrical
Definition: electrical.c:16
uint8_t vsupply
Supply voltage in deciVolt.
Definition: main_ap.c:128