Bug 1508 - Simplify grey code calculation
Summary: Simplify grey code calculation
Status: CONFIRMED
Alias: None
Product: libsigrok
Classification: Unclassified
Component: Driver: hantek-dso (show other bugs)
Version: unreleased development snapshot
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-26 21:48 CET by Soeren Apel
Modified: 2020-02-27 06:05 CET (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Soeren Apel 2020-02-26 21:48:14 CET
https://sigrok.org/gitweb/?p=libsigrok.git;a=blob;f=src/hardware/hantek-dso/protocol.c;h=c74187ada435f2441e7aa3b88ed926194c9d530b;hb=HEAD#l851

According to Renate on IRC:

The trigger point is coming in Gray code so that capture and data skew are not a problem.
toff ^= (toff>>1); toff ^= (toff>>2); toff ^= (toff>4); toff ^= (toff>>8); toff ^= (toff>>16);
That's it. That's how they convert Gray code in the big leagues.
Comment 1 Gerhard Sittig 2020-02-27 06:05:26 CET
Apparently the sigrok project has been aware how to do Gray decoding for ages, 
according to
 
  libsigrokdecode/decoders/graycode/pd.py:gray_decode()

The question is whether the hantek-dso driver's dso_get_capturestate() routine 
does Gray decoding in that spot. The reporter claims to have no access to the 
device, and would not provide a fix or improvement. And the existing driver 
code reads somewhat different to me. Instead of a repeated

  x ^= x >> 1

the code instead reads

  x ^= b - 1

which may or may not be a totally different operation. The comment suggests 
something Gray like, haven't "decoded" the implementation in detail, whether 
it's a very unfortunate re-invention of an XOR or not.

I'd say before blindly replacing the code and its comment the report needs 
verification on hardware, or comparison to a known working upstream project 
which parts of the driver are based on. The reporter provided neither.