attempt to get pwm_input and xtend_rssi module working:

* added pwm_input.c and pwm_input_arch.c to sources
* make pwm_input_isr normal void functions for now
* define PWM_INPUT_ITx to zero if not used
This commit is contained in:
Felix Ruess
2011-11-07 20:27:51 +01:00
committed by Stephen Dwyer
parent 3154730a7b
commit fff2dabbb8
5 changed files with 85 additions and 68 deletions
+4 -3
View File
@@ -12,11 +12,12 @@
</header>
<init fun="xtend_rssi_init()"/>
<periodic fun="xtend_rssi_periodic()" freq="2."/>
<makefile>
<file name="xtend_rssi.c"/>
</makefile>
<makefile target="ap">
<file name="xtend_rssi.c"/>
<file name="pwm_input.c" dir="mcu_periph"/>
<file_arch name="pwm_input_arch.c" dir="mcu_periph"/>
<define name="XTEND_RSSI_PWM_INPUT_CHANNEL" value="$(XTEND_RSSI_PWM_INPUT_CHANNEL)"/>
<define name="USE_PWM_INPUT"/>
<define name="USE_PWM_INPUT$(XTEND_RSSI_PWM_INPUT_CHANNEL)" value="PWM_PULSE_TYPE_ACTIVE_HIGH"/>
</makefile>
</module>
@@ -22,10 +22,10 @@
*/
/** \brief handling of arm7 PWM input using a timer with capture
*
*
*/
#include "mcu_periph/pwm_input.h"
#include "mcu_periph/pwm_input_arch.h"
#include "LPC21xx.h"
#include "interrupt_hw.h"
@@ -66,8 +66,7 @@
void pwm_input_init ( void )
{
// initialize the arrays to 0 to avoid junk
int i = 0;
for (int i; i < PWM_INPUT_NB; i++)
for (int i=0; i < PWM_INPUT_NB; i++)
{
pwm_input_duty_tics[i] = 0;
pwm_input_duty_valid[i] = 0;
@@ -97,4 +96,67 @@ void pwm_input_init ( void )
T0CCR |= TCCR_CR2_R | TCCR_CR2_I;
#endif
*/
}
}
#ifdef USE_PWM_INPUT1
void pwm_input_isr1(void)
{
static uint32_t t_rise;
static uint32_t t_fall;
static uint32_t t_oldrise = 0;
static uint32_t t_oldfall = 0;
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 (T0CCR & TCCR_CR0_F) {
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
}
}
#endif //USE_PWM_INPUT2
@@ -22,7 +22,7 @@
*/
/** \brief handling of arm7 PWM input using a timer with capture
*
*
*/
#ifndef PWM_INPUT_ARCH_H
@@ -34,70 +34,17 @@
#define PWM_INPUT_NB 4 //this is architecture dependent
#include "mcu_periph/pwm_input.h"
//FIXME what about clock time overflow???
#ifdef USE_PWM_INPUT1
static inline void pwm_input_isr1()
{
static uint32_t t_rise;
static uint32_t t_fall;
static uint32_t t_oldrise = 0;
static uint32_t t_oldfall = 0;
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
}
}
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
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;
#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
}
}
extern void pwm_input_isr2(void);
#define PWM_INPUT_IT2 TIR_CR0I
#define PWM_INPUT_ISR_2() pwm_input_isr2()
#endif //USE_PWM_INPUT2
+8 -1
View File
@@ -36,10 +36,17 @@ uint32_t sys_time_chrono; /* T0TC ticks */
#ifdef USE_PWM_INPUT
#include "mcu_periph/pwm_input.h"
#else
#endif
#ifndef USE_PWM_INPUT1
#define PWM_INPUT_IT1 0x00
#endif
#ifndef USE_PWM_INPUT2
#define PWM_INPUT_IT2 0x00
#endif
#ifndef USE_PWM_INPUT3
#define PWM_INPUT_IT3 0x00
#endif
#ifndef USE_PWM_INPUT4
#define PWM_INPUT_IT4 0x00
#endif
+1 -1
View File
@@ -42,7 +42,7 @@ extern volatile uint8_t pwm_input_duty_valid[PWM_INPUT_NB];
extern volatile uint32_t pwm_input_period_tics[PWM_INPUT_NB];
extern volatile uint8_t pwm_input_period_valid[PWM_INPUT_NB];
void pwm_input_init(void);
extern void pwm_input_init(void);
#endif /* USE_PWM_INPUT */