X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fonewire_link%2Fonewire_link.py;h=ab73b6fb1a48318a956afc2a82d168223c04bffe;hp=3236f4d9e866ec3d549fc2db09c17630644f3ea9;hb=671cc3009b967bd105757d0a0c267a68f18c58b9;hpb=9cfb16e8532e34b40edf1d980c7438afb31668e0 diff --git a/decoders/onewire_link/onewire_link.py b/decoders/onewire_link/onewire_link.py index 3236f4d..ab73b6f 100644 --- a/decoders/onewire_link/onewire_link.py +++ b/decoders/onewire_link/onewire_link.py @@ -40,9 +40,11 @@ class Decoder(srd.Decoder): options = { 'overdrive' : ['Overdrive', 1], 'cnt_normal_bit' : ['Time (in samplerate periods) for normal mode sample bit' , 0], + 'cnt_normal_slot' : ['Time (in samplerate periods) for normal mode data slot' , 0], 'cnt_normal_presence' : ['Time (in samplerate periods) for normal mode sample presence', 0], 'cnt_normal_reset' : ['Time (in samplerate periods) for normal mode reset' , 0], 'cnt_overdrive_bit' : ['Time (in samplerate periods) for overdrive mode sample bit' , 0], + 'cnt_overdrive_slot' : ['Time (in samplerate periods) for overdrive mode data slot' , 0], 'cnt_overdrive_presence': ['Time (in samplerate periods) for overdrive mode sample presence', 0], 'cnt_overdrive_reset' : ['Time (in samplerate periods) for overdrive mode reset' , 0], } @@ -57,8 +59,9 @@ class Decoder(srd.Decoder): self.state = 'WAIT FOR FALLING EDGE' self.present = 0 self.bit = 0 + self.bit_cnt = 0 + self.command = 0 self.overdrive = 0 - self.cmd_cnt = 0 # Event timing variables self.fall = 0 self.rise = 0 @@ -93,6 +96,10 @@ class Decoder(srd.Decoder): self.cnt_normal_bit = self.options['cnt_normal_bit'] else: self.cnt_normal_bit = int(float(self.samplerate) * 0.000015) - 1 # 15ns + if (self.options['cnt_normal_slot']): + self.cnt_normal_slot = self.options['cnt_normal_slot'] + else: + self.cnt_normal_slot = int(float(self.samplerate) * 0.000060) - 1 # 60ns if (self.options['cnt_normal_presence']): self.cnt_normal_presence = self.options['cnt_normal_presence'] else: @@ -105,6 +112,10 @@ class Decoder(srd.Decoder): self.cnt_overdrive_bit = self.options['cnt_overdrive_bit'] else: self.cnt_overdrive_bit = int(float(self.samplerate) * 0.000002) - 1 # 2ns + if (self.options['cnt_overdrive_slot']): + self.cnt_overdrive_slot = self.options['cnt_overdrive_slot'] + else: + self.cnt_overdrive_slot = int(float(self.samplerate) * 0.0000073) - 1 # 6ns+1.3ns if (self.options['cnt_overdrive_presence']): self.cnt_overdrive_presence = self.options['cnt_overdrive_presence'] else: @@ -114,10 +125,6 @@ class Decoder(srd.Decoder): else: self.cnt_overdrive_reset = int(float(self.samplerate) * 0.000048) - 1 # 48ns - # calculating the slot size - self.cnt_normal_slot = int(float(self.samplerate) * 0.000060) - 1 # 60ns - self.cnt_overdrive_slot = int(float(self.samplerate) * 0.000006) - 1 # 6ns - # organize values into lists self.cnt_bit = [self.cnt_normal_bit , self.cnt_overdrive_bit ] self.cnt_presence = [self.cnt_normal_presence, self.cnt_overdrive_presence] @@ -167,57 +174,64 @@ class Decoder(srd.Decoder): elif self.state == 'WAIT FOR DATA SAMPLE': # Sample data bit if (self.samplenum - self.fall == self.cnt_bit[self.overdrive]): - self.bit = owr & 0x1 - if (self.bit): self.state = 'WAIT FOR FALLING EDGE' - else : self.state = 'WAIT FOR RISING EDGE' - self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['BIT: %01x' % self.bit]]) - self.put(self.out_proto, ['BIT', self.bit]) - # Checking the first command to see if overdrive mode should be entered - if (self.cmd_cnt <= 8): - self.command = self.command | (self.bit << self.cmd_cnt) - elif (self.cmd_cnt == 8): - if (self.command in [0x3c, 0x69]): - self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['ENTER OVERDRIVE MODE']]) - # incrementing the bit counter - self.bit_cnt += 1 + self.bit = owr + self.state = 'WAIT FOR DATA SLOT END' + elif self.state == 'WAIT FOR DATA SLOT END': + # A data slot ends in a recovery period, otherwise, this is probably a reset + if (self.samplenum - self.fall == self.cnt_slot[self.overdrive]): + if (owr): + self.put(self.fall, self.samplenum, self.out_ann, [0, ['BIT: %01x' % self.bit]]) + self.put(self.fall, self.samplenum, self.out_proto, ['BIT', self.bit]) + # Checking the first command to see if overdrive mode should be entered + if (self.bit_cnt <= 8): + self.command = self.command | (self.bit << self.bit_cnt) + elif (self.bit_cnt == 8): + if (self.command in [0x3c, 0x69]): + self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['ENTER OVERDRIVE MODE']]) + # Incrementing the bit counter + self.bit_cnt += 1 + # Wait for next slot + self.state = 'WAIT FOR FALLING EDGE' + else: + # This seems to be a reset slot, wait for its end + self.state = 'WAIT FOR RISING EDGE' elif self.state == 'WAIT FOR RISING EDGE': # The end of a cycle is a rising edge. - if (owr == 1): + if (owr): # Check if this was a reset cycle if (self.samplenum - self.fall > self.cnt_normal_reset): # Save the sample number for the falling edge. self.rise = self.samplenum self.state = "WAIT FOR PRESENCE DETECT" - self.put(self.fall, self.rise, self.out_ann, [0, ['RESET']]) - self.put(self.fall, self.rise, self.out_proto, ['RESET', 0]) - # Reset the timer. - self.fall = self.samplenum # Exit overdrive mode - self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['EXIT OVERDRIVE MODE']]) - self.overdrive = 0 - self.cmd_cnt = 0 + if (self.overdrive): + self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['EXIT OVERDRIVE MODE']]) + self.overdrive = 0 + # Clear command bit counter and data register + self.bit_cnt = 0 self.command = 0 elif ((self.samplenum - self.fall > self.cnt_overdrive_reset) and (self.overdrive)): # Save the sample number for the falling edge. self.rise = self.samplenum self.state = "WAIT FOR PRESENCE DETECT" - self.put(self.fall, self.rise, self.out_ann, [0, ['RESET']]) - self.put(self.fall, self.rise, self.out_proto, ['RESET', 0]) - # Reset the timer. - self.fall = self.samplenum # Otherwise this is assumed to be a data bit. else : self.state = "WAIT FOR FALLING EDGE" elif self.state == 'WAIT FOR PRESENCE DETECT': # Sample presence status if (self.samplenum - self.rise == self.cnt_presence[self.overdrive]): - self.present = owr & 0x1 - # Save the sample number for the falling edge. - if not (self.present) : self.fall = self.samplenum - # create presence detect event - if (self.present) : self.state = 'WAIT FOR FALLING EDGE' - else : self.state = 'WAIT FOR RISING EDGE' - self.put(self.samplenum, 0, self.out_ann, [0, ['PRESENCE: ' + "False" if self.present else "True"]]) - self.put(self.samplenum, 0, self.out_proto, ['PRESENCE', self.present]) + self.present = owr + self.state = 'WAIT FOR RESET SLOT END' + elif self.state == 'WAIT FOR RESET SLOT END': + # A reset slot ends in a long recovery period + if (self.samplenum - self.rise == self.cnt_reset[self.overdrive]): + if (owr): + self.put(self.fall, self.samplenum, self.out_ann, [0, ['RESET/PRESENCE: %s' % ('False' if self.present else 'True')]]) + self.put(self.fall, self.samplenum, self.out_proto, ['RESET/PRESENCE', not self.present]) + # Wait for next slot + self.state = 'WAIT FOR FALLING EDGE' + else: + # This seems to be a reset slot, wait for its end + self.state = 'WAIT FOR RISING EDGE' else: raise Exception('Invalid state: %d' % self.state)