+ # Calculate time since start of presence signal.
+ time = ((self.samplenum - self.fall) / self.samplerate) * 1000000.0
+ if time < timing['PDL']['min'][self.overdrive]:
+ self.put(self.fall, self.samplenum, self.out_ann,
+ [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.put(self.fall, self.samplenum, self.out_ann,
+ [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.
+ # Calculate time since falling edge.
+ time = ((self.samplenum - self.fall) / self.samplerate) * 1000000.0
+ if owr != 0 and time < timing['SLOT']['min'][self.overdrive]:
+ continue
+ elif owr == 0: # Low detected before end of slot.
+ # Warn about irregularity.
+ self.put(self.fall, self.samplenum, self.out_ann,
+ [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.put(self.fall, self.samplenum, self.out_ann,
+ [0, ['Bit: %d' % self.bit, '%d' % self.bit]])
+ self.put(self.fall, self.samplenum, self.out_python,
+ ['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'
+
+ if self.state == 'PRESENCE DETECT':
+ # Wait for end of presence detect.
+ # Calculate time since falling edge.
+ time = ((self.samplenum - self.rise) / self.samplerate) * 1000000.0
+ if owr != 0 and time < timing['RSTH']['min'][self.overdrive]:
+ continue
+ elif owr == 0: # Low detected before end of presence detect.
+ # Warn about irregularity.
+ self.put(self.fall, self.samplenum, self.out_ann,
+ [1, ['Presence detect not long enough',
+ 'Presence detect too short',
+ 'RTSH < ' + str(timing['RSTH']['min'][self.overdrive])]])
+ # Inform about presence detected.
+ self.put(self.rise, self.samplenum, self.out_ann,
+ [3, ['Slave presence detected', 'Slave present',
+ 'Present', 'P']])
+ self.put(self.rise, self.samplenum, self.out_python,
+ ['RESET/PRESENCE', True])
+ self.fall = self.samplenum
+ self.state = 'LOW'
+ else: # End of time slot.
+ # Inform about presence detected.
+ self.put(self.rise, self.samplenum, self.out_ann,
+ [3, ['Presence: true', 'Presence', 'Pres', 'P']])
+ self.put(self.rise, self.samplenum, self.out_python,
+ ['RESET/PRESENCE', True])
+ self.rise = self.samplenum
+ # Start counting the first 8 bits to get the ROM command.
+ self.bit_count = 0
+ self.command = 0
+ self.state = 'IDLE'