diff --git a/Doxyfile b/Doxyfile index 7f6269cd89..6510743f83 100644 --- a/Doxyfile +++ b/Doxyfile @@ -450,7 +450,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = sw/airborne/autopilot sw/airborne/fly_by_wire var/include var/Twin1 +INPUT = sw/airborne/autopilot sw/airborne/fly_by_wire var/include var/Twin1 sw/airborne/avr sw/airborne # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff --git a/conf/Makefile.avr b/conf/Makefile.avr index 276f746245..9dc4bf2811 100644 --- a/conf/Makefile.avr +++ b/conf/Makefile.avr @@ -117,6 +117,9 @@ $(OBJDIR)/%.s: %.c $(OBJDIR)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< +$(OBJDIR)/%.o: $(PAPARAZZI_SRC)/sw/airborne/avr/%.c + $(CC) $(CFLAGS) -c -o $@ $< + $(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(OBJCOPY) -O ihex -R .eeprom $< $@ diff --git a/sw/airborne/fly_by_wire/adc_fbw.h b/sw/airborne/adc_fbw.h similarity index 100% rename from sw/airborne/fly_by_wire/adc_fbw.h rename to sw/airborne/adc_fbw.h diff --git a/sw/airborne/autopilot/Makefile b/sw/airborne/autopilot/Makefile index ec0c795b73..6f9d1971b9 100644 --- a/sw/airborne/autopilot/Makefile +++ b/sw/airborne/autopilot/Makefile @@ -43,7 +43,7 @@ endif EXT_FUSE = ff LOCK_FUSE = ff -INCLUDES = -I $(FBW) -I ../../include -I $(VARINCLUDE) -I $(ACINCLUDE) +INCLUDES = -I .. -I ../../include -I $(VARINCLUDE) -I $(ACINCLUDE) GPS = gps_ubx.c GPS_FLAGS=-DUBX diff --git a/sw/airborne/autopilot/adc.c b/sw/airborne/autopilot/adc.c index edec2e4c63..5f00256797 100644 --- a/sw/airborne/autopilot/adc.c +++ b/sw/airborne/autopilot/adc.c @@ -88,7 +88,7 @@ adc_init( void ) /** * Called when the voltage conversion is finished * - * 8.913kHz on mega128@16MHz 1kHz/channel ?? + * 8.913kHz on mega128 16MHz 1kHz/channel ?? */ diff --git a/sw/airborne/avr/adc_fbw.c b/sw/airborne/avr/adc_fbw.c new file mode 100644 index 0000000000..def373c2f9 --- /dev/null +++ b/sw/airborne/avr/adc_fbw.c @@ -0,0 +1,121 @@ +/* + * Paparazzi fly by wire adc functions + * + * Copied from autopilot (autopilot.sf.net) thanx alot Trammell + * + * Copyright (C) 2002 Trammell Hudson + * Copyright (C) 2003 Pascal Brisset, Antoine Drouin + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +//// ADC3 MVSUP +//// ADC6 MVSERVO + + +#include +#include +#include +#include "adc_fbw.h" +#include "std.h" + + +#define VOLTAGE_TIME 0x07 +#define ANALOG_PORT PORTC +#define ANALOG_PORT_DIR DDRC + + +#ifdef IMU_ANALOG +#define ANALOG_VREF _BV(REFS0) +#else +#define ANALOG_VREF _BV(REFS0) | _BV(REFS1) +#endif + + + +uint16_t adc_samples[ NB_ADC ]; + +static struct adc_buf* buffers[NB_ADC]; + +void adc_buf_channel(uint8_t adc_channel, struct adc_buf* s) { + buffers[adc_channel] = s; +} + +void +adc_init( void ) +{ + uint8_t i; + /* Ensure that our port is for input with no pull-ups */ + ANALOG_PORT = 0x00; + ANALOG_PORT_DIR = 0x00; + + /* Select our external voltage ref */ + ADMUX = ANALOG_VREF; + + /* Select out clock, turn on the ADC interrupt and start conversion */ + ADCSRA = 0 + | VOLTAGE_TIME + | _BV(ADEN ) + | _BV(ADIE ) + | _BV(ADSC ); + + /* Init to 0 (usefull ?) */ + for(i = 0; i < NB_ADC; i++) + buffers[i] = (struct adc_buf*)0; +} + +/** + * Called when the voltage conversion is finished + * + * 8.913kHz on mega128@16MHz 1kHz/channel ?? +*/ + + +SIGNAL( SIG_ADC ) +{ + uint8_t adc_input = ADMUX & 0x7; + struct adc_buf* buf = buffers[adc_input]; + uint16_t adc_value = ADCW; + /* Store result */ + adc_samples[ adc_input ] = adc_value; + + if (buf) { + uint8_t new_head = buf->head + 1; + if (new_head >= AV_NB_SAMPLE) new_head = 0; + buf->sum -= buf->values[new_head]; + buf->values[new_head] = adc_value; + buf->sum += adc_value; + buf->head = new_head; + } + + /* Find the next input */ + adc_input++; + if (adc_input == 4) + adc_input = 6; // ADC 4 and 5 for i2c + if( adc_input >= 8 ) { + adc_input = 0; +#ifdef CTL_BRD_V1_2 + adc_input = 1; // WARNING ADC0 is for rservo driver reset on v1.2.0 +#endif /* CTL_BRD_V1_2 */ + } + /* Select it */ + ADMUX = adc_input | ANALOG_VREF; + /* Restart the conversion */ + sbi( ADCSR, ADSC ); +} diff --git a/sw/airborne/avr/int.h b/sw/airborne/avr/int.h new file mode 100644 index 0000000000..85161a117b --- /dev/null +++ b/sw/airborne/avr/int.h @@ -0,0 +1,3 @@ +#include + +#define int_enable() sei() diff --git a/sw/airborne/fly_by_wire/led.h b/sw/airborne/avr/led.h similarity index 100% rename from sw/airborne/fly_by_wire/led.h rename to sw/airborne/avr/led.h diff --git a/sw/airborne/fly_by_wire/ppm.c b/sw/airborne/avr/ppm.c similarity index 100% rename from sw/airborne/fly_by_wire/ppm.c rename to sw/airborne/avr/ppm.c diff --git a/sw/airborne/fly_by_wire/ppm.h b/sw/airborne/avr/ppm.h similarity index 100% rename from sw/airborne/fly_by_wire/ppm.h rename to sw/airborne/avr/ppm.h diff --git a/sw/airborne/fly_by_wire/servo.c b/sw/airborne/avr/servo.c similarity index 93% rename from sw/airborne/fly_by_wire/servo.c rename to sw/airborne/avr/servo.c index f93907b772..654cc4fffe 100644 --- a/sw/airborne/fly_by_wire/servo.c +++ b/sw/airborne/avr/servo.c @@ -31,8 +31,6 @@ #include "airframe.h" -#include "uart.h" - /* * Paparazzi boards have one 4017 servo driver. @@ -197,17 +195,18 @@ void servo_set_one(uint8_t servo, uint16_t value_us) { servo_widths[servo] = ChopServo(CLOCK*value_us); } -void -servo_transmit(void) { - uint8_t servo; - uart_transmit((uint8_t)0); uart_transmit((uint8_t)0); - for(servo = 0; servo < _4017_NB_CHANNELS; servo++) { - uart_transmit((uint8_t)(servo_widths[servo] >> 8)); - uart_transmit((uint8_t)(servo_widths[servo] & 0xff)); - } - uart_transmit((uint8_t)'\n'); -} +/* void */ +/* servo_transmit(void) { */ +/* uint8_t servo; */ +/* uart_transmit((uint8_t)0); uart_transmit((uint8_t)0); */ + +/* for(servo = 0; servo < _4017_NB_CHANNELS; servo++) { */ +/* uart_transmit((uint8_t)(servo_widths[servo] >> 8)); */ +/* uart_transmit((uint8_t)(servo_widths[servo] & 0xff)); */ +/* } */ +/* uart_transmit((uint8_t)'\n'); */ +/* } */ /* diff --git a/sw/airborne/fly_by_wire/spi.c b/sw/airborne/avr/spi.c similarity index 99% rename from sw/airborne/fly_by_wire/spi.c rename to sw/airborne/avr/spi.c index 12dcb8bed5..02dfd85c2b 100644 --- a/sw/airborne/fly_by_wire/spi.c +++ b/sw/airborne/avr/spi.c @@ -76,7 +76,6 @@ void spi_reset(void) { mega128_receive_valid = FALSE; } -#include "uart.h" /** c.f. autopilot/link_fbw.c */ SIGNAL(SIG_SPI) { diff --git a/sw/airborne/avr/spi_fbw_hw.h b/sw/airborne/avr/spi_fbw_hw.h new file mode 100644 index 0000000000..17ecad8a3b --- /dev/null +++ b/sw/airborne/avr/spi_fbw_hw.h @@ -0,0 +1,7 @@ + + +#define SPI_PORT PORTB +#define SPI_PIN PINB +#define SPI_SS_PIN 2 + +#define SpiIsSelected() (bit_is_clear(SPI_PIN, SPI_SS_PIN)) diff --git a/sw/airborne/fly_by_wire/timer.h b/sw/airborne/avr/timer.h similarity index 100% rename from sw/airborne/fly_by_wire/timer.h rename to sw/airborne/avr/timer.h diff --git a/sw/airborne/fly_by_wire/uart.c b/sw/airborne/avr/uart_fbw.c similarity index 99% rename from sw/airborne/fly_by_wire/uart.c rename to sw/airborne/avr/uart_fbw.c index 12450d2f41..e1737fde2d 100644 --- a/sw/airborne/fly_by_wire/uart.c +++ b/sw/airborne/avr/uart_fbw.c @@ -28,7 +28,7 @@ #include "std.h" -#include "uart.h" +#include "uart_fbw.h" #define TX_BUF_SIZE 256 static uint8_t tx_head; /* next free in buf */ diff --git a/sw/airborne/avr/uart_fbw_hw.h b/sw/airborne/avr/uart_fbw_hw.h new file mode 100644 index 0000000000..352801a206 --- /dev/null +++ b/sw/airborne/avr/uart_fbw_hw.h @@ -0,0 +1,6 @@ + +#define ReceiveUart(cb) \ + SIGNAL( SIG_UART_RECV ) { \ + uint8_t c = UDR; \ + cb(c); \ +} diff --git a/sw/airborne/fly_by_wire/3dmg.c b/sw/airborne/fly_by_wire/3dmg.c index d9f5fd29ca..1f882cc0b3 100644 --- a/sw/airborne/fly_by_wire/3dmg.c +++ b/sw/airborne/fly_by_wire/3dmg.c @@ -33,7 +33,7 @@ #include #include #include "3dmg.h" -#include "uart.h" +#include "uart_fbw.h" volatile bool_t _3dmg_data_ready; int16_t _3dmg_roll, _3dmg_pitch, _3dmg_yaw; diff --git a/sw/airborne/fly_by_wire/Makefile b/sw/airborne/fly_by_wire/Makefile index ace0e8d0e6..418e955615 100644 --- a/sw/airborne/fly_by_wire/Makefile +++ b/sw/airborne/fly_by_wire/Makefile @@ -34,7 +34,7 @@ EXT_FUSE = ff LOCK_FUSE = ff VARINCLUDE = $(PAPARAZZI_HOME)/var/include ACINCLUDE = $(PAPARAZZI_HOME)/var/$(AIRCRAFT) -INCLUDES = -I ../../include -I $(VARINCLUDE) -I $(ACINCLUDE) +INCLUDES = -I ../../include -I .. -I ../avr -I $(VARINCLUDE) -I $(ACINCLUDE) -I $(PAPARAZZI_SRC)/sw/airborne/fly_by_wire ifeq ($(CTL_BRD_VERSION),V1_2_1) CTL_BRD_FLAGS=-DCTL_BRD_V1_2_1 @@ -49,8 +49,8 @@ $(TARGET).srcs = \ ppm.c \ servo.c \ spi.c \ - uart.c \ - adc_fbw.c \ + uart_fbw.c \ + adc_fbw.c \ include $(PAPARAZZI_HOME)/var/$(AIRCRAFT)/Makefile.ac diff --git a/sw/airborne/fly_by_wire/main.c b/sw/airborne/fly_by_wire/main.c index 0f65464397..01d8adb3dd 100644 --- a/sw/airborne/fly_by_wire/main.c +++ b/sw/airborne/fly_by_wire/main.c @@ -25,23 +25,19 @@ #include -#include -#include -#include - - - +#include "int.h" #include "timer.h" #include "servo.h" #include "ppm.h" +#include "spi_fbw_hw.h" #include "spi.h" #include "link_autopilot.h" #include "radio.h" #include "led.h" -#include "uart.h" +#include "uart_fbw.h" #ifdef IMU_3DMG #include "3dmg.h" @@ -173,7 +169,7 @@ int main( void ) ppm_init(); spi_init(); - sei(); + int_enable(); #if IMU_RESET_ON_BOOT #warning IMU_RESET_ON_BOOT @@ -255,7 +251,7 @@ int main( void ) if (_20Hz >= 3) { _20Hz = 0; #ifndef IMU_3DMG - servo_transmit(); +/* servo_transmit(); */ #endif } if (time_since_last_mega128 < STALLED_TIME) diff --git a/sw/airborne/fly_by_wire/link_autopilot.h b/sw/airborne/link_autopilot.h similarity index 100% rename from sw/airborne/fly_by_wire/link_autopilot.h rename to sw/airborne/link_autopilot.h diff --git a/sw/airborne/fly_by_wire/servo.h b/sw/airborne/servo.h similarity index 99% rename from sw/airborne/fly_by_wire/servo.h rename to sw/airborne/servo.h index e0d8434cae..4d4bb9a9b6 100644 --- a/sw/airborne/fly_by_wire/servo.h +++ b/sw/airborne/servo.h @@ -50,7 +50,6 @@ #define SERVO_H #include -#include "timer.h" #include "link_autopilot.h" extern void servo_init( void ); diff --git a/sw/airborne/fly_by_wire/spi.h b/sw/airborne/spi.h similarity index 89% rename from sw/airborne/fly_by_wire/spi.h rename to sw/airborne/spi.h index 84ca3a2bdc..928b6f5547 100644 --- a/sw/airborne/fly_by_wire/spi.h +++ b/sw/airborne/spi.h @@ -28,13 +28,6 @@ #include "link_autopilot.h" - -#define SPI_PORT PORTB -#define SPI_PIN PINB -#define SPI_SS_PIN 2 - -#define SpiIsSelected() (bit_is_clear(SPI_PIN, SPI_SS_PIN)) - extern struct inter_mcu_msg from_mega128; extern struct inter_mcu_msg to_mega128; extern volatile bool_t mega128_receive_valid; diff --git a/sw/airborne/fly_by_wire/uart.h b/sw/airborne/uart_fbw.h similarity index 92% rename from sw/airborne/fly_by_wire/uart.h rename to sw/airborne/uart_fbw.h index 3c01ca1942..7f6ba2d021 100644 --- a/sw/airborne/fly_by_wire/uart.h +++ b/sw/airborne/uart_fbw.h @@ -27,6 +27,8 @@ #include +#include "uart_fbw_hw.h" + void uart_init_tx( void ); void uart_init_rx( void ); void uart_transmit( unsigned char data ); @@ -36,10 +38,4 @@ void uart_print_hex16 ( uint16_t c ); void uart_print_string(const uint8_t* s); void uart_print_float( const float * f); -#define ReceiveUart(cb) \ - SIGNAL( SIG_UART_RECV ) { \ - uint8_t c = UDR; \ - cb(c); \ -} - #endif diff --git a/sw/simulator/Makefile b/sw/simulator/Makefile index 4a4b0629d1..3103e47869 100644 --- a/sw/simulator/Makefile +++ b/sw/simulator/Makefile @@ -41,6 +41,7 @@ OCAMLOPT=ocamlopt -p INCLUDES= -I +lablgtk2 -I ../lib/ocaml OCAMLCC = gcc -O2 -I /usr/include/glib-2.0 -I /usr/lib/glib-2.0/include -DUBX -DCTL_BRD_V1_2 -DMOBILE_CAM -I $(OBJDIR) -I $(ACDIR) +AIRBORNE = ../airborne FBW = ../airborne/fly_by_wire AP = ../airborne/autopilot VARINCLUDE=$(PAPARAZZI_HOME)/var/include @@ -84,13 +85,13 @@ gaia : gaia.ml @chmod a+x $@ $(OBJDIR)/%.o : %.c - $(OCAMLCC) -c -o $@ -I $(SIMDIR) -I $(FBW) -I $(AP) -I ../include -I $(VARINCLUDE) $< + $(OCAMLCC) -c -o $@ -I $(SIMDIR) -I $(AIRBORNE) -I $(AP) -I ../include -I $(VARINCLUDE) $< $(OBJDIR)/%.o : $(AP)/%.c - $(OCAMLCC) -c -o $@ -I $(SIMDIR) -I $(FBW) -I $(AP) -I ../include -I $(VARINCLUDE) $< + $(OCAMLCC) -c -o $@ -I $(SIMDIR) -I $(AIRBORNE) -I $(AP) -I ../include -I $(VARINCLUDE) $< $(OBJDIR)/main.o : $(OBJDIR)/main.c - $(OCAMLCC) -c -o $@ -I $(SIMDIR) -I $(FBW) -I $(AP) -I ../include -I $(VARINCLUDE) $< + $(OCAMLCC) -c -o $@ -I $(SIMDIR) -I $(AIRBORNE) -I $(AP) -I ../include -I $(VARINCLUDE) $< $(OBJDIR)/sim_gps.o $(OBJDIR)/nav.o $(OBJDIR)/main.o $(OBJDIR)/sim_ir.o $(OBJDIR)/sim_ap.o $(OBJDIR)/pid.o $(OBJDIR)/estimator.o $(OBJDIR)/cam.o : $(ACINCLUDE)/flight_plan.h $(ACINCLUDE)/airframe.h