Splitting hardware dependent code

This commit is contained in:
Pascal Brisset
2005-12-13 17:06:08 +00:00
parent 56b9994b23
commit 8e0afe00ea
24 changed files with 170 additions and 47 deletions
+1 -1
View File
@@ -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
+3
View File
@@ -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 $< $@
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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 ??
*/
+121
View File
@@ -0,0 +1,121 @@
/*
* Paparazzi fly by wire adc functions
*
* Copied from autopilot (autopilot.sf.net) thanx alot Trammell
*
* Copyright (C) 2002 Trammell Hudson <hudson@rotomotion.com>
* 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 <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#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 );
}
+3
View File
@@ -0,0 +1,3 @@
#include <avr/interrupt.h>
#define int_enable() sei()
@@ -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'); */
/* } */
/*
@@ -76,7 +76,6 @@ void spi_reset(void) {
mega128_receive_valid = FALSE;
}
#include "uart.h"
/** c.f. autopilot/link_fbw.c */
SIGNAL(SIG_SPI) {
+7
View File
@@ -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))
@@ -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 */
+6
View File
@@ -0,0 +1,6 @@
#define ReceiveUart(cb) \
SIGNAL( SIG_UART_RECV ) { \
uint8_t c = UDR; \
cb(c); \
}
+1 -1
View File
@@ -33,7 +33,7 @@
#include <avr/io.h>
#include <avr/signal.h>
#include "3dmg.h"
#include "uart.h"
#include "uart_fbw.h"
volatile bool_t _3dmg_data_ready;
int16_t _3dmg_roll, _3dmg_pitch, _3dmg_yaw;
+3 -3
View File
@@ -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
+5 -9
View File
@@ -25,23 +25,19 @@
#include <inttypes.h>
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#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)
@@ -50,7 +50,6 @@
#define SERVO_H
#include <inttypes.h>
#include "timer.h"
#include "link_autopilot.h"
extern void servo_init( void );
@@ -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;
@@ -27,6 +27,8 @@
#include <inttypes.h>
#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
+4 -3
View File
@@ -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