[tests] mag ms2100 peripheral test prog

This commit is contained in:
Felix Ruess
2013-03-02 01:02:36 +01:00
parent 9cbc44d847
commit ece92c0752
4 changed files with 96 additions and 124 deletions
@@ -46,6 +46,7 @@
<target name="test_imu_b2_nomag" board="lisa_l_1.1"/>
<target name="test_imu_b2" board="lisa_l_1.1"/>
<target name="test_imu_b2_2" board="lisa_l_1.1"/>
<target name="test_ms2100" board="lisa_l_1.1"/>
<target name="test_rc_spektrum" board="lisa_l_1.1"/>
<target name="test_rc_ppm" board="lisa_l_1.1"/>
<target name="test_adc" board="lisa_l_1.1"/>
+14 -2
View File
@@ -480,9 +480,21 @@ endif
#
# test ms2100 mag
#
test_ms2100.ARCHDIR = $(ARCH)
test_ms2100.CFLAGS = $(COMMON_TEST_CFLAGS)
test_ms2100.srcs = $(COMMON_TEST_SRCS)
test_ms2100.CFLAGS += $(COMMON_TELEMETRY_CFLAGS)
test_ms2100.srcs += $(COMMON_TELEMETRY_SRCS)
test_ms2100.CFLAGS += -I$(SRC_LISA)
test_ms2100.srcs += test/peripherals/test_ms2100.c
test_ms2100.srcs += peripherals/ms2100.c $(SRC_ARCH)/peripherals/ms2100_arch.c
test_ms2100.CFLAGS += -DUSE_SPI_SLAVE4 -DMS2100_SLAVE_IDX=4 -DMS2100_SPI_DEV=spi2
test_ms2100.CFLAGS += -DUSE_SPI -DSPI_MASTER -DUSE_SPI2
test_ms2100.srcs += mcu_periph/spi.c $(SRC_ARCH)/mcu_periph/spi_arch.c
#
# test hmc5843
-122
View File
@@ -1,122 +0,0 @@
/*
* Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
*
* 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 <stm32/gpio.h>
#include <stm32/flash.h>
#include <stm32/misc.h>
#include <stm32/spi.h>
#include <stm32/dma.h>
#include <stm32/exti.h>
#include BOARD_CONFIG
#include "mcu.h"
#include "mcu_periph/sys_time.h"
#include "subsystems/datalink/downlink.h"
#include "peripherals/ms2100.h"
#include "led.h"
static inline void main_init( void );
static inline void main_periodic_task( void );
static inline void main_event_task( void );
static inline void main_spi2_init(void);
int main(void) {
main_init();
while(1) {
if (sys_time_check_and_ack_timer(0))
main_periodic_task();
main_event_task();
}
return 0;
}
static inline void main_init( void ) {
mcu_init();
sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
ms2100_init();
main_spi2_init();
}
static inline void main_periodic_task( void ) {
RunOnceEvery(10,
{
DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &sys_time.nb_sec);
LED_PERIODIC();
});
switch(ms2100_status) {
case MS2100_IDLE:
Ms2100SendReq();
break;
case MS2100_WAITING_EOC:
if (Ms2100HasEOC()) {
Ms2100ReadRes();
}
break;
}
}
static inline void main_event_task( void ) {
if (ms2100_status == MS2100_DATA_AVAILABLE) {
RunOnceEvery(10, {
DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice,
&ms2100_values[0],
&ms2100_values[1],
&ms2100_values[2]);
});
ms2100_status = MS2100_IDLE;
}
}
static inline void main_spi2_init( void ) {
/* set max1168 slave select as output and assert it ( on PB12) */
GPIOB->BSRR = GPIO_Pin_12;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Enable SPI2 Periph clock -------------------------------------------------*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
/* Configure GPIOs: SCK, MISO and MOSI --------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);
/* Enable SPI_2 DMA clock ---------------------------------------------------*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
}
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
*
* 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 BOARD_CONFIG
#include "mcu.h"
#include "mcu_periph/sys_time.h"
#include "mcu_periph/uart.h"
#include "subsystems/datalink/downlink.h"
#include "peripherals/ms2100.h"
#include "led.h"
static inline void main_init( void );
static inline void main_periodic_task( void );
static inline void main_event_task( void );
int main(void) {
main_init();
while(1) {
if (sys_time_check_and_ack_timer(0))
main_periodic_task();
main_event_task();
}
return 0;
}
static inline void main_init( void ) {
mcu_init();
sys_time_register_timer((1./50), NULL);
ms2100_init(&ms2100, &(MS2100_SPI_DEV), MS2100_SLAVE_IDX);
mcu_int_enable();
}
static inline void main_periodic_task( void ) {
RunOnceEvery(10,
{
DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &sys_time.nb_sec);
LED_TOGGLE(2);
LED_PERIODIC();
});
ms2100_periodic(&ms2100);
}
static inline void main_event_task( void ) {
ms2100_event(&ms2100);
if (ms2100.status == MS2100_DATA_AVAILABLE) {
RunOnceEvery(10, {
DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice,
&ms2100.data.vect.x,
&ms2100.data.vect.y,
&ms2100.data.vect.z);
});
ms2100.status = MS2100_IDLE;
}
}