diff --git a/conf/airframes/plaster1.xml b/conf/airframes/plaster1.xml
index 8d55076b56..4c47d0aae9 100755
--- a/conf/airframes/plaster1.xml
+++ b/conf/airframes/plaster1.xml
@@ -116,9 +116,9 @@ include $(PAPARAZZI_SRC)/conf/autopilot/twin_mcu_avr.makefile
ap.CFLAGS += -DDOWNLINK -DDOWNLINK_TRANSPORT=PprzTransport
ap.srcs += pprz_transport.c downlink.c
-# ap.CFLAGS += -DUSE_UART0 -DDOWNLINK_AP_DEVICE=Uart0
-ap.CFLAGS += -DMODEM -DDOWNLINK_AP_DEVICE=Modem
-ap.srcs += $(SRC_ARCH)/modem_hw.c
+ ap.CFLAGS += -DUSE_UART0 -DDOWNLINK_AP_DEVICE=Uart0
+#ap.CFLAGS += -DMODEM -DDOWNLINK_AP_DEVICE=Modem
+#ap.srcs += $(SRC_ARCH)/modem_hw.c
ap.CFLAGS += -DRADIO_CONTROL_CALIB
ap.srcs += if_calib.c
diff --git a/conf/airframes/twinjet1.xml b/conf/airframes/twinjet1.xml
index d5c34ede69..76ed043ce5 100644
--- a/conf/airframes/twinjet1.xml
+++ b/conf/airframes/twinjet1.xml
@@ -33,88 +33,73 @@
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
-
include $(PAPARAZZI_SRC)/conf/autopilot/robostix.makefile
-ap.srcs += commands.c
-
-ap.CFLAGS += -DACTUATORS=\"servos_direct_hw.h\"
-ap.srcs += $(SRC_ARCH)/servos_direct_hw.c
-
-ap.CFLAGS += -DRADIO_CONTROL
-ap.srcs += radio_control.c $(SRC_ARCH)/ppm_hw.c
-
-ap.CFLAGS += -DDOWNLINK -DUART0
-ap.srcs += fbw_downlink.c $(SRC_ARCH)/uart_hw.c
-
-#ap.CFLAGS += -DCONTROL -DAUTOPILOT
-#ap.EXTRA_SRCS += $(ACINCLUDE)/ap/control.c
-#ap.CFLAGS += -DADC
-#ap.EXTRA_SRCS += $(SRC_ARCH)/adc_hw.c
-#ap.CFLAGS += -DDATALINK
-#ap.EXTRA_SRCS += datalink.c nav.c estimator.c
-
+ap.CFLAGS += -DDOWNLINK -DDOWNLINK_TRANSPORT=PprzTransport
+ap.srcs += pprz_transport.c downlink.c
+ap.CFLAGS += -DUSE_UART0 -DDOWNLINK_AP_DEVICE=Uart0 -DDOWNLINK_FBW_DEVICE=Uart0
+ap.srcs += $(SRC_ARCH)/uart_hw.c
diff --git a/conf/autopilot/robostix.makefile b/conf/autopilot/robostix.makefile
index dad23c996a..25420cd72f 100644
--- a/conf/autopilot/robostix.makefile
+++ b/conf/autopilot/robostix.makefile
@@ -10,6 +10,5 @@ ap.LOW_FUSE = 0xbf
ap.HIGH_FUSE = 0xc9
ap.EXT_FUSE = ff
ap.LOCK_FUSE = ff
-ap.CFLAGS += -DFBW -DCONFIG=\"robostix.h\" -DLED
-ap.srcs = sys_time.c $(SRC_ARCH)/adc_hw.c main_fbw.c main.c
-# ap.srcs += main_ap.c
+ap.CFLAGS += -DFBW -DAP -DCONFIG=\"robostix.h\" -DLED -DGPS -DUBX -DINFRARED -DRADIO_CONTROL -DINTER_MCU -DRADIO_CONTROL -DACTUATORS=\"servos_direct_hw.h\" -DGPS_LINK=Uart1
+ap.srcs = sys_time.c $(SRC_ARCH)/adc_hw.c inter_mcu.c gps_ubx.c gps.c infrared.c pid.c nav.c estimator.c main_fbw.c main_ap.c main.c commands.c radio_control.c $(SRC_ARCH)/ppm_hw.c $(SRC_ARCH)/servos_direct_hw.c
diff --git a/conf/autopilot/twin_mcu.makefile b/conf/autopilot/twin_mcu.makefile
index ca737a61c4..45813647a6 100644
--- a/conf/autopilot/twin_mcu.makefile
+++ b/conf/autopilot/twin_mcu.makefile
@@ -1,4 +1,4 @@
-ap.srcs += main_ap.c sys_time.c main.c inter_mcu.c link_mcu.c gps_ubx.c gps.c infrared.c pid.c nav.c estimator.c cam.c downlink.c spi.c
+ap.srcs += main_ap.c sys_time.c main.c inter_mcu.c link_mcu.c gps_ubx.c gps.c infrared.c pid.c nav.c estimator.c cam.c spi.c
ap.CFLAGS += -DMCU_SPI_LINK -DGPS -DUBX -DINFRARED -DRADIO_CONTROL -DINTER_MCU
fbw.srcs += sys_time.c main_fbw.c main.c commands.c radio_control.c pprz_transport.c downlink.c inter_mcu.c spi.c link_mcu.c
diff --git a/conf/autopilot/twin_mcu_avr.makefile b/conf/autopilot/twin_mcu_avr.makefile
index ddde5f55b7..2c484f7849 100644
--- a/conf/autopilot/twin_mcu_avr.makefile
+++ b/conf/autopilot/twin_mcu_avr.makefile
@@ -2,7 +2,7 @@ include $(PAPARAZZI_SRC)/conf/autopilot/twin_avr.makefile
include $(PAPARAZZI_SRC)/conf/autopilot/twin_mcu.makefile
ap.srcs += $(SRC_ARCH)/adc_hw.c $(SRC_ARCH)/uart_hw.c $(SRC_ARCH)/spi_hw.c
-ap.CFLAGS += -DUSE_UART1 -DGPS_LINK=uart1
+ap.CFLAGS += -DUSE_UART1 -DGPS_LINK=Uart1
fbw.CFLAGS += -DACTUATORS=\"servos_4017.h\" -DSERVOS_4017 -DADC
fbw.srcs += $(SRC_ARCH)/adc_hw.c $(SRC_ARCH)/servos_4017.c $(SRC_ARCH)/ppm_hw.c $(SRC_ARCH)/uart_hw.c $(SRC_ARCH)/spi_hw.c
diff --git a/conf/messages.xml b/conf/messages.xml
index 57d4e59ef3..268e67cd4d 100644
--- a/conf/messages.xml
+++ b/conf/messages.xml
@@ -218,7 +218,11 @@
-
+
+
+
+
+
diff --git a/sw/airborne/ap_downlink.h b/sw/airborne/ap_downlink.h
index 17304de436..8d3f78d8c0 100644
--- a/sw/airborne/ap_downlink.h
+++ b/sw/airborne/ap_downlink.h
@@ -117,7 +117,11 @@ extern uint8_t telemetry_mode_Ap;
#define SEND_NAVIGATION() Downlink({ int16_t pos_x = estimator_x; int16_t pos_y = estimator_y; int16_t d_course = DeciDegOfRad(desired_course); DOWNLINK_SEND_NAVIGATION(&nav_block, &nav_stage, &pos_x, &pos_y, &d_course, &dist2_to_wp, &dist2_to_home);})
+#ifdef CAM
#define SEND_CAM() Downlink({ int16_t x = target_x; int16_t y = target_y; int8_t phi = DegOfRad(phi_c); int8_t theta = DegOfRad(theta_c); DOWNLINK_SEND_CAM(&phi, &theta, &x, &y);})
+#else
+#define SEND_CAM() {}
+#endif
#define PERIODIC_SEND_DL_VALUE() PeriodicSendDlValue() /** from flight_plan.h*/
diff --git a/sw/airborne/avr/spi_hw.c b/sw/airborne/avr/spi_hw.c
index 48c33f50d2..c0dd2b5edc 100644
--- a/sw/airborne/avr/spi_hw.c
+++ b/sw/airborne/avr/spi_hw.c
@@ -49,7 +49,6 @@ volatile uint8_t spi_idx_buf;
spi_message_received = TRUE; \
SpiStop(); \
} \
- spi_idx_buf++; \
}
@@ -113,6 +112,11 @@ void spi_init( void) {
/* SS1 idles high (don't select slave yet)*/
SpiUnselectSlave1();
+ /* Set SS2 output */
+ SetBit( SPI_SS2_DDR, SPI_SS2_PIN);
+ /* SS2 idles high (don't select slave yet)*/
+ SpiUnselectSlave2();
+
spi_cur_slave = SPI_NONE;
}
@@ -134,8 +138,8 @@ SIGNAL(SIG_SPI) {
}
#define SpiStop() { \
- cbi(SPCR,SPIE); \
- cbi(SPCR, SPE); \
+ ClearBit(SPCR,SPIE); \
+ ClearBit(SPCR, SPE); \
SpiUnselectSlave0(); \
}
diff --git a/sw/airborne/avr/spi_hw.h b/sw/airborne/avr/spi_hw.h
index c899aed602..0e4e01e0a8 100644
--- a/sw/airborne/avr/spi_hw.h
+++ b/sw/airborne/avr/spi_hw.h
@@ -8,7 +8,9 @@ extern volatile uint8_t spi_idx_buf;
SPDR = spi_buffer_input[0]; \
spi_message_received = FALSE; \
}
-
+#define SPI_IT1_PIN 6
+#define SPI_IT1_PORT PORTE
+#define SPI_IT1_DDR DDRE
#ifdef FBW
#define SPI_PORT PORTB
@@ -25,17 +27,25 @@ extern volatile uint8_t spi_idx_buf;
#define SPI_SS0_PIN 0
#define SPI_SS0_PORT PORTB
#define SPI_SS0_DDR DDRB
-#define SPI_IT0_PIN 1
-#define SPI_IT0_PORT PORTD
-#define SPI_IT0_DDR DDRD
+#define SPI_IT0_PIN 7
+#define SPI_IT0_PORT PORTE
+#define SPI_IT0_DDR DDRE
-#define SPI_SS1_PIN 7
+#define SPI_SS1_PIN 3
#define SPI_SS1_PORT PORTE
#define SPI_SS1_DDR DDRE
#define SPI_IT1_PIN 6
#define SPI_IT1_PORT PORTE
#define SPI_IT1_DDR DDRE
+#define SPI_SS2_PIN 2
+#define SPI_SS2_PORT PORTE
+#define SPI_SS2_DDR DDRE
+#define SPI_IT2_PIN 5
+#define SPI_IT2_PORT PORTE
+#define SPI_IT2_DDR DDRE
+
+
#define SPI_SCK_PIN 1
#define SPI_MOSI_PIN 2
#define SPI_MISO_PIN 3
@@ -72,6 +82,16 @@ extern volatile uint8_t spi_idx_buf;
SetBit( SPI_SS1_PORT, SPI_SS1_PIN );\
}
+#define SpiSelectSlave2() { \
+ spi_cur_slave = SPI_SLAVE2; \
+ ClearBit( SPI_SS2_PORT, SPI_SS2_PIN );\
+}
+
+#define SpiUnselectSlave2() { \
+ spi_cur_slave = SPI_NONE; \
+ SetBit( SPI_SS2_PORT, SPI_SS2_PIN );\
+}
+
#endif /* AP */
diff --git a/sw/airborne/avr/uart_hw.h b/sw/airborne/avr/uart_hw.h
index 1f0b924891..ebbab6041b 100644
--- a/sw/airborne/avr/uart_hw.h
+++ b/sw/airborne/avr/uart_hw.h
@@ -74,8 +74,8 @@ extern void uart1_transmit(const uint8_t);
extern uint8_t uart1_char;
extern bool_t uart1_char_available;
-#define uart1ChAvailable() (uart1_char_available)
-static inline uint8_t uart1Getch( void ) {
+#define Uart1ChAvailable() (uart1_char_available)
+static inline uint8_t Uart1Getch( void ) {
uart1_char_available = FALSE;
return uart1_char;
}
diff --git a/sw/airborne/gps.h b/sw/airborne/gps.h
index 2fd02e5ef1..d5e63da3ce 100644
--- a/sw/airborne/gps.h
+++ b/sw/airborne/gps.h
@@ -86,7 +86,7 @@ extern struct svinfo gps_svinfos[GPS_NB_CHANNELS];
#define GpsBuffer() GpsLink(ChAvailable())
#define ReadGpsBuffer() { while (GpsLink(ChAvailable())) parse_ubx(GpsLink(Getch())); }
-#define GpsUartSend1(c) GpsLink(_transmit(c))
+#define GpsUartSend1(c) GpsLink(Transmit(c))
#endif
diff --git a/sw/airborne/inter_mcu.c b/sw/airborne/inter_mcu.c
index 022a9ee9c5..f5dc2c68b5 100644
--- a/sw/airborne/inter_mcu.c
+++ b/sw/airborne/inter_mcu.c
@@ -24,7 +24,7 @@
#include "inter_mcu.h"
-#if defined FBW && defined AP
+#if defined SINGLE_MCU
struct fbw_state _fbw_state;
struct ap_state _ap_state;
struct fbw_state* fbw_state = &_fbw_state;
diff --git a/sw/airborne/inter_mcu.h b/sw/airborne/inter_mcu.h
index 5951f3a818..8b2c6d5af1 100644
--- a/sw/airborne/inter_mcu.h
+++ b/sw/airborne/inter_mcu.h
@@ -117,7 +117,6 @@ static inline void inter_mcu_fill_fbw_state (void) {
static inline void inter_mcu_event_task( void) {
time_since_last_ap = 0;
ap_ok = TRUE;
- inter_mcu_fill_fbw_state();
#if defined SINGLE_MCU
/**Directly set the flag indicating to AP that shared buffer is available*/
inter_mcu_received_fbw = TRUE;
diff --git a/sw/airborne/link_mcu.c b/sw/airborne/link_mcu.c
index d29b65a9bb..7df9729abc 100644
--- a/sw/airborne/link_mcu.c
+++ b/sw/airborne/link_mcu.c
@@ -37,10 +37,11 @@ static uint16_t crc = 0;
#define LINK_MCU_FRAME_LENGTH sizeof(link_mcu_from_fbw_msg)
#define ComputeChecksum(_buf) { \
- uint8_t i = 0; \
+ uint8_t i; \
crc = CRC_INIT; \
for(i = 0; i < PAYLOAD_LENGTH; i++) { \
- crc = CrcUpdate(crc, ((uint8_t*)&_buf)[i]); \
+ uint8_t _byte = ((uint8_t*)&_buf)[i]; \
+ crc = CrcUpdate(crc, _byte); \
} \
}
@@ -82,12 +83,17 @@ void link_mcu_init(void) {
link_mcu_nb_err = 0;
}
+#include "spi_hw.h"
+
void link_mcu_send(void) {
+
+ ClearBit( SPI_SS2_PORT, SPI_SS2_PIN );
+
if (!SpiCheckAvailable()) {
SpiOverRun();
return;
}
-
+
ComputeChecksum(link_mcu_from_ap_msg);
link_mcu_from_ap_msg.checksum = crc;
spi_buffer_input = (uint8_t*)&link_mcu_from_fbw_msg;
@@ -95,6 +101,9 @@ void link_mcu_send(void) {
spi_buffer_length = LINK_MCU_FRAME_LENGTH;
SpiSelectSlave0();
SpiStart();
+
+ SetBit( SPI_SS2_PORT, SPI_SS2_PIN );
+
}
void link_mcu_event_task( void ) {
diff --git a/sw/airborne/main_ap.c b/sw/airborne/main_ap.c
index 790c018d03..0cccd45ddd 100644
--- a/sw/airborne/main_ap.c
+++ b/sw/airborne/main_ap.c
@@ -378,6 +378,7 @@ static void navigation_task( void ) {
* - do navigation with \a navigation_task
*
*/
+
inline void periodic_task_ap( void ) {
static uint8_t _20Hz = 0;
static uint8_t _10Hz = 0;
@@ -471,7 +472,11 @@ inline void periodic_task_ap( void ) {
ap_state->commands[COMMAND_PITCH] = desired_elevator;
#if defined MCU_SPI_LINK
+
+ // ClearBit( SPI_SS2_PORT, SPI_SS2_PIN );
link_mcu_send();
+ // SetBit( SPI_SS2_PORT, SPI_SS2_PIN );
+
#elif defined INTER_MCU && defined SINGLE_MCU
/**Directly set the flag indicating to FBW that shared buffer is available*/
inter_mcu_received_ap = TRUE;
@@ -632,10 +637,10 @@ void event_task_ap( void ) {
#ifdef MCU_SPI_LINK
if (spi_message_received) {
+ DOWNLINK_SEND_DEBUG2(sizeof(link_mcu_from_fbw_msg), ((uint8_t*)&link_mcu_from_fbw_msg));
/* Got a message on SPI. */
spi_message_received = FALSE;
link_mcu_event_task();
- DOWNLINK_SEND_DEBUG2(sizeof(link_mcu_from_fbw_msg), ((uint8_t*)&link_mcu_from_fbw_msg));
}
#endif
diff --git a/sw/airborne/main_fbw.c b/sw/airborne/main_fbw.c
index b48892f8fa..717fb0ed08 100644
--- a/sw/airborne/main_fbw.c
+++ b/sw/airborne/main_fbw.c
@@ -125,12 +125,12 @@ void event_task_fbw( void) {
/* Got a message on SPI. */
spi_message_received = FALSE;
link_mcu_event_task(); /** Sets inter_mcu_received_ap if checksum is ok */
- DOWNLINK_SEND_DEBUG2(sizeof(link_mcu_from_ap_msg), ((uint8_t*)&link_mcu_from_ap_msg));
+ DOWNLINK_SEND_DEBUG1(sizeof(link_mcu_from_ap_msg), ((uint8_t*)&link_mcu_from_ap_msg));
}
#endif /* MCU_SPI_LINK */
if (inter_mcu_received_ap) {
inter_mcu_received_ap = FALSE;
- inter_mcu_event_task(); /** Prepares the next message for AP */
+ inter_mcu_event_task();
if (fbw_mode == FBW_MODE_AUTO) {
SetCommands(ap_state->commands);
}
@@ -138,6 +138,7 @@ void event_task_fbw( void) {
#ifdef MCU_SPI_LINK
if (link_mcu_received) {
link_mcu_received = FALSE;
+ inter_mcu_fill_fbw_state(); /** Prepares the next message for AP */
link_mcu_restart(); /** Prepares the next SPI communication */
}
#endif /* MCU_SPI_LINK */
diff --git a/sw/airborne/spi.h b/sw/airborne/spi.h
index e531052e06..3b27713a84 100644
--- a/sw/airborne/spi.h
+++ b/sw/airborne/spi.h
@@ -29,6 +29,8 @@
#ifndef SPI_H
#define SPI_H
+#ifdef MCU_SPI_LINK
+
#include "std.h"
#include "spi_hw.h"
@@ -45,6 +47,7 @@ void spi_init(void);
#define SPI_NONE 0
#define SPI_SLAVE0 1
#define SPI_SLAVE1 2
+#define SPI_SLAVE2 3
extern volatile uint8_t spi_cur_slave;
extern uint8_t spi_nb_ovrn;
@@ -54,6 +57,8 @@ extern uint8_t spi_nb_ovrn;
#endif /* AP */
+#endif /* MCU_SPI_LINK */
+
#endif /* SPI_H */