}
#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;
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;
#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;
}
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) {
#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);
}
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;
}