[stm32] merge new i2c driver

* the old i2c driver is still the default
* to use the new i2c driver, add to the firmware section in the airframe file
  <configure name="USE_NEW_I2C_DRIVER" value="1"/>
This commit is contained in:
Felix Ruess
2012-04-26 16:23:04 +02:00
31 changed files with 6258 additions and 133 deletions
+1 -1
View File
@@ -216,7 +216,7 @@
<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="radio_control" type="ppm"/>
<subsystem name="actuators" type="asctec"/>
</target>
<target name="sim" board="pc">
+215
View File
@@ -0,0 +1,215 @@
<!DOCTYPE airframe SYSTEM "../airframe.dtd">
<!--
YAPA + XSens + XBee
-->
<airframe name="Yapa v1">
<servos>
<servo name="THROTTLE" no="0" min="1000" neutral="1000" max="2000"/>
<servo name="AILERON_LEFT" no="2" min="1000" neutral="1500" max="2000"/>
<servo name="AILERON_RIGHT" no="6" min="2000" neutral="1500" max="1000"/>
<servo name="ELEVATOR" no="3" min="2000" neutral="1500" max="1000"/>
<servo name="RUDDER" no="4" min="1100" neutral="1500" max="1900"/>
</servos>
<commands>
<axis name="THROTTLE" failsafe_value="0"/>
<axis name="ROLL" failsafe_value="0"/>
<axis name="PITCH" failsafe_value="0"/>
<axis name="BRAKE" failsafe_value="0"/> <!-- both elerons up as butterfly brake ? -->
</commands>
<rc_commands>
<set command="THROTTLE" value="@THROTTLE"/>
<set command="ROLL" value="@ROLL"/>
<set command="PITCH" value="@PITCH"/>
<set command="BRAKE" value="@YAW"/>
</rc_commands>
<section name="SERVO_MIXER_GAINS">
<define name="AILERON_RATE_UP" value="0.50f"/>
<define name="AILERON_RATE_DOWN" value="0.25f"/>
<define name="AILERON_RATE_UP_BRAKE" value="0.5f"/>
<define name="AILERON_RATE_DOWN_BRAKE" value="0.9f"/>
<define name="PITCH_GAIN" value="0.9f"/>
<define name="YAW_THRUST" value="0.0f"/>
<define name="BRAKE_AILEVON" value="-0.68f"/>
<define name="BRAKE_PITCH" value="0.0f"/>
<define name="MAX_BRAKE_RATE" value="150"/>
<define name="RATELIMIT(X,RATE)" value="( _rate_limited_value + Chop( (X) - _rate_limited_value, -(RATE), (RATE) )); \
int16_t _rate_limited_value = 0;"/>
</section>
<command_laws>
<!-- Brake Rate Limiter -->
<let var="brake_value" value="Chop(-@BRAKE, 0, MAX_PPRZ)"/>
<!--<let var="brake_value" value="RATELIMIT( $brake_value , MAX_BRAKE_RATE )"/>
<let var="test; \
static int16_t _var_brake_value = 0; \
_var_brake_value += LIMIT(_var_brake_value_nofilt - _var_brake_value,-MAX_BRAKE_RATE,MAX_BRAKE_RATE); \
int verwaarloos_deze_warning_CDW" value="0"/>
-->
<!-- Differential Aileron Depending on Brake Value -->
<let var="aileron_up_rate" value="(AILERON_RATE_UP * (MAX_PPRZ - $brake_value)) + (AILERON_RATE_UP_BRAKE * $brake_value)"/>
<let var="aileron_down_rate" value="(AILERON_RATE_DOWN * (MAX_PPRZ - $brake_value)) + (AILERON_RATE_DOWN_BRAKE * $brake_value)"/>
<let var="aileron_up" value="(@ROLL * (((float)$aileron_up_rate) / ((float)MAX_PPRZ)))"/>
<let var="aileron_down" value="(@ROLL * (((float)$aileron_down_rate) / ((float)MAX_PPRZ)))"/>
<let var="leftturn" value="(@ROLL >= 0? 1 : 0)"/>
<let var="rightturn" value="(1 - $leftturn)"/>
<set servo="AILERON_LEFT" value="($aileron_up * $leftturn) + ($aileron_down * $rightturn) - $brake_value*(BRAKE_AILEVON)"/>
<set servo="AILERON_RIGHT" value="($aileron_up * $rightturn) + ($aileron_down * $leftturn) + $brake_value*(BRAKE_AILEVON)"/>
<!-- Differential Thurst -->
<set servo="THROTTLE" value="@THROTTLE"/>
<!-- Pitch with Brake-Trim Function -->
<set servo="ELEVATOR" value="-@PITCH * PITCH_GAIN + BRAKE_PITCH * $brake_value"/>
</command_laws>
<section name="AUTO1" prefix="AUTO1_">
<define name="MAX_ROLL" value="0.7"/>
<define name="MAX_PITCH" value="0.7"/>
</section>
<section name="BAT">
<define name="MilliAmpereOfAdc(adc)" value="((adc) - 505) * 124.0f"/>
<define name="LOW_BAT_LEVEL" value="10.5" unit="V"/>
<define name="CRITIC_BAT_LEVEL" value="10" unit="V"/>
<define name="CATASTROPHIC_BAT_LEVEL" value="9.1" unit="V"/>
</section>
<section name="INS" prefix="INS_">
<define name="ROLL_NEUTRAL_DEFAULT" value="0" unit="deg"/>
<define name="PITCH_NEUTRAL_DEFAULT" value="0" unit="deg"/>
</section>
<section name="MISC">
<define name="NOMINAL_AIRSPEED" value="13." unit="m/s"/>
<define name="CARROT" value="5." unit="s"/>
<define name="CONTROL_RATE" value="60" unit="Hz"/>
<define name="XBEE_INIT" value="&quot;ATPL2\rATRN5\rATTT80\r&quot;"/>
<!-- <define name="NO_XBEE_API_INIT" value="TRUE"/> -->
<define name="ALT_KALMAN_ENABLED" value="TRUE"/>
<define name="DEFAULT_CIRCLE_RADIUS" value="80."/>
<define name="GLIDE_AIRSPEED" value="10"/>
<define name="GLIDE_VSPEED" value="3."/>
<define name="GLIDE_PITCH" value="45" unit="deg"/>
</section>
<section name="VERTICAL CONTROL" prefix="V_CTL_">
<define name="POWER_CTL_BAT_NOMINAL" value="11.1" unit="volt"/>
<!-- outer loop proportional gain -->
<define name="ALTITUDE_PGAIN" value="-0.03"/>
<!-- outer loop saturation -->
<define name="ALTITUDE_MAX_CLIMB" value="2."/>
<!-- auto throttle inner loop -->
<define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.32"/>
<define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.25"/>
<define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.65"/>
<define name="AUTO_THROTTLE_LOITER_TRIM" value="1500"/>
<define name="AUTO_THROTTLE_DASH_TRIM" value="-4000"/>
<define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.15" unit="%/(m/s)"/>
<define name="AUTO_THROTTLE_PGAIN" value="-0.01"/>
<define name="AUTO_THROTTLE_IGAIN" value="0.1"/>
<define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.05"/>
<define name="THROTTLE_SLEW_LIMITER" value="2" unit="s"/>
</section>
<section name="HORIZONTAL CONTROL" prefix="H_CTL_">
<define name="COURSE_PGAIN" value="-1.20000004768"/>
<define name="COURSE_DGAIN" value="0.3"/>
<define name="COURSE_PRE_BANK_CORRECTION" value="0.2"/>
<define name="ROLL_MAX_SETPOINT" value="0.75" unit="radians"/>
<define name="PITCH_MAX_SETPOINT" value="0.5" unit="radians"/>
<define name="PITCH_MIN_SETPOINT" value="-0.5" unit="radians"/>
<define name="PITCH_PGAIN" value="-12000."/>
<define name="PITCH_DGAIN" value="1.5"/>
<define name="ELEVATOR_OF_ROLL" value="1000."/>
<define name="ROLL_SLEW" value="1."/>
<define name="ROLL_ATTITUDE_GAIN" value="-7500"/>
<define name="ROLL_RATE_GAIN" value="0."/>
</section>
<section name="AGGRESSIVE" prefix="AGR_">
<define name="BLEND_START" value="20"/><!-- Altitude Error to Initiate Aggressive Climb CANNOT BE ZERO!!-->
<define name="BLEND_END" value="10"/><!-- Altitude Error to Blend Aggressive to Regular Climb Modes CANNOT BE ZERO!!-->
<define name="CLIMB_THROTTLE" value="1.00"/><!-- Gaz for Aggressive Climb -->
<define name="CLIMB_PITCH" value="0.3"/><!-- Pitch for Aggressive Climb -->
<define name="DESCENT_THROTTLE" value="0.1"/><!-- Gaz for Aggressive Decent -->
<define name="DESCENT_PITCH" value="-0.25"/><!-- Pitch for Aggressive Decent -->
<define name="CLIMB_NAV_RATIO" value="0.8"/><!-- Percent Navigation for Altitude Error Equal to Start Altitude -->
<define name="DESCENT_NAV_RATIO" value="1.0"/>
</section>
<section name="FAILSAFE" prefix="FAILSAFE_">
<define name="DEFAULT_THROTTLE" value="0.35" unit="%"/>
<define name="DEFAULT_ROLL" value="0.17" unit="rad"/>
<define name="DEFAULT_PITCH" value="0.08" unit="rad"/>
<define name="HOME_RADIUS" value="DEFAULT_CIRCLE_RADIUS" unit="m"/>
<define name="KILL_MODE_DISTANCE" value="(MAX_DIST_FROM_HOME*1.5)"/>
<define name="DELAY_WITHOUT_GPS" value="3" unit="s"/>
</section>
<section name="DIGITAL_CAMERA" prefix="DC_">
<define name="AUTOSHOOT_QUARTERSEC_PERIOD" value="6" unit="quarter_second"/>
<define name="AUTOSHOOT_METER_GRID" value="50" unit="meter"/>
</section>
<modules>
<load name="ins_xsens_MTiG_fixedwing.xml">
<configure name="XSENS_UART_NR" value="0"/>
</load>
<load name="i2c_abuse_test.xml"/>
</modules>
<firmware name="fixedwing">
<target name="ap" board="tiny_2.11">
<define name="STRONG_WIND"/>
<define name="WIND_INFO"/>
<define name="WIND_INFO_RET"/>
<define name="LOITER_TRIM"/>
<define name="ALT_KALMAN"/>
</target>
<target name="sim" board="pc"/>
<subsystem name="radio_control" type="ppm"/>
<!-- Communication -->
<subsystem name="telemetry" type="xbee_api">
<configure name="MODEM_BAUD" value="B57600"/>
</subsystem>
<!-- Actuators -->
<subsystem name="control"/>
<!-- Sensors -->
<subsystem name="navigation"/>
<subsystem name="gps" type="xsens"/>
</firmware>
</airframe>
@@ -15,6 +15,7 @@
<define name="ACTUATORS_START_DELAY" value="3"/>
<define name="USE_INS_NAV_INIT"/>
<configure name="AHRS_ALIGNER_LED" value="3"/>
<configure name="USE_NEW_I2C_DRIVER" value="1"/>
<define name="USE_KILL_SWITCH_FOR_MOTOR_ARMING"/>
</target>
<target name="sim" board="pc">
@@ -4,8 +4,11 @@
$(TARGET).srcs += mcu_periph/i2c.c
ifeq ($(ARCH), stm32)
ifeq ($(USE_NEW_I2C_DRIVER), 1)
$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.rewritten.c
else
$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c
#$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.rewritten.c
endif
else
$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c
endif
+12 -2
View File
@@ -8,11 +8,21 @@
<file name="i2c_abuse_test.h"/>
</header>
<init fun="init_i2c_abuse_test()"/>
<periodic fun="periodic_50Hz_i2c_abuse_test()" period="0.02" autorun="TRUE" />
<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"/>
<raw>
ifeq ($(ARCH), lpc21)
$(TARGET).CFLAGS += -DI2C_ABUSE_LED=3
$(TARGET).CFLAGS += -DUSE_I2C0
$(TARGET).CFLAGS += -DI2C_ABUSE_PORT=i2c0
else ifeq ($(ARCH), stm32)
$(TARGET).CFLAGS += -DI2C_ABUSE_LED=7
$(TARGET).CFLAGS += -DI2C_ABUSE_PORT=i2c2
endif
</raw>
</makefile>
</module>
+1
View File
@@ -16,6 +16,7 @@
<message name="BOOZ2_CAM" period="1."/>
<message name="GPS_INT" period=".25"/>
<message name="INS" period=".25"/>
<message name="I2C_ERRORS" period="6."/>
</mode>
<mode name="ppm">
@@ -161,3 +161,7 @@ void i2c_init(void) {
sbi(TWSR, TWPS0);
*/
}
void i2c_event(void) { }
void i2c2_setbitrate(int bitrate __attribute__ ((unused))) { }
@@ -340,3 +340,45 @@ bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t) {
return TRUE;
}
void i2c_event(void) { }
void i2c_setbitrate(struct i2c_periph* p, int bitrate)
{
int period = 15000000 / 2 / bitrate;
// Max 400kpbs
if (period < 19)
period = 19;
// Min 5kbps
if (period > 1500)
period = 1500;
/* default clock speed 37.5KHz with our 15MHz PCLK
I2C1_CLOCK = PCLK / (I2C1_SCLL + I2C1_SCLH) */
#if (PCLK == 30000000)
period *= 2;
#endif
#if (PCLK == 60000000)
period *= 4;
#endif
#ifdef USE_I2C0
if (p == &i2c0)
{
/* set bitrate */
I2C0SCLL = period;
I2C0SCLH = period;
}
#endif
#ifdef USE_I2C1
if (p == &i2c1)
{
/* set bitrate */
I2C1SCLL = period;
I2C1SCLH = period;
}
#endif
}
@@ -4,3 +4,6 @@ void i2c_hw_init ( void ) {}
bool_t i2c_idle(struct i2c_periph *p __attribute__ ((unused))) { return TRUE; }
bool_t i2c_submit(struct i2c_periph* p __attribute__ ((unused)), struct i2c_transaction* t __attribute__ ((unused))) { return TRUE;}
void i2c_event(void) { }
void i2c2_setbitrate(int bitrate __attribute__ ((unused))) { }
+6 -4
View File
@@ -287,9 +287,11 @@ static inline void on_status_restart_requested(struct i2c_periph *periph, struct
}
}
void i2c_event(void)
{
}
static inline void i2c_event(struct i2c_periph *p, uint32_t event)
static inline void i2c_driver_event(struct i2c_periph *p, uint32_t event)
{
struct i2c_transaction* trans = p->trans[p->trans_extract_idx];
switch (p->status) {
@@ -509,7 +511,7 @@ void i2c1_hw_init(void) {
void i2c1_ev_irq_handler(void) {
uint32_t event = I2C_GetLastEvent(I2C1);
i2c_event(&i2c1, event);
i2c_driver_event(&i2c1, event);
}
@@ -586,7 +588,7 @@ void i2c2_hw_init(void) {
void i2c2_ev_irq_handler(void) {
uint32_t event = I2C_GetLastEvent(I2C2);
i2c_event(&i2c2, event);
i2c_driver_event(&i2c2, event);
}
void i2c2_er_irq_handler(void) {
@@ -34,8 +34,6 @@
#ifdef USE_I2C1
extern struct i2c_errors i2c1_errors;
extern void i2c1_hw_init(void);
extern void i2c1_ev_irq_handler(void);
extern void i2c1_er_irq_handler(void);
@@ -46,8 +44,6 @@ extern void i2c1_er_irq_handler(void);
#ifdef USE_I2C2
extern struct i2c_errors i2c2_errors;
extern void i2c2_hw_init(void);
extern void i2c2_ev_irq_handler(void);
extern void i2c2_er_irq_handler(void);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1
View File
@@ -26,6 +26,7 @@ void baro_init(void) {
void baro_periodic(void) {
// check i2c_done
if (!i2c_idle(&i2c2)) return;
switch (baro_board.status) {
case LBS_UNINITIALIZED:
baro_board_send_reset();
+10 -12
View File
@@ -1,6 +1,4 @@
/*
* $Id$
*
* Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
*
* This file is part of paparazzi.
@@ -32,6 +30,7 @@
#include "mcu.h"
#include "mcu_periph/sys_time.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/i2c.h"
#include "led.h"
@@ -47,7 +46,6 @@ static inline void main_event_task( void );
static inline void main_on_baro_diff(void);
static inline void main_on_baro_abs(void);
int main(void) {
main_init();
@@ -81,15 +79,15 @@ static inline void main_periodic_task( void ) {
RunOnceEvery(256,
{
DOWNLINK_SEND_I2C_ERRORS(DefaultChannel, DefaultDevice,
&i2c2_errors.ack_fail_cnt,
&i2c2_errors.miss_start_stop_cnt,
&i2c2_errors.arb_lost_cnt,
&i2c2_errors.over_under_cnt,
&i2c2_errors.pec_recep_cnt,
&i2c2_errors.timeout_tlow_cnt,
&i2c2_errors.smbus_alert_cnt,
&i2c2_errors.unexpected_event_cnt,
&i2c2_errors.last_unexpected_event);
&i2c2.errors->ack_fail_cnt,
&i2c2.errors->miss_start_stop_cnt,
&i2c2.errors->arb_lost_cnt,
&i2c2.errors->over_under_cnt,
&i2c2.errors->pec_recep_cnt,
&i2c2.errors->timeout_tlow_cnt,
&i2c2.errors->smbus_alert_cnt,
&i2c2.errors->unexpected_event_cnt,
&i2c2.errors->last_unexpected_event);
});
}
@@ -583,6 +583,10 @@ void monitor_task( void ) {
/*********** EVENT ***********************************************************/
void event_task_ap( void ) {
#ifndef SINGLE_MCU
i2c_event();
#endif
#if USE_AHRS
#if USE_IMU
ImuEvent(on_gyro_event, on_accel_event, on_mag_event);
@@ -43,6 +43,7 @@
#include "firmwares/fixedwing/autopilot.h"
#include "fbw_downlink.h"
#include "paparazzi.h"
#include "mcu_periph/i2c.h"
#ifdef MCU_SPI_LINK
#include "link_mcu.h"
@@ -119,6 +120,7 @@ void event_task_fbw( void) {
RadioControlEvent(handle_rc_frame);
#endif
i2c_event();
#ifdef INTER_MCU
#ifdef MCU_SPI_LINK
+2
View File
@@ -196,6 +196,8 @@ STATIC_INLINE void failsafe_check( void ) {
STATIC_INLINE void main_event( void ) {
i2c_event();
DatalinkEvent();
if (autopilot_rc) {
+39 -12
View File
@@ -48,8 +48,8 @@
#endif
#include "subsystems/ins.h"
#include "subsystems/ahrs.h"
//FIXME: wtf ??!!
#include "mcu_periph/i2c_arch.h"
// I2C Error counters
#include "mcu_periph/i2c.h"
#define PERIODIC_SEND_ALIVE(_trans, _dev) DOWNLINK_SEND_ALIVE(_trans, _dev, 16, MD5SUM)
@@ -736,16 +736,43 @@
&ahrs.ltp_to_body_euler.psi); \
}
#define PERIODIC_SEND_I2C_ERRORS(_trans, _dev) { \
DOWNLINK_SEND_I2C_ERRORS(_trans, _dev, \
&i2c_errc_ack_fail, \
&i2c_errc_miss_start_stop, \
&i2c_errc_arb_lost, \
&i2c_errc_over_under, \
&i2c_errc_pec_recep, \
&i2c_errc_timeout_tlow, \
&i2c_errc_smbus_alert \
); \
#ifdef USE_I2C1
#define PERIODIC_SEND_I2C1_ERRORS(_trans, _dev) { \
DOWNLINK_SEND_I2C_ERRORS(_trans, _dev, \
&i2c1.errors->ack_fail_cnt, \
&i2c1.errors->miss_start_stop_cnt, \
&i2c1.errors->arb_lost_cnt, \
&i2c1.errors->over_under_cnt, \
&i2c1.errors->pec_recep_cnt, \
&i2c1.errors->timeout_tlow_cnt, \
&i2c1.errors->smbus_alert_cnt, \
&i2c1.errors->unexpected_event_cnt, \
&i2c1.errors->last_unexpected_event); \
}
#else
#define PERIODIC_SEND_I2C1_ERRORS(_trans, _dev) {}
#endif
#ifdef USE_I2C2
#define PERIODIC_SEND_I2C2_ERRORS(_trans, _dev) { \
DOWNLINK_SEND_I2C_ERRORS(_trans, _dev, \
&i2c2.errors->ack_fail_cnt, \
&i2c2.errors->miss_start_stop_cnt, \
&i2c2.errors->arb_lost_cnt, \
&i2c2.errors->over_under_cnt, \
&i2c2.errors->pec_recep_cnt, \
&i2c2.errors->timeout_tlow_cnt, \
&i2c2.errors->smbus_alert_cnt, \
&i2c2.errors->unexpected_event_cnt, \
&i2c2.errors->last_unexpected_event); \
}
#else
#define PERIODIC_SEND_I2C2_ERRORS(_trans, _dev) {}
#endif
#define PERIODIC_SEND_I2C_ERRORS(_trans, _dev) { \
PERIODIC_SEND_I2C1_ERRORS(_trans, _dev); \
PERIODIC_SEND_I2C2_ERRORS(_trans, _dev); \
}
// FIXME: still used?? or replace by EXTRA_ADC
+10 -9
View File
@@ -41,6 +41,7 @@
#include "led.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/i2c.h"
#include "peripherals/hmc5843.h"
#include "my_debug_servo.h"
#include "math/pprz_algebra_int.h"
@@ -91,15 +92,15 @@ static inline void main_periodic_task( void ) {
RunOnceEvery(256,
{
DOWNLINK_SEND_I2C_ERRORS(DefaultChannel, DefaultDevice,
&i2c2_errors.ack_fail_cnt,
&i2c2_errors.miss_start_stop_cnt,
&i2c2_errors.arb_lost_cnt,
&i2c2_errors.over_under_cnt,
&i2c2_errors.pec_recep_cnt,
&i2c2_errors.timeout_tlow_cnt,
&i2c2_errors.smbus_alert_cnt,
&i2c2_errors.unexpected_event_cnt,
&i2c2_errors.last_unexpected_event);
&i2c2.errors->ack_fail_cnt,
&i2c2.errors->miss_start_stop_cnt,
&i2c2.errors->arb_lost_cnt,
&i2c2.errors->over_under_cnt,
&i2c2.errors->pec_recep_cnt,
&i2c2.errors->timeout_tlow_cnt,
&i2c2.errors->smbus_alert_cnt,
&i2c2.errors->unexpected_event_cnt,
&i2c2.errors->last_unexpected_event);
});
if (mag_state == 2) send_config();
+9 -9
View File
@@ -88,15 +88,15 @@ static inline void main_periodic_task( void ) {
});
RunOnceEvery(256, {
DOWNLINK_SEND_I2C_ERRORS(DefaultChannel, DefaultDevice,
&i2c2_errors.ack_fail_cnt,
&i2c2_errors.miss_start_stop_cnt,
&i2c2_errors.arb_lost_cnt,
&i2c2_errors.over_under_cnt,
&i2c2_errors.pec_recep_cnt,
&i2c2_errors.timeout_tlow_cnt,
&i2c2_errors.smbus_alert_cnt,
&i2c2_errors.unexpected_event_cnt,
&i2c2_errors.last_unexpected_event);
&i2c2.errors->ack_fail_cnt,
&i2c2.errors->miss_start_stop_cnt,
&i2c2.errors->arb_lost_cnt,
&i2c2.errors->over_under_cnt,
&i2c2.errors->pec_recep_cnt,
&i2c2.errors->timeout_tlow_cnt,
&i2c2.errors->smbus_alert_cnt,
&i2c2.errors->unexpected_event_cnt,
&i2c2.errors->last_unexpected_event);
});
switch (gyro_state) {
+19 -20
View File
@@ -1,6 +1,4 @@
/*
* $Id$
*
* Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
*
* This file is part of paparazzi.
@@ -31,6 +29,7 @@
#include "std.h"
#include "mcu.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/i2c.h"
#include "mcu_periph/sys_time.h"
#include "subsystems/datalink/downlink.h"
#include "led.h"
@@ -157,15 +156,15 @@ static void test_baro_periodic(void) {
RunOnceEvery(2, {baro_periodic();});
RunOnceEvery(100,{
DOWNLINK_SEND_I2C_ERRORS(DefaultChannel, DefaultDevice,
&i2c2_errors.ack_fail_cnt,
&i2c2_errors.miss_start_stop_cnt,
&i2c2_errors.arb_lost_cnt,
&i2c2_errors.over_under_cnt,
&i2c2_errors.pec_recep_cnt,
&i2c2_errors.timeout_tlow_cnt,
&i2c2_errors.smbus_alert_cnt,
&i2c2_errors.unexpected_event_cnt,
&i2c2_errors.last_unexpected_event);
&i2c2.errors->ack_fail_cnt,
&i2c2.errors->miss_start_stop_cnt,
&i2c2.errors->arb_lost_cnt,
&i2c2.errors->over_under_cnt,
&i2c2.errors->pec_recep_cnt,
&i2c2.errors->timeout_tlow_cnt,
&i2c2.errors->smbus_alert_cnt,
&i2c2.errors->unexpected_event_cnt,
&i2c2.errors->last_unexpected_event);
});
}
static void test_baro_event(void) {BaroEvent(test_baro_on_baro_abs, test_baro_on_baro_diff);}
@@ -191,15 +190,15 @@ static void test_bldc_periodic(void) {
RunOnceEvery(100,{
DOWNLINK_SEND_I2C_ERRORS(DefaultChannel, DefaultDevice,
&i2c1_errors.ack_fail_cnt,
&i2c1_errors.miss_start_stop_cnt,
&i2c1_errors.arb_lost_cnt,
&i2c1_errors.over_under_cnt,
&i2c1_errors.pec_recep_cnt,
&i2c1_errors.timeout_tlow_cnt,
&i2c1_errors.smbus_alert_cnt,
&i2c1_errors.unexpected_event_cnt,
&i2c1_errors.last_unexpected_event);
&i2c1.errors->ack_fail_cnt,
&i2c1.errors->miss_start_stop_cnt,
&i2c1.errors->arb_lost_cnt,
&i2c1.errors->over_under_cnt,
&i2c1.errors->pec_recep_cnt,
&i2c1.errors->timeout_tlow_cnt,
&i2c1.errors->smbus_alert_cnt,
&i2c1.errors->unexpected_event_cnt,
&i2c1.errors->last_unexpected_event);
});
}
+3
View File
@@ -133,6 +133,9 @@ extern void i2c2_init(void);
extern void i2c_init(struct i2c_periph* p);
extern bool_t i2c_idle(struct i2c_periph* p);
extern bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t);
extern void i2c_setbitrate(struct i2c_periph* p, int bitrate);
extern void i2c_event(void);
#define I2CReceive(_p, _t, _s_addr, _len) { \
_t.type = I2CTransRx; \
+26 -39
View File
@@ -1,7 +1,7 @@
/*
* $Id$
*
* Copyright (C) 2009 Gautier Hattenberger
* Copyright (C) 2011 Christophe De Wagter
*
* This file is part of paparazzi.
*
@@ -29,8 +29,8 @@
struct i2c_transaction i2c_test1;
struct i2c_transaction i2c_test2;
uint8_t i2c_abuse_test_counter = 0;
uint16_t i2c_abuse_test_bitrate = 1000;
volatile uint8_t i2c_abuse_test_counter = 0;
volatile uint32_t i2c_abuse_test_bitrate = 1000;
void init_i2c_abuse_test(void) {
//LED_INIT(DEMO_MODULE_LED);
@@ -62,59 +62,59 @@ static void i2c_abuse_send_transaction(uint8_t _init)
i2c_test1.buf[2] = 0x01<<5;
i2c_test1.buf[3] = 0x00;
i2c_test1.len_w = 4;
i2c_submit(&i2c2,&i2c_test1);
i2c_submit(&I2C_ABUSE_PORT,&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);
i2c_submit(&I2C_ABUSE_PORT,&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);
i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
break;
case 4:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 1;
i2c_submit(&i2c2,&i2c_test1);
i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
break;
case 5:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 2;
i2c_submit(&i2c2,&i2c_test1);
i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
break;
case 6:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 3;
i2c_submit(&i2c2,&i2c_test1);
i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
break;
case 7:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 4;
i2c_submit(&i2c2,&i2c_test1);
i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
break;
case 8:
i2c_test1.type = I2CTransRx;
i2c_test1.len_r = 5;
i2c_submit(&i2c2,&i2c_test1);
i2c_submit(&I2C_ABUSE_PORT,&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);
i2c_submit(&I2C_ABUSE_PORT,&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);
i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
break;
case 11:
i2c_test1.slave_addr = 0x3C;
@@ -122,7 +122,7 @@ static void i2c_abuse_send_transaction(uint8_t _init)
i2c_test1.len_r = 1;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
break;
case 12:
i2c_test1.slave_addr = 0x3C;
@@ -130,7 +130,7 @@ static void i2c_abuse_send_transaction(uint8_t _init)
i2c_test1.len_r = 2;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
break;
case 13:
i2c_test1.slave_addr = 0x3C;
@@ -138,7 +138,7 @@ static void i2c_abuse_send_transaction(uint8_t _init)
i2c_test1.len_r = 3;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
break;
case 14:
i2c_test1.slave_addr = 0x3C;
@@ -146,7 +146,7 @@ static void i2c_abuse_send_transaction(uint8_t _init)
i2c_test1.len_r = 4;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
break;
case 15:
i2c_test1.slave_addr = 0x3C;
@@ -154,7 +154,7 @@ static void i2c_abuse_send_transaction(uint8_t _init)
i2c_test1.len_r = 4;
i2c_test1.len_w = 2;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
break;
default:
i2c_test1.slave_addr = 0x3C;
@@ -162,25 +162,14 @@ static void i2c_abuse_send_transaction(uint8_t _init)
i2c_test1.len_r = 5;
i2c_test1.len_w = 1;
i2c_test1.buf[0] = 0x03;
i2c_submit(&i2c2, &i2c_test1);
i2c_submit(&I2C_ABUSE_PORT, &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))
if (i2c_idle(&I2C_ABUSE_PORT))
{
LED_ON(5); // green = idle
LED_OFF(4);
@@ -200,7 +189,7 @@ void event_i2c_abuse_test(void)
i2c_test2.type = I2CTransRx;
i2c_test2.slave_addr = 0x92;
i2c_test2.len_r = 2;
i2c_submit(&i2c2,&i2c_test2);
i2c_submit(&I2C_ABUSE_PORT,&i2c_test2);
}
}
@@ -214,31 +203,29 @@ void event_i2c_abuse_test(void)
else
{
// wait until ready:
if (i2c_idle(&i2c2))
if (i2c_idle(&I2C_ABUSE_PORT))
{
i2c_abuse_test_counter = 1;
i2c_setbitrate(&i2c2, i2c_abuse_test_bitrate);
i2c_setbitrate(&I2C_ABUSE_PORT, i2c_abuse_test_bitrate);
i2c_abuse_test_bitrate += 17000;
if (i2c_abuse_test_bitrate > 500000)
if (i2c_abuse_test_bitrate > 410000)
{
i2c_abuse_test_bitrate -= 500000;
i2c_abuse_test_bitrate -= 410000;
}
LED_TOGGLE(4);
}
}
if (i2c_abuse_test_counter < 16)
{
RunOnceEvery(100,LED_TOGGLE(I2C_ABUSE_LED));
i2c_abuse_send_transaction( i2c_abuse_test_counter );
LED_TOGGLE(5);
}
}
}
void periodic_50Hz_i2c_abuse_test(void) {
// LED_TOGGLE(DEMO_MODULE_LED);
}
@@ -1,7 +1,7 @@
/*
* $Id$
*
* Copyright (C) 2009 C. De Wagter
* Copyright (C) 2011 Christophe De Wagter
*
* This file is part of paparazzi.
*
+3
View File
@@ -151,6 +151,9 @@ extern void imu_aspirin_arch_init(void);
static inline void gyro_read_i2c(void)
{
imu_aspirin.i2c_trans_gyro.type = I2CTransTxRx;
imu_aspirin.i2c_trans_gyro.len_w = 1;
imu_aspirin.i2c_trans_gyro.len_r = 6;
imu_aspirin.i2c_trans_gyro.buf[0] = ITG3200_REG_GYRO_XOUT_H;
i2c_submit(&i2c2,&imu_aspirin.i2c_trans_gyro);
imu_aspirin.reading_gyro = 1;
+10 -9
View File
@@ -28,6 +28,7 @@
#include "mcu_periph/sys_time.h"
#include "led.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/i2c.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
@@ -161,15 +162,15 @@ static inline void main_report(void) {
{
#ifdef USE_I2C2
DOWNLINK_SEND_I2C_ERRORS(DefaultChannel, DefaultDevice,
&i2c2_errors.ack_fail_cnt,
&i2c2_errors.miss_start_stop_cnt,
&i2c2_errors.arb_lost_cnt,
&i2c2_errors.over_under_cnt,
&i2c2_errors.pec_recep_cnt,
&i2c2_errors.timeout_tlow_cnt,
&i2c2_errors.smbus_alert_cnt,
&i2c2_errors.unexpected_event_cnt,
&i2c2_errors.last_unexpected_event);
&i2c2.errors->ack_fail_cnt,
&i2c2.errors->miss_start_stop_cnt,
&i2c2.errors->arb_lost_cnt,
&i2c2.errors->over_under_cnt,
&i2c2.errors->pec_recep_cnt,
&i2c2.errors->timeout_tlow_cnt,
&i2c2.errors->smbus_alert_cnt,
&i2c2.errors->unexpected_event_cnt,
&i2c2.errors->last_unexpected_event);
#endif
},
{
+11 -10
View File
@@ -31,6 +31,7 @@
#include "mcu_periph/sys_time.h"
#include "led.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/i2c.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
@@ -82,18 +83,18 @@ static inline void main_periodic_task( void ) {
#ifdef USE_I2C2
RunOnceEvery(111, {
DOWNLINK_SEND_I2C_ERRORS(DefaultChannel, DefaultDevice,
&i2c2_errors.ack_fail_cnt,
&i2c2_errors.miss_start_stop_cnt,
&i2c2_errors.arb_lost_cnt,
&i2c2_errors.over_under_cnt,
&i2c2_errors.pec_recep_cnt,
&i2c2_errors.timeout_tlow_cnt,
&i2c2_errors.smbus_alert_cnt,
&i2c2_errors.unexpected_event_cnt,
&i2c2_errors.last_unexpected_event);
&i2c2.errors->ack_fail_cnt,
&i2c2.errors->miss_start_stop_cnt,
&i2c2.errors->arb_lost_cnt,
&i2c2.errors->over_under_cnt,
&i2c2.errors->pec_recep_cnt,
&i2c2.errors->timeout_tlow_cnt,
&i2c2.errors->smbus_alert_cnt,
&i2c2.errors->unexpected_event_cnt,
&i2c2.errors->last_unexpected_event);
});
#endif
if (cpu_time_sec > 1) imu_periodic();
if (sys_time.nb_sec > 1) imu_periodic();
RunOnceEvery(10, { LED_PERIODIC();});
}