@ -61,7 +61,13 @@
volatile unsigned int timer1_rising [ 4 ] ;
volatile unsigned int timer1_width [ 4 ] ;
unsigned int timer_map [ ] = { 0 , 3 , 2 , 1 } ;
# ifdef TIMER_CPPM
volatile unsigned int timer1_cppm [ 8 ] ;
volatile unsigned int timer1_cppm_chan = 0 ;
volatile unsigned int timer1_sync_timestamp ;
# endif
unsigned int timer_map [ ] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 } ;
void __attribute__ ( ( interrupt ( " IRQ " ) ) ) timer_interrupt_handler ( void ) ;
void __attribute__ ( ( interrupt ( " IRQ " ) ) ) timer1_interrupt_handler ( void ) ;
@ -174,6 +180,18 @@ void __attribute__((interrupt("IRQ"))) timer1_interrupt_handler(void)
timer1_rising [ 0 ] = T1WREG ( CR0 ) ;
} else {
timer1_width [ 0 ] = T1WREG ( CR0 ) - timer1_rising [ 0 ] ;
# ifdef TIMER_CPPM
if ( timer1_width [ 0 ] > TIMER_CPPM_SYNC ) {
timer1_cppm_chan = 0 ;
timer1_sync_timestamp = timer1_rising [ 0 ] ;
} else {
if ( timer1_cppm_chan < 8 ) {
timer1_cppm [ timer1_cppm_chan ] =
timer1_width [ 0 ] ;
timer1_cppm_chan + + ;
}
}
# endif
}
}
if ( ir & ( 1 < < 5 ) ) {
@ -212,6 +230,14 @@ bool timer_valid(int channel) {
return ( time - chtime ) < TIMER_INPUT_TIMEOUT ;
}
# ifdef TIMER_CPPM
bool timer_allvalid ( void ) {
/* Be careful here to ensure that this can't be in the past */
unsigned int chtime = timer1_sync_timestamp ; /* Atomic */
unsigned int time = T1WREG ( TC ) ; /* Atomic */
return ( time - chtime ) < TIMER_INPUT_TIMEOUT ;
}
# else
bool timer_allvalid ( void ) {
unsigned int time ;
unsigned int chtime [ 4 ] ;
@ -225,6 +251,7 @@ bool timer_allvalid(void) {
return FALSE ;
return TRUE ;
}
# endif
void timer_set_pwm_value ( int channel , int value )
{