+ if self.matched[0] and not self.matched[1]:
+ # Presence detected.
+ if time < timing['PDH']['min'][self.overdrive]:
+ self.putrs([1, ['Presence detect signal is too early',
+ 'Presence detect too early',
+ 'PDH < ' + str(timing['PDH']['min'][self.overdrive])]])
+ self.fall = self.samplenum
+ self.state = 'PRESENCE DETECT LOW'
+ else: # No presence detected.
+ self.putrs([3, ['Presence: false', 'Presence', 'Pres', 'P']])
+ self.putprs(['RESET/PRESENCE', False])
+ self.state = 'IDLE'
+ elif self.state == 'PRESENCE DETECT LOW': # Slave presence signalled.
+ # Wait for end of presence signal (on rising edge).
+ self.wait({0: 'r'})
+ # Calculate time since start of presence signal.
+ time = ((self.samplenum - self.fall) / self.samplerate) * 1000000.0
+ if time < timing['PDL']['min'][self.overdrive]:
+ self.putfs([1, ['Presence detect signal is too short',
+ 'Presence detect too short',
+ 'PDL < ' + str(timing['PDL']['min'][self.overdrive])]])
+ elif time > timing['PDL']['max'][self.overdrive]:
+ self.putfs([1, ['Presence detect signal is too long',
+ 'Presence detect too long',
+ 'PDL > ' + str(timing['PDL']['max'][self.overdrive])]])
+ if time > timing['RSTH']['min'][self.overdrive]:
+ self.rise = self.samplenum
+ # Wait for end of presence detect.
+ self.state = 'PRESENCE DETECT'
+
+ # End states (for additional checks).
+ if self.state == 'SLOT': # Wait for end of time slot.
+ # Wait for a falling edge and/or end of timeslot.
+ self.wait_falling_timeout(self.fall, timing['SLOT']['min'])
+
+ if self.matched[0] and not self.matched[1]:
+ # Low detected before end of slot.
+ self.putfs([1, ['Time slot not long enough',
+ 'Slot too short',
+ 'SLOT < ' + str(timing['SLOT']['min'][self.overdrive])]])
+ # Don't output invalid bit.
+ self.fall = self.samplenum
+ self.state = 'LOW'
+ else: # End of time slot.
+ # Output bit.
+ self.putfs([0, ['Bit: %d' % self.bit, '%d' % self.bit]])
+ self.putpfs(['BIT', self.bit])
+ # Save command bits.
+ if self.bit_count >= 0:
+ self.command += (self.bit << self.bit_count)
+ self.bit_count += 1
+ # Check for overdrive ROM command.
+ if self.bit_count >= 8:
+ if self.command == 0x3c or self.command == 0x69:
+ self.overdrive = True
+ self.put(self.samplenum, self.samplenum,
+ self.out_ann,
+ [4, ['Entering overdrive mode', 'Overdrive on']])
+ self.bit_count = -1
+ self.state = 'IDLE'