Skip to content

Commit

Permalink
Merge pull request #88 from scdwyer/dev-xtend
Browse files Browse the repository at this point in the history
Added xtend_rssi module, pwm_meas and pwm_input mcu peripheral for lpc21xx arch
  • Loading branch information
flixr committed Nov 14, 2011
2 parents fa96ce7 + 17d1001 commit 01c5059
Show file tree
Hide file tree
Showing 14 changed files with 514 additions and 178 deletions.
6 changes: 5 additions & 1 deletion conf/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
19 changes: 19 additions & 0 deletions conf/modules/pwm_meas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE module SYSTEM "module.dtd">
<!-- Currently only available on LPC21xx arch
pwm input measurement mcu periph access and init wrapper for other modules
For LPC21xx on the TWOG:
1 - INPUT CAPTURE CAP0.3 on P0.29 (TWOG ADC5, 5V->3.3V voltage divider)
2 - INPUT CAPTURE CAP0.0 on P0.30 (TWOG ADC4, no voltage divider)
-->
<module name="pwm_meas" dir="core">
<header>
<file name="pwm_meas.h"/>
</header>
<init fun="pwm_meas_init()"/>
<makefile target="ap">
<file name="pwm_meas.c"/>
<file name="pwm_input.c" dir="mcu_periph"/>
<file_arch name="pwm_input_arch.c" dir="mcu_periph"/>
<define name="USE_PWM_INPUT"/> <!-- needed to enable the pwm_input interrupts in sys_time_hw.c -->
</makefile>
</module>
21 changes: 21 additions & 0 deletions conf/modules/xtend_rssi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE module SYSTEM "module.dtd">
<!-- Currently only available on LPC21xx arch
Digi Xtend RSSI PWM Module
@configure XTEND_RSSI_PWM_INPUT_CHANNEL on which arch dep input the pwm line is connected
For LPC21xx on the TWOG:
1 - INPUT CAPTURE CAP0.3 on P0.29 (TWOG ADC5, 5V->3.3V voltage divider)
2 - INPUT CAPTURE CAP0.0 on P0.30 (TWOG ADC4, no voltage divider)
-->
<module name="xtend_rssi" dir="datalink">
<depend require="pwm_meas.xml"/>
<header>
<file name="xtend_rssi.h"/>
</header>
<periodic fun="xtend_rssi_periodic()" freq="0.5"/>
<makefile target="ap">
<file name="xtend_rssi.c"/>
<define name="XTEND_RSSI_PWM_INPUT_CHANNEL" value="$(XTEND_RSSI_PWM_INPUT_CHANNEL)"/> <!-- configure the pwm input to be used in airframe file -->
<define name="USE_PWM_INPUT$(XTEND_RSSI_PWM_INPUT_CHANNEL)" value="PWM_PULSE_TYPE_ACTIVE_HIGH"/> <!-- rssi signal is active high -->
</makefile>
</module>

150 changes: 150 additions & 0 deletions sw/airborne/arch/lpc21/mcu_periph/pwm_input_arch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/* $Id$
*
* Copyright (C) 2011 The Paparazzi Team
*
* 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.
*
*/

/** \brief handling of arm7 PWM input using a timer with capture
*
*/

#include "mcu_periph/pwm_input_arch.h"

#include "LPC21xx.h"
#include "interrupt_hw.h"

//UPDATE THESE TO BE MORE ACCESSIBLE AND BE WARY OF EXISTING USAGE
//POSSIBLY MAKE MORE INPUTS ACCESSIBLE
#ifdef USE_PWM_INPUT1
//INPUT CAPTURE CAP0.3 on P0.29
#define PWM_INPUT1_PINSEL PINSEL1
#define PWM_INPUT1_PINSEL_BIT 26
#define PWM_INPUT1_PINSEL_VAL (0x2 << PWM_INPUT1_PINSEL_BIT)
#define PWM_INPUT1_PINSEL_MASK (0x3 <<PWM_INPUT1_PINSEL_BIT)
#endif
#ifdef USE_PWM_INPUT2
//INPUT CAPTURE CAP0.0 on P0.30
#define PWM_INPUT2_PINSEL PINSEL1
#define PWM_INPUT2_PINSEL_BIT 28
#define PWM_INPUT2_PINSEL_VAL (0x3 << PWM_INPUT2_PINSEL_BIT)
#define PWM_INPUT2_PINSEL_MASK (0x3 <<PWM_INPUT2_PINSEL_BIT)
#endif

void pwm_input_init ( void )
{
// initialize the arrays to 0 to avoid junk
for (int i=0; i < PWM_INPUT_NB; i++)
{
pwm_input_duty_tics[i] = 0;
pwm_input_duty_valid[i] = 0;
pwm_input_period_tics[i] = 0;
pwm_input_period_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 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 rising edge + trigger interrupt
T0CCR |= TCCR_CR0_R | TCCR_CR0_I;
#endif
}

//FIXME what about clock time overflow???
#ifdef USE_PWM_INPUT1
void pwm_input_isr1(void)
{
static uint32_t t_rise;
static uint32_t t_fall;
#if USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_HIGH
static uint32_t t_oldrise = 0;
#elif USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_LOW
static uint32_t t_oldfall = 0;
#endif

if (T0CCR & TCCR_CR3_F) {
t_fall = T0CR3;
T0CCR |= TCCR_CR3_R;
T0CCR &= ~TCCR_CR3_F;
#if USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_HIGH
pwm_input_duty_tics[0] = t_fall - t_rise;
pwm_input_duty_valid[0] = TRUE;
#elif USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_LOW
pwm_input_period_tics[0] = t_fall - t_oldfall;
pwm_input_period_valid[0] = TRUE;
t_oldfall = t_fall;
#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_duty_tics[0] = t_rise - t_fall;
pwm_input_duty_valid[0] = TRUE;
#elif USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_HIGH
pwm_input_period_tics[0] = t_rise - t_oldrise;
pwm_input_period_valid[0] = TRUE;
t_oldrise = t_rise;
#endif //ACTIVE_LOW
}
}
#endif //USE_PWM_INPUT1

#ifdef USE_PWM_INPUT2
void pwm_input_isr2(void)
{
static uint32_t t_rise;
static uint32_t t_fall;
#if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_HIGH
static uint32_t t_oldrise = 0;
#elif USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
static uint32_t t_oldfall = 0;
#endif

if (T0CCR & TCCR_CR0_F) {
t_fall = T0CR0;
T0CCR |= TCCR_CR0_R;
T0CCR &= ~TCCR_CR0_F;
#if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_HIGH
pwm_input_duty_tics[1] = t_fall - t_rise;
pwm_input_duty_valid[1] = TRUE;
#elif USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
pwm_input_period_tics[1] = t_fall - t_oldfall;
pwm_input_period_valid[1] = TRUE;
t_oldfall = t_fall;
#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_duty_tics[1] = t_rise - t_fall;
pwm_input_duty_valid[1] = TRUE;
#elif USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_HIGH
pwm_input_period_tics[1] = t_rise - t_oldrise;
pwm_input_period_valid[1] = TRUE;
t_oldrise = t_rise;
#endif //ACTIVE_LOW
}
}
#endif //USE_PWM_INPUT2
51 changes: 51 additions & 0 deletions sw/airborne/arch/lpc21/mcu_periph/pwm_input_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* $Id$
*
* Copyright (C) 2011 The Paparazzi Team
*
* 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.
*
*/

/** \brief handling of arm7 PWM input using a timer with capture
*
*/

#ifndef PWM_INPUT_ARCH_H
#define PWM_INPUT_ARCH_H

#include "std.h"
#include "LPC21xx.h"
#include "interrupt_hw.h"

#define PWM_INPUT_NB 2 //this is architecture dependent

#include "mcu_periph/pwm_input.h"

#ifdef USE_PWM_INPUT1
extern void pwm_input_isr1(void);
#define PWM_INPUT_IT1 TIR_CR3I
#define PWM_INPUT_ISR_1() pwm_input_isr1()
#endif //USE_PWM_INPUT1

#ifdef USE_PWM_INPUT2
extern void pwm_input_isr2(void);
#define PWM_INPUT_IT2 TIR_CR0I
#define PWM_INPUT_ISR_2() pwm_input_isr2()
#endif //USE_PWM_INPUT2

#endif /* PWM_INPUT_ARCH_H */
62 changes: 0 additions & 62 deletions sw/airborne/arch/lpc21/pwm_input.c

This file was deleted.

Loading

0 comments on commit 01c5059

Please sign in to comment.