Merge remote-tracking branch 'paparazzi/master' into telemetry

Conflicts:
	sw/airborne/firmwares/rotorcraft/autopilot.c
This commit is contained in:
Gautier Hattenberger
2013-07-10 19:25:12 +02:00
80 changed files with 2176 additions and 620 deletions
+77 -2
View File
@@ -1,11 +1,86 @@
Paparazzi 4.9 - development branch Paparazzi 5.0.0_stable
================================== ======================
Stable version release
General
-------
- STM libs completely replaced by libopencm3 - STM libs completely replaced by libopencm3
- [gcc-arm-embedded] (https://launchpad.net/gcc-arm-embedded) is the new recommended toolchain
- Use findlib (ocamlfind) for ocaml packages. Faster build.
[#274] (https://github.com/paparazzi/paparazzi/pull/274)
- Building/Running the groundsegment on an ARM (e.g. RaspberryPi).
- Input2ivy uses SDL for joysticks (cross-platform, works on OSX as well now) - Input2ivy uses SDL for joysticks (cross-platform, works on OSX as well now)
[#220] (https://github.com/paparazzi/paparazzi/pull/220) [#220] (https://github.com/paparazzi/paparazzi/pull/220)
- Option to change text papget color using a combobox - Option to change text papget color using a combobox
[#194] (https://github.com/paparazzi/paparazzi/pull/194) [#194] (https://github.com/paparazzi/paparazzi/pull/194)
- Redundant communications
[#429] (https://github.com/paparazzi/paparazzi/pull/429)
- Log also contains includes like procedures now, so replay if these missions is possible.
[#227] (https://github.com/paparazzi/paparazzi/issues/227)
- Paparazzi Center
- New simulation launcher with dialog and detection of available ones.
[#354] (https://github.com/paparazzi/paparazzi/pull/354)
- Checkbox to print extra configuration information during build.
- GCS:
- Fix panning with mouse if there are no background tiles.
[#9] (https://github.com/paparazzi/paparazzi/issues/9)
- Higher zoom level for maps.
[#277] (https://github.com/paparazzi/paparazzi/issues/277)
Hardware support
----------------
- initial support for STM32F4
- Apogee autopilot
- KroozSD autopilot
- Parrot AR Drone 2 support: raw and sdk versions
- CH Robotics UM6 IMU/AHRS
- GPS/INS XSens Mti-G support
- GPS Sirf support
- GPS Skytraq now usable for fixedwings as well
[#167] (https://github.com/paparazzi/paparazzi/issues/167)
- Mikrokopter V2 BLDC
[#377] (https://github.com/paparazzi/paparazzi/pull/377)
- PX4Flow sensor
[#379] (https://github.com/paparazzi/paparazzi/pull/379)
- Dropped AVR support
Airborne
--------
- State interface with automatic coordinate transformations
[#237] (https://github.com/paparazzi/paparazzi/pull/237)
- New AHRS filter: Multiplicative quaternion linearized Kalman Filter
- New SPI driver with transaction queues.
- Fix transactions with zero length input.
[#348] (https://github.com/paparazzi/paparazzi/issues/348)
- Peripherals: Cleanup and refactoring.
- MPU60x0 peripheral supporting SPI and I2C with slave.
- UDP datalink.
- Magnetometer current offset calibration.
[#346] (https://github.com/paparazzi/paparazzi/pull/346)
- Gain scheduling module.
[#335] (https://github.com/paparazzi/paparazzi/pull/335)
Rotorcraft firmware specific
----------------------------
- Quadshot transitioning vehicle support.
- Care Free Mode
Paparazzi 4.2.1_stable
======================
Maintenance release
- fix elf PT_LOAD type in lpc21iap LPC USB download
- fix electrical.current estimate in sim
- fix LPC+xbee_api in rotorcraft
- fix conversion of vsupply to decivolts if offset is used
- more robust dfu flash script, only upload to Lisa/M
Paparazzi 4.2.0_stable Paparazzi 4.2.0_stable
+1 -2
View File
@@ -37,7 +37,7 @@
<subsystem name="gps" type="ublox"> <subsystem name="gps" type="ublox">
<configure name="GPS_BAUD" value="B57600"/> <configure name="GPS_BAUD" value="B57600"/>
</subsystem> </subsystem>
<subsystem name="stabilization" type="euler"/> <subsystem name="stabilization" type="int_euler"/>
<subsystem name="ahrs" type="int_cmpl_quat"/> <subsystem name="ahrs" type="int_cmpl_quat"/>
<subsystem name="ins" type="hff"/> <subsystem name="ins" type="hff"/>
</firmware> </firmware>
@@ -133,7 +133,6 @@
<!-- Magnetic field for Gifhorn (declination 2°) --> <!-- Magnetic field for Gifhorn (declination 2°) -->
<section name="AHRS" prefix="AHRS_"> <section name="AHRS" prefix="AHRS_">
<define name="PROPAGATE_FREQUENCY" value="512"/>
<define name="PROPAGATE_LOW_PASS_RATES" value="1"/> <define name="PROPAGATE_LOW_PASS_RATES" value="1"/>
<define name="H_X" value="0.3794131"/> <define name="H_X" value="0.3794131"/>
<define name="H_Y" value="0.0141005"/> <define name="H_Y" value="0.0141005"/>
+10 -9
View File
@@ -47,7 +47,7 @@
<subsystem name="gps" type="ublox"> <subsystem name="gps" type="ublox">
<configure name="GPS_BAUD" value="B57600"/> <configure name="GPS_BAUD" value="B57600"/>
</subsystem> </subsystem>
<subsystem name="stabilization" type="euler"/> <subsystem name="stabilization" type="int_euler"/>
<subsystem name="ahrs" type="int_cmpl_euler"/> <subsystem name="ahrs" type="int_cmpl_euler"/>
<subsystem name="ins" type="extended"/> <subsystem name="ins" type="extended"/>
</firmware> </firmware>
@@ -102,13 +102,13 @@
<define name="ACCEL_Y_SENS" value="2.55480391706" integer="16"/> <define name="ACCEL_Y_SENS" value="2.55480391706" integer="16"/>
<define name="ACCEL_Z_SENS" value="2.57076132924" integer="16"/> <define name="ACCEL_Z_SENS" value="2.57076132924" integer="16"/>
<define name="MAG_X_NEUTRAL" value="-12"/> <define name="MAG_X_NEUTRAL" value="19"/>
<define name="MAG_Y_NEUTRAL" value="-10"/> <define name="MAG_Y_NEUTRAL" value="-91"/>
<define name="MAG_Z_NEUTRAL" value="-11"/> <define name="MAG_Z_NEUTRAL" value="-40"/>
<define name="MAG_X_SENS" value="22.008352" integer="16"/> <define name="MAG_X_SENS" value="4.93239693731" integer="16"/>
<define name="MAG_Y_SENS" value="21.79885" integer="16"/> <define name="MAG_Y_SENS" value="4.91905188125" integer="16"/>
<define name="MAG_Z_SENS" value="14.675745" integer="16"/> <define name="MAG_Z_SENS" value="3.3560174578" integer="16"/>
<define name="BODY_TO_IMU_PHI" value="1.3" unit="deg"/> <define name="BODY_TO_IMU_PHI" value="1.3" unit="deg"/>
<define name="BODY_TO_IMU_THETA" value="-2.6" unit="deg"/> <define name="BODY_TO_IMU_THETA" value="-2.6" unit="deg"/>
@@ -206,9 +206,10 @@
<section name="GUIDANCE_H" prefix="GUIDANCE_H_"> <section name="GUIDANCE_H" prefix="GUIDANCE_H_">
<define name="USE_REF" value="FALSE"/>
<define name="MAX_BANK" value="30" unit="deg"/> <define name="MAX_BANK" value="30" unit="deg"/>
<define name="PGAIN" value="50"/> <define name="PGAIN" value="40"/>
<define name="DGAIN" value="100"/> <define name="DGAIN" value="70"/>
<define name="IGAIN" value="15"/> <define name="IGAIN" value="15"/>
<define name="NGAIN" value="0"/> <define name="NGAIN" value="0"/>
<!-- feedforward --> <!-- feedforward -->
+2 -1
View File
@@ -14,7 +14,7 @@
<subsystem name="radio_control" type="datalink" /> <subsystem name="radio_control" type="datalink" />
<subsystem name="telemetry" type="udp" /> <subsystem name="telemetry" type="udp" />
<subsystem name="gps" type="sirf" /> <subsystem name="gps" type="ardrone2" />
<subsystem name="ahrs" type="ardrone2" /> <subsystem name="ahrs" type="ardrone2" />
<subsystem name="ins" type="ardrone2" /> <subsystem name="ins" type="ardrone2" />
<subsystem name="actuators" type="ardrone2" /> <subsystem name="actuators" type="ardrone2" />
@@ -97,6 +97,7 @@
</section> </section>
<section name="AUTOPILOT"> <section name="AUTOPILOT">
<define name="MODE_STARTUP" value="AP_MODE_NAV" />
<define name="MODE_MANUAL" value="AP_MODE_RC_DIRECT" /> <define name="MODE_MANUAL" value="AP_MODE_RC_DIRECT" />
<define name="MODE_AUTO1" value="AP_MODE_HOVER_Z_HOLD" /> <define name="MODE_AUTO1" value="AP_MODE_HOVER_Z_HOLD" />
<define name="MODE_AUTO2" value="AP_MODE_NAV" /> <define name="MODE_AUTO2" value="AP_MODE_NAV" />
@@ -32,7 +32,7 @@
</subsystem> </subsystem>
<subsystem name="telemetry" type="transparent"/> <subsystem name="telemetry" type="transparent"/>
<subsystem name="imu" type="aspirin_v2.1_new"/> <subsystem name="imu" type="aspirin_v2.1"/>
<subsystem name="gps" type="ublox"/> <subsystem name="gps" type="ublox"/>
<subsystem name="stabilization" type="int_quat"/> <subsystem name="stabilization" type="int_quat"/>
<subsystem name="ahrs" type="int_cmpl_quat"> <subsystem name="ahrs" type="int_cmpl_quat">
+228
View File
@@ -0,0 +1,228 @@
<!DOCTYPE airframe SYSTEM "../airframe.dtd">
<airframe name="Quadrotor with floating point unit">
<firmware name="rotorcraft">
<target name="ap" board="lisa_m_2.0">
<configure name="FLASH_MODE" value="SWD"/>
<!-- MPU6000 is configured to output data at 500Hz -->
<configure name="AHRS_PROPAGATE_FREQUENCY" value="500"/>
<configure name="USE_MAGNETOMETER" value="1"/>
</target>
<target name="nps" board="pc">
<subsystem name="fdm" type="jsbsim"/>
</target>
<subsystem name="radio_control" type="ppm"/>
<subsystem name="motor_mixing"/>
<subsystem name="actuators" type="pwm">
<define name="SERVO_HZ" value="400"/>
<define name="USE_SERVOS_7AND8"/>
</subsystem>
<subsystem name="telemetry" type="transparent">
<configure name="MODEM_PORT" value="UART1"/>
</subsystem>
<subsystem name="imu" type="aspirin_v2.1"/>
<subsystem name="gps" type="ublox"/>
<subsystem name="stabilization" type="float_quat"/>
<subsystem name="ahrs" type="float_mlkf">
<define name="AHRS_GRAVITY_UPDATE_NORM_HEURISTIC" value="TRUE"/>
</subsystem>
<subsystem name="ins"/>
</firmware>
<modules main_freq="512">
<load name="sys_mon.xml"/>
</modules>
<servos driver="Pwm">
<servo name="FRONT" no="0" min="1000" neutral="1100" max="1900"/>
<servo name="BACK" no="1" min="1000" neutral="1100" max="1900"/>
<servo name="RIGHT" no="2" min="1000" neutral="1100" max="1900"/>
<servo name="LEFT" no="3" min="1000" neutral="1100" max="1900"/>
</servos>
<commands>
<axis name="ROLL" failsafe_value="0"/>
<axis name="PITCH" failsafe_value="0"/>
<axis name="YAW" failsafe_value="0"/>
<axis name="THRUST" failsafe_value="0"/>
</commands>
<section name="MIXING" prefix="MOTOR_MIXING_">
<define name="TRIM_ROLL" value="0"/>
<define name="TRIM_PITCH" value="0"/>
<define name="TRIM_YAW" value="0"/>
<define name="NB_MOTOR" value="4"/>
<define name="SCALE" value="256"/>
<!-- front/back turning CW, right/left CCW -->
<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>
<command_laws>
<call fun="motor_mixing_run(autopilot_motors_on,FALSE,values)"/>
<set servo="FRONT" value="motor_mixing.commands[SERVO_FRONT]"/>
<set servo="BACK" value="motor_mixing.commands[SERVO_BACK]"/>
<set servo="RIGHT" value="motor_mixing.commands[SERVO_RIGHT]"/>
<set servo="LEFT" value="motor_mixing.commands[SERVO_LEFT]"/>
</command_laws>
<section name="IMU" prefix="IMU_">
<define name="ACCEL_X_NEUTRAL" value="11"/>
<define name="ACCEL_Y_NEUTRAL" value="11"/>
<define name="ACCEL_Z_NEUTRAL" value="-25"/>
<!-- replace this with your own calibration -->
<define name="MAG_X_NEUTRAL" value="-179"/>
<define name="MAG_Y_NEUTRAL" value="-21"/>
<define name="MAG_Z_NEUTRAL" value="79"/>
<define name="MAG_X_SENS" value="4.17334785618" integer="16"/>
<define name="MAG_Y_SENS" value="3.98885954135" integer="16"/>
<define name="MAG_Z_SENS" value="4.40442339014" integer="16"/>
<define name="MAG_X_SIGN" value="1"/>
<define name="MAG_Y_SIGN" value="1"/>
<define name="MAG_Z_SIGN" value="1"/>
<define name="BODY_TO_IMU_PHI" value="0." unit="deg"/>
<define name="BODY_TO_IMU_THETA" value="0." unit="deg"/>
<define name="BODY_TO_IMU_PSI" value="0." unit="deg"/>
</section>
<section name="AHRS" prefix="AHRS_">
<define name="H_X" value="0.3770441"/>
<define name="H_Y" value="0.0193986"/>
<define name="H_Z" value="0.9259921"/>
</section>
<section name="INS" prefix="INS_">
<define name="BARO_SENS" value="22.3" integer="16"/>
</section>
<section name="STABILIZATION_RATE" prefix="STABILIZATION_RATE_">
<!-- setpoints -->
<define name="SP_MAX_P" value="10000"/>
<define name="SP_MAX_Q" value="10000"/>
<define name="SP_MAX_R" value="10000"/>
<define name="DEADBAND_P" value="20"/>
<define name="DEADBAND_Q" value="20"/>
<define name="DEADBAND_R" value="200"/>
<define name="REF_TAU" value="4"/>
<!-- feedback -->
<define name="GAIN_P" value="400"/>
<define name="GAIN_Q" value="400"/>
<define name="GAIN_R" value="350"/>
<define name="IGAIN_P" value="75"/>
<define name="IGAIN_Q" value="75"/>
<define name="IGAIN_R" value="50"/>
<!-- feedforward -->
<define name="DDGAIN_P" value="300"/>
<define name="DDGAIN_Q" value="300"/>
<define name="DDGAIN_R" value="300"/>
</section>
<section name="STABILIZATION_ATTITUDE" prefix="STABILIZATION_ATTITUDE_">
<!-- setpoints -->
<define name="SP_MAX_PHI" value="45." unit="deg"/>
<define name="SP_MAX_THETA" value="45." unit="deg"/>
<define name="SP_MAX_R" value="90." unit="deg/s"/>
<define name="DEADBAND_A" value="0"/>
<define name="DEADBAND_E" value="0"/>
<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="400." unit="deg/s"/>
<define name="REF_MAX_PDOT" value="RadOfDeg(8000.)"/>
<define name="REF_OMEGA_Q" value="{RadOfDeg(800)}"/>
<define name="REF_ZETA_Q" value="{0.85}"/>
<define name="REF_MAX_Q" value="400." unit="deg/s"/>
<define name="REF_MAX_QDOT" value="RadOfDeg(8000.)"/>
<define name="REF_OMEGA_R" value="{RadOfDeg(500)}"/>
<define name="REF_ZETA_R" value="{0.85}"/>
<define name="REF_MAX_R" value="180." unit="deg/s"/>
<define name="REF_MAX_RDOT" value="RadOfDeg(1800.)"/>
<!-- feedback -->
<define name="PHI_PGAIN" value="{1000}"/>
<define name="PHI_DGAIN" value="{1000}"/>
<define name="PHI_IGAIN" value="{200}"/>
<define name="THETA_PGAIN" value="{1000}"/>
<define name="THETA_DGAIN" value="{1000}"/>
<define name="THETA_IGAIN" value="{200}"/>
<define name="PSI_PGAIN" value="{500}"/>
<define name="PSI_DGAIN" value="{500}"/>
<define name="PSI_IGAIN" value="{10}"/>
<!-- feedback angular acceleration error -->
<define name="PHI_DGAIN_D" value="{100}"/>
<define name="THETA_DGAIN_D" value="{100}"/>
<define name="PSI_DGAIN_D" value="{100}"/>
<!-- feedforward -->
<define name="PHI_DDGAIN" value="{300}"/>
<define name="THETA_DDGAIN" value="{300}"/>
<define name="PSI_DDGAIN" value="{300}"/>
</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="150"/>
<define name="HOVER_KD" value="80"/>
<define name="HOVER_KI" value="20"/>
<!-- 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"/>
<!-- NOMINAL_HOVER_THROTTLE sets a fixed value instead of the adaptive estimation -->
<!--define name="NOMINAL_HOVER_THROTTLE" value="0.5"/-->
</section>
<section name="GUIDANCE_H" prefix="GUIDANCE_H_">
<define name="MAX_BANK" value="20" unit="deg"/>
<define name="PGAIN" value="50"/>
<define name="DGAIN" value="100"/>
<define name="AGAIN" value="100"/>
<define name="IGAIN" value="20"/>
</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_default.h&quot;"/>
<!-- mode switch on joystick channel 5 (axis numbering starting at zero) -->
<define name="JS_MODE_AXIS" value="4"/>
</section>
<section name="AUTOPILOT">
<define name="MODE_MANUAL" value="AP_MODE_ATTITUDE_DIRECT"/>
<define name="MODE_AUTO1" value="AP_MODE_HOVER_Z_HOLD"/>
<define name="MODE_AUTO2" value="AP_MODE_NAV"/>
</section>
<section name="BAT">
<define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
<define name="CRITIC_BAT_LEVEL" value="9.6" unit="V"/>
<define name="LOW_BAT_LEVEL" value="9.7" unit="V"/>
<define name="MAX_BAT_LEVEL" value="12.4" unit="V"/>
</section>
</airframe>
+1 -17
View File
@@ -83,28 +83,12 @@
<section name="sessions"> <section name="sessions">
<session name="ARDrone2 RAW Flight"> <session name="ARDrone2 Flight">
<program name="Server"/> <program name="Server"/>
<program name="GCS"/> <program name="GCS"/>
<program name="Data Link"> <program name="Data Link">
<arg flag="-udp"/> <arg flag="-udp"/>
</program> </program>
<program name="Joystick">
<arg flag="-ac" constant="ardrone2_raw"/>
<arg flag="extreme_3d_pro.xml"/>
</program>
</session>
<session name="ARDrone2 SDK Flight">
<program name="Server"/>
<program name="GCS"/>
<program name="Data Link">
<arg flag="-udp"/>
</program>
<program name="Joystick">
<arg flag="-ac" constant="ardrone2_sdk"/>
<arg flag="extreme_3d_pro.xml"/>
</program>
</session> </session>
<session name="Flight USB-serial@9600"> <session name="Flight USB-serial@9600">
@@ -22,7 +22,7 @@ nps.MAKEFILE = nps
nps.CFLAGS += -DSITL -DUSE_NPS nps.CFLAGS += -DSITL -DUSE_NPS
nps.CFLAGS += $(shell pkg-config glib-2.0 --cflags) nps.CFLAGS += $(shell pkg-config glib-2.0 --cflags)
nps.LDFLAGS += $(shell pkg-config glib-2.0 --libs) -lm -lglibivy -lgsl -lgslcblas nps.LDFLAGS += $(shell pkg-config glib-2.0 --libs) -lm -lglibivy -lpcre -lgsl -lgslcblas
nps.CFLAGS += -I$(NPSDIR) -I$(SRC_FIRMWARE) -I$(SRC_BOARD) -I../simulator -I$(PAPARAZZI_HOME)/conf/simulator/nps nps.CFLAGS += -I$(NPSDIR) -I$(SRC_FIRMWARE) -I$(SRC_BOARD) -I../simulator -I$(PAPARAZZI_HOME)/conf/simulator/nps
nps.LDFLAGS += $(shell sdl-config --libs) nps.LDFLAGS += $(shell sdl-config --libs)
@@ -0,0 +1,20 @@
# Hey Emacs, this is a -*- makefile -*-
# ARDrone 2 Flightrecorder GPS unit
ap.CFLAGS += -DUSE_GPS -DUSE_GPS_ARDRONE2
ifneq ($(GPS_LED),none)
ap.CFLAGS += -DGPS_LED=$(GPS_LED)
endif
ap.CFLAGS += -DGPS_TYPE_H=\"subsystems/gps/gps_ardrone2.h\"
ap.srcs += $(SRC_SUBSYSTEMS)/gps/gps_ardrone2.c
$(TARGET).srcs += $(SRC_SUBSYSTEMS)/gps.c
nps.CFLAGS += -DUSE_GPS
nps.CFLAGS += -DGPS_TYPE_H=\"subsystems/gps/gps_sim.h\"
nps.srcs += $(SRC_SUBSYSTEMS)/gps/gps_sim_nps.c
@@ -39,32 +39,37 @@
# for fixedwing firmware and ap only # for fixedwing firmware and ap only
ifeq ($(TARGET), ap) ifeq ($(TARGET), ap)
IMU_ASPIRIN_CFLAGS = -DUSE_IMU IMU_ASPIRIN_2_CFLAGS = -DUSE_IMU
endif endif
IMU_ASPIRIN_CFLAGS += -DIMU_TYPE_H=\"imu/imu_aspirin2.h\" IMU_ASPIRIN_2_CFLAGS += -DIMU_TYPE_H=\"imu/imu_aspirin_2_spi.h\"
IMU_ASPIRIN_SRCS = $(SRC_SUBSYSTEMS)/imu.c \ IMU_ASPIRIN_2_SRCS = $(SRC_SUBSYSTEMS)/imu.c
$(SRC_SUBSYSTEMS)/imu/imu_aspirin2.c IMU_ASPIRIN_2_SRCS += $(SRC_SUBSYSTEMS)/imu/imu_aspirin_2_spi.c
IMU_ASPIRIN_2_SRCS += peripherals/mpu60x0.c
IMU_ASPIRIN_2_SRCS += peripherals/mpu60x0_spi.c
# Magnetometer
#IMU_ASPIRIN_2_SRCS += peripherals/hmc58xx.c
include $(CFG_SHARED)/spi_master.makefile include $(CFG_SHARED)/spi_master.makefile
ifeq ($(ARCH), lpc21) ifeq ($(ARCH), lpc21)
IMU_ASPIRIN_CFLAGS += -DUSE_SPI1 IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI_SLAVE0
IMU_ASPIRIN_CFLAGS += -DUSE_SPI_SLAVE0 IMU_ASPIRIN_2_CFLAGS += -DASPIRIN_2_SPI_SLAVE_IDX=SPI_SLAVE0
IMU_ASPIRIN_2_CFLAGS += -DASPIRIN_2_SPI_DEV=spi1
IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI1
else ifeq ($(ARCH), stm32) else ifeq ($(ARCH), stm32)
IMU_ASPIRIN_CFLAGS += -DUSE_SPI2 IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI2
# Slave select configuration # Slave select configuration
# SLAVE2 is on PB12 (NSS) (MPU600 CS) # SLAVE2 is on PB12 (NSS) (MPU600 CS)
IMU_ASPIRIN_CFLAGS += -DUSE_SPI_SLAVE2 IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI_SLAVE2
endif endif
IMU_ASPIRIN_CFLAGS += -DIMU_ASPIRIN_VERSION_2_1
# Keep CFLAGS/Srcs for imu in separate expression so we can assign it to other targets # Keep CFLAGS/Srcs for imu in separate expression so we can assign it to other targets
# see: conf/autopilot/subsystems/lisa_passthrough/imu_b2_v1.1.makefile for example # see: conf/autopilot/subsystems/lisa_passthrough/imu_b2_v1.1.makefile for example
ap.CFLAGS += $(IMU_ASPIRIN_CFLAGS) ap.CFLAGS += $(IMU_ASPIRIN_2_CFLAGS)
ap.srcs += $(IMU_ASPIRIN_SRCS) ap.srcs += $(IMU_ASPIRIN_2_SRCS)
# #
@@ -39,39 +39,32 @@
# for fixedwing firmware and ap only # for fixedwing firmware and ap only
ifeq ($(TARGET), ap) ifeq ($(TARGET), ap)
IMU_ASPIRIN_2_CFLAGS = -DUSE_IMU IMU_ASPIRIN_CFLAGS = -DUSE_IMU
endif endif
IMU_ASPIRIN_2_CFLAGS += -DIMU_TYPE_H=\"imu/imu_aspirin_2.h\" IMU_ASPIRIN_CFLAGS += -DIMU_TYPE_H=\"imu/imu_aspirin2.h\"
IMU_ASPIRIN_2_SRCS = $(SRC_SUBSYSTEMS)/imu.c IMU_ASPIRIN_SRCS = $(SRC_SUBSYSTEMS)/imu.c \
IMU_ASPIRIN_2_SRCS += $(SRC_SUBSYSTEMS)/imu/imu_aspirin_2.c $(SRC_SUBSYSTEMS)/imu/imu_aspirin2.c
IMU_ASPIRIN_2_SRCS += peripherals/mpu60x0.c
IMU_ASPIRIN_2_SRCS += peripherals/mpu60x0_spi.c
# Magnetometer
#IMU_ASPIRIN_2_SRCS += peripherals/hmc58xx.c
include $(CFG_SHARED)/spi_master.makefile include $(CFG_SHARED)/spi_master.makefile
ifeq ($(ARCH), lpc21) ifeq ($(ARCH), lpc21)
IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI_SLAVE0 IMU_ASPIRIN_CFLAGS += -DUSE_SPI1
IMU_ASPIRIN_2_CFLAGS += -DASPIRIN_2_SPI_SLAVE_IDX=SPI_SLAVE0 IMU_ASPIRIN_CFLAGS += -DUSE_SPI_SLAVE0
IMU_ASPIRIN_2_CFLAGS += -DASPIRIN_2_SPI_DEV=spi1
IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI1
else ifeq ($(ARCH), stm32) else ifeq ($(ARCH), stm32)
IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI2 IMU_ASPIRIN_CFLAGS += -DUSE_SPI2
# Slave select configuration # Slave select configuration
# SLAVE2 is on PB12 (NSS) (MPU600 CS) # SLAVE2 is on PB12 (NSS) (MPU600 CS)
IMU_ASPIRIN_2_CFLAGS += -DUSE_SPI_SLAVE2 IMU_ASPIRIN_CFLAGS += -DUSE_SPI_SLAVE2
endif endif
#IMU_ASPIRIN_2_CFLAGS += -DIMU_ASPIRIN_VERSION_2_1 IMU_ASPIRIN_CFLAGS += -DIMU_ASPIRIN_VERSION_2_1
# Keep CFLAGS/Srcs for imu in separate expression so we can assign it to other targets # Keep CFLAGS/Srcs for imu in separate expression so we can assign it to other targets
# see: conf/autopilot/subsystems/lisa_passthrough/imu_b2_v1.1.makefile for example # see: conf/autopilot/subsystems/lisa_passthrough/imu_b2_v1.1.makefile for example
ap.CFLAGS += $(IMU_ASPIRIN_2_CFLAGS) ap.CFLAGS += $(IMU_ASPIRIN_CFLAGS)
ap.srcs += $(IMU_ASPIRIN_2_SRCS) ap.srcs += $(IMU_ASPIRIN_SRCS)
# #
@@ -2,11 +2,13 @@
# #
# Aspirin IMU v2.2 # Aspirin IMU v2.2
# #
# actually identical with v2.1 since baro is not read in IMU driver
#
# #
# required xml: # required xml:
# <section name="IMU" prefix="IMU_"> # <section name="IMU" prefix="IMU_">
# #
# <!-- these gyro and accel calib values are the defaults for aspirin2.2 --> # <!-- these gyro and accel calib values are the defaults for aspirin2.1 -->
# <define name="GYRO_X_NEUTRAL" value="0"/> # <define name="GYRO_X_NEUTRAL" value="0"/>
# <define name="GYRO_Y_NEUTRAL" value="0"/> # <define name="GYRO_Y_NEUTRAL" value="0"/>
# <define name="GYRO_Z_NEUTRAL" value="0"/> # <define name="GYRO_Z_NEUTRAL" value="0"/>
@@ -37,37 +39,4 @@
# #
# for fixedwing firmware and ap only include $(CFG_SHARED)/imu_aspirin_v2.1.makefile
ifeq ($(TARGET), ap)
IMU_ASPIRIN_CFLAGS = -DUSE_IMU
endif
IMU_ASPIRIN_CFLAGS += -DIMU_TYPE_H=\"imu/imu_aspirin2.h\"
IMU_ASPIRIN_SRCS = $(SRC_SUBSYSTEMS)/imu.c \
$(SRC_SUBSYSTEMS)/imu/imu_aspirin2.c
include $(CFG_SHARED)/spi_master.makefile
ifeq ($(ARCH), lpc21)
IMU_ASPIRIN_CFLAGS += -DUSE_SPI1
IMU_ASPIRIN_CFLAGS += -DUSE_SPI_SLAVE0
else ifeq ($(ARCH), stm32)
IMU_ASPIRIN_CFLAGS += -DUSE_SPI2
# Slave select configuration
# SLAVE2 is on PB12 (NSS) (MPU600 CS)
IMU_ASPIRIN_CFLAGS += -DUSE_SPI_SLAVE2
endif
IMU_ASPIRIN_CFLAGS += -DIMU_ASPIRIN_VERSION_2_2
# Keep CFLAGS/Srcs for imu in separate expression so we can assign it to other targets
# see: conf/autopilot/subsystems/lisa_passthrough/imu_b2_v1.1.makefile for example
ap.CFLAGS += $(IMU_ASPIRIN_CFLAGS)
ap.srcs += $(IMU_ASPIRIN_SRCS)
#
# NPS simulator
#
include $(CFG_SHARED)/imu_nps.makefile
@@ -0,0 +1,81 @@
# Hey Emacs, this is a -*- makefile -*-
#
# Drotek 10DOF V2 IMU via I2C
#
#
# required xml:
# <section name="IMU" prefix="IMU_">
#
# <!-- these gyro and accel calib values are the defaults for aspirin2.1 -->
# <define name="GYRO_X_NEUTRAL" value="0"/>
# <define name="GYRO_Y_NEUTRAL" value="0"/>
# <define name="GYRO_Z_NEUTRAL" value="0"/>
#
# <define name="GYRO_X_SENS" value="4.359" integer="16"/>
# <define name="GYRO_Y_SENS" value="4.359" integer="16"/>
# <define name="GYRO_Z_SENS" value="4.359" integer="16"/>
#
# <define name="ACCEL_X_NEUTRAL" value="0"/>
# <define name="ACCEL_Y_NEUTRAL" value="0"/>
# <define name="ACCEL_Z_NEUTRAL" value="0"/>
#
# <define name="ACCEL_X_SENS" value="4.905" integer="16"/>
# <define name="ACCEL_Y_SENS" value="4.905" integer="16"/>
# <define name="ACCEL_Z_SENS" value="4.905" integer="16"/>
#
# <!-- replace the mag calibration with your own-->
# <define name="MAG_X_NEUTRAL" value="-45"/>
# <define name="MAG_Y_NEUTRAL" value="334"/>
# <define name="MAG_Z_NEUTRAL" value="7"/>
#
# <define name="MAG_X_SENS" value="3.4936416" integer="16"/>
# <define name="MAG_Y_SENS" value="3.607713" integer="16"/>
# <define name="MAG_Z_SENS" value="4.90788848" integer="16"/>
#
# </section>
#
#
# for fixedwing firmware and ap only
ifeq ($(TARGET), ap)
IMU_DROTEK_2_CFLAGS = -DUSE_IMU
endif
IMU_DROTEK_2_CFLAGS += -DIMU_TYPE_H=\"imu/imu_drotek_10dof_v2.h\"
IMU_DROTEK_2_SRCS = $(SRC_SUBSYSTEMS)/imu.c
IMU_DROTEK_2_SRCS += $(SRC_SUBSYSTEMS)/imu/imu_drotek_10dof_v2.c
IMU_DROTEK_2_SRCS += peripherals/mpu60x0.c
IMU_DROTEK_2_SRCS += peripherals/mpu60x0_i2c.c
# Magnetometer
IMU_DROTEK_2_SRCS += peripherals/hmc58xx.c
# set default i2c bus
ifndef DROTEK_2_I2C_DEV
ifeq ($(ARCH), lpc21)
DROTEK_2_I2C_DEV=i2c0
else ifeq ($(ARCH), stm32)
DROTEK_2_I2C_DEV=i2c2
endif
endif
# convert i2cx to upper case
DROTEK_2_I2C_DEV_UPPER=$(shell echo $(DROTEK_2_I2C_DEV) | tr a-z A-Z)
IMU_DROTEK_2_CFLAGS += -DDROTEK_2_I2C_DEV=$(DROTEK_2_I2C_DEV)
IMU_DROTEK_2_CFLAGS += -DUSE_$(DROTEK_2_I2C_DEV_UPPER)
# Keep CFLAGS/Srcs for imu in separate expression so we can assign it to other targets
# see: conf/autopilot/subsystems/lisa_passthrough/imu_b2_v1.1.makefile for example
ap.CFLAGS += $(IMU_DROTEK_2_CFLAGS)
ap.srcs += $(IMU_DROTEK_2_SRCS)
#
# NPS simulator
#
include $(CFG_SHARED)/imu_nps.makefile
+30 -11
View File
@@ -4,8 +4,6 @@
axis 1: pitch axis 1: pitch
axis 2: yaw axis 2: yaw
axis 3: throttle (reversed) axis 3: throttle (reversed)
axis 4: hat switch left/right (right is positive)
axis 5: hat switch up/down (down is positive)
It has 9 buttons. It has 9 buttons.
b0 - fire b0 - fire
@@ -18,6 +16,11 @@ It has 9 buttons.
b7 - button D b7 - button D
b8 - shift button b8 - shift button
and a POV hat.
You can use the Hat<Position>(<hat_name>) function to trigger events,
where <Position> is one of
Centered/Up/Right/Down/Left/RightUp/RightDown/LeftUp/LeftDown
so e.g. HatDown(hat)
--> -->
<joystick> <joystick>
@@ -26,8 +29,6 @@ It has 9 buttons.
<axis index="1" name="pitch" limit="1.00" exponent="0.7" trim="0"/> <axis index="1" name="pitch" limit="1.00" exponent="0.7" trim="0"/>
<axis index="2" name="yaw" limit="1.00" exponent="0.7" trim="0"/> <axis index="2" name="yaw" limit="1.00" exponent="0.7" trim="0"/>
<axis index="3" name="throttle"/> <axis index="3" name="throttle"/>
<axis index="4" name="hat_lr"/>
<axis index="5" name="hat_ud"/>
<button index="0" name="fire"/> <button index="0" name="fire"/>
<button index="1" name="fire2"/> <button index="1" name="fire2"/>
<button index="2" name="up"/> <button index="2" name="up"/>
@@ -37,22 +38,40 @@ It has 9 buttons.
<button index="6" name="C"/> <button index="6" name="C"/>
<button index="7" name="D"/> <button index="7" name="D"/>
<button index="8" name="shift"/> <button index="8" name="shift"/>
<hat index="0" name="hat"/>
</input> </input>
<variables>
<!-- manual by default and when pressing A, AUTO1 on B, AUTO2 on C -->
<var name="mode" default="0"/>
<set var="mode" value="0" on_event="A"/>
<set var="mode" value="1" on_event="B"/>
<set var="mode" value="2" on_event="C"/>
</variables>
<messages period="0.1"> <messages period="0.1">
<!--message class="datalink" name="RC_4CH" send_always="true"> <message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="1-fire+A"/> <field name="mode" value="mode"/>
<field name="throttle" value="Fit(-throttle,-127,127,0,127)"/> <field name="throttle" value="Fit(-throttle,-127,127,0,127)"/>
<field name="roll" value="roll"/> <field name="roll" value="roll"/>
<field name="pitch" value="pitch"/> <field name="pitch" value="pitch"/>
<field name="yaw" value="yaw"/> <field name="yaw" value="yaw"/>
</message--> </message>
<message class="datalink" name="RC_3CH" send_always="true"> <!-- go to "Start Engine" block if in AUTO2 and pressing shift + fire2 -->
<field name="throttle_mode" value="0"/> <message class="ground" name="JUMP_TO_BLOCK" on_event="(mode > 1) && shift && fire2">
<field name="roll" value="roll"/> <field name="block_id" value="IndexOfBlock('Start Engine')"/>
<field name="pitch" value="pitch"/> </message>
<!-- go to "Takeoff" block if in AUTO2 and pressing shift + up -->
<message class="ground" name="JUMP_TO_BLOCK" on_event="(mode > 1) && shift && up">
<field name="block_id" value="IndexOfBlock('Takeoff')"/>
</message>
<!-- go to "land here" block if in AUTO2 and pressing shift + down -->
<message class="ground" name="JUMP_TO_BLOCK" on_event="(mode > 1) && shift && down">
<field name="block_id" value="IndexOfBlock('land here')"/>
</message> </message>
</messages> </messages>
+91
View File
@@ -0,0 +1,91 @@
<!-- Generic X-Box gamepad
e.g. Logitech wireless gamepad F710
This config is for Xinput mode. Make sure slider switch on back of controller is on X (not D)
Also make sure controller not in sports mode (mode light should be off)
Has six axes:
axis 0: LTS_H (left thumb stick horizontal) (or DPad horizontal in sports mode)
axis 1: LTS_V (left thumb stick vertical) (or DPad vertical in sports mode)
axis 2: LT (left trigger)
axis 3: RTS_H (right thumb stick horizontal)
axis 4: RTS_V (right thumb stick vertical)
axis 5: RT (right trigger)
It has 11 buttons.
b0 - A (green)
b1 - B (red)
b2 - X (blue)
b3 - Y (yellow)
b4 - LB (left shoulder button)
b5 - RB (right shoulder button)
b6 - back
b7 - start
b8 - ?
b9 - LSB (left stick button)
b10 - RSB (right stick button)
and the DPad as a hat (in normal mode)
You can use the Hat<Position>(<hat_name>) function to trigger events,
where <Position> is one of
Centered/Up/Right/Down/Left/RightUp/RightDown/LeftUp/LeftDown
so e.g. HatDown(dpad)
-->
<joystick>
<input>
<axis index="0" name="yaw" limit="1.00" exponent="0.7" trim="0"/>
<axis index="1" name="throttle"/>
<axis index="2" name="LT" limit="1.00" trim="127"/>
<axis index="3" name="roll" limit="1.00" exponent="0.7" trim="0"/>
<axis index="4" name="pitch" limit="1.00" exponent="0.7" trim="0"/>
<axis index="5" name="RT" limit="1.00" trim="127"/>
<button index="0" name="A"/>
<button index="1" name="B"/>
<button index="2" name="X"/>
<button index="3" name="Y"/>
<button index="4" name="LB"/>
<button index="5" name="RB"/>
<button index="6" name="back"/>
<button index="7" name="start"/>
<button index="9" name="LSB"/>
<button index="10" name="RSB"/>
<hat index="0" name="dpad"/>
</input>
<variables>
<!-- manual by default and when pressing A, AUTO1 on B, AUTO2 on Y -->
<var name="mode" default="0"/>
<set var="mode" value="0" on_event="A"/>
<set var="mode" value="1" on_event="B"/>
<set var="mode" value="2" on_event="Y"/>
</variables>
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-throttle,-127,127,0,127)"/>
<field name="roll" value="roll"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="yaw"/>
</message>
<!-- go to "Start Engine" block if in AUTO2 and pressing start button -->
<message class="ground" name="JUMP_TO_BLOCK" on_event="(mode > 1) && start">
<field name="block_id" value="IndexOfBlock('Start Engine')"/>
</message>
<!-- go to "Takeoff" block if in AUTO2 and pressing up on dpad -->
<message class="ground" name="JUMP_TO_BLOCK" on_event="(mode > 1) && HatUp(dpad)">
<field name="block_id" value="IndexOfBlock('Takeoff')"/>
</message>
<!-- go to "land here" block if in AUTO2 and pressing down on dpad -->
<message class="ground" name="JUMP_TO_BLOCK" on_event="(mode > 1) && HatDown(dpad)">
<field name="block_id" value="IndexOfBlock('land here')"/>
</message>
</messages>
</joystick>
+3 -2
View File
@@ -8,10 +8,11 @@
(AMS 5812-0003-D) (AMS 5812-0003-D)
</description> </description>
<define name="AIRSPEED_AMSYS_I2C_DEV" value="i2c0" description="change default i2c peripheral"/> <define name="AIRSPEED_AMSYS_I2C_DEV" value="i2c0" description="change default i2c peripheral"/>
<define name="AIRSPEED_AMSYS_OFFSET" value="0" description="sensor offset (default: 0)"/> <define name="AIRSPEED_AMSYS_MAXPRESURE" value="2068" description="max sensor pressure (Pa) (default: 2068 for -003)(for -001 use 689)"/>
<define name="AIRSPEED_AMSYS_SCALE" value="1.0" description="sensor scale factor (default: 1.0)"/> <define name="AIRSPEED_AMSYS_SCALE" value="1.0" description="sensor scale factor (default: 1.0)"/>
<define name="AIRSPEED_AMSYS_FILTER" value="0." description="sensor filter (default: 0. max:1)"/>
<define name="USE_AIRSPEED" description="flag to use the data for airspeed control"/> <define name="USE_AIRSPEED" description="flag to use the data for airspeed control"/>
<define name="SENSOR_SYNC_SEND" description="flag to transmit the data as it is acquired"/> <define name="AIRSPEED_AMSYS_SYNC_SEND" description="flag to transmit the data as it is acquired"/>
</doc> </doc>
<header> <header>
@@ -0,0 +1,27 @@
<!DOCTYPE settings SYSTEM "../settings.dtd">
<settings>
<dl_settings>
<dl_settings NAME="Att Loop">
<dl_setting var="stabilization_gains[0].p.x" min="1" step="1" max="8000" module="stabilization/stabilization_attitude" shortname="pgain phi" param="STABILIZATION_ATTITUDE_PHI_PGAIN"/>
<dl_setting var="stabilization_gains[0].i.x" min="0" step="1" max="800" module="stabilization/stabilization_attitude" shortname="igain phi" param="STABILIZATION_ATTITUDE_PHI_IGAIN" />
<dl_setting var="stabilization_gains[0].d.x" min="1" step="1" max="4000" module="stabilization/stabilization_attitude" shortname="dgain p" param="STABILIZATION_ATTITUDE_PHI_DGAIN"/>
<dl_setting var="stabilization_gains[0].rates_d.x" min="0" step="1" max="500" module="stabilization/stabilization_attitude" shortname="dgaind p" param="STABILIZATION_ATTITUDE_PHI_DGAIN_D"/>
<dl_setting var="stabilization_gains[0].dd.x" min="0" step="1" max="1000" module="stabilization/stabilization_attitude" shortname="ddgain p" param="STABILIZATION_ATTITUDE_PHI_DDGAIN"/>
<dl_setting var="stabilization_gains[0].p.y" min="1" step="1" max="8000" module="stabilization/stabilization_attitude" shortname="pgain theta" param="STABILIZATION_ATTITUDE_THETA_PGAIN"/>
<dl_setting var="stabilization_gains[0].i.y" min="0" step="1" max="800" module="stabilization/stabilization_attitude" shortname="igain theta" param="STABILIZATION_ATTITUDE_THETA_IGAIN"/>
<dl_setting var="stabilization_gains[0].d.y" min="1" step="1" max="4000" module="stabilization/stabilization_attitude" shortname="dgain q" param="STABILIZATION_ATTITUDE_THETA_DGAIN"/>
<dl_setting var="stabilization_gains[0].rates_d.y" min="0" step="1" max="500" module="stabilization/stabilization_attitude" shortname="dgaind q" param="STABILIZATION_ATTITUDE_THETA_DGAIN_D"/>
<dl_setting var="stabilization_gains[0].dd.y" min="0" step="1" max="1000" module="stabilization/stabilization_attitude" shortname="ddgain q" param="STABILIZATION_ATTITUDE_THETA_DDGAIN"/>
<dl_setting var="stabilization_gains[0].p.z" min="1" step="1" max="4000" module="stabilization/stabilization_attitude" shortname="pgain psi" param="STABILIZATION_ATTITUDE_PSI_PGAIN"/>
<dl_setting var="stabilization_gains[0].i.z" min="0" step="1" max="400" module="stabilization/stabilization_attitude" shortname="igain psi" param="STABILIZATION_ATTITUDE_PSI_IGAIN"/>
<dl_setting var="stabilization_gains[0].d.z" min="1" step="1" max="4000" module="stabilization/stabilization_attitude" shortname="dgain r" param="STABILIZATION_ATTITUDE_PSI_DGAIN"/>
<dl_setting var="stabilization_gains[0].rates_d.z" min="0" step="1" max="500" module="stabilization/stabilization_attitude" shortname="dgaind r" param="STABILIZATION_ATTITUDE_PHI_DGAIN_D"/>
<dl_setting var="stabilization_gains[0].dd.z" min="0" step="1" max="1000" module="stabilization/stabilization_attitude" shortname="ddgain r" param="STABILIZATION_ATTITUDE_PSI_DDGAIN"/>
</dl_settings>
</dl_settings>
</settings>
@@ -0,0 +1,3 @@
Package: lpc21isp
Pin: version 1.48*
Pin-Priority: 1001
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
DEF_VER=v4.9_devel DEF_VER=v5.0.0_stable
# First try git describe (if running on a git repo), # First try git describe (if running on a git repo),
# then use default version from above (for release tarballs). # then use default version from above (for release tarballs).
@@ -382,6 +382,7 @@ __attribute__ ((always_inline)) static inline void SpiSlaveAutomaton(struct spi_
#if SPI_MASTER #if SPI_MASTER
#if USE_SPI0 #if USE_SPI0
#error "SPI0 is currently not implemented in the mcu_periph/spi HAL for the LPC!"
// void spi0_ISR(void) __attribute__((naked)); // void spi0_ISR(void) __attribute__((naked));
// //
+1 -5
View File
@@ -33,11 +33,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <libopencm3/stm32/gpio.h> #include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h> #include <libopencm3/stm32/rcc.h>
#if defined(STM32F1) #include <libopencm3/stm32/flash.h>
#include <libopencm3/stm32/f1/flash.h>
#elif defined(STM32F4)
#include <libopencm3/stm32/f4/flash.h>
#endif
#include <libopencm3/cm3/scb.h> #include <libopencm3/cm3/scb.h>
#include "std.h" #include "std.h"
+2 -2
View File
@@ -166,9 +166,9 @@ int can_hw_transmit(uint32_t id, const uint8_t *buf, uint8_t len)
void usb_lp_can_rx0_isr(void) void usb_lp_can_rx0_isr(void)
{ {
u32 id, fmi; uint32_t id, fmi;
bool ext, rtr; bool ext, rtr;
u8 length, data[8]; uint8_t length, data[8];
can_receive(CAN1, can_receive(CAN1,
0, /* FIFO: 0 */ 0, /* FIFO: 0 */
+30 -30
View File
@@ -71,7 +71,7 @@ static inline void __enable_irq(void) { asm volatile ("cpsie i"); }
#define __I2C_REG_CRITICAL_ZONE_STOP __enable_irq(); #define __I2C_REG_CRITICAL_ZONE_STOP __enable_irq();
static inline void PPRZ_I2C_SEND_STOP(u32 i2c) static inline void PPRZ_I2C_SEND_STOP(uint32_t i2c)
{ {
// Man: p722: Stop generation after the current byte transfer or after the current Start condition is sent. // Man: p722: Stop generation after the current byte transfer or after the current Start condition is sent.
I2C_CR1(i2c) |= I2C_CR1_STOP; I2C_CR1(i2c) |= I2C_CR1_STOP;
@@ -88,7 +88,7 @@ static inline void PPRZ_I2C_SEND_STOP(u32 i2c)
static inline void PPRZ_I2C_SEND_START(struct i2c_periph *periph) static inline void PPRZ_I2C_SEND_START(struct i2c_periph *periph)
{ {
u32 i2c = (u32) periph->reg_addr; uint32_t i2c = (uint32_t) periph->reg_addr;
// Reset the buffer pointer to the first byte // Reset the buffer pointer to the first byte
periph->idx_buf = 0; periph->idx_buf = 0;
@@ -134,7 +134,7 @@ enum STMI2CSubTransactionStatus {
// Doc ID 13902 Rev 11 p 710/1072 // Doc ID 13902 Rev 11 p 710/1072
// Transfer Sequence Diagram for Master Transmitter // Transfer Sequence Diagram for Master Transmitter
static inline enum STMI2CSubTransactionStatus stmi2c_send(u32 i2c, struct i2c_periph *periph, struct i2c_transaction *trans) static inline enum STMI2CSubTransactionStatus stmi2c_send(uint32_t i2c, struct i2c_periph *periph, struct i2c_transaction *trans)
{ {
uint16_t SR1 = I2C_SR1(i2c); uint16_t SR1 = I2C_SR1(i2c);
@@ -215,7 +215,7 @@ static inline enum STMI2CSubTransactionStatus stmi2c_send(u32 i2c, struct i2c_pe
// Doc ID 13902 Rev 11 p 714/1072 // Doc ID 13902 Rev 11 p 714/1072
// Transfer Sequence Diagram for Master Receiver for N=1 // Transfer Sequence Diagram for Master Receiver for N=1
static inline enum STMI2CSubTransactionStatus stmi2c_read1(u32 i2c, struct i2c_periph *periph, struct i2c_transaction *trans) static inline enum STMI2CSubTransactionStatus stmi2c_read1(uint32_t i2c, struct i2c_periph *periph, struct i2c_transaction *trans)
{ {
uint16_t SR1 = I2C_SR1(i2c); uint16_t SR1 = I2C_SR1(i2c);
@@ -278,7 +278,7 @@ static inline enum STMI2CSubTransactionStatus stmi2c_read1(u32 i2c, struct i2c_p
// Doc ID 13902 Rev 11 p 713/1072 // Doc ID 13902 Rev 11 p 713/1072
// Transfer Sequence Diagram for Master Receiver for N=2 // Transfer Sequence Diagram for Master Receiver for N=2
static inline enum STMI2CSubTransactionStatus stmi2c_read2(u32 i2c, struct i2c_periph *periph, struct i2c_transaction *trans) static inline enum STMI2CSubTransactionStatus stmi2c_read2(uint32_t i2c, struct i2c_periph *periph, struct i2c_transaction *trans)
{ {
uint16_t SR1 = I2C_SR1(i2c); uint16_t SR1 = I2C_SR1(i2c);
@@ -348,7 +348,7 @@ static inline enum STMI2CSubTransactionStatus stmi2c_read2(u32 i2c, struct i2c_p
// Doc ID 13902 Rev 11 p 712/1072 // Doc ID 13902 Rev 11 p 712/1072
// Transfer Sequence Diagram for Master Receiver for N>2 // Transfer Sequence Diagram for Master Receiver for N>2
static inline enum STMI2CSubTransactionStatus stmi2c_readmany(u32 i2c, struct i2c_periph *periph, struct i2c_transaction *trans) static inline enum STMI2CSubTransactionStatus stmi2c_readmany(uint32_t i2c, struct i2c_periph *periph, struct i2c_transaction *trans)
{ {
uint16_t SR1 = I2C_SR1(i2c); uint16_t SR1 = I2C_SR1(i2c);
@@ -473,51 +473,51 @@ static inline void i2c_error(struct i2c_periph *periph)
uint8_t err_nr = 0; uint8_t err_nr = 0;
#endif #endif
periph->errors->er_irq_cnt; periph->errors->er_irq_cnt;
if ((I2C_SR1((u32)periph->reg_addr) & I2C_SR1_AF) != 0) { /* Acknowledge failure */ if ((I2C_SR1((uint32_t)periph->reg_addr) & I2C_SR1_AF) != 0) { /* Acknowledge failure */
periph->errors->ack_fail_cnt++; periph->errors->ack_fail_cnt++;
I2C_SR1((u32)periph->reg_addr) &= ~I2C_SR1_AF; I2C_SR1((uint32_t)periph->reg_addr) &= ~I2C_SR1_AF;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
err_nr = 1; err_nr = 1;
#endif #endif
} }
if ((I2C_SR1((u32)periph->reg_addr) & I2C_SR1_BERR) != 0) { /* Misplaced Start or Stop condition */ if ((I2C_SR1((uint32_t)periph->reg_addr) & I2C_SR1_BERR) != 0) { /* Misplaced Start or Stop condition */
periph->errors->miss_start_stop_cnt++; periph->errors->miss_start_stop_cnt++;
I2C_SR1((u32)periph->reg_addr) &= ~I2C_SR1_BERR; I2C_SR1((uint32_t)periph->reg_addr) &= ~I2C_SR1_BERR;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
err_nr = 2; err_nr = 2;
#endif #endif
} }
if ((I2C_SR1((u32)periph->reg_addr) & I2C_SR1_ARLO) != 0) { /* Arbitration lost */ if ((I2C_SR1((uint32_t)periph->reg_addr) & I2C_SR1_ARLO) != 0) { /* Arbitration lost */
periph->errors->arb_lost_cnt++; periph->errors->arb_lost_cnt++;
I2C_SR1((u32)periph->reg_addr) &= ~I2C_SR1_ARLO; I2C_SR1((uint32_t)periph->reg_addr) &= ~I2C_SR1_ARLO;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
err_nr = 3; err_nr = 3;
#endif #endif
} }
if ((I2C_SR1((u32)periph->reg_addr) & I2C_SR1_OVR) != 0) { /* Overrun/Underrun */ if ((I2C_SR1((uint32_t)periph->reg_addr) & I2C_SR1_OVR) != 0) { /* Overrun/Underrun */
periph->errors->over_under_cnt++; periph->errors->over_under_cnt++;
I2C_SR1((u32)periph->reg_addr) &= ~I2C_SR1_OVR; I2C_SR1((uint32_t)periph->reg_addr) &= ~I2C_SR1_OVR;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
err_nr = 4; err_nr = 4;
#endif #endif
} }
if ((I2C_SR1((u32)periph->reg_addr) & I2C_SR1_PECERR) != 0) { /* PEC Error in reception */ if ((I2C_SR1((uint32_t)periph->reg_addr) & I2C_SR1_PECERR) != 0) { /* PEC Error in reception */
periph->errors->pec_recep_cnt++; periph->errors->pec_recep_cnt++;
I2C_SR1((u32)periph->reg_addr) &= ~I2C_SR1_PECERR; I2C_SR1((uint32_t)periph->reg_addr) &= ~I2C_SR1_PECERR;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
err_nr = 5; err_nr = 5;
#endif #endif
} }
if ((I2C_SR1((u32)periph->reg_addr) & I2C_SR1_TIMEOUT) != 0) { /* Timeout or Tlow error */ if ((I2C_SR1((uint32_t)periph->reg_addr) & I2C_SR1_TIMEOUT) != 0) { /* Timeout or Tlow error */
periph->errors->timeout_tlow_cnt++; periph->errors->timeout_tlow_cnt++;
I2C_SR1((u32)periph->reg_addr) &= ~I2C_SR1_TIMEOUT; I2C_SR1((uint32_t)periph->reg_addr) &= ~I2C_SR1_TIMEOUT;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
err_nr = 6; err_nr = 6;
#endif #endif
} }
if ((I2C_SR1((u32)periph->reg_addr) & I2C_SR1_SMBALERT) != 0) { /* SMBus alert */ if ((I2C_SR1((uint32_t)periph->reg_addr) & I2C_SR1_SMBALERT) != 0) { /* SMBus alert */
periph->errors->smbus_alert_cnt++; periph->errors->smbus_alert_cnt++;
I2C_SR1((u32)periph->reg_addr) &= ~I2C_SR1_SMBALERT; I2C_SR1((uint32_t)periph->reg_addr) &= ~I2C_SR1_SMBALERT;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
err_nr = 7; err_nr = 7;
#endif #endif
@@ -531,7 +531,7 @@ static inline void i2c_error(struct i2c_periph *periph)
} }
static inline void stmi2c_clear_pending_interrupts(u32 i2c) static inline void stmi2c_clear_pending_interrupts(uint32_t i2c)
{ {
uint16_t SR1 = I2C_SR1(i2c); uint16_t SR1 = I2C_SR1(i2c);
@@ -648,7 +648,7 @@ static inline void i2c_irq(struct i2c_periph *periph)
#endif #endif
// Save Some Direct Access to the I2C Registers ... // Save Some Direct Access to the I2C Registers ...
u32 i2c = (u32) periph->reg_addr; uint32_t i2c = (uint32_t) periph->reg_addr;
///////////////////////////// /////////////////////////////
// Check if we were ready ... // Check if we were ready ...
@@ -944,7 +944,7 @@ void i2c1_hw_init(void) {
} }
void i2c1_ev_isr(void) { void i2c1_ev_isr(void) {
u32 i2c = (u32) i2c1.reg_addr; uint32_t i2c = (uint32_t) i2c1.reg_addr;
I2C_CR2(i2c) &= ~I2C_CR2_ITERREN; I2C_CR2(i2c) &= ~I2C_CR2_ITERREN;
i2c_irq(&i2c1); i2c_irq(&i2c1);
i2c1_watchdog_counter = 0; i2c1_watchdog_counter = 0;
@@ -952,7 +952,7 @@ void i2c1_ev_isr(void) {
} }
void i2c1_er_isr(void) { void i2c1_er_isr(void) {
u32 i2c = (u32) i2c1.reg_addr; uint32_t i2c = (uint32_t) i2c1.reg_addr;
I2C_CR2(i2c) &= ~I2C_CR2_ITEVTEN; I2C_CR2(i2c) &= ~I2C_CR2_ITEVTEN;
i2c_irq(&i2c1); i2c_irq(&i2c1);
i2c1_watchdog_counter = 0; i2c1_watchdog_counter = 0;
@@ -1033,7 +1033,7 @@ void i2c2_hw_init(void) {
} }
void i2c2_ev_isr(void) { void i2c2_ev_isr(void) {
u32 i2c = (u32) i2c2.reg_addr; uint32_t i2c = (uint32_t) i2c2.reg_addr;
I2C_CR2(i2c) &= ~I2C_CR2_ITERREN; I2C_CR2(i2c) &= ~I2C_CR2_ITERREN;
i2c_irq(&i2c2); i2c_irq(&i2c2);
i2c2_watchdog_counter = 0; i2c2_watchdog_counter = 0;
@@ -1041,7 +1041,7 @@ void i2c2_ev_isr(void) {
} }
void i2c2_er_isr(void) { void i2c2_er_isr(void) {
u32 i2c = (u32) i2c2.reg_addr; uint32_t i2c = (uint32_t) i2c2.reg_addr;
I2C_CR2(i2c) &= ~I2C_CR2_ITEVTEN; I2C_CR2(i2c) &= ~I2C_CR2_ITEVTEN;
i2c_irq(&i2c2); i2c_irq(&i2c2);
i2c2_watchdog_counter = 0; i2c2_watchdog_counter = 0;
@@ -1121,7 +1121,7 @@ void i2c3_hw_init(void) {
} }
void i2c3_ev_isr(void) { void i2c3_ev_isr(void) {
u32 i2c = (u32) i2c3.reg_addr; uint32_t i2c = (uint32_t) i2c3.reg_addr;
I2C_CR2(i2c) &= ~I2C_CR2_ITERREN; I2C_CR2(i2c) &= ~I2C_CR2_ITERREN;
i2c_irq(&i2c3); i2c_irq(&i2c3);
i2c3_watchdog_counter = 0; i2c3_watchdog_counter = 0;
@@ -1129,7 +1129,7 @@ void i2c3_ev_isr(void) {
} }
void i2c3_er_isr(void) { void i2c3_er_isr(void) {
u32 i2c = (u32) i2c3.reg_addr; uint32_t i2c = (uint32_t) i2c3.reg_addr;
I2C_CR2(i2c) &= ~I2C_CR2_ITEVTEN; I2C_CR2(i2c) &= ~I2C_CR2_ITEVTEN;
i2c_irq(&i2c3); i2c_irq(&i2c3);
i2c3_watchdog_counter = 0; i2c3_watchdog_counter = 0;
@@ -1151,7 +1151,7 @@ void i2c_setbitrate(struct i2c_periph *periph, int bitrate)
volatile int devider; volatile int devider;
volatile int risetime; volatile int risetime;
u32 i2c = (u32) periph->reg_addr; uint32_t i2c = (uint32_t) periph->reg_addr;
/***************************************************** /*****************************************************
Bitrate: Bitrate:
@@ -1361,7 +1361,7 @@ bool_t i2c_idle(struct i2c_periph* periph)
// This is actually a difficult function: // This is actually a difficult function:
// -simply reading the status flags can clear bits and corrupt the transaction // -simply reading the status flags can clear bits and corrupt the transaction
u32 i2c = (u32) periph->reg_addr; uint32_t i2c = (uint32_t) periph->reg_addr;
#ifdef I2C_DEBUG_LED #ifdef I2C_DEBUG_LED
#ifdef USE_I2C1 #ifdef USE_I2C1
+47 -47
View File
@@ -69,11 +69,11 @@
* Libopencm3 specifc communication parameters for a SPI peripheral in master mode. * Libopencm3 specifc communication parameters for a SPI peripheral in master mode.
*/ */
struct locm3_spi_comm { struct locm3_spi_comm {
u32 br; ///< baudrate (clock divider) uint32_t br; ///< baudrate (clock divider)
u32 cpol; ///< clock polarity uint32_t cpol; ///< clock polarity
u32 cpha; ///< clock phase uint32_t cpha; ///< clock phase
u32 dff; ///< data frame format 8/16 bits uint32_t dff; ///< data frame format 8/16 bits
u32 lsbfirst; ///< frame format lsb/msb first uint32_t lsbfirst; ///< frame format lsb/msb first
}; };
/** /**
@@ -81,19 +81,19 @@ struct locm3_spi_comm {
* which allows for more code reuse. * which allows for more code reuse.
*/ */
struct spi_periph_dma { struct spi_periph_dma {
u32 spi; ///< SPI peripheral identifier uint32_t spi; ///< SPI peripheral identifier
u32 spidr; ///< SPI DataRegister address for DMA uint32_t spidr; ///< SPI DataRegister address for DMA
u32 dma; ///< DMA controller base address (DMA1 or DMA2) uint32_t dma; ///< DMA controller base address (DMA1 or DMA2)
u8 rx_chan; ///< receive DMA channel number uint8_t rx_chan; ///< receive DMA channel number
u8 tx_chan; ///< transmit DMA channel number uint8_t tx_chan; ///< transmit DMA channel number
u8 rx_nvic_irq; ///< receive interrupt uint8_t rx_nvic_irq; ///< receive interrupt
u8 tx_nvic_irq; ///< transmit interrupt uint8_t tx_nvic_irq; ///< transmit interrupt
u16 tx_dummy_buf; ///< dummy tx buffer for receive only cases uint16_t tx_dummy_buf; ///< dummy tx buffer for receive only cases
bool_t tx_extra_dummy_dma; ///< extra tx dummy dma flag for tx_len < rx_len bool_t tx_extra_dummy_dma; ///< extra tx dummy dma flag for tx_len < rx_len
u16 rx_dummy_buf; ///< dummy rx buffer for receive only cases uint16_t rx_dummy_buf; ///< dummy rx buffer for receive only cases
bool_t rx_extra_dummy_dma; ///< extra rx dummy dma flag for tx_len > rx_len bool_t rx_extra_dummy_dma; ///< extra rx dummy dma flag for tx_len > rx_len
struct locm3_spi_comm comm; ///< current communication paramters struct locm3_spi_comm comm; ///< current communication paramters
u8 comm_sig; ///< comm config signature used to check for changes uint8_t comm_sig; ///< comm config signature used to check for changes
}; };
@@ -112,8 +112,8 @@ static struct spi_periph_dma spi3_dma;
static void spi_start_dma_transaction(struct spi_periph* periph, struct spi_transaction* _trans); static void spi_start_dma_transaction(struct spi_periph* periph, struct spi_transaction* _trans);
static void spi_next_transaction(struct spi_periph* periph); static void spi_next_transaction(struct spi_periph* periph);
static void spi_configure_dma(u32 dma, u8 chan, u32 periph_addr, u32 buf_addr, static void spi_configure_dma(uint32_t dma, uint8_t chan, uint32_t periph_addr, uint32_t buf_addr,
u16 len, enum SPIDataSizeSelect dss, bool_t increment); uint16_t len, enum SPIDataSizeSelect dss, bool_t increment);
static void process_rx_dma_interrupt(struct spi_periph* periph); static void process_rx_dma_interrupt(struct spi_periph* periph);
static void process_tx_dma_interrupt(struct spi_periph* periph); static void process_tx_dma_interrupt(struct spi_periph* periph);
static void spi_arch_int_enable(struct spi_periph *spi); static void spi_arch_int_enable(struct spi_periph *spi);
@@ -436,8 +436,8 @@ static void set_comm_from_transaction(struct locm3_spi_comm* c, struct spi_trans
* Helpers for SPI transactions with DMA * Helpers for SPI transactions with DMA
* *
*****************************************************************************/ *****************************************************************************/
static void spi_configure_dma(u32 dma, u8 chan, u32 periph_addr, u32 buf_addr, static void spi_configure_dma(uint32_t dma, uint8_t chan, uint32_t periph_addr, uint32_t buf_addr,
u16 len, enum SPIDataSizeSelect dss, bool_t increment) uint16_t len, enum SPIDataSizeSelect dss, bool_t increment)
{ {
dma_channel_reset(dma, chan); dma_channel_reset(dma, chan);
dma_set_peripheral_address(dma, chan, periph_addr); dma_set_peripheral_address(dma, chan, periph_addr);
@@ -519,12 +519,12 @@ static void spi_start_dma_transaction(struct spi_periph* periph, struct spi_tran
dma->comm_sig = sig; dma->comm_sig = sig;
/* apply the new configuration */ /* apply the new configuration */
spi_disable((u32)periph->reg_addr); spi_disable((uint32_t)periph->reg_addr);
spi_init_master((u32)periph->reg_addr, dma->comm.br, dma->comm.cpol, spi_init_master((uint32_t)periph->reg_addr, dma->comm.br, dma->comm.cpol,
dma->comm.cpha, dma->comm.dff, dma->comm.lsbfirst); dma->comm.cpha, dma->comm.dff, dma->comm.lsbfirst);
spi_enable_software_slave_management((u32)periph->reg_addr); spi_enable_software_slave_management((uint32_t)periph->reg_addr);
spi_set_nss_high((u32)periph->reg_addr); spi_set_nss_high((uint32_t)periph->reg_addr);
spi_enable((u32)periph->reg_addr); spi_enable((uint32_t)periph->reg_addr);
} }
/* /*
@@ -554,12 +554,12 @@ static void spi_start_dma_transaction(struct spi_periph* periph, struct spi_tran
*/ */
if (trans->input_length == 0) { if (trans->input_length == 0) {
/* run the dummy rx dma for the complete transaction length */ /* run the dummy rx dma for the complete transaction length */
spi_configure_dma(dma->dma, dma->rx_chan, (u32)dma->spidr, spi_configure_dma(dma->dma, dma->rx_chan, (uint32_t)dma->spidr,
(u32)&(dma->rx_dummy_buf), trans->output_length, trans->dss, FALSE); (uint32_t)&(dma->rx_dummy_buf), trans->output_length, trans->dss, FALSE);
} else { } else {
/* run the real rx dma for input_length */ /* run the real rx dma for input_length */
spi_configure_dma(dma->dma, dma->rx_chan, (u32)dma->spidr, spi_configure_dma(dma->dma, dma->rx_chan, (uint32_t)dma->spidr,
(u32)trans->input_buf, trans->input_length, trans->dss, TRUE); (uint32_t)trans->input_buf, trans->input_length, trans->dss, TRUE);
/* use dummy rx dma for the rest */ /* use dummy rx dma for the rest */
if (trans->output_length > trans->input_length) { if (trans->output_length > trans->input_length) {
/* Enable use of second dma transfer with dummy buffer (cleared in ISR) */ /* Enable use of second dma transfer with dummy buffer (cleared in ISR) */
@@ -581,11 +581,11 @@ static void spi_start_dma_transaction(struct spi_periph* periph, struct spi_tran
* the dummy is used right from the start. * the dummy is used right from the start.
*/ */
if (trans->output_length == 0) { if (trans->output_length == 0) {
spi_configure_dma(dma->dma, dma->tx_chan, (u32)dma->spidr, spi_configure_dma(dma->dma, dma->tx_chan, (uint32_t)dma->spidr,
(u32)&(dma->tx_dummy_buf), trans->input_length, trans->dss, FALSE); (uint32_t)&(dma->tx_dummy_buf), trans->input_length, trans->dss, FALSE);
} else { } else {
spi_configure_dma(dma->dma, dma->tx_chan, (u32)dma->spidr, spi_configure_dma(dma->dma, dma->tx_chan, (uint32_t)dma->spidr,
(u32)trans->output_buf, trans->output_length, trans->dss, TRUE); (uint32_t)trans->output_buf, trans->output_length, trans->dss, TRUE);
if (trans->input_length > trans->output_length) { if (trans->input_length > trans->output_length) {
/* Enable use of second dma transfer with dummy buffer (cleared in ISR) */ /* Enable use of second dma transfer with dummy buffer (cleared in ISR) */
dma->tx_extra_dummy_dma = TRUE; dma->tx_extra_dummy_dma = TRUE;
@@ -604,8 +604,8 @@ static void spi_start_dma_transaction(struct spi_periph* periph, struct spi_tran
dma_enable_channel(dma->dma, dma->tx_chan); dma_enable_channel(dma->dma, dma->tx_chan);
/* Enable SPI transfers via DMA */ /* Enable SPI transfers via DMA */
spi_enable_rx_dma((u32)periph->reg_addr); spi_enable_rx_dma((uint32_t)periph->reg_addr);
spi_enable_tx_dma((u32)periph->reg_addr); spi_enable_tx_dma((uint32_t)periph->reg_addr);
} }
@@ -619,7 +619,7 @@ static void spi_start_dma_transaction(struct spi_periph* periph, struct spi_tran
void spi1_arch_init(void) { void spi1_arch_init(void) {
// set dma options // set dma options
spi1_dma.spidr = (u32)&SPI1_DR; spi1_dma.spidr = (uint32_t)&SPI1_DR;
spi1_dma.dma = DMA1; spi1_dma.dma = DMA1;
spi1_dma.rx_chan = DMA_CHANNEL2; spi1_dma.rx_chan = DMA_CHANNEL2;
spi1_dma.tx_chan = DMA_CHANNEL3; spi1_dma.tx_chan = DMA_CHANNEL3;
@@ -690,7 +690,7 @@ void spi1_arch_init(void) {
void spi2_arch_init(void) { void spi2_arch_init(void) {
// set dma options // set dma options
spi2_dma.spidr = (u32)&SPI2_DR; spi2_dma.spidr = (uint32_t)&SPI2_DR;
spi2_dma.dma = DMA1; spi2_dma.dma = DMA1;
spi2_dma.rx_chan = DMA_CHANNEL4; spi2_dma.rx_chan = DMA_CHANNEL4;
spi2_dma.tx_chan = DMA_CHANNEL5; spi2_dma.tx_chan = DMA_CHANNEL5;
@@ -760,7 +760,7 @@ void spi2_arch_init(void) {
void spi3_arch_init(void) { void spi3_arch_init(void) {
// set the default configuration // set the default configuration
spi3_dma.spidr = (u32)&SPI3_DR; spi3_dma.spidr = (uint32_t)&SPI3_DR;
spi3_dma.dma = DMA2; spi3_dma.dma = DMA2;
spi3_dma.rx_chan = DMA_CHANNEL1; spi3_dma.rx_chan = DMA_CHANNEL1;
spi3_dma.tx_chan = DMA_CHANNEL2; spi3_dma.tx_chan = DMA_CHANNEL2;
@@ -914,7 +914,7 @@ void process_rx_dma_interrupt(struct spi_periph *periph) {
dma_disable_transfer_complete_interrupt(dma->dma, dma->rx_chan); dma_disable_transfer_complete_interrupt(dma->dma, dma->rx_chan);
/* Disable SPI Rx request */ /* Disable SPI Rx request */
spi_disable_rx_dma((u32)periph->reg_addr); spi_disable_rx_dma((uint32_t)periph->reg_addr);
/* Disable DMA rx channel */ /* Disable DMA rx channel */
dma_disable_channel(dma->dma, dma->rx_chan); dma_disable_channel(dma->dma, dma->rx_chan);
@@ -931,10 +931,10 @@ void process_rx_dma_interrupt(struct spi_periph *periph) {
dma->rx_extra_dummy_dma = FALSE; dma->rx_extra_dummy_dma = FALSE;
/* Use the difference in length between rx and tx */ /* Use the difference in length between rx and tx */
u16 len_remaining = trans->output_length - trans->input_length; uint16_t len_remaining = trans->output_length - trans->input_length;
spi_configure_dma(dma->dma, dma->rx_chan, (u32)dma->spidr, spi_configure_dma(dma->dma, dma->rx_chan, (uint32_t)dma->spidr,
(u32)&(dma->rx_dummy_buf), len_remaining, trans->dss, FALSE); (uint32_t)&(dma->rx_dummy_buf), len_remaining, trans->dss, FALSE);
dma_set_read_from_peripheral(dma->dma, dma->rx_chan); dma_set_read_from_peripheral(dma->dma, dma->rx_chan);
dma_set_priority(dma->dma, dma->rx_chan, DMA_CCR_PL_HIGH); dma_set_priority(dma->dma, dma->rx_chan, DMA_CCR_PL_HIGH);
@@ -943,7 +943,7 @@ void process_rx_dma_interrupt(struct spi_periph *periph) {
/* Enable DMA channels */ /* Enable DMA channels */
dma_enable_channel(dma->dma, dma->rx_chan); dma_enable_channel(dma->dma, dma->rx_chan);
/* Enable SPI transfers via DMA */ /* Enable SPI transfers via DMA */
spi_enable_rx_dma((u32)periph->reg_addr); spi_enable_rx_dma((uint32_t)periph->reg_addr);
} }
else { else {
/* /*
@@ -976,7 +976,7 @@ void process_tx_dma_interrupt(struct spi_periph *periph) {
dma_disable_transfer_complete_interrupt(dma->dma, dma->tx_chan); dma_disable_transfer_complete_interrupt(dma->dma, dma->tx_chan);
/* Disable SPI TX request */ /* Disable SPI TX request */
spi_disable_tx_dma((u32)periph->reg_addr); spi_disable_tx_dma((uint32_t)periph->reg_addr);
/* Disable DMA tx channel */ /* Disable DMA tx channel */
dma_disable_channel(dma->dma, dma->tx_chan); dma_disable_channel(dma->dma, dma->tx_chan);
@@ -992,10 +992,10 @@ void process_tx_dma_interrupt(struct spi_periph *periph) {
dma->tx_extra_dummy_dma = FALSE; dma->tx_extra_dummy_dma = FALSE;
/* Use the difference in length between tx and rx */ /* Use the difference in length between tx and rx */
u16 len_remaining = trans->input_length - trans->output_length; uint16_t len_remaining = trans->input_length - trans->output_length;
spi_configure_dma(dma->dma, dma->tx_chan, (u32)dma->spidr, spi_configure_dma(dma->dma, dma->tx_chan, (uint32_t)dma->spidr,
(u32)&(dma->tx_dummy_buf), len_remaining, trans->dss, FALSE); (uint32_t)&(dma->tx_dummy_buf), len_remaining, trans->dss, FALSE);
dma_set_read_from_memory(dma->dma, dma->tx_chan); dma_set_read_from_memory(dma->dma, dma->tx_chan);
dma_set_priority(dma->dma, dma->tx_chan, DMA_CCR_PL_MEDIUM); dma_set_priority(dma->dma, dma->tx_chan, DMA_CCR_PL_MEDIUM);
@@ -1004,7 +1004,7 @@ void process_tx_dma_interrupt(struct spi_periph *periph) {
/* Enable DMA channels */ /* Enable DMA channels */
dma_enable_channel(dma->dma, dma->tx_chan); dma_enable_channel(dma->dma, dma->tx_chan);
/* Enable SPI transfers via DMA */ /* Enable SPI transfers via DMA */
spi_enable_tx_dma((u32)periph->reg_addr); spi_enable_tx_dma((uint32_t)periph->reg_addr);
} }
} }
+35 -35
View File
@@ -42,40 +42,40 @@
void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) { void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) {
/* Configure USART */ /* Configure USART */
usart_set_baudrate((u32)p->reg_addr, baud); usart_set_baudrate((uint32_t)p->reg_addr, baud);
usart_set_databits((u32)p->reg_addr, 8); usart_set_databits((uint32_t)p->reg_addr, 8);
usart_set_stopbits((u32)p->reg_addr, USART_STOPBITS_1); usart_set_stopbits((uint32_t)p->reg_addr, USART_STOPBITS_1);
usart_set_parity((u32)p->reg_addr, USART_PARITY_NONE); usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_NONE);
/* Disable Idle Line interrupt */ /* Disable Idle Line interrupt */
USART_CR1((u32)p->reg_addr) &= ~USART_CR1_IDLEIE; USART_CR1((uint32_t)p->reg_addr) &= ~USART_CR1_IDLEIE;
/* Disable LIN break detection interrupt */ /* Disable LIN break detection interrupt */
USART_CR2((u32)p->reg_addr) &= ~USART_CR2_LBDIE; USART_CR2((uint32_t)p->reg_addr) &= ~USART_CR2_LBDIE;
/* Enable USART1 Receive interrupts */ /* Enable USART1 Receive interrupts */
USART_CR1((u32)p->reg_addr) |= USART_CR1_RXNEIE; USART_CR1((uint32_t)p->reg_addr) |= USART_CR1_RXNEIE;
/* Enable the USART */ /* Enable the USART */
usart_enable((u32)p->reg_addr); usart_enable((uint32_t)p->reg_addr);
} }
void uart_periph_set_mode(struct uart_periph* p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control) { void uart_periph_set_mode(struct uart_periph* p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control) {
u32 mode = 0; uint32_t mode = 0;
if (tx_enabled) if (tx_enabled)
mode |= USART_MODE_TX; mode |= USART_MODE_TX;
if (rx_enabled) if (rx_enabled)
mode |= USART_MODE_RX; mode |= USART_MODE_RX;
/* set mode to Tx, Rx or TxRx */ /* set mode to Tx, Rx or TxRx */
usart_set_mode((u32)p->reg_addr, mode); usart_set_mode((uint32_t)p->reg_addr, mode);
if (hw_flow_control) { if (hw_flow_control) {
usart_set_flow_control((u32)p->reg_addr, USART_FLOWCONTROL_RTS_CTS); usart_set_flow_control((uint32_t)p->reg_addr, USART_FLOWCONTROL_RTS_CTS);
} }
else { else {
usart_set_flow_control((u32)p->reg_addr, USART_FLOWCONTROL_NONE); usart_set_flow_control((uint32_t)p->reg_addr, USART_FLOWCONTROL_NONE);
} }
} }
@@ -86,7 +86,7 @@ void uart_transmit(struct uart_periph* p, uint8_t data ) {
if (temp == p->tx_extract_idx) if (temp == p->tx_extract_idx)
return; // no room return; // no room
USART_CR1((u32)p->reg_addr) &= ~USART_CR1_TXEIE; // Disable TX interrupt USART_CR1((uint32_t)p->reg_addr) &= ~USART_CR1_TXEIE; // Disable TX interrupt
// check if in process of sending data // check if in process of sending data
if (p->tx_running) { // yes, add to queue if (p->tx_running) { // yes, add to queue
@@ -95,61 +95,61 @@ void uart_transmit(struct uart_periph* p, uint8_t data ) {
} }
else { // no, set running flag and write to output register else { // no, set running flag and write to output register
p->tx_running = TRUE; p->tx_running = TRUE;
usart_send((u32)p->reg_addr, data); usart_send((uint32_t)p->reg_addr, data);
} }
USART_CR1((u32)p->reg_addr) |= USART_CR1_TXEIE; // Enable TX interrupt USART_CR1((uint32_t)p->reg_addr) |= USART_CR1_TXEIE; // Enable TX interrupt
} }
static inline void usart_isr(struct uart_periph* p) { static inline void usart_isr(struct uart_periph* p) {
if (((USART_CR1((u32)p->reg_addr) & USART_CR1_TXEIE) != 0) && if (((USART_CR1((uint32_t)p->reg_addr) & USART_CR1_TXEIE) != 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_TXE) != 0)) { ((USART_SR((uint32_t)p->reg_addr) & USART_SR_TXE) != 0)) {
// check if more data to send // check if more data to send
if (p->tx_insert_idx != p->tx_extract_idx) { if (p->tx_insert_idx != p->tx_extract_idx) {
usart_send((u32)p->reg_addr,p->tx_buf[p->tx_extract_idx]); usart_send((uint32_t)p->reg_addr,p->tx_buf[p->tx_extract_idx]);
p->tx_extract_idx++; p->tx_extract_idx++;
p->tx_extract_idx %= UART_TX_BUFFER_SIZE; p->tx_extract_idx %= UART_TX_BUFFER_SIZE;
} }
else { else {
p->tx_running = FALSE; // clear running flag p->tx_running = FALSE; // clear running flag
USART_CR1((u32)p->reg_addr) &= ~USART_CR1_TXEIE; // Disable TX interrupt USART_CR1((uint32_t)p->reg_addr) &= ~USART_CR1_TXEIE; // Disable TX interrupt
} }
} }
if (((USART_CR1((u32)p->reg_addr) & USART_CR1_RXNEIE) != 0) && if (((USART_CR1((uint32_t)p->reg_addr) & USART_CR1_RXNEIE) != 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_RXNE) != 0) && ((USART_SR((uint32_t)p->reg_addr) & USART_SR_RXNE) != 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_ORE) == 0) && ((USART_SR((uint32_t)p->reg_addr) & USART_SR_ORE) == 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_NE) == 0) && ((USART_SR((uint32_t)p->reg_addr) & USART_SR_NE) == 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_FE) == 0)) { ((USART_SR((uint32_t)p->reg_addr) & USART_SR_FE) == 0)) {
uint16_t temp = (p->rx_insert_idx + 1) % UART_RX_BUFFER_SIZE;; uint16_t temp = (p->rx_insert_idx + 1) % UART_RX_BUFFER_SIZE;;
p->rx_buf[p->rx_insert_idx] = usart_recv((u32)p->reg_addr); p->rx_buf[p->rx_insert_idx] = usart_recv((uint32_t)p->reg_addr);
// check for more room in queue // check for more room in queue
if (temp != p->rx_extract_idx) if (temp != p->rx_extract_idx)
p->rx_insert_idx = temp; // update insert index p->rx_insert_idx = temp; // update insert index
} }
else { else {
/* ORE, NE or FE error - read USART_DR reg and log the error */ /* ORE, NE or FE error - read USART_DR reg and log the error */
if (((USART_CR1((u32)p->reg_addr) & USART_CR1_RXNEIE) != 0) && if (((USART_CR1((uint32_t)p->reg_addr) & USART_CR1_RXNEIE) != 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_ORE) != 0)) { ((USART_SR((uint32_t)p->reg_addr) & USART_SR_ORE) != 0)) {
usart_recv((u32)p->reg_addr); usart_recv((uint32_t)p->reg_addr);
p->ore++; p->ore++;
} }
if (((USART_CR1((u32)p->reg_addr) & USART_CR1_RXNEIE) != 0) && if (((USART_CR1((uint32_t)p->reg_addr) & USART_CR1_RXNEIE) != 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_NE) != 0)) { ((USART_SR((uint32_t)p->reg_addr) & USART_SR_NE) != 0)) {
usart_recv((u32)p->reg_addr); usart_recv((uint32_t)p->reg_addr);
p->ne_err++; p->ne_err++;
} }
if (((USART_CR1((u32)p->reg_addr) & USART_CR1_RXNEIE) != 0) && if (((USART_CR1((uint32_t)p->reg_addr) & USART_CR1_RXNEIE) != 0) &&
((USART_SR((u32)p->reg_addr) & USART_SR_FE) != 0)) { ((USART_SR((uint32_t)p->reg_addr) & USART_SR_FE) != 0)) {
usart_recv((u32)p->reg_addr); usart_recv((uint32_t)p->reg_addr);
p->fe_err++; p->fe_err++;
} }
} }
} }
static inline void usart_enable_irq(u8 IRQn) { static inline void usart_enable_irq(uint8_t IRQn) {
/* Note: /* Note:
* In libstm32 times the priority of this interrupt was set to * In libstm32 times the priority of this interrupt was set to
* preemption priority 2 and sub priority 1 * preemption priority 2 and sub priority 1
@@ -65,7 +65,7 @@ int32_t actuators_pwm_values[ACTUATORS_PWM_NB];
/** Set PWM channel configuration /** Set PWM channel configuration
*/ */
static inline void actuators_pwm_arch_channel_init(u32 timer_peripheral, static inline void actuators_pwm_arch_channel_init(uint32_t timer_peripheral,
enum tim_oc_id oc_id) { enum tim_oc_id oc_id) {
timer_disable_oc_output(timer_peripheral, oc_id); timer_disable_oc_output(timer_peripheral, oc_id);
@@ -80,13 +80,13 @@ static inline void actuators_pwm_arch_channel_init(u32 timer_peripheral,
/** Set GPIO configuration /** Set GPIO configuration
*/ */
#if defined(STM32F4) #if defined(STM32F4)
static inline void set_servo_gpio(u32 gpioport, u16 pin, u8 af_num, u32 en) { static inline void set_servo_gpio(uint32_t gpioport, uint16_t pin, uint8_t af_num, uint32_t en) {
rcc_peripheral_enable_clock(&RCC_AHB1ENR, en); rcc_peripheral_enable_clock(&RCC_AHB1ENR, en);
gpio_mode_setup(gpioport, GPIO_MODE_AF, GPIO_PUPD_NONE, pin); gpio_mode_setup(gpioport, GPIO_MODE_AF, GPIO_PUPD_NONE, pin);
gpio_set_af(gpioport, af_num, pin); gpio_set_af(gpioport, af_num, pin);
} }
#elif defined(STM32F1) #elif defined(STM32F1)
static inline void set_servo_gpio(u32 gpioport, u16 pin, u8 none, u32 en) { static inline void set_servo_gpio(uint32_t gpioport, uint16_t pin, uint8_t none, uint32_t en) {
rcc_peripheral_enable_clock(&RCC_APB2ENR, en | RCC_APB2ENR_AFIOEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, en | RCC_APB2ENR_AFIOEN);
gpio_set_mode(gpioport, GPIO_MODE_OUTPUT_50_MHZ, gpio_set_mode(gpioport, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, pin); GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, pin);
@@ -95,7 +95,7 @@ static inline void set_servo_gpio(u32 gpioport, u16 pin, u8 none, u32 en) {
/** Set Timer configuration /** Set Timer configuration
*/ */
static inline void set_servo_timer(u32 timer, u32 period, u8 channels_mask) { static inline void set_servo_timer(uint32_t timer, uint32_t period, uint8_t channels_mask) {
timer_reset(timer); timer_reset(timer);
/* Timer global mode: /* Timer global mode:
@@ -52,6 +52,20 @@ uint32_t ppm_last_pulse_time;
bool_t ppm_data_valid; bool_t ppm_data_valid;
static uint32_t timer_rollover_cnt; static uint32_t timer_rollover_cnt;
/*
* Timer clock frequency (before prescaling) is twice the frequency
* of the APB domain to which the timer is connected.
*/
#ifdef STM32F1
/**
* HCLK = 72MHz, Timer clock also 72MHz since
* TIM1_CLK = APB2 = 72MHz
* TIM2_CLK = 2 * APB1 = 2 * 32MHz
*/
#define PPM_TIMER_CLK AHB_CLK
#endif
#if USE_PPM_TIM2 #if USE_PPM_TIM2
PRINT_CONFIG_MSG("Using TIM2 for PPM input.") PRINT_CONFIG_MSG("Using TIM2 for PPM input.")
@@ -60,6 +74,14 @@ PRINT_CONFIG_MSG("Using TIM2 for PPM input.")
#define PPM_PERIPHERAL RCC_APB1ENR_TIM2EN #define PPM_PERIPHERAL RCC_APB1ENR_TIM2EN
#define PPM_TIMER TIM2 #define PPM_TIMER TIM2
#ifdef STM32F4
/* Since APB prescaler != 1 :
* Timer clock frequency (before prescaling) is twice the frequency
* of the APB domain to which the timer is connected.
*/
#define PPM_TIMER_CLK (rcc_ppre1_frequency * 2)
#endif
#elif USE_PPM_TIM1 #elif USE_PPM_TIM1
PRINT_CONFIG_MSG("Using TIM1 for PPM input.") PRINT_CONFIG_MSG("Using TIM1 for PPM input.")
@@ -68,6 +90,12 @@ PRINT_CONFIG_MSG("Using TIM1 for PPM input.")
#define PPM_PERIPHERAL RCC_APB2ENR_TIM1EN #define PPM_PERIPHERAL RCC_APB2ENR_TIM1EN
#define PPM_TIMER TIM1 #define PPM_TIMER TIM1
#ifdef STM32F4
#define PPM_TIMER_CLK (rcc_ppre2_frequency * 2)
#endif
#else
#error Unknown PPM input timer configuration.
#endif #endif
void ppm_arch_init ( void ) { void ppm_arch_init ( void ) {
@@ -86,7 +114,7 @@ void ppm_arch_init ( void ) {
timer_set_mode(PPM_TIMER, TIM_CR1_CKD_CK_INT, timer_set_mode(PPM_TIMER, TIM_CR1_CKD_CK_INT,
TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
timer_set_period(PPM_TIMER, 0xFFFF); timer_set_period(PPM_TIMER, 0xFFFF);
timer_set_prescaler(PPM_TIMER, (AHB_CLK / (RC_PPM_TICKS_PER_USEC*ONE_MHZ_CLK)) - 1); timer_set_prescaler(PPM_TIMER, (PPM_TIMER_CLK / (RC_PPM_TICKS_PER_USEC*ONE_MHZ_CLK)) - 1);
/* TIM configuration: Input Capture mode --------------------- /* TIM configuration: Input Capture mode ---------------------
The Rising edge is used as active edge The Rising edge is used as active edge
@@ -96,7 +124,7 @@ void ppm_arch_init ( void ) {
#elif defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_NEGATIVE #elif defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_NEGATIVE
timer_ic_set_polarity(PPM_TIMER, PPM_CHANNEL, TIM_IC_FALLING); timer_ic_set_polarity(PPM_TIMER, PPM_CHANNEL, TIM_IC_FALLING);
#else #else
#error "Unknown PM_PULSE_TYPE" #error "Unknown PPM_PULSE_TYPE"
#endif #endif
timer_ic_set_input(PPM_TIMER, PPM_CHANNEL, PPM_TIMER_INPUT); timer_ic_set_input(PPM_TIMER, PPM_CHANNEL, PPM_TIMER_INPUT);
timer_ic_set_prescaler(PPM_TIMER, PPM_CHANNEL, TIM_IC_PSC_OFF); timer_ic_set_prescaler(PPM_TIMER, PPM_CHANNEL, TIM_IC_PSC_OFF);
@@ -33,10 +33,17 @@
#include "mcu_periph/sys_time.h" #include "mcu_periph/sys_time.h"
/** /**
* The ppm counter is running at cpu freq / 72 or 168 / 8 * The ppm counter is set-up to have 1/6 us resolution.
* so the counter has 1/8 us resolution *
* The timer clock frequency (before prescaling):
* STM32F1:
* TIM1 -> APB2 = HCLK = 72MHz
* TIM2 -> 2 * APB1 = 2 * 36MHz = 72MHz
* STM32F4:
* TIM1 -> 2 * APB2 = 2 * 84MHz = 168MHz
* TIM2 -> 2 * APB1 = 2 * 42MHz = 84MHz
*/ */
#define RC_PPM_TICKS_PER_USEC 8 #define RC_PPM_TICKS_PER_USEC 6
#define RC_PPM_TICKS_OF_USEC(_v) ((_v)*RC_PPM_TICKS_PER_USEC) #define RC_PPM_TICKS_OF_USEC(_v) ((_v)*RC_PPM_TICKS_PER_USEC)
#define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (int32_t)((_v)*RC_PPM_TICKS_PER_USEC) #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (int32_t)((_v)*RC_PPM_TICKS_PER_USEC)
@@ -35,12 +35,7 @@
#include "subsystems/settings.h" #include "subsystems/settings.h"
#if defined(STM32F1) #include <libopencm3/stm32/flash.h>
#include <libopencm3/stm32/f1/flash.h>
#elif defined(STM32F4)
#include <libopencm3/stm32/f4/flash.h>
#endif
#include <libopencm3/stm32/crc.h> #include <libopencm3/stm32/crc.h>
#include <libopencm3/stm32/dbgmcu.h> #include <libopencm3/stm32/dbgmcu.h>
+51
View File
@@ -29,6 +29,8 @@
#ifndef BOARDS_ARDRONE_AT_COM_H #ifndef BOARDS_ARDRONE_AT_COM_H
#define BOARDS_ARDRONE_AT_COM_H #define BOARDS_ARDRONE_AT_COM_H
#define NAVDATA_HEADER (0x55667788)
//Define the AT_REF bits //Define the AT_REF bits
typedef enum { typedef enum {
REF_TAKEOFF = 1U << 9, REF_TAKEOFF = 1U << 9,
@@ -149,6 +151,55 @@ typedef struct _navdata_phys_measures_t {
uint32_t vrefIDG; // ref volt IDG gyro [LSB] uint32_t vrefIDG; // ref volt IDG gyro [LSB]
} __attribute__ ((packed)) navdata_phys_measures_t; } __attribute__ ((packed)) navdata_phys_measures_t;
//Navdata gps packet
typedef double float64_t; //TODO: Fix this nicely, but this is only used here
typedef float float32_t; //TODO: Fix this nicely, but this is only used here
typedef struct _navdata_gps_t {
uint16_t tag; /*!< Navdata block ('option') identifier */
uint16_t size; /*!< set this to the size of this structure */
float64_t lat; /*!< Latitude */
float64_t lon; /*!< Longitude */
float64_t elevation; /*!< Elevation */
float64_t hdop; /*!< hdop */
int32_t data_available; /*!< When there is data available */
uint8_t unk_0[8];
float64_t lat0; /*!< Latitude ??? */
float64_t lon0; /*!< Longitude ??? */
float64_t lat_fuse; /*!< Latitude fused */
float64_t lon_fuse; /*!< Longitude fused */
uint32_t gps_state; /*!< State of the GPS, still need to figure out */
uint8_t unk_1[40];
float64_t vdop; /*!< vdop */
float64_t pdop; /*!< pdop */
float32_t speed; /*!< speed */
uint32_t last_frame_timestamp; /*!< Timestamp from the last frame */
float32_t degree; /*!< Degree */
float32_t degree_mag; /*!< Degree of the magnetic */
uint8_t unk_2[16];
struct{
uint8_t sat;
uint8_t unk;
}channels[12];
int32_t gps_plugged; /*!< When the gps is plugged */
uint8_t unk_3[108];
float64_t gps_time; /*!< The gps time of week */
uint16_t week; /*!< The gps week */
uint8_t gps_fix; /*!< The gps fix */
uint8_t num_sattelites; /*!< Number of sattelites */
uint8_t unk_4[24];
float64_t ned_vel_c0; /*!< NED velocity */
float64_t ned_vel_c1; /*!< NED velocity */
float64_t ned_vel_c2; /*!< NED velocity */
float64_t pos_accur_c0; /*!< Position accuracy */
float64_t pos_accur_c1; /*!< Position accuracy */
float64_t pos_accur_c2; /*!< Position accuracy */
float32_t speed_acur; /*!< Speed accuracy */
float32_t time_acur; /*!< Time accuracy */
uint8_t unk_5[72];
float32_t temprature;
float32_t pressure;
} __attribute__ ((packed)) navdata_gps_t;
//External functions //External functions
extern void init_at_com(void); extern void init_at_com(void);
extern void at_com_recieve_navdata(unsigned char* buffer); extern void at_com_recieve_navdata(unsigned char* buffer);
+1 -1
View File
@@ -6,7 +6,7 @@
/* Internal communication */ /* Internal communication */
#define ARDRONE_NAVDATA_PORT 5554 #define ARDRONE_NAVDATA_PORT 5554
#define ARDRONE_AT_PORT 5556 #define ARDRONE_AT_PORT 5556
#define ARDRONE_NAVDATA_BUFFER_SIZE 2048 #define ARDRONE_NAVDATA_BUFFER_SIZE 4096
#define ARDRONE_IP "192.168.1.1" #define ARDRONE_IP "192.168.1.1"
/* Default actuators driver */ /* Default actuators driver */
+4 -4
View File
@@ -3,7 +3,7 @@
#define BOARD_KROOZ #define BOARD_KROOZ
/* Krooz/M has a 12MHz external clock and 168MHz internal. */ /* KroozSD has a 12MHz external clock and 168MHz internal. */
#define EXT_CLK 12000000 #define EXT_CLK 12000000
#define AHB_CLK 168000000 #define AHB_CLK 168000000
@@ -210,7 +210,7 @@
#define BOARD_HAS_BARO 1 #define BOARD_HAS_BARO 1
/* PWM */ /* PWM */
#define PWM_USE_TIM2 1 //#define PWM_USE_TIM2 1
#define PWM_USE_TIM3 1 #define PWM_USE_TIM3 1
#define PWM_USE_TIM4 1 #define PWM_USE_TIM4 1
#define PWM_USE_TIM5 1 #define PWM_USE_TIM5 1
@@ -383,11 +383,11 @@
#define USE_PPM_TIM2 1 #define USE_PPM_TIM2 1
#define PPM_CHANNEL TIM_IC2 #define PPM_CHANNEL TIM_IC2
#define PPM_TIMER_INPUT TIM_IC_IN_TI1 #define PPM_TIMER_INPUT TIM_IC_IN_TI2
#define PPM_IRQ NVIC_TIM2_IRQ #define PPM_IRQ NVIC_TIM2_IRQ
//#define PPM_IRQ2 NVIC_TIM2_UP_TIM10_IRQ //#define PPM_IRQ2 NVIC_TIM2_UP_TIM10_IRQ
// Capture/Compare InteruptEnable and InterruptFlag // Capture/Compare InteruptEnable and InterruptFlag
#define PPM_CC_EN TIM_DIER_CC2IE #define PPM_CC_IE TIM_DIER_CC2IE
#define PPM_CC_IF TIM_SR_CC2IF #define PPM_CC_IF TIM_SR_CC2IF
#define PPM_GPIO_PORT GPIOB #define PPM_GPIO_PORT GPIOB
#define PPM_GPIO_PIN GPIO3 #define PPM_GPIO_PIN GPIO3
+2 -1
View File
@@ -59,7 +59,7 @@
*/ */
#define UART1_GPIO_AF 0 #define UART1_GPIO_AF 0
#define UART1_GPIO_PORT_RX GPIO_BANK_USART1_RX #define UART1_GPIO_PORT_RX GPIO_BANK_USART1_RX
#define UART1_GPIO_RX GPIO_BANK_USART1_RX #define UART1_GPIO_RX GPIO_USART1_RX
#define UART1_GPIO_PORT_TX GPIO_BANK_USART1_TX #define UART1_GPIO_PORT_TX GPIO_BANK_USART1_TX
#define UART1_GPIO_TX GPIO_USART1_TX #define UART1_GPIO_TX GPIO_USART1_TX
@@ -129,6 +129,7 @@
#define PPM_CC_IF TIM_SR_CC2IF #define PPM_CC_IF TIM_SR_CC2IF
#define PPM_GPIO_PORT GPIOA #define PPM_GPIO_PORT GPIOA
#define PPM_GPIO_PIN GPIO1 #define PPM_GPIO_PIN GPIO1
#define PPM_GPIO_AF 0
/* ADC */ /* ADC */
+1 -1
View File
@@ -253,7 +253,7 @@ void event_task_fbw( void) {
trimmed_commands[COMMAND_PITCH] += ChopAbs(command_pitch_trim, MAX_PPRZ/10); trimmed_commands[COMMAND_PITCH] += ChopAbs(command_pitch_trim, MAX_PPRZ/10);
#endif #endif
#ifdef COMMAND_YAW #ifdef COMMAND_YAW
trimmed_commands[COMMAND_YAW] = ChopAbs(command_yaw_trim, MAX_PPRZ); trimmed_commands[COMMAND_YAW] += ChopAbs(command_yaw_trim, MAX_PPRZ);
#endif #endif
SetActuatorsFromCommands(trimmed_commands, autopilot_mode); SetActuatorsFromCommands(trimmed_commands, autopilot_mode);
+40 -1
View File
@@ -78,6 +78,11 @@ static inline int ahrs_is_aligned(void) {
#include "autopilot_arming_yaw.h" #include "autopilot_arming_yaw.h"
#endif #endif
#ifndef MODE_STARTUP
#define MODE_STARTUP AP_MODE_KILL
PRINT_CONFIG_MSG("Using AP_MODE_KILL as MODE_STARTUP")
#endif
static void send_alive(void) { static void send_alive(void) {
DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM); DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
} }
@@ -168,7 +173,7 @@ static void send_baro_raw(void) {
} }
void autopilot_init(void) { void autopilot_init(void) {
autopilot_mode = AP_MODE_KILL; autopilot_mode = MODE_STARTUP;
autopilot_motors_on = FALSE; autopilot_motors_on = FALSE;
kill_throttle = ! autopilot_motors_on; kill_throttle = ! autopilot_motors_on;
autopilot_in_flight = FALSE; autopilot_in_flight = FALSE;
@@ -200,6 +205,36 @@ void autopilot_init(void) {
} }
static inline void autopilot_check_in_flight_no_rc( bool_t motors_on ) {
if (autopilot_in_flight) {
if (autopilot_in_flight_counter > 0) {
if (stabilization_cmd[COMMAND_THRUST] == 0) {
autopilot_in_flight_counter--;
if (autopilot_in_flight_counter == 0) {
autopilot_in_flight = FALSE;
}
}
else { /* !THROTTLE_STICK_DOWN */
autopilot_in_flight_counter = AUTOPILOT_IN_FLIGHT_TIME;
}
}
}
else { /* not in flight */
if (autopilot_in_flight_counter < AUTOPILOT_IN_FLIGHT_TIME &&
motors_on) {
if (stabilization_cmd[COMMAND_THRUST] > 0) {
autopilot_in_flight_counter++;
if (autopilot_in_flight_counter == AUTOPILOT_IN_FLIGHT_TIME)
autopilot_in_flight = TRUE;
}
else { /* THROTTLE_STICK_DOWN */
autopilot_in_flight_counter = 0;
}
}
}
}
void autopilot_periodic(void) { void autopilot_periodic(void) {
RunOnceEvery(NAV_PRESCALER, nav_periodic_task()); RunOnceEvery(NAV_PRESCALER, nav_periodic_task());
@@ -226,6 +261,10 @@ INFO("Using FAILSAFE_GROUND_DETECT")
SetRotorcraftCommands(stabilization_cmd, autopilot_in_flight, autopilot_motors_on); SetRotorcraftCommands(stabilization_cmd, autopilot_in_flight, autopilot_motors_on);
} }
// when we dont have RC, check in flight by looking at throttle
if (radio_control.status != RC_OK) {
autopilot_check_in_flight_no_rc(autopilot_motors_on);
}
} }
@@ -19,7 +19,7 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
/** @file firmwares/rotorcraft/stabilization_attitude.h /** @file firmwares/rotorcraft/stabilization/stabilization_attitude.h
* General attitude stabilization interface for rotorcrafts. * General attitude stabilization interface for rotorcrafts.
* The actual implementation is automatically included. * The actual implementation is automatically included.
*/ */
@@ -24,6 +24,7 @@
#include "subsystems/radio_control.h" #include "subsystems/radio_control.h"
#include "firmwares/rotorcraft/stabilization/stabilization_attitude_rc_setpoint.h" #include "firmwares/rotorcraft/stabilization/stabilization_attitude_rc_setpoint.h"
#include "paparazzi.h"
#include "generated/airframe.h" #include "generated/airframe.h"
@@ -84,16 +84,16 @@ float stabilization_attitude_get_heading_f(void) {
* @param[out] sp attitude setpoint as euler angles * @param[out] sp attitude setpoint as euler angles
*/ */
void stabilization_attitude_read_rc_setpoint_eulers(struct Int32Eulers *sp, bool_t in_flight) { void stabilization_attitude_read_rc_setpoint_eulers(struct Int32Eulers *sp, bool_t in_flight) {
const int32_t max_phi_scale = (int32_t)ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_PHI) / MAX_PPRZ; const int32_t max_rc_phi = (int32_t) ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_PHI);
const int32_t max_theta_scale = (int32_t)ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_THETA) / MAX_PPRZ; const int32_t max_rc_theta = (int32_t) ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_THETA);
const int32_t max_r_scale = (int32_t)ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_R) / MAX_PPRZ; const int32_t max_rc_r = (int32_t) ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_R);
sp->phi = ((int32_t) radio_control.values[RADIO_ROLL] * max_phi_scale); sp->phi = (int32_t) ((radio_control.values[RADIO_ROLL] * max_rc_phi) / MAX_PPRZ);
sp->theta = ((int32_t) radio_control.values[RADIO_PITCH] * max_theta_scale); sp->theta = (int32_t) ((radio_control.values[RADIO_PITCH] * max_rc_theta) / MAX_PPRZ);
if (in_flight) { if (in_flight) {
if (YAW_DEADBAND_EXCEEDED()) { if (YAW_DEADBAND_EXCEEDED()) {
sp->psi += ((int32_t) radio_control.values[RADIO_YAW] * max_r_scale / RC_UPDATE_FREQ); sp->psi += (int32_t) ((radio_control.values[RADIO_YAW] * max_rc_r) / MAX_PPRZ / RC_UPDATE_FREQ);
INT32_ANGLE_NORMALIZE(sp->psi); INT32_ANGLE_NORMALIZE(sp->psi);
} }
if (autopilot_mode == AP_MODE_FORWARD) { if (autopilot_mode == AP_MODE_FORWARD) {
+27 -12
View File
@@ -142,9 +142,34 @@ void ned_of_ecef_vect_i(struct NedCoor_i* ned, struct LtpDef_i* def, struct Ecef
ENU_OF_TO_NED(*ned, enu); ENU_OF_TO_NED(*ned, enu);
} }
/* check if resolution of INT32_TRIG_FRAC (14) is enough here */
void ecef_of_enu_vect_i(struct EcefCoor_i* ecef, struct LtpDef_i* def, struct EnuCoor_i* enu) {
const int64_t tmpx = (int64_t)def->ltp_of_ecef.m[0] * enu->x +
(int64_t)def->ltp_of_ecef.m[3] * enu->y +
(int64_t)def->ltp_of_ecef.m[6] * enu->z;
ecef->x = (int32_t)(tmpx>>HIGH_RES_TRIG_FRAC);
const int64_t tmpy = (int64_t)def->ltp_of_ecef.m[1] * enu->x +
(int64_t)def->ltp_of_ecef.m[4] * enu->y +
(int64_t)def->ltp_of_ecef.m[7] * enu->z;
ecef->y = (int32_t)(tmpy>>HIGH_RES_TRIG_FRAC);
/* first element is always zero http://en.wikipedia.org/wiki/Geodetic_system#From_ENU_to_ECEF */
const int64_t tmpz = (int64_t)def->ltp_of_ecef.m[5] * enu->y +
(int64_t)def->ltp_of_ecef.m[8] * enu->z;
ecef->z = (int32_t)(tmpz>>HIGH_RES_TRIG_FRAC);
}
void ecef_of_ned_vect_i(struct EcefCoor_i* ecef, struct LtpDef_i* def, struct NedCoor_i* ned) {
struct EnuCoor_i enu;
ENU_OF_TO_NED(enu, *ned);
ecef_of_enu_vect_i(ecef, def, &enu);
}
void ecef_of_enu_point_i(struct EcefCoor_i* ecef, struct LtpDef_i* def, struct EnuCoor_i* enu) { void ecef_of_enu_point_i(struct EcefCoor_i* ecef, struct LtpDef_i* def, struct EnuCoor_i* enu) {
INT32_RMAT_TRANSP_VMULT(*ecef, def->ltp_of_ecef, *enu); ecef_of_enu_vect_i(ecef, def, enu);
INT32_VECT3_ADD(*ecef, def->ecef); INT32_VECT3_ADD(*ecef, def->ecef);
} }
@@ -154,16 +179,6 @@ void ecef_of_ned_point_i(struct EcefCoor_i* ecef, struct LtpDef_i* def, struct N
ecef_of_enu_point_i(ecef, def, &enu); ecef_of_enu_point_i(ecef, def, &enu);
} }
void ecef_of_enu_vect_i(struct EcefCoor_i* ecef, struct LtpDef_i* def, struct EnuCoor_i* enu) {
INT32_RMAT_TRANSP_VMULT(*ecef, def->ltp_of_ecef, *enu);
}
void ecef_of_ned_vect_i(struct EcefCoor_i* ecef, struct LtpDef_i* def, struct NedCoor_i* ned) {
struct EnuCoor_i enu;
ENU_OF_TO_NED(enu, *ned);
ecef_of_enu_vect_i(ecef, def, &enu);
}
void enu_of_lla_point_i(struct EnuCoor_i* enu, struct LtpDef_i* def, struct LlaCoor_i* lla) { void enu_of_lla_point_i(struct EnuCoor_i* enu, struct LtpDef_i* def, struct LlaCoor_i* lla) {
struct EcefCoor_i ecef; struct EcefCoor_i ecef;
+3 -2
View File
@@ -22,8 +22,9 @@
* *
*/ */
/** \file xsens.c /**
* \brief Parser for the Xsens protocol * @file modules/ins/ins_xsens700.c
* Parser for the Xsens protocol.
*/ */
#include "ins_module.h" #include "ins_module.h"
@@ -62,8 +62,8 @@ void high_speed_logger_spi_link_periodic(void)
high_speed_logger_spi_link_data.acc_y = imu.accel_unscaled.y; high_speed_logger_spi_link_data.acc_y = imu.accel_unscaled.y;
high_speed_logger_spi_link_data.acc_z = imu.accel_unscaled.z; high_speed_logger_spi_link_data.acc_z = imu.accel_unscaled.z;
high_speed_logger_spi_link_data.mag_x = imu.mag_unscaled.x; high_speed_logger_spi_link_data.mag_x = imu.mag_unscaled.x;
high_speed_logger_spi_link_data.mag_y = imu.mag_unscaled.x; high_speed_logger_spi_link_data.mag_y = imu.mag_unscaled.y;
high_speed_logger_spi_link_data.mag_z = imu.mag_unscaled.x; high_speed_logger_spi_link_data.mag_z = imu.mag_unscaled.z;
spi_submit(&(HIGH_SPEED_LOGGER_SPI_LINK_DEVICE), &high_speed_logger_spi_link_transaction); spi_submit(&(HIGH_SPEED_LOGGER_SPI_LINK_DEVICE), &high_speed_logger_spi_link_transaction);
} }
-8
View File
@@ -195,14 +195,6 @@ void pcap01readRegister(uint8_t reg)
* *
* function where current measurement data from pcap01 is read into * function where current measurement data from pcap01 is read into
* global sensor variable * global sensor variable
*
* \param control Control command
* possible commands:
* PCAP01_PU_RESET : Hard reset of the device
* PCAP01_IN_RESET : Software reset
* PCAP01_START : Start measurement
* PCAP01_START : Start measurement
* PCAP01_TERM : Stop measurement
*/ */
void pcap01_periodic(void) void pcap01_periodic(void)
{ {
+57 -24
View File
@@ -42,16 +42,16 @@
#ifndef AIRSPEED_AMSYS_SCALE #ifndef AIRSPEED_AMSYS_SCALE
#define AIRSPEED_AMSYS_SCALE 1 #define AIRSPEED_AMSYS_SCALE 1
#endif #endif
#ifndef AIRSPEED_AMSYS_OFFSET
#define AIRSPEED_AMSYS_OFFSET 0
#endif
#define AIRSPEED_AMSYS_OFFSET_MAX 29491 #define AIRSPEED_AMSYS_OFFSET_MAX 29491
#define AIRSPEED_AMSYS_OFFSET_MIN 3277 #define AIRSPEED_AMSYS_OFFSET_MIN 3277
#define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_INIT 40 #define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_INIT 40
#define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_AVRG 60 #define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_AVRG 60
#define AIRSPEED_AMSYS_NBSAMPLES_AVRG 10 #define AIRSPEED_AMSYS_NBSAMPLES_AVRG 10
#ifndef AIRSPEED_AMSYS_MAXPRESURE #ifndef AIRSPEED_AMSYS_MAXPRESURE
#define AIRSPEED_AMSYS_MAXPRESURE 2068//2073 //Pascal #define AIRSPEED_AMSYS_MAXPRESURE 2068 //003-2068, 001-689 //Pascal
#endif
#ifndef AIRSPEED_AMSYS_FILTER
#define AIRSPEED_AMSYS_FILTER 0
#endif #endif
#ifndef AIRSPEED_AMSYS_I2C_DEV #ifndef AIRSPEED_AMSYS_I2C_DEV
#define AIRSPEED_AMSYS_I2C_DEV i2c0 #define AIRSPEED_AMSYS_I2C_DEV i2c0
@@ -68,8 +68,9 @@
uint16_t airspeed_amsys_raw; uint16_t airspeed_amsys_raw;
uint16_t tempAS_amsys_raw; uint16_t tempAS_amsys_raw;
bool_t airspeed_amsys_valid; bool_t airspeed_amsys_valid;
float airspeed_tmp; float airspeed_amsys_offset;
float pressure_amsys; //Pascal float airspeed_amsys_tmp;
float airspeed_amsys_p; //Pascal
float airspeed_amsys; //mps float airspeed_amsys; //mps
float airspeed_scale; float airspeed_scale;
float airspeed_filter; float airspeed_filter;
@@ -79,17 +80,23 @@ struct i2c_transaction airspeed_amsys_i2c_trans;
volatile bool_t airspeed_amsys_i2c_done; volatile bool_t airspeed_amsys_i2c_done;
float airspeed_temperature = 0.0; float airspeed_temperature = 0.0;
float airspeed_old = 0.0; float airspeed_old = 0.0;
bool_t airspeed_amsys_offset_init;
double airspeed_amsys_offset_tmp;
uint16_t airspeed_amsys_cnt;
void airspeed_amsys_init( void ) { void airspeed_amsys_init( void ) {
airspeed_amsys_raw = 0; airspeed_amsys_raw = 0;
airspeed_amsys = 0.0; airspeed_amsys = 0.0;
pressure_amsys = 0.0; airspeed_amsys_p = 0.0;
airspeed_amsys_offset = 0;
airspeed_amsys_offset_tmp = 0;
airspeed_amsys_i2c_done = TRUE; airspeed_amsys_i2c_done = TRUE;
airspeed_amsys_valid = TRUE; airspeed_amsys_valid = TRUE;
airspeed_scale = AIRSPEED_SCALE; airspeed_amsys_offset_init = FALSE;
airspeed_filter = AIRSPEED_FILTER; airspeed_scale = AIRSPEED_AMSYS_SCALE;
airspeed_filter = AIRSPEED_AMSYS_FILTER;
airspeed_amsys_i2c_trans.status = I2CTransDone; airspeed_amsys_i2c_trans.status = I2CTransDone;
airspeed_amsys_cnt = AIRSPEED_AMSYS_OFFSET_NBSAMPLES_INIT + AIRSPEED_AMSYS_OFFSET_NBSAMPLES_AVRG;
} }
void airspeed_amsys_read_periodic( void ) { void airspeed_amsys_read_periodic( void ) {
@@ -101,10 +108,21 @@ void airspeed_amsys_read_periodic( void ) {
i2c_receive(&AIRSPEED_AMSYS_I2C_DEV, &airspeed_amsys_i2c_trans, AIRSPEED_AMSYS_ADDR, 4); i2c_receive(&AIRSPEED_AMSYS_I2C_DEV, &airspeed_amsys_i2c_trans, AIRSPEED_AMSYS_ADDR, 4);
#endif #endif
#if USE_AIRSPEED
stateSetAirspeed_f(&airspeed_amsys);
#endif
#else // SITL #else // SITL
extern float sim_air_speed; extern float sim_air_speed;
stateSetAirspeed_f(&sim_air_speed); stateSetAirspeed_f(&sim_air_speed);
#endif //SITL #endif //SITL
#ifdef AIRSPEED_AMSYS_SYNC_SEND
DOWNLINK_SEND_AMSYS_AIRSPEED(DefaultChannel, DefaultDevice, &airspeed_amsys_raw, &airspeed_amsys_p, &airspeed_amsys_tmp, &airspeed_amsys, &airspeed_amsys_offset);
#else
RunOnceEvery(10, DOWNLINK_SEND_AMSYS_AIRSPEED(DefaultChannel, DefaultDevice, &airspeed_amsys_raw, &airspeed_amsys_p, &airspeed_amsys_tmp, &airspeed_amsys, &airspeed_temperature));
#endif
} }
void airspeed_amsys_read_event( void ) { void airspeed_amsys_read_event( void ) {
@@ -134,23 +152,38 @@ void airspeed_amsys_read_event( void ) {
airspeed_amsys_raw = AIRSPEED_AMSYS_OFFSET_MAX; airspeed_amsys_raw = AIRSPEED_AMSYS_OFFSET_MAX;
// calculate raw to pressure // calculate raw to pressure
pressure_amsys = (float)(airspeed_amsys_raw-AIRSPEED_AMSYS_OFFSET_MIN)*AIRSPEED_AMSYS_MAXPRESURE/(float)(AIRSPEED_AMSYS_OFFSET_MAX-AIRSPEED_AMSYS_OFFSET_MIN); airspeed_amsys_p = (float)(airspeed_amsys_raw-AIRSPEED_AMSYS_OFFSET_MIN)*AIRSPEED_AMSYS_MAXPRESURE/(float)(AIRSPEED_AMSYS_OFFSET_MAX-AIRSPEED_AMSYS_OFFSET_MIN);
if (!airspeed_amsys_offset_init) {
--airspeed_amsys_cnt;
// Check if averaging completed
if (airspeed_amsys_cnt == 0) {
// Calculate average
airspeed_amsys_offset = (float)(airspeed_amsys_offset_tmp / AIRSPEED_AMSYS_OFFSET_NBSAMPLES_AVRG);
airspeed_amsys_offset_init = TRUE;
}
// Check if averaging needs to continue
else if (airspeed_amsys_cnt <= AIRSPEED_AMSYS_OFFSET_NBSAMPLES_AVRG)
airspeed_amsys_offset_tmp += airspeed_amsys_p;
airspeed_amsys = 0.;
}
else {
airspeed_amsys_p = airspeed_amsys_p - airspeed_amsys_offset;
if (airspeed_amsys_p <= 0) airspeed_amsys_p=0.000000001;
airspeed_amsys_tmp = sqrtf(2*(airspeed_amsys_p)*airspeed_scale/1.2041); // convert pressure to airspeed
// Lowpassfiltering
airspeed_amsys = airspeed_filter * airspeed_old + (1 - airspeed_filter) * airspeed_amsys_tmp;
airspeed_old = airspeed_amsys;
//New value available
}
} /*else {
airspeed_amsys = 0.0;
}*/
airspeed_tmp = sqrtf(2*(pressure_amsys)*airspeed_scale/1.2041); //without offset
// Lowpass filter
airspeed_amsys = airspeed_filter * airspeed_old + (1 - airspeed_filter) * airspeed_tmp;
airspeed_old = airspeed_amsys;
#if USE_AIRSPEED
stateSetAirspeed_f(&airspeed_amsys);
#endif
#ifdef SENSOR_SYNC_SEND
DOWNLINK_SEND_AMSYS_AIRSPEED(DefaultChannel, DefaultDevice, &airspeed_amsys_raw, &pressure_amsys, &airspeed_tmp, &airspeed_amsys, &airspeed_temperature);
#else
RunOnceEvery(10, DOWNLINK_SEND_AMSYS_AIRSPEED(DefaultChannel, DefaultDevice, &airspeed_amsys_raw, &pressure_amsys, &airspeed_tmp, &airspeed_amsys, &airspeed_temperature));
#endif
}
// Transaction has been read // Transaction has been read
airspeed_amsys_i2c_trans.status = I2CTransDone; airspeed_amsys_i2c_trans.status = I2CTransDone;
+3 -2
View File
@@ -20,8 +20,9 @@
* *
*/ */
/** \file met_ap_otf.c /**
* \brief UART interface for Aeroprobe On-The-Fly! air data computer * @file modules/sensors/airspeed_otf.c
* UART interface for Aeroprobe On-The-Fly! air data computer.
* *
*/ */
-1
View File
@@ -33,7 +33,6 @@
extern uint16_t baro_amsys_adc; extern uint16_t baro_amsys_adc;
// extern float baro_amsys_offset; // extern float baro_amsys_offset;
extern bool_t baro_amsys_valid; extern bool_t baro_amsys_valid;
// extern bool_t baro_amsys_updated;
// extern bool_t baro_amsys_enabled; // extern bool_t baro_amsys_enabled;
extern float baro_amsys_altitude; extern float baro_amsys_altitude;
// extern float baro_amsys_r; // extern float baro_amsys_r;
-1
View File
@@ -50,7 +50,6 @@
extern uint16_t baro_ets_adc; extern uint16_t baro_ets_adc;
extern uint16_t baro_ets_offset; extern uint16_t baro_ets_offset;
extern bool_t baro_ets_valid; extern bool_t baro_ets_valid;
extern bool_t baro_ets_updated;
extern bool_t baro_ets_enabled; extern bool_t baro_ets_enabled;
extern float baro_ets_altitude; extern float baro_ets_altitude;
extern float baro_ets_r; extern float baro_ets_r;
@@ -20,8 +20,9 @@
* *
*/ */
/** \file baro_ms5611_i2c.c /**
* \brief Measurement Specialties (Intersema) MS5611-01BA pressure/temperature sensor interface for I2C * @file modules/sensors/baro_ms5611_i2c.c
* Measurement Specialties (Intersema) MS5611-01BA pressure/temperature sensor interface for I2C.
* *
*/ */
+31 -5
View File
@@ -31,18 +31,38 @@
void mpu60x0_set_default_config(struct Mpu60x0Config *c) void mpu60x0_set_default_config(struct Mpu60x0Config *c)
{ {
c->clk_sel = MPU60X0_DEFAULT_CLK_SEL;
c->smplrt_div = MPU60X0_DEFAULT_SMPLRT_DIV; c->smplrt_div = MPU60X0_DEFAULT_SMPLRT_DIV;
c->dlpf_cfg = MPU60X0_DEFAULT_DLPF_CFG; c->dlpf_cfg = MPU60X0_DEFAULT_DLPF_CFG;
c->gyro_range = MPU60X0_DEFAULT_FS_SEL; c->gyro_range = MPU60X0_DEFAULT_FS_SEL;
c->accel_range = MPU60X0_DEFAULT_AFS_SEL; c->accel_range = MPU60X0_DEFAULT_AFS_SEL;
c->i2c_bypass = TRUE;
c->drdy_int_enable = FALSE; c->drdy_int_enable = FALSE;
c->clk_sel = MPU60X0_DEFAULT_CLK_SEL;
/* Number of bytes to read starting with MPU60X0_REG_INT_STATUS
* By default read only gyro and accel data -> 15 bytes.
* Increase to include slave data.
*/
c->nb_bytes = 15;
c->nb_slaves = 0;
c->i2c_bypass = FALSE;
} }
void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void* mpu, struct Mpu60x0Config* config) void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void* mpu, struct Mpu60x0Config* config)
{ {
switch (config->init_status) { switch (config->init_status) {
case MPU60X0_CONF_RESET:
/* device reset, set register values to defaults */
mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, (1<<6));
config->init_status++;
break;
case MPU60X0_CONF_USER_RESET:
/* trigger FIFO, I2C_MST and SIG_COND resets */
mpu_set(mpu, MPU60X0_REG_USER_CTRL, ((1 << MPU60X0_FIFO_RESET) |
(1 << MPU60X0_I2C_MST_RESET) |
(1 << MPU60X0_SIG_COND_RESET)));
config->init_status++;
break;
case MPU60X0_CONF_PWR: case MPU60X0_CONF_PWR:
/* switch to gyroX clock by default */ /* switch to gyroX clock by default */
mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, ((config->clk_sel)|(0<<6))); mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, ((config->clk_sel)|(0<<6)));
@@ -68,9 +88,15 @@ void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void* mpu, struct Mpu60x0Conf
mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG, (config->accel_range<<3)); mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG, (config->accel_range<<3));
config->init_status++; config->init_status++;
break; break;
case MPU60X0_CONF_I2C_BYPASS: case MPU60X0_CONF_I2C_SLAVES:
mpu_set(mpu, MPU60X0_REG_INT_PIN_CFG, (config->i2c_bypass<<1)); /* if any, set MPU for I2C slaves and configure them*/
config->init_status++; if (config->nb_slaves > 0) {
/* returns TRUE when all slaves are configured */
if (mpu60x0_configure_i2c_slaves(mpu_set, mpu))
config->init_status++;
}
else
config->init_status++;
break; break;
case MPU60X0_CONF_INT_ENABLE: case MPU60X0_CONF_INT_ENABLE:
/* configure data ready interrupt */ /* configure data ready interrupt */
+33 -5
View File
@@ -48,34 +48,62 @@
enum Mpu60x0ConfStatus { enum Mpu60x0ConfStatus {
MPU60X0_CONF_UNINIT, MPU60X0_CONF_UNINIT,
MPU60X0_CONF_RESET,
MPU60X0_CONF_USER_RESET,
MPU60X0_CONF_PWR, MPU60X0_CONF_PWR,
MPU60X0_CONF_SD, MPU60X0_CONF_SD,
MPU60X0_CONF_DLPF, MPU60X0_CONF_DLPF,
MPU60X0_CONF_GYRO, MPU60X0_CONF_GYRO,
MPU60X0_CONF_ACCEL, MPU60X0_CONF_ACCEL,
MPU60X0_CONF_I2C_BYPASS, MPU60X0_CONF_I2C_SLAVES,
MPU60X0_CONF_INT_ENABLE, MPU60X0_CONF_INT_ENABLE,
MPU60X0_CONF_DONE MPU60X0_CONF_DONE
}; };
/// Configuration function prototype
typedef void (*Mpu60x0ConfigSet)(void* mpu, uint8_t _reg, uint8_t _val);
/// function prototype for configuration of a single I2C slave
typedef bool_t (*Mpu60x0I2cSlaveConfigure)(Mpu60x0ConfigSet mpu_set, void* mpu);
struct Mpu60x0I2cSlave {
Mpu60x0I2cSlaveConfigure configure;
};
struct Mpu60x0Config { struct Mpu60x0Config {
uint8_t smplrt_div; ///< Sample rate divider uint8_t smplrt_div; ///< Sample rate divider
enum Mpu60x0DLPF dlpf_cfg; ///< Digital Low Pass Filter enum Mpu60x0DLPF dlpf_cfg; ///< Digital Low Pass Filter
enum Mpu60x0GyroRanges gyro_range; ///< deg/s Range enum Mpu60x0GyroRanges gyro_range; ///< deg/s Range
enum Mpu60x0AccelRanges accel_range; ///< g Range enum Mpu60x0AccelRanges accel_range; ///< g Range
bool_t i2c_bypass; ///< bypass mpu i2c
bool_t drdy_int_enable; ///< Enable Data Ready Interrupt bool_t drdy_int_enable; ///< Enable Data Ready Interrupt
uint8_t clk_sel; ///< Clock select uint8_t clk_sel; ///< Clock select
uint8_t nb_bytes; ///< number of bytes to read starting with MPU60X0_REG_INT_STATUS
enum Mpu60x0ConfStatus init_status; ///< init status enum Mpu60x0ConfStatus init_status; ///< init status
bool_t initialized; ///< config done flag bool_t initialized; ///< config done flag
/** Bypass MPU I2C.
* Only effective if using the I2C implementation.
*/
bool_t i2c_bypass;
uint8_t nb_slaves; ///< number of used I2C slaves
struct Mpu60x0I2cSlave slaves[5]; ///< I2C slaves
enum Mpu60x0MstClk i2c_mst_clk; ///< MPU I2C master clock speed
uint8_t i2c_mst_delay; ///< MPU I2C slaves delayed sample rate
}; };
extern void mpu60x0_set_default_config(struct Mpu60x0Config *c); extern void mpu60x0_set_default_config(struct Mpu60x0Config *c);
/// Configuration function prototype
typedef void (*Mpu60x0ConfigSet)(void* mpu, uint8_t _reg, uint8_t _val);
/// Configuration sequence called once before normal use /// Configuration sequence called once before normal use
extern void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void* mpu, struct Mpu60x0Config* config); extern void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void* mpu, struct Mpu60x0Config* config);
/**
* Configure I2C slaves of the MPU.
* This is I2C/SPI implementation specific.
* @param mpu_set configuration function
* @param mpu Mpu60x0Spi or Mpu60x0I2c peripheral
* @return TRUE when all slaves are configured
*/
extern bool_t mpu60x0_configure_i2c_slaves(Mpu60x0ConfigSet mpu_set, void* mpu);
#endif // MPU60X0_H #endif // MPU60X0_H
+80 -10
View File
@@ -44,6 +44,8 @@ void mpu60x0_i2c_init(struct Mpu60x0_I2c *mpu, struct i2c_periph *i2c_p, uint8_t
mpu->data_available = FALSE; mpu->data_available = FALSE;
mpu->config.initialized = FALSE; mpu->config.initialized = FALSE;
mpu->config.init_status = MPU60X0_CONF_UNINIT; mpu->config.init_status = MPU60X0_CONF_UNINIT;
mpu->slave_init_status = MPU60X0_I2C_CONF_UNINIT;
} }
@@ -70,7 +72,7 @@ void mpu60x0_i2c_read(struct Mpu60x0_I2c *mpu)
if (mpu->config.initialized && mpu->i2c_trans.status == I2CTransDone) { if (mpu->config.initialized && mpu->i2c_trans.status == I2CTransDone) {
/* set read bit and multiple byte bit, then address */ /* set read bit and multiple byte bit, then address */
mpu->i2c_trans.buf[0] = MPU60X0_REG_INT_STATUS; mpu->i2c_trans.buf[0] = MPU60X0_REG_INT_STATUS;
i2c_transceive(mpu->i2c_p, &(mpu->i2c_trans), mpu->i2c_trans.slave_addr, 1, 15); i2c_transceive(mpu->i2c_p, &(mpu->i2c_trans), mpu->i2c_trans.slave_addr, 1, mpu->config.nb_bytes);
} }
} }
@@ -84,14 +86,19 @@ void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
} }
else if (mpu->i2c_trans.status == I2CTransSuccess) { else if (mpu->i2c_trans.status == I2CTransSuccess) {
// Successfull reading // Successfull reading
if (bit_is_set(mpu->i2c_trans.buf[0],0)) { if (bit_is_set(mpu->i2c_trans.buf[0], 0)) {
// new data // new data
mpu->data_accel.vect.x = Int16FromBuf(mpu->i2c_trans.buf,1); mpu->data_accel.vect.x = Int16FromBuf(mpu->i2c_trans.buf, 1);
mpu->data_accel.vect.y = Int16FromBuf(mpu->i2c_trans.buf,3); mpu->data_accel.vect.y = Int16FromBuf(mpu->i2c_trans.buf, 3);
mpu->data_accel.vect.z = Int16FromBuf(mpu->i2c_trans.buf,5); mpu->data_accel.vect.z = Int16FromBuf(mpu->i2c_trans.buf, 5);
mpu->data_rates.rates.p = Int16FromBuf(mpu->i2c_trans.buf,9); mpu->data_rates.rates.p = Int16FromBuf(mpu->i2c_trans.buf, 9);
mpu->data_rates.rates.q = Int16FromBuf(mpu->i2c_trans.buf,11); mpu->data_rates.rates.q = Int16FromBuf(mpu->i2c_trans.buf, 11);
mpu->data_rates.rates.r = Int16FromBuf(mpu->i2c_trans.buf,13); mpu->data_rates.rates.r = Int16FromBuf(mpu->i2c_trans.buf, 13);
// if we are reading slaves through the mpu, copy the ext_sens_data
if ((mpu->config.i2c_bypass == FALSE) && (mpu->config.nb_slaves > 0))
memcpy(mpu->data_ext, (void *) &(mpu->i2c_trans.buf[15]), mpu->config.nb_bytes - 15);
mpu->data_available = TRUE; mpu->data_available = TRUE;
} }
mpu->i2c_trans.status = I2CTransDone; mpu->i2c_trans.status = I2CTransDone;
@@ -103,12 +110,75 @@ void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
mpu->config.init_status--; // Retry config (TODO max retry) mpu->config.init_status--; // Retry config (TODO max retry)
case I2CTransSuccess: case I2CTransSuccess:
case I2CTransDone: case I2CTransDone:
mpu->i2c_trans.status = I2CTransDone;
mpu60x0_send_config(mpu60x0_i2c_write_to_reg, (void*)mpu, &(mpu->config)); mpu60x0_send_config(mpu60x0_i2c_write_to_reg, (void*)mpu, &(mpu->config));
if (mpu->config.initialized) mpu->i2c_trans.status = I2CTransDone; if (mpu->config.initialized)
mpu->i2c_trans.status = I2CTransDone;
break; break;
default: default:
break; break;
} }
} }
} }
/** @todo: only one slave so far. */
bool_t mpu60x0_configure_i2c_slaves(Mpu60x0ConfigSet mpu_set, void* mpu)
{
struct Mpu60x0_I2c* mpu_i2c = (struct Mpu60x0_I2c*)(mpu);
if (mpu_i2c->slave_init_status == MPU60X0_I2C_CONF_UNINIT)
mpu_i2c->slave_init_status++;
switch (mpu_i2c->slave_init_status) {
case MPU60X0_I2C_CONF_I2C_MST_DIS:
mpu_set(mpu, MPU60X0_REG_USER_CTRL, 0);
mpu_i2c->slave_init_status++;
break;
case MPU60X0_I2C_CONF_I2C_BYPASS_EN:
/* switch to I2C passthrough */
mpu_set(mpu, MPU60X0_REG_INT_PIN_CFG, (1<<1));
mpu_i2c->slave_init_status++;
break;
case MPU60X0_I2C_CONF_SLAVES_CONFIGURE:
/* configure each slave. TODO: currently only one */
if (mpu_i2c->config.slaves[0].configure(mpu_set, mpu))
mpu_i2c->slave_init_status++;
break;
case MPU60X0_I2C_CONF_I2C_BYPASS_DIS:
if (mpu_i2c->config.i2c_bypass) {
/* if bypassing I2C skip MPU I2C master setup */
mpu_i2c->slave_init_status = MPU60X0_I2C_CONF_DONE;
}
else {
/* disable I2C passthrough again */
mpu_set(mpu, MPU60X0_REG_INT_PIN_CFG, (0<<1));
mpu_i2c->slave_init_status++;
}
break;
case MPU60X0_I2C_CONF_I2C_MST_CLK:
/* configure MPU I2C master clock and stop/start between slave reads */
mpu_set(mpu, MPU60X0_REG_I2C_MST_CTRL,
((1<<4) | mpu_i2c->config.i2c_mst_clk));
mpu_i2c->slave_init_status++;
break;
case MPU60X0_I2C_CONF_I2C_MST_DELAY:
/* Set I2C slaves delayed sample rate */
mpu_set(mpu, MPU60X0_REG_I2C_MST_DELAY, mpu_i2c->config.i2c_mst_delay);
mpu_i2c->slave_init_status++;
break;
case MPU60X0_I2C_CONF_I2C_SMPLRT:
/* I2C slave0 sample rate/2 = 100/2 = 50Hz */
mpu_set(mpu, MPU60X0_REG_I2C_SLV4_CTRL, 0);
mpu_i2c->slave_init_status++;
break;
case MPU60X0_I2C_CONF_I2C_MST_EN:
/* enable internal I2C master */
mpu_set(mpu, MPU60X0_REG_USER_CTRL, (1 << MPU60X0_I2C_MST_EN));
mpu_i2c->slave_init_status++;
break;
case MPU60X0_I2C_CONF_DONE:
return TRUE;
default:
break;
}
return FALSE;
}

Some files were not shown because too many files have changed in this diff Show More