The unified diff between revisions [be147b11..] and [9f05a1eb..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'timer.c'
# # old_revision [be147b11caac304fda1579ac71017eecc3bb79e0] # new_revision [9f05a1eb606ea1c0421aa4a0b25b83b4fe4a20c8] # # patch "timer.c" # from [7f173b22d8e013f1c5ce08dfb04bb4cd59f5932c] # to [80f539706b746c7f6a4cbc52c6ebe93064f0b7f9] # ============================================================ --- timer.c 7f173b22d8e013f1c5ce08dfb04bb4cd59f5932c +++ timer.c 80f539706b746c7f6a4cbc52c6ebe93064f0b7f9 @@ -61,8 +61,14 @@ volatile unsigned int timer1_width[4]; 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"))) t 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,7 +230,15 @@ 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]; int i; @@ -225,6 +251,7 @@ bool timer_allvalid(void) { return FALSE; return TRUE; } +#endif void timer_set_pwm_value(int channel, int value) {