i2c test code

This commit is contained in:
Christophe De Wagter
2011-11-22 09:55:39 +01:00
parent f8f68db40c
commit 6a64132d70
7 changed files with 606 additions and 5 deletions
+279
View File
@@ -0,0 +1,279 @@
<!-- this is an asctec frame equiped with Lisa/L#3 and asctec V2 controllers -->
<airframe name="booz2_a7">
<servos min="0" neutral="0" max="0xff">
<servo name="FRONT" no="0" min="0" neutral="0" max="255"/>
<servo name="BACK" no="1" min="0" neutral="0" max="255"/>
<servo name="LEFT" no="2" min="0" neutral="0" max="255"/>
<servo name="RIGHT" no="3" min="0" neutral="0" max="255"/>
</servos>
<commands>
<axis name="PITCH" failsafe_value="0"/>
<axis name="ROLL" failsafe_value="0"/>
<axis name="YAW" failsafe_value="0"/>
<axis name="THRUST" failsafe_value="0"/>
</commands>
<!-- for the sim -->
<section name="ACTUATORS_MKK" prefix="ACTUATORS_MKK_">
<define name="NB" value="4"/>
<define name="ADDR" value="{ 0x52, 0x54, 0x56, 0x58 }"/>
</section>
<section name="SUPERVISION" prefix="SUPERVISION_">
<define name="MIN_MOTOR" value="3"/>
<define name="MAX_MOTOR" value="200"/>
<define name="TRIM_A" value="0"/>
<define name="TRIM_E" value="0"/>
<define name="TRIM_R" value="0"/>
<define name="NB_MOTOR" value="4"/>
<define name="SCALE" value="256"/>
<define name="ROLL_COEF" value="{ 0 , 0, 256, -256 }"/>
<define name="PITCH_COEF" value="{ 256, -256, 0, 0 }"/>
<define name="YAW_COEF" value="{ 256, 256, -256, -256 }"/>
<define name="THRUST_COEF" value="{ 256, 256, 256, 256 }"/>
</section>
<section name="IMU" prefix="IMU_">
<define name="GYRO_P_NEUTRAL" value="32858"/>
<define name="GYRO_Q_NEUTRAL" value="33152"/>
<define name="GYRO_R_NEUTRAL" value="31779"/>
<define name="GYRO_P_SENS" value=" 1.101357422" integer="16"/>
<define name="GYRO_Q_SENS" value=" 1.122670898" integer="16"/>
<define name="GYRO_R_SENS" value=" 1.104890137" integer="16"/>
<define name="ACCEL_X_NEUTRAL" value="32899"/>
<define name="ACCEL_Y_NEUTRAL" value="33281"/>
<define name="ACCEL_Z_NEUTRAL" value="32569"/>
<define name="ACCEL_X_SENS" value="2.57702956051" integer="16"/>
<define name="ACCEL_Y_SENS" value="2.57835230627" integer="16"/>
<define name="ACCEL_Z_SENS" value="2.54311399868" integer="16"/>
<define name="MAG_X_NEUTRAL" value="58"/>
<define name="MAG_Y_NEUTRAL" value="92"/>
<define name="MAG_Z_NEUTRAL" value="-3"/>
<define name="MAG_X_SENS" value="4.70018395734" integer="16"/>
<define name="MAG_Y_SENS" value="4.884119848" integer="16"/>
<define name="MAG_Z_SENS" value="2.59926404993" integer="16"/>
<define name="BODY_TO_IMU_PHI" value="RadOfDeg( 0. )"/>
<define name="BODY_TO_IMU_THETA" value="RadOfDeg( 0. )"/>
<define name="BODY_TO_IMU_PSI" value="RadOfDeg( 135.)"/>
</section>
<section name="AUTOPILOT">
<define name="MODE_MANUAL" value="AP_MODE_ATTITUDE_DIRECT"/>
<define name="MODE_AUTO1" value="AP_MODE_ATTITUDE_Z_HOLD"/>
<define name="MODE_AUTO2" value="AP_MODE_ATTITUDE_Z_HOLD"/>
</section>
<section name="BAT">
<define name="MILLIAMP_PER_PERCENT" value="0.86"/>
<define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
<define name="BATTERY_SENS" value="0.48" integer="16"/>
</section>
<section name="STABILIZATION_RATE" prefix="STABILIZATION_RATE_">
<define name="SP_MAX_P" value="10000"/>
<define name="SP_MAX_Q" value="10000"/>
<define name="SP_MAX_R" value="10000"/>
<define name="GAIN_P" value="-400"/>
<define name="GAIN_Q" value="-400"/>
<define name="GAIN_R" value="-350"/>
</section>
<section name="STABILIZATION_ATTITUDE" prefix="STABILIZATION_ATTITUDE_">
<!-- setpoints -->
<define name="SP_MAX_PHI" value="RadOfDeg(45.)"/>
<define name="SP_MAX_THETA" value="RadOfDeg(45.)"/>
<define name="SP_MAX_R" value="RadOfDeg(90.)"/>
<define name="DEADBAND_R" value="250"/>
<!-- reference -->
<define name="REF_OMEGA_P" value="RadOfDeg(800)"/>
<define name="REF_ZETA_P" value="0.85"/>
<define name="REF_MAX_P" value="RadOfDeg(300.)"/>
<define name="REF_MAX_PDOT" value="RadOfDeg(7000.)"/>
<define name="REF_OMEGA_Q" value="RadOfDeg(800)"/>
<define name="REF_ZETA_Q" value="0.85"/>
<define name="REF_MAX_Q" value="RadOfDeg(300.)"/>
<define name="REF_MAX_QDOT" value="RadOfDeg(7000.)"/>
<define name="REF_OMEGA_R" value="RadOfDeg(500)"/>
<define name="REF_ZETA_R" value="0.85"/>
<define name="REF_MAX_R" value="RadOfDeg(180.)"/>
<define name="REF_MAX_RDOT" value="RadOfDeg(1800.)"/>
<!-- gaui props
<define name="PHI_PGAIN" value="-900"/>
<define name="PHI_DGAIN" value="-200"/>
<define name="PHI_IGAIN" value="-200"/>
<define name="THETA_PGAIN" value="-900"/>
<define name="THETA_DGAIN" value="-200"/>
<define name="THETA_IGAIN" value="-200"/>
<define name="PSI_PGAIN" value="-900"/>
<define name="PSI_DGAIN" value="-200"/>
<define name="PSI_IGAIN" value="-10"/>
<define name="PHI_DDGAIN" value=" 200"/>
<define name="THETA_DDGAIN" value=" 200"/>
<define name="PSI_DDGAIN" value=" 200"/>
-->
<!-- feedback -->
<define name="PHI_PGAIN" value="-2000"/>
<define name="PHI_DGAIN" value="-400"/>
<define name="PHI_IGAIN" value="-200"/>
<define name="THETA_PGAIN" value="-2000"/>
<define name="THETA_DGAIN" value="-400"/>
<define name="THETA_IGAIN" value="-200"/>
<define name="PSI_PGAIN" value="-2000"/>
<define name="PSI_DGAIN" value="-400"/>
<define name="PSI_IGAIN" value="-10"/>
<!-- feedforward -->
<define name="PHI_DDGAIN" value=" 300"/>
<define name="THETA_DDGAIN" value=" 300"/>
<define name="PSI_DDGAIN" value=" 300"/>
</section>
<section name="AHRS" prefix="AHRS_">
<define name="PROPAGATE_FREQUENCY" value="512"/>
<define name="H_X" value=" 0.51562740288882"/>
<define name="H_Y" value="-0.05707735220832"/>
<define name="H_Z" value=" 0.85490967783446"/>
</section>
<section name="INS" prefix="INS_">
<define name="BARO_SENS" value="10." integer="16"/>
<define name="UNTILT_ACCEL" value="1"/>
</section>
<section name="GUIDANCE_V" prefix="GUIDANCE_V_">
<define name="MIN_ERR_Z" value="POS_BFP_OF_REAL(-10.)"/>
<define name="MAX_ERR_Z" value="POS_BFP_OF_REAL( 10.)"/>
<define name="MIN_ERR_ZD" value="SPEED_BFP_OF_REAL(-10.)"/>
<define name="MAX_ERR_ZD" value="SPEED_BFP_OF_REAL( 10.)"/>
<define name="MAX_SUM_ERR" value="2000000"/>
<!--
<define name="HOVER_KP" value="-500"/>
<define name="HOVER_KD" value="-200"/>
<define name="HOVER_KI" value="0"/>
-->
<define name="HOVER_KP" value="-150"/>
<define name="HOVER_KD" value="-80"/>
<define name="HOVER_KI" value="0"/>
<!-- 1.5m/s for full stick : BOOZ_SPEED_I_OF_F(1.5) / (MAX_PPRZ/2) -->
<define name="RC_CLIMB_COEF" value ="163"/>
<!-- BOOZ_SPEED_I_OF_F(1.5) * 20% -->
<define name="RC_CLIMB_DEAD_BAND" value ="160000"/>
<!-- <define name="INV_M" value ="0.2"/> -->
</section>
<section name="GUIDANCE_H" prefix="GUIDANCE_H_">
<define name="PGAIN" value="-50"/>
<define name="DGAIN" value="-100"/>
<define name="IGAIN" value="-15"/>
<define name="NGAIN" value="-0"/>
</section>
<section name="MISC">
<define name="FACE_REINJ_1" value="1024"/>
</section>
<section name="SIMULATOR" prefix="NPS_">
<define name="ACTUATOR_NAMES" value="{&quot;front_motor&quot;, &quot;back_motor&quot;, &quot;right_motor&quot;, &quot;left_motor&quot;}"/>
<define name="INITIAL_CONDITITONS" value="&quot;reset00&quot;"/>
<define name="SENSORS_PARAMS" value="&quot;nps_sensors_params_booz2_a1.h&quot;"/>
</section>
<modules main_freq="512">
<load name="i2c_abuse_test.xml"/>
</modules>
<firmware name="rotorcraft">
<!-- <define name="USE_PERSISTENT_SETTINGS"/> -->
<!-- <define name="USE_INS_NAV_INIT"/> -->
<define name="USE_ADAPT_HOVER"/>
<define name="FAILSAFE_GROUND_DETECT"/>
<define name="USE_GPS_ACC4R"/>
<target name="ap" board="lisa_l_1.0">
<subsystem name="radio_control" type="spektrum"/>
<subsystem name="actuators" type="asctec"/>
</target>
<target name="sim" board="pc">
<subsystem name="fdm" type="nps"/>
<subsystem name="radio_control" type="ppm"/>
<subsystem name="actuators" type="mkk"/>
</target>
<subsystem name="telemetry" type="transparent"/>
<subsystem name="imu" type="b2_v1.1"/>
<subsystem name="gps" type="ublox">
<configure name="GPS_BAUD" value="B57600"/>
</subsystem>
<!--subsystem name="ahrs" type="int_cmpl_euler"/-->
<subsystem name="stabilization" type="euler"/>
<subsystem name="ahrs" type="int_cmpl_quat"/>
<subsystem name="ins" type="hff"/>
</firmware>
<firmware name="lisa_l_test_progs">
<target name="test_led" board="lisa_l_1.0"/>
<target name="test_uart" board="lisa_l_1.0"/>
<target name="test_servos" board="lisa_l_1.0"/>
<target name="test_telemetry" board="lisa_l_1.0"/>
<target name="test_baro" board="lisa_l_1.0"/>
<target name="test_imu_b2" board="lisa_l_1.0"/>
<target name="test_imu_b2_2" board="lisa_l_1.0"/>
<target name="test_imu_aspirin" board="lisa_l_1.0"/>
<target name="test_rc_spektrum" board="lisa_l_1.0"/>
<target name="test_rc_ppm" board="lisa_l_1.0"/>
<target name="test_adc" board="lisa_l_1.0"/>
<target name="test_hmc5843" board="lisa_l_1.0"/>
<target name="test_itg3200" board="lisa_l_1.0"/>
<target name="test_adxl345" board="lisa_l_1.0"/>
<target name="test_esc_mkk_simple" board="lisa_l_1.0"/>
<target name="test_esc_asctecv1_simple" board="lisa_l_1.0"/>
<target name="test_actuators_mkk" board="lisa_l_1.0"/>
<target name="test_actuators_asctecv1" board="lisa_l_1.0"/>
<target name="tunnel_sw" board="lisa_l_1.0"/>
<target name="tunnel_hw" board="lisa_l_1.0"/>
</firmware>
<firmware name="lisa_passthrough">
<target name="overo_test_passthrough" board="lisa_l_1.0" >
<param name="HOST" value="A7"/>
<param name="USER" value=""/>
<param name="TARGET_DIR" value="~"/>
<param name="PERIODIC_FREQ" value="512"/>
</target>
<target name="stm_passthrough" board="lisa_l_1.0">
<subsystem name="radio_control" type="spektrum"/>
<subsystem name="imu" type="b2_v1.1"/>
</target>
</firmware>
</airframe>
+1 -2
View File
@@ -101,8 +101,7 @@ ap.srcs += mcu_periph/uart.c
ap.srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c
# I2C is needed for speed controllers and barometers on lisa
ap.srcs += mcu_periph/i2c.c
ap.srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c
include $(CFG_SHARED)/i2c_select.makefile
ap.srcs += $(SRC_FIRMWARE)/commands.c
@@ -87,9 +87,8 @@ $(TARGET).srcs += math/pprz_geodetic_int.c math/pprz_geodetic_float.c math/pprz_
#
# I2C
#
$(TARGET).srcs += mcu_periph/i2c.c
$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c
include $(CFG_SHARED)/i2c_select.makefile
######################################################################
##
## COMMON FOR ALL NON-SIMULATION TARGETS
@@ -0,0 +1,12 @@
#generic i2c driver
# TODO: this file was created to be able to select different driver files. Once 1 driver is selected as the best others can be removed including this file
$(TARGET).srcs += mcu_periph/i2c.c
ifeq ($(ARCH), stm32)
$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c
#$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.rewritten.c
else
$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c
endif
+15
View File
@@ -0,0 +1,15 @@
<!DOCTYPE module SYSTEM "module.dtd">
<module name="benchmark">
<header>
<file name="i2c_abuse_test.h"/>
</header>
<init fun="init_i2c_abuse_test()"/>
<event fun="event_i2c_abuse_test()" />
<!-- <periodic fun="periodic_50Hz_i2c_abuse_test()" period="0.02" autorun="FALSE"/> -->
<makefile>
<!-- define name="i2c_abuse_test_MODULE_LED" value="2"/ -->
<file name="i2c_abuse_test.c"/>
</makefile>
</module>
@@ -0,0 +1,245 @@
/*
* $Id$
*
* Copyright (C) 2009 Gautier Hattenberger
*
* 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 "i2c_abuse_test.h"
#include "led.h"
#include "mcu_periph/i2c.h"
struct i2c_transaction i2c_test1;
struct i2c_transaction i2c_test2;
uint8_t i2c_abuse_test_counter = 0;
uint16_t i2c_abuse_test_bitrate = 1000;
void init_i2c_abuse_test(void) {
//LED_INIT(DEMO_MODULE_LED);
//LED_OFF(DEMO_MODULE_LED);
i2c_test1.status = I2CTransSuccess;
i2c_test1.slave_addr = 0x3C;
i2c_abuse_test_counter = 0;
i2c_abuse_test_bitrate = 10000;
i2c_test2.status = I2CTransSuccess;
}
static void i2c_abuse_send_transaction(uint8_t _init)
{
i2c_test1.slave_addr = 0x3C;
i2c_test1.len_w = 0;
i2c_test1.len_r = 0;
switch (_init)
{
case 1:
i2c_test1.type = I2CTransTx;
i2c_test1.buf[0] = 0x00; // set to rate to 50Hz
i2c_test1.buf[1] = 0x00 | (0x06 << 2);
i2c_test1.buf[2] = 0x01<<5;
i2c_test1.buf[3] = 0x00;
i2c_test1.len_w = 4;
i2c_submit(&i2c2,&i2c_test1);
break;
case 2:
i2c_test1.type = I2CTransTx;
i2c_test1.buf[0] = 0x01; // set to gain to 1 Gauss
i2c_test1.buf[1] = 0x01<<5;
i2c_test1.len_w = 2;
i2c_submit(&i2c2,&i2c_test1);
break;
case 3:
i2c_test1.type = I2CTransTx;
i2c_test1.buf[0] = 0x00; // set to continuous mode
i2c_test1.len_w = 1;
i2c_submit(&i2c2,&i2c_test1);
break;
case 4:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 1;
i2c_submit(&i2c2,&i2c_test1);
break;
case 5:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 2;
i2c_submit(&i2c2,&i2c_test1);
break;
case 6:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 3;
i2c_submit(&i2c2,&i2c_test1);
break;
case 7:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 4;
i2c_submit(&i2c2,&i2c_test1);
break;
case 8:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 5;
i2c_submit(&i2c2,&i2c_test1);
break;
case 9:
// bad addr
i2c_test1.slave_addr = 0x3C + 2;
i2c_test1.type = I2CTransTx;
i2c_test1.len_w = 1;
i2c_submit(&i2c2,&i2c_test1);
break;
case 10:
// 2 consecutive
i2c_test1.type = I2CTransTx;
i2c_test1.buf[0] = 0x00; // set to continuous mode
i2c_test1.len_w = 1;
i2c_submit(&i2c2,&i2c_test1);
break;
case 11:
i2c_test1.slave_addr = 0x3C;
i2c_test1.type = I2CTransTxRx;
i2c_test1.len_r = 1;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
break;
case 12:
i2c_test1.slave_addr = 0x3C;
i2c_test1.type = I2CTransTxRx;
i2c_test1.len_r = 2;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
break;
case 13:
i2c_test1.slave_addr = 0x3C;
i2c_test1.type = I2CTransTxRx;
i2c_test1.len_r = 3;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
break;
case 14:
i2c_test1.slave_addr = 0x3C;
i2c_test1.type = I2CTransTxRx;
i2c_test1.len_r = 4;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
break;
case 15:
i2c_test1.slave_addr = 0x3C;
i2c_test1.type = I2CTransTxRx;
i2c_test1.len_r = 4;
i2c_test1.len_w = 2;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
break;
default:
i2c_test1.slave_addr = 0x3C;
i2c_test1.type = I2CTransTxRx;
i2c_test1.len_r = 5;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
}
}
void event_i2c_abuse_test(void)
{
if (i2c_idle(&i2c1))
{
LED_ON(7); // green = idle
LED_OFF(6);
}
else
{
LED_ON(6); // red = busy
LED_OFF(7);
}
if (i2c_idle(&i2c2))
{
LED_ON(5); // green = idle
LED_OFF(4);
}
else
{
LED_ON(4); // red = busy
LED_OFF(5);
}
// Wait for I2C transaction object to be released by the I2C driver before changing anything
if ((i2c_abuse_test_counter < 12) && (i2c_abuse_test_counter > 3))
{
if ((i2c_test2.status == I2CTransFailed) || (i2c_test2.status == I2CTransSuccess))
{
//i2c_test2.slave_addr = 0x90;
i2c_test2.type = I2CTransRx;
i2c_test2.slave_addr = 0x92;
i2c_test2.len_r = 2;
i2c_submit(&i2c2,&i2c_test2);
}
}
if ((i2c_test1.status == I2CTransFailed) || (i2c_test1.status == I2CTransSuccess))
{
if (i2c_abuse_test_counter < 16)
{
i2c_abuse_test_counter++;
}
else
{
// wait until ready:
if (i2c_idle(&i2c2))
{
i2c_abuse_test_counter = 1;
i2c_setbitrate(&i2c2, i2c_abuse_test_bitrate);
i2c_abuse_test_bitrate += 17000;
if (i2c_abuse_test_bitrate > 500000)
{
i2c_abuse_test_bitrate -= 500000;
}
LED_TOGGLE(4);
}
}
if (i2c_abuse_test_counter < 16)
{
i2c_abuse_send_transaction( i2c_abuse_test_counter );
LED_TOGGLE(5);
}
}
}
void periodic_50Hz_i2c_abuse_test(void) {
// LED_TOGGLE(DEMO_MODULE_LED);
}
@@ -0,0 +1,52 @@
/*
* $Id$
*
* Copyright (C) 2009 C. De Wagter
*
* 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 I2C_ABUSE_TEST_module.h
*
* Total I2C Abuse:
*
* -all transaction types: T1 T2 T3 T4 R1 R2 R3 R4 T1R1 T2R1 T1R2 T1R3 T1R4 T1R5 T2R5
* -all bitrates: 1k (way too slow) to 1M (way to fast)
* -occasional Short circuit (simulate bus capacitance or EMI errors)
* -variable bus load: from empty to full stack
*
* -Connect LED to MosFet that pulls-down the SCL and SDA lines
*/
#ifndef I2C_ABUSE_TEST_MODULE_H
#define I2C_ABUSE_TEST_MODULE_H
#ifndef I2C_ABUSE_SHORT_SCL_LED
#define I2C_ABUSE_SHORT_SCL_LED 2
#endif
#ifndef I2C_ABUSE_SHORT_SDA_LED
#define I2C_ABUSE_SHORT_SDA_LED 3
#endif
void init_i2c_abuse_test(void);
void event_i2c_abuse_test(void);
void periodic_50Hz_i2c_abuse_test(void);
#endif