mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-28 09:58:23 +08:00
added module to measure and report digi xtend rssi, based on pwm_input driver for lpc21xx
This commit is contained in:
+5
-1
@@ -546,7 +546,11 @@
|
||||
<field name="AOA" type="float" unit="rad"></field>
|
||||
</message>
|
||||
|
||||
<!-- 70 is free -->
|
||||
<message name="XTEND_RSSI" id="70">
|
||||
<field name="datalink_time" type="uint16" unit="s"/>
|
||||
<field name="rssi_fade_margin" type="uint8" unit="dB"/>
|
||||
<field name="duty" type="uint8" unit="%"/>
|
||||
</message>
|
||||
<!-- 71 is free -->
|
||||
<!-- 72 is free -->
|
||||
<!-- 73 is free -->
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
<!--
|
||||
To enable each pwm measurement input, one must define
|
||||
USE_PWM_INPUTx where x is the channel(s) to use.
|
||||
For the lpc21xx, there are 4 channels:
|
||||
USE_PWM_INPUT1 on P0.29 (TWOG ADC_5)
|
||||
USE_PWM_INPUT2 on P0.30 (TWOG ADC_4)
|
||||
USE_PWM_INPUT3 on P0.27 (Not Available?)
|
||||
USE_PWM_INPUT4 on P0.28 (TWOG ADC_6)
|
||||
-->
|
||||
<module name="pwm_measure" dir="core">
|
||||
<header>
|
||||
<file name="pwm_measure.h"/>
|
||||
</header>
|
||||
<init fun="pwm_measure_init()"/>
|
||||
<makefile>
|
||||
<file_arch name="pwm_measure_hw.c"/>
|
||||
<file name="pwm_measure.c"/>
|
||||
<define name="USE_PWM_INPUT"/> <!-- required to enable pwm_input driver on lpc21 arch -->
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
<!-- Currently only available on LPC21xx arch
|
||||
Need to also load/use the pwm_measure.xml module
|
||||
Possible rssi pwm input pin values for TWOG:
|
||||
<define name="PWM_MEAS_ON_TWOG_ADC5"/> (P0.29)
|
||||
<define name="PWM_MEAS_ON_TWOG_ADC4"/> (P0.30)
|
||||
<define name="PWM_MEAS_ON_TWOG_ADC6"/> (P0.28)
|
||||
-->
|
||||
<module name="xtend_rssi" dir="datalink">
|
||||
<depend require="pwm_measure.xml"/>
|
||||
<header>
|
||||
<file name="xtend_rssi.h"/>
|
||||
</header>
|
||||
<periodic fun="xtend_rssi_periodic()" freq="2"/>
|
||||
<makefile>
|
||||
<file name="xtend_rssi.c"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2011 Stephen Dwyer, based on trigger_ext_hw by Martin Mueller
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "core/pwm_measure_hw.h"
|
||||
#include "pwm_input.h" //get the pwm_input drivers
|
||||
#include "std.h"
|
||||
#include "sys_time_hw.h"
|
||||
#include "LPC21xx.h"
|
||||
#include BOARD_CONFIG
|
||||
|
||||
|
||||
void pwm_measure_init ( void ) {
|
||||
|
||||
//Assign the arch indep array as alias of arch dep array, links arch indep to arch dep parts of code
|
||||
pwm_meas_duty_tics = pwm_input_duration;
|
||||
pwm_meas_duty_valid = pwm_input_valid;
|
||||
|
||||
//Use the pwm_input.* hardware dependent for lpc2148, this will change for each arch
|
||||
pwm_input_init();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2011 Stephen Dwyer, based on trigger_ext_hw by Martin Mueller
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PWM_MEASURE_HW_H
|
||||
#define PWM_MEAUSURE_HW_H
|
||||
|
||||
#include "core/pwm_measure.h"
|
||||
|
||||
#endif /* PWM_MEASURE_HW_H */
|
||||
|
||||
@@ -38,25 +38,32 @@ volatile uint8_t pwm_input_valid[PWM_INPUT_NB];
|
||||
|
||||
void pwm_input_init ( void )
|
||||
{
|
||||
// initialize the arrays to 0 to avoid junk
|
||||
int i = 0;
|
||||
for (int i; i < PWM_INPUT_NUM; i++)
|
||||
{
|
||||
pwm_input_duration[i] = 0;
|
||||
pwm_input_valid[i] = 0;
|
||||
}
|
||||
/* select pin for capture */
|
||||
#ifdef USE_PWM_INPUT1
|
||||
PWM_INPUT1_PINSEL = (PWM_INPUT1_PINSEL & ~PWM_INPUT1_PINSEL_MASK) | PWM_INPUT1_PINSEL_VAL;
|
||||
/* enable capture 0.3 on falling edge + trigger interrupt */
|
||||
/* enable capture 0.3 on rising edge + trigger interrupt */
|
||||
T0CCR |= TCCR_CR3_R | TCCR_CR3_I;
|
||||
#endif
|
||||
#ifdef USE_PWM_INPUT2
|
||||
PWM_INPUT2_PINSEL = (PWM_INPUT2_PINSEL & ~PWM_INPUT2_PINSEL_MASK) | PWM_INPUT2_PINSEL_VAL;
|
||||
/* enable capture 0.0 on falling edge + trigger interrupt */
|
||||
/* enable capture 0.0 on rising edge + trigger interrupt */
|
||||
T0CCR |= TCCR_CR0_R | TCCR_CR0_I;
|
||||
#endif
|
||||
#ifdef USE_PWM_INPUT3
|
||||
PWM_INPUT3_PINSEL = (PWM_INPUT3_PINSEL & ~PWM_INPUT3_PINSEL_MASK) | PWM_INPUT3_PINSEL_VAL;
|
||||
/* enable capture 0.1 on falling edge + trigger interrupt */
|
||||
/* enable capture 0.1 on rising edge + trigger interrupt */
|
||||
T0CCR |= TCCR_CR1_R | TCCR_CR1_I;
|
||||
#endif
|
||||
#ifdef USE_PWM_INPUT4
|
||||
PWM_INPUT4_PINSEL = (PWM_INPUT4_PINSEL & ~PWM_INPUT4_PINSEL_MASK) | PWM_INPUT4_PINSEL_VAL;
|
||||
/* enable capture 0.2 on falling edge + trigger interrupt */
|
||||
/* enable capture 0.2 on rising edge + trigger interrupt */
|
||||
T0CCR |= TCCR_CR2_R | TCCR_CR2_I;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#define PWM_INPUT_NB 4
|
||||
|
||||
|
||||
|
||||
void pwm_input_init ( void );
|
||||
|
||||
/* tracks of length of positive pulse duration */
|
||||
@@ -22,12 +24,19 @@ static inline void pwm_input_isr1()
|
||||
t_fall = T0CR3;
|
||||
T0CCR |= TCCR_CR3_R;
|
||||
T0CCR &= ~TCCR_CR3_F;
|
||||
#if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
#else
|
||||
pwm_input_duration[0] = t_fall - t_rise;
|
||||
pwm_input_valid[0] = TRUE;
|
||||
#endif //ACTIVE_HIGH
|
||||
} else if (T0CCR & TCCR_CR3_R) {
|
||||
t_rise = T0CR3;
|
||||
T0CCR |= TCCR_CR3_F;
|
||||
T0CCR &= ~TCCR_CR3_R;
|
||||
#if USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
pwm_input_duration[0] = t_rise - t_fall;
|
||||
pwm_input_valid[0] = TRUE;
|
||||
#endif //ACTIVE_LOW
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +49,19 @@ static inline void pwm_input_isr2()
|
||||
t_fall = T0CR0;
|
||||
T0CCR |= TCCR_CR0_R;
|
||||
T0CCR &= ~TCCR_CR0_F;
|
||||
#if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
#else
|
||||
pwm_input_duration[1] = t_fall - t_rise;
|
||||
pwm_input_valid[1] = TRUE;
|
||||
#endif //ACTIVE_HIGH
|
||||
} else if (T0CCR & TCCR_CR0_R) {
|
||||
t_rise = T0CR0;
|
||||
T0CCR |= TCCR_CR0_F;
|
||||
T0CCR &= ~TCCR_CR0_R;
|
||||
#if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
pwm_input_duration[1] = t_rise - t_fall;
|
||||
pwm_input_valid[1] = TRUE;
|
||||
#endif //ACTIVE_LOW
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,12 +74,19 @@ static inline void pwm_input_isr3()
|
||||
t_fall = T0CR1;
|
||||
T0CCR |= TCCR_CR1_R;
|
||||
T0CCR &= ~TCCR_CR1_F;
|
||||
#if USE_PWM_INPUT3 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
#else
|
||||
pwm_input_duration[2] = t_fall - t_rise;
|
||||
pwm_input_valid[2] = TRUE;
|
||||
#endif //ACTIVE_HIGH
|
||||
} else if (T0CCR & TCCR_CR1_R) {
|
||||
t_rise = T0CR1;
|
||||
T0CCR |= TCCR_CR1_F;
|
||||
T0CCR &= ~TCCR_CR1_R;
|
||||
#if USE_PWM_INPUT3 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
pwm_input_duration[2] = t_rise - t_fall;
|
||||
pwm_input_valid[2] = TRUE;
|
||||
#endif //ACTIVE_LOW
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,12 +99,19 @@ static inline void pwm_input_isr4()
|
||||
t_fall = T0CR2;
|
||||
T0CCR |= TCCR_CR2_R;
|
||||
T0CCR &= ~TCCR_CR2_F;
|
||||
#if USE_PWM_INPUT4 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
#else
|
||||
pwm_input_duration[3] = t_fall - t_rise;
|
||||
pwm_input_valid[3] = TRUE;
|
||||
#endif //ACTIVE_HIGH
|
||||
} else if (T0CCR & TCCR_CR2_R) {
|
||||
t_rise = T0CR2;
|
||||
T0CCR |= TCCR_CR2_F;
|
||||
T0CCR &= ~TCCR_CR2_R;
|
||||
#if USE_PWM_INPUT4 == PWM_PULSE_TYPE_ACTIVE_LOW
|
||||
pwm_input_duration[3] = t_rise - t_fall;
|
||||
pwm_input_valid[3] = TRUE;
|
||||
#endif //ACTIVE_LOW
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2011 Stephen Dwyer, based on trigger_ext by Martin Mueller
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file pwm_measure.c
|
||||
* \brief Measure external pwm pulse at a capture input
|
||||
*
|
||||
* This measures the duty active
|
||||
*/
|
||||
|
||||
|
||||
#include "core/pwm_measure.h"
|
||||
|
||||
volatile uint32_t *pwm_meas_duty_tics; // this is an alias for the hw dep array, array length linked to PWM_INPUT_NB
|
||||
volatile uint8_t *pwm_meas_duty_valid; // this is an alias for the hw dep array, array length linked to PWM_INPUT_NB
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2011 Stephen Dwyer, based on trigger_ext by Martin Mueller
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file pwm_measure.h
|
||||
* \brief Measure external pwm pulse at a capture input
|
||||
*
|
||||
* This measures the duty active
|
||||
*/
|
||||
|
||||
#ifndef PWM_MEASURE_H
|
||||
#define PWM_MEASURE_H
|
||||
|
||||
#include "std.h"
|
||||
|
||||
/**
|
||||
* active high starts period measure at rising edge, and vice versa
|
||||
*/
|
||||
#define PWM_PULSE_TYPE_ACTIVE_HIGH 0
|
||||
#define PWM_PULSE_TYPE_ACTIVE_LOW 1
|
||||
|
||||
extern volatile uint32_t *pwm_meas_duty_tics; // this is an alias for the hw dep array, array length linked to PWM_INPUT_NB
|
||||
extern volatile uint8_t *pwm_meas_duty_valid; // this is an alias for the hw dep array, array length linked to PWM_INPUT_NB
|
||||
|
||||
void pwm_measure_init ( void );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2010 2011 Stephen Dwyer, based on windturbine by Martin Mueller
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file xtend_rssi.c
|
||||
*
|
||||
* This measures the rssi pwm signal from a Digi XTend radio modem
|
||||
* and sends a message with the info.
|
||||
*/
|
||||
|
||||
|
||||
#include "datalink/xtend_rssi.h"
|
||||
#include "core/pwm_measure.h"
|
||||
#include "sys_time.h"
|
||||
|
||||
#ifndef DOWNLINK_DEVICE
|
||||
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
|
||||
#endif
|
||||
|
||||
#include "mcu_periph/uart.h"
|
||||
#include "messages.h"
|
||||
#include "downlink.h"
|
||||
|
||||
//from Digi XTend manual
|
||||
#define XTEND_RSSI_PWM_PERIOD_ST (uint32_t)(8320 * (PCLK/1000000) / T0_PCLK_DIV + 0.5) //rssi pwm period in sys tics
|
||||
|
||||
//architecture dependent pin assignment, update for new architectures? move to arch files?
|
||||
#ifdef PWM_MEAS_ON_TWOG_ADC5
|
||||
#define PWM_MEAS_XTEND_RSSI_INDEX 0
|
||||
#define USE_PWM_INPUT1
|
||||
#elif PWM_MEAS_ON_TWOG_ADC4
|
||||
#define PWM_MEAS_XTEND_RSSI_INDEX 1
|
||||
#define USE_PWM_INPUT2
|
||||
#elif PWM_MEAS_ON_TWOG_ADC6
|
||||
#define PWM_MEAS_XTEND_RSSI_INDEX 3
|
||||
#define USE_PWM_INPUT4
|
||||
#else
|
||||
#error "Invalid or missing pwm measurement input pin defined for xtend_rssi module"
|
||||
#endif
|
||||
|
||||
void xtend_rssi_periodic( void ) {
|
||||
|
||||
/* get the last duty if valid then reset valid flag (this says if we got another pulse since the last one)
|
||||
calculate the % and dB from the duty using datasheet specs
|
||||
send the %, dB, datalink time
|
||||
*/
|
||||
|
||||
uint32_t duty_tics = pwm_meas_duty_tics[PWM_MEAS_XTEND_RSSI_INDEX];
|
||||
uint8_t duty_percent = 0;
|
||||
uint8_t rssi_dB_fade_margin = 0; //shows dB fade margin above rated minimum sensitivity
|
||||
|
||||
if (pwm_meas_duty_valid[PWM_MEAS_XTEND_RSSI_INDEX])
|
||||
{
|
||||
duty_percent = (duty_tics * 100) / XTEND_RSSI_PWM_PERIOD_ST;
|
||||
rssi_dB_fade_margin = (2 * duty_percent + 10) / 3; //not sure if this is right, datasheet isn't very informative
|
||||
pwm_meas_duty_valid[PWM_MEAS_XTEND_RSSI_INDEX] = FALSE;
|
||||
}
|
||||
DOWNLINK_SEND_XTEND_RSSI(DefaultChannel,
|
||||
&datalink_time,
|
||||
&rssi_dB_fade_margin,
|
||||
&duty_percent );
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2011 Stephen Dwyer, based on windturbine by Martin Mueller
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file xtend_rssi.h
|
||||
*
|
||||
* This measures the rssi pwm signal from a Digi XTend radio modem
|
||||
* and sends a message with the info.
|
||||
*
|
||||
* Module pwm_measure needs to be loaded
|
||||
*/
|
||||
|
||||
#ifndef XTEND_RSSI_H
|
||||
#define XTEND_RSSI_H
|
||||
|
||||
void xtend_rssi_periodic( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user