Move MAX11040 ADC into a module

This commit is contained in:
Martin Mueller
2010-10-20 21:20:45 +00:00
parent d3bba1d542
commit 435cdd2b52
8 changed files with 255 additions and 231 deletions
+36 -63
View File
@@ -1,6 +1,40 @@
<!DOCTYPE airframe SYSTEM "../../airframe.dtd">
<airframe name="Pressure test">
<airframe name="MAX11040 ADC test">
<firmware name="fixedwing">
<target name="ap" board="tiny_2.11">
<define name="AGR_CLIMB"/>
<define name="LOITER_TRIM"/>
<define name="ALT_KALMAN"/>
<define name="WIND_INFO"/>
<define name="WIND_INFO_RET"/>
<define name="MAX11040_DRDY_VIC_SLOT" value="12"/>
<define name="SSP_VIC_SLOT" value="11"/>
<define name="USE_MAX11040"/>
<define name="MAX11040_DEBUG"/>
</target>
<subsystem name="telemetry" type="xbee_api">
<param name="MODEM_BAUD" value="B57600"/>
</subsystem>
<subsystem name="control"/>
<subsystem name="attitude" type="infrared"/>
<subsystem name="gps" type="ublox_lea5h">
<param name="GPS_BAUD" value="B38400"/>
</subsystem>
<subsystem name="navigation"/>
</firmware>
<firmware name="setup">
<target name="tunnel" board="tiny_2.11"/>
<target name="usb_tunnel_0" board="tiny_2.11"/>
<target name="usb_tunnel_1" board="tiny_2.11"/>
</firmware>
<!-- modules -->
<modules>
<load name="max11040.xml"/>
</modules>
<!-- commands section -->
<servos>
@@ -184,66 +218,5 @@
<define name="MAXM_DRDY_VIC_IT" value="VIC_EINT0"/>
</section>
<makefile>
CONFIG = \"tiny_2_1.h\"
include $(PAPARAZZI_SRC)/conf/autopilot/tiny.makefile
FLASH_MODE=IAP
ap.CFLAGS += -DFBW -DAP -DBOARD_CONFIG=$(CONFIG) -DLED -DTIME_LED=1
ap.srcs = sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c main_fbw.c main_ap.c main.c
ap.srcs += commands.c
ap.CFLAGS += -DACTUATORS=\"servos_4017_hw.h\" -DSERVOS_4017
ap.srcs += $(SRC_ARCH)/servos_4017_hw.c actuators.c
ap.CFLAGS += -DRADIO_CONTROL
ap.srcs += radio_control.c $(SRC_ARCH)/ppm_hw.c
ap.CFLAGS += -DDOWNLINK -DUSE_UART1 -DDOWNLINK_TRANSPORT=XBeeTransport -DXBEE_UART=Uart1 -DDATALINK=XBEE -DUART1_BAUD=B57600
ap.srcs += downlink.c $(SRC_ARCH)/uart_hw.c datalink.c xbee.c
#TRANSPARENT
#ap.CFLAGS += -DDOWNLINK -DUSE_UART1 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_FBW_DEVICE=Uart1 -DDOWNLINK_AP_DEVICE=Uart1 -DPPRZ_UART=Uart1 -DDATALINK=PPRZ -DUART1_BAUD=B9600
#ap.srcs += downlink.c $(SRC_ARCH)/uart_hw.c datalink.c pprz_transport.c
ap.CFLAGS += -DINTER_MCU
ap.srcs += inter_mcu.c
ap.CFLAGS += -DADC -DUSE_ADC_0 -DUSE_ADC_1 -DUSE_ADC_2
ap.srcs += $(SRC_ARCH)/adc_hw.c
ap.CFLAGS += -DGPS -DUBX -DUSE_UART0 -DGPS_LINK=Uart0 -DUART0_BAUD=B38400 -DGPS_USE_LATLONG
# -DGPS_LED=2
ap.srcs += gps_ubx.c gps.c latlong.c
ap.CFLAGS += -DINFRARED -DALT_KALMAN -DWIND_INFO -DWIND_INFO_RET
ap.srcs += infrared.c estimator.c
ap.CFLAGS += -DNAV -DAGR_CLIMB -DLOITER_TRIM
ap.srcs += nav.c fw_h_ctl.c fw_v_ctl.c
ap.srcs += nav_line.c
ap.srcs += nav_survey_rectangle.c
# MAX11040 adc
ap.CFLAGS += -DMAX11040_DRDY_VIC_SLOT=12 -DSSP_VIC_SLOT=11 -DUSE_MAX11040
ap.srcs += max11040.c $(SRC_ARCH)/max11040_hw.c
ap.srcs += snav.c
# Config for SITL simulation
include $(PAPARAZZI_SRC)/conf/autopilot/sitl.makefile
sim.CFLAGS += -DBOARD_CONFIG=\"tiny.h\" -DAGR_CLIMB -DLOITER_TRIM -DALT_KALMAN
sim.srcs += nav_line.c nav_survey_rectangle.c
sim.srcs += joystick.c
sim.CFLAGS += -DUSE_JOYSTICK
</makefile>
</airframe>
+14
View File
@@ -0,0 +1,14 @@
<!DOCTYPE module SYSTEM "module.dtd">
<module name="max11040" dir="adcs">
<header>
<file name="max11040.h"/>
</header>
<init fun="max11040_init()"/>
<periodic fun="max11040_periodic()" freq="4"/>
<makefile>
<file_hw name="max11040_hw.c"/>
<file name="max11040.c"/>
</makefile>
</module>
-76
View File
@@ -1,76 +0,0 @@
/* MAX11040 connected on SPI1
SS on P0.20 (SSEL)
DRDY on P0.16 (EINT0)
*/
#include "led.h"
#include "max11040.h"
#ifdef LOGGER
extern unsigned int getclock(void);
#endif
volatile uint8_t num_irqs = 0;
static void EXTINT_ISR(void) __attribute__((naked));
void max11040_hw_init( void ) {
/* configure DRDY pin */
/* connected pin to EXINT */
MAXM_DRDY_PINSEL |= MAXM_DRDY_PINSEL_VAL << MAXM_DRDY_PINSEL_BIT;
SetBit(EXTMODE, MAXM_DRDY_EINT); /* EINT is edge trigered */
ClearBit(EXTPOLAR, MAXM_DRDY_EINT); /* EINT is trigered on falling edge */
SetBit(EXTINT, MAXM_DRDY_EINT); /* clear pending EINT */
/* initialize interrupt vector */
VICIntSelect &= ~VIC_BIT( MAXM_DRDY_VIC_IT ); /* select EINT as IRQ source */
VICIntEnable = VIC_BIT( MAXM_DRDY_VIC_IT ); /* enable it */
_VIC_CNTL(MAX11040_DRDY_VIC_SLOT) = VIC_ENABLE | MAXM_DRDY_VIC_IT;
_VIC_ADDR(MAX11040_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; /* address of the ISR */
}
void EXTINT_ISR(void) {
ISR_ENTRY();
if (num_irqs++ == 5)
{
/* switch SSEL P0.20 to be used as GPIO */
PINSEL1 &= ~(3 << 8);
IO0DIR |= 1 << 20;
max11040_status = MAX11040_DATA2;
}
if (max11040_status == MAX11040_DATA2) {
//LED_TOGGLE(2);
//LED_TOGGLE(3);
#ifdef LOGGER
max11040_timestamp[max11040_buf_in] = getclock();
#endif
MaxmSelect();
/* read data */
SSP_Send(0xF0);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
max11040_count = 0;
}
/* clear EINT */
SetBit(EXTINT, MAXM_DRDY_EINT);
VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
ISR_EXIT();
}
@@ -1,15 +1,46 @@
/*
* $Id$
*
* Copyright (C) 2010 Martin Mueller
*
* 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.
*
*/
#include "max11040.h"
/** \file max11040.c
* \brief Maxim MAX11040 ADC hw interface
*
* SS on P0.20 (SSEL)
* DRDY on P0.16 (EINT0)
*/
volatile uint8_t max11040_status;
volatile uint8_t max11040_data;
volatile int32_t max11040_values[MAX11040_BUF_SIZE][MAXM_NB_CHAN] = {{0}};
volatile uint32_t max11040_timestamp[MAX11040_BUF_SIZE] = {0};
volatile uint8_t max11040_count = 0;
volatile uint32_t max11040_buf_in = 0;
volatile uint32_t max11040_buf_out = 0;
#include "armVIC.h"
#include "max11040_hw.h"
#include "modules/adcs/max11040.h"
#ifdef LOGGER
extern unsigned int getclock(void);
#endif
volatile uint8_t num_irqs = 0;
static void SSP_ISR(void) __attribute__((naked));
static void EXTINT_ISR(void) __attribute__((naked));
static void SSP_ISR(void) {
@@ -25,10 +56,10 @@ static void SSP_ISR(void) {
foo = SSPDR;
foo = SSPDR;
/* write configuration register */
SSP_Send(0x60); /* wr conf */
SSP_Send(0x30); /* adc0: en24bit, xtalen, no faultdis */
SSP_Send(0x60); /* wr conf */
SSP_Send(0x30); /* adc0: en24bit, xtalen, no faultdis */
for (i=1; i<MAXM_NB_ADCS; i++) {
SSP_Send(0x20); /* adcx: en24bit, no xtalen, no faultdis */
SSP_Send(0x20); /* adcx: en24bit, no xtalen, no faultdis */
}
max11040_status = MAX11040_CONF;
SSP_ClearRti();
@@ -44,9 +75,9 @@ static void SSP_ISR(void) {
foo = SSPDR;
}
/* write sampling instant register */
SSP_Send(0x40); /* wr instant */
SSP_Send(0x40); /* wr instant */
for (i=0; i<MAXM_NB_ADCS; i++) {
SSP_Send(0); /* adcx: no delay */
SSP_Send(0); /* adcx: no delay */
SSP_Send(0);
SSP_Send(0);
SSP_Send(0);
@@ -83,9 +114,9 @@ static void SSP_ISR(void) {
foo = SSPDR;
foo = SSPDR;
/* read data register */
SSP_Send(0xF0); /* rd data */
SSP_Send(0xF0); /* rd data */
for (i=0; i<MAXM_NB_ADCS; i++) {
SSP_Send(0x00); /* adcx: data */
SSP_Send(0x00); /* adcx: data */
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
@@ -124,9 +155,9 @@ static void SSP_ISR(void) {
/* read data */
/* read data register */
SSP_Send(0xF0); /* rd data */
SSP_Send(0xF0); /* rd data */
for (i=0; i<MAXM_NB_ADCS; i++) {
SSP_Send(0x00); /* adc0: data */
SSP_Send(0x00); /* adc0: data */
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
@@ -200,8 +231,49 @@ static void SSP_ISR(void) {
ISR_EXIT();
}
void max11040_init_ssp(void) {
void EXTINT_ISR(void) {
ISR_ENTRY();
if (num_irqs++ == 5)
{
/* switch SSEL P0.20 to be used as GPIO */
PINSEL1 &= ~(3 << 8);
IO0DIR |= 1 << 20;
max11040_status = MAX11040_DATA2;
}
if (max11040_status == MAX11040_DATA2) {
#ifdef LOGGER
max11040_timestamp[max11040_buf_in] = getclock();
#endif
MaxmSelect();
/* read data */
SSP_Send(0xF0);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
SSP_Send(0x00);
max11040_count = 0;
}
/* clear EINT */
SetBit(EXTINT, MAXM_DRDY_EINT);
VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
ISR_EXIT();
}
void max11040_hw_init( void ) {
int i;
/* *** configure SPI *** */
/* setup pins for SSP (SCK, MISO, MOSI, SSEL) */
PINSEL1 |= SSP_PINSEL1_SCK | SSP_PINSEL1_MISO | SSP_PINSEL1_MOSI | SSP_PINSEL1_SSEL;
@@ -211,20 +283,26 @@ void max11040_init_ssp(void) {
SSPCPSR = 0x02;
/* initialize interrupt vector */
VICIntSelect &= ~VIC_BIT( VIC_SPI1 ); /* SPI1 selected as IRQ */
VICIntEnable = VIC_BIT( VIC_SPI1 ); /* enable it */
VICIntSelect &= ~VIC_BIT( VIC_SPI1 ); /* SPI1 selected as IRQ */
VICIntEnable = VIC_BIT( VIC_SPI1 ); /* enable it */
_VIC_CNTL(SSP_VIC_SLOT) = VIC_ENABLE | VIC_SPI1;
_VIC_ADDR(SSP_VIC_SLOT) = (uint32_t)SSP_ISR; /* address of the ISR */
}
_VIC_ADDR(SSP_VIC_SLOT) = (uint32_t)SSP_ISR; /* address of the ISR */
void max11040_init( void ) {
int i;
max11040_hw_init();
max11040_status = MAX11040_RESET;
max11040_data = MAX11040_RESET;
/* *** configure DRDY pin*** */
/* connected pin to EXINT */
MAXM_DRDY_PINSEL |= MAXM_DRDY_PINSEL_VAL << MAXM_DRDY_PINSEL_BIT;
SetBit(EXTMODE, MAXM_DRDY_EINT); /* EINT is edge trigered */
ClearBit(EXTPOLAR, MAXM_DRDY_EINT); /* EINT is trigered on falling edge */
SetBit(EXTINT, MAXM_DRDY_EINT); /* clear pending EINT */
/* initialize interrupt vector */
VICIntSelect &= ~VIC_BIT( MAXM_DRDY_VIC_IT ); /* select EINT as IRQ source */
VICIntEnable = VIC_BIT( MAXM_DRDY_VIC_IT ); /* enable it */
_VIC_CNTL(MAX11040_DRDY_VIC_SLOT) = VIC_ENABLE | MAXM_DRDY_VIC_IT;
_VIC_ADDR(MAX11040_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; /* address of the ISR */
/* write configuration register */
SSP_Send(0x60); /* wr conf */
for (i=0; i<MAXM_NB_ADCS; i++) {
@@ -235,7 +313,3 @@ void max11040_init( void ) {
SSP_EnableRti();
}
void max11040_reset() {
max11040_status = MAX11040_IDLE;
}
@@ -5,11 +5,10 @@
#include "LPC21xx.h"
#include "interrupt_hw.h"
#include "ssp_hw.h"
#include "airframe.h"
#include BOARD_CONFIG
#include "airframe.h"
#define MAXM_DIVISOR_128 2
#define MAXM_DIVISOR_256 3
@@ -58,4 +57,7 @@
#define MaxmUnselect() SetBit(MAXM_SS_IOSET, MAXM_SS_PIN)
void max11040_hw_init( void );
#endif /* MAX11040_HW_H */
-48
View File
@@ -91,10 +91,6 @@
#include "srf08.h"
#endif
#ifdef USE_MAX11040
#include "max11040.h"
#endif
#ifdef TRAFFIC_INFO
#include "traffic_info.h"
#endif
@@ -501,45 +497,6 @@ void periodic_task_ap( void ) {
break;
#endif
#ifdef USE_MAX11040
case 5:
{
float max11040_values_f[16];
int i;
if (max11040_data == MAX11040_DATA_AVAILABLE) {
LED_TOGGLE(3);
for (i=0; i<16; i++) {
/* we assume that the buffer will be full always in this test mode anyway */
max11040_values_f[i] = (max11040_values[max11040_buf_in][i] * 2.2) / 8388608.0;
}
DOWNLINK_SEND_TURB_PRESSURE_VOLTAGE(
DefaultChannel,
&max11040_values_f[0],
&max11040_values_f[1],
&max11040_values_f[2],
&max11040_values_f[3],
&max11040_values_f[4],
&max11040_values_f[5],
&max11040_values_f[6],
&max11040_values_f[7],
&max11040_values_f[8],
&max11040_values_f[9],
&max11040_values_f[10],
&max11040_values_f[11],
&max11040_values_f[12],
&max11040_values_f[13],
&max11040_values_f[14],
&max11040_values_f[15] );
max11040_data = MAX11040_IDLE;
}
}
break;
#endif
#ifdef USE_ADC_GENERIC
case 6:
adc_generic_periodic();
@@ -718,11 +675,6 @@ void init_ap( void ) {
micromag_init();
#endif
#ifdef USE_MAX11040
max11040_init_ssp();
max11040_init();
#endif
modules_init();
/** - start interrupt task */
+90
View File
@@ -0,0 +1,90 @@
/*
* $Id$
*
* Copyright (C) 2010 Martin Mueller
*
* 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.
*
*/
/** \file max11040.c
* \brief Maxim MAX11040 ADC interface
*
*/
#include "led.h"
#include "uart.h"
#include "messages.h"
#include "downlink.h"
#include "max11040.h"
#include "modules/adcs/max11040_hw.h"
volatile uint8_t max11040_status;
volatile uint8_t max11040_data;
volatile int32_t max11040_values[MAX11040_BUF_SIZE][MAXM_NB_CHAN] = {{0}};
volatile uint32_t max11040_timestamp[MAX11040_BUF_SIZE] = {0};
volatile uint8_t max11040_count;
volatile uint32_t max11040_buf_in;
volatile uint32_t max11040_buf_out;
void max11040_init( void ) {
max11040_status = MAX11040_RESET;
max11040_data = MAX11040_RESET;
max11040_count = 0;
max11040_buf_in = 0;
max11040_buf_out = 0;
max11040_hw_init();
}
void max11040_periodic(void) {
#ifdef MAX11040_DEBUG
float max11040_values_f[16];
int i;
if (max11040_data == MAX11040_DATA_AVAILABLE) {
// LED_TOGGLE(3);
for (i=0; i<16; i++) {
/* we assume that the buffer will be full always in this test mode anyway */
max11040_values_f[i] = (max11040_values[max11040_buf_in][i] * 2.2) / 8388608.0;
}
DOWNLINK_SEND_TURB_PRESSURE_VOLTAGE(
DefaultChannel,
&max11040_values_f[0],
&max11040_values_f[1],
&max11040_values_f[2],
&max11040_values_f[3],
&max11040_values_f[4],
&max11040_values_f[5],
&max11040_values_f[6],
&max11040_values_f[7],
&max11040_values_f[8],
&max11040_values_f[9],
&max11040_values_f[10],
&max11040_values_f[11],
&max11040_values_f[12],
&max11040_values_f[13],
&max11040_values_f[14],
&max11040_values_f[15] );
max11040_data = MAX11040_IDLE;
}
#endif
}
@@ -3,20 +3,11 @@
#include "std.h"
#include "max11040_hw.h"
#define MAXM_NB_CHAN 16
#define MAXM_NB_ADCS ((MAXM_NB_CHAN+3)/4)
#define MAX11040_BUF_SIZE 320
extern void max11040_init_ssp(void);
extern void max11040_init( void );
extern void max11040_reset( void);
extern void max11040_periodic( void );
extern void max11040_hw_init( void );
extern volatile uint8_t max11040_status;
extern volatile uint8_t max11040_data;
extern volatile int32_t max11040_values[MAX11040_BUF_SIZE][MAXM_NB_CHAN];
@@ -37,5 +28,9 @@ extern volatile uint32_t max11040_buf_out;
#define MAX11040_IDLE 0
#define MAX11040_DATA_AVAILABLE 1
void max11040_init( void );
void max11040_periodic(void);
#endif /* MAX11040_H */