From: Philipp Hachtmann Date: Sat, 11 Feb 2017 05:04:57 +0000 (+0100) Subject: trennfix/sw: Single timer single delay solution seems to work X-Git-Url: http://gitweb.hachti.de/?p=eisenbahn.git;a=commitdiff_plain;h=9c77e706fc1758805d7141ffaea00beeccd77b9a trennfix/sw: Single timer single delay solution seems to work Signed-off-by: Philipp Hachtmann --- diff --git a/trennfix/sw/mm/include/mm/mm_switch.h b/trennfix/sw/mm/include/mm/mm_switch.h index 94655a9..f7f0d15 100644 --- a/trennfix/sw/mm/include/mm/mm_switch.h +++ b/trennfix/sw/mm/include/mm/mm_switch.h @@ -9,7 +9,9 @@ enum mm_recstate { MM_FIRST_SLOW_SAMPLE, /* If clock arrives, we stay on the fast path! */ MM_FAST_SAMPLE, MM_FAST_WAIT_FOR_CLOCK, + MM_SLOW_SAMPLE_DELAY, MM_SLOW_SAMPLE, + MM_SLOW_WAIT_FOR_CLOCK_DELAY, MM_SLOW_WAIT_FOR_CLOCK, }; diff --git a/trennfix/sw/mm/src/mm_switch.c b/trennfix/sw/mm/src/mm_switch.c index 30f43cb..ba68a8b 100644 --- a/trennfix/sw/mm/src/mm_switch.c +++ b/trennfix/sw/mm/src/mm_switch.c @@ -222,9 +222,10 @@ void shift(uint8_t value) } #endif +static volatile uint8_t mm_rec_tolerated_timeouts; + ISR(MM_TIMER_INT_VECT) { - static uint8_t tolerated_timeouts = 0; static volatile uint8_t shift_command_first; static volatile uint8_t shift_function_first; @@ -232,6 +233,8 @@ ISR(MM_TIMER_INT_VECT) { uint8_t address; uint8_t command; + MM_TSTART_FAST; + #ifdef MM_FILTER_REPEATED static uint8_t address_last = 0xff; static uint8_t function_last = 0xff; @@ -239,43 +242,48 @@ ISR(MM_TIMER_INT_VECT) { #endif switch(recstate) { + case MM_FIRST_FAST_SAMPLE: - recstate = MM_FIRST_SLOW_SAMPLE; - MM_TSTART_FAST; /* Will not run out in fast! */ + recstate = MM_FIRST_SLOW_SAMPLE ; break; case MM_FIRST_SLOW_SAMPLE: bitno = 0; case MM_SLOW_SAMPLE: - recstate = MM_SLOW_WAIT_FOR_CLOCK; - MM_TSTART_SLOW; + recstate = MM_SLOW_WAIT_FOR_CLOCK_DELAY; break; - + case MM_FAST_SAMPLE: recstate = MM_FAST_WAIT_FOR_CLOCK; - MM_TSTART_FAST; break; case MM_FAST_WAIT_FOR_CLOCK: /* A timeout! */ - if (tolerated_timeouts) { - tolerated_timeouts--; - MM_TSTART_FAST; - return; + if (mm_rec_tolerated_timeouts) { + mm_rec_tolerated_timeouts--; + } else { + recstate = MM_IDLE; + } - recstate = MM_IDLE; - MM_TSTOP; + return; + + case MM_SLOW_SAMPLE_DELAY: + recstate = MM_SLOW_SAMPLE; + return; + + case MM_SLOW_WAIT_FOR_CLOCK_DELAY: + recstate = MM_SLOW_WAIT_FOR_CLOCK; return; case MM_SLOW_WAIT_FOR_CLOCK: - if (tolerated_timeouts) { - tolerated_timeouts--; - MM_TSTART_SLOW; + if (mm_rec_tolerated_timeouts) { + mm_rec_tolerated_timeouts--; + recstate = MM_SLOW_WAIT_FOR_CLOCK_DELAY; return; } default: - MM_TSTOP; recstate = MM_IDLE; + case MM_IDLE: return; } @@ -286,8 +294,7 @@ ISR(MM_TIMER_INT_VECT) { shift_address_first = shift_address; shift_function_first = shift_function; shift_command_first = shift_command; - - tolerated_timeouts = 18; + mm_rec_tolerated_timeouts = 18; } if (bitno == 36) { @@ -301,9 +308,11 @@ ISR(MM_TIMER_INT_VECT) { #endif address = lookup_decoder(shift_address); - if (recstate == MM_SLOW_WAIT_FOR_CLOCK) { + if (recstate == MM_SLOW_WAIT_FOR_CLOCK_DELAY) { + trigger(); mm_switch_drive(address, shift_function, shift_command); } else if (recstate == MM_FAST_WAIT_FOR_CLOCK) { + trigger(); command = lookup_command(shift_command); mm_switch_command(address, command); } @@ -359,29 +368,37 @@ void mm_pinchange_handler(void) if (!sense_last) return; + MM_TSTART_FAST; + switch(recstate) { case MM_IDLE: bitno = 0; recstate = MM_FIRST_FAST_SAMPLE; - MM_TSTART_FAST; break; + case MM_FIRST_SLOW_SAMPLE: recstate = MM_FAST_SAMPLE; - MM_TSTART_FAST; break; + case MM_FAST_WAIT_FOR_CLOCK: recstate = MM_FAST_SAMPLE; - MM_TSTART_FAST; + mm_rec_tolerated_timeouts = 0; break; + + case MM_SLOW_WAIT_FOR_CLOCK_DELAY: /* If clock comes early */ + recstate = MM_SLOW_WAIT_FOR_CLOCK; + break; + case MM_SLOW_WAIT_FOR_CLOCK: - recstate = MM_SLOW_SAMPLE; - MM_TSTART_SLOW; + recstate = MM_SLOW_SAMPLE_DELAY; + mm_rec_tolerated_timeouts = 0; break; /* Not expected */ case MM_FIRST_FAST_SAMPLE: case MM_FAST_SAMPLE: case MM_SLOW_SAMPLE: + recstate = MM_IDLE; default: break; }