[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paparazzi-commits] [4365] Update pwm_input to support Timer0 CR0 and CR
From: |
Allen Ibara |
Subject: |
[paparazzi-commits] [4365] Update pwm_input to support Timer0 CR0 and CR3 (to read two sensors) |
Date: |
Tue, 08 Dec 2009 07:08:20 +0000 |
Revision: 4365
http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=4365
Author: aibara
Date: 2009-12-08 07:08:19 +0000 (Tue, 08 Dec 2009)
Log Message:
-----------
Update pwm_input to support Timer0 CR0 and CR3 (to read two sensors)
Modified Paths:
--------------
paparazzi3/trunk/sw/airborne/arm7/pwm_input.c
paparazzi3/trunk/sw/airborne/arm7/pwm_input.h
paparazzi3/trunk/sw/airborne/arm7/sys_time_hw.c
Modified: paparazzi3/trunk/sw/airborne/arm7/pwm_input.c
===================================================================
--- paparazzi3/trunk/sw/airborne/arm7/pwm_input.c 2009-12-08 07:07:17 UTC
(rev 4364)
+++ paparazzi3/trunk/sw/airborne/arm7/pwm_input.c 2009-12-08 07:08:19 UTC
(rev 4365)
@@ -4,19 +4,35 @@
#include "interrupt_hw.h"
-volatile uint32_t pwm_input_duration;
-volatile uint8_t pwm_input_valid;
+volatile uint32_t pwm_input_duration[PWM_INPUT_NB];
+volatile uint8_t pwm_input_valid[PWM_INPUT_NB];
+#ifdef USE_PWM_INPUT1
/* INPUT CAPTURE CAP0.3 on P0.29 */
-#define PWM_INPUT_PINSEL PINSEL1
-#define PWM_INPUT_PINSEL_BIT 26
-#define PWM_INPUT_PINSEL_VAL (0x2 << PWM_INPUT_PINSEL_BIT)
-#define PWM_INPUT_PINSEL_MASK (0x3 <<PWM_INPUT_PINSEL_BIT)
+#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 )
{
/* select pin for capture */
- PWM_INPUT_PINSEL = (PWM_INPUT_PINSEL & ~PWM_INPUT_PINSEL_MASK) |
PWM_INPUT_PINSEL_VAL;
+#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 */
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 */
+ T0CCR |= TCCR_CR0_R | TCCR_CR0_I;
+#endif
}
Modified: paparazzi3/trunk/sw/airborne/arm7/pwm_input.h
===================================================================
--- paparazzi3/trunk/sw/airborne/arm7/pwm_input.h 2009-12-08 07:07:17 UTC
(rev 4364)
+++ paparazzi3/trunk/sw/airborne/arm7/pwm_input.h 2009-12-08 07:08:19 UTC
(rev 4365)
@@ -5,13 +5,15 @@
#include "LPC21xx.h"
#include "interrupt_hw.h"
+#define PWM_INPUT_NB 2
+
void pwm_input_init ( void );
/* tracks of length of positive pulse duration */
-extern volatile uint32_t pwm_input_duration;
-extern volatile uint8_t pwm_input_valid;
+extern volatile uint32_t pwm_input_duration[PWM_INPUT_NB];
+extern volatile uint8_t pwm_input_valid[PWM_INPUT_NB];
-static inline void pwm_input_isr()
+static inline void pwm_input_isr1()
{
static uint32_t t_rise;
static uint32_t t_fall;
@@ -20,16 +22,36 @@
t_fall = T0CR3;
T0CCR |= TCCR_CR3_R;
T0CCR &= ~TCCR_CR3_F;
- pwm_input_duration = t_fall - t_rise;
- pwm_input_valid = TRUE;
- } else {
+ pwm_input_duration[0] = t_fall - t_rise;
+ pwm_input_valid[0] = TRUE;
+ } else if (T0CCR & TCCR_CR3_R) {
t_rise = T0CR3;
T0CCR |= TCCR_CR3_F;
T0CCR &= ~TCCR_CR3_R;
}
}
-#define PWM_INPUT_IT TIR_CR3I
-#define PWM_INPUT_ISR() pwm_input_isr()
+static inline void pwm_input_isr2()
+{
+ static uint32_t t_rise;
+ static uint32_t t_fall;
+ if (T0CCR & TCCR_CR0_F) {
+ t_fall = T0CR0;
+ T0CCR |= TCCR_CR0_R;
+ T0CCR &= ~TCCR_CR0_F;
+ pwm_input_duration[1] = t_fall - t_rise;
+ pwm_input_valid[1] = TRUE;
+ } else if (T0CCR & TCCR_CR0_R) {
+ t_rise = T0CR0;
+ T0CCR |= TCCR_CR0_F;
+ T0CCR &= ~TCCR_CR0_R;
+ }
+}
+
+#define PWM_INPUT_IT1 TIR_CR3I
+#define PWM_INPUT_IT2 TIR_CR0I
+#define PWM_INPUT_ISR_1() pwm_input_isr1()
+#define PWM_INPUT_ISR_2() pwm_input_isr2()
+
#endif /* PWM_INPUT_H */
Modified: paparazzi3/trunk/sw/airborne/arm7/sys_time_hw.c
===================================================================
--- paparazzi3/trunk/sw/airborne/arm7/sys_time_hw.c 2009-12-08 07:07:17 UTC
(rev 4364)
+++ paparazzi3/trunk/sw/airborne/arm7/sys_time_hw.c 2009-12-08 07:08:19 UTC
(rev 4365)
@@ -40,7 +40,8 @@
#ifdef USE_PWM_INPUT
#include "pwm_input.h"
#else
-#define PWM_INPUT_IT 0x00
+#define PWM_INPUT_IT1 0x00
+#define PWM_INPUT_IT2 0x00
#endif
#ifdef USE_AMI601
@@ -55,7 +56,8 @@
RADIO_CONTROL_PPM_IT |\
MB_SCALE_IT |\
MB_TACHO_IT |\
- PWM_INPUT_IT |\
+ PWM_INPUT_IT1 |\
+ PWM_INPUT_IT2 |\
AMI601_IT)
void TIMER0_ISR ( void ) {
@@ -101,12 +103,18 @@
T0IR = MB_TACHO_IT;
}
#endif
-#ifdef USE_PWM_INPUT
- if (T0IR&PWM_INPUT_IT) {
- PWM_INPUT_ISR();
- T0IR = PWM_INPUT_IT;
+#ifdef USE_PWM_INPUT1
+ if (T0IR&PWM_INPUT_IT1) {
+ PWM_INPUT_ISR_1();
+ T0IR = PWM_INPUT_IT1;
}
#endif
+#ifdef USE_PWM_INPUT2
+ if (T0IR&PWM_INPUT_IT2) {
+ PWM_INPUT_ISR_2();
+ T0IR = PWM_INPUT_IT2;
+ }
+#endif
#ifdef USE_AMI601
if (T0IR&AMI601_IT) {
AMI601_ISR();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paparazzi-commits] [4365] Update pwm_input to support Timer0 CR0 and CR3 (to read two sensors),
Allen Ibara <=