Bug 877 - PWM doesn't handle decode back in time.
Summary: PWM doesn't handle decode back in time.
Status: RESOLVED DUPLICATE of bug 876
Alias: None
Product: libsigrokdecode
Classification: Unclassified
Component: PD: pwm (show other bugs)
Version: unreleased development snapshot
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-12 18:22 CET by karlp
Modified: 2017-02-26 19:45 CET (History)
1 user (show)



Attachments
restart on backwards time jump (1.83 KB, patch)
2016-12-12 18:22 CET, karlp
Details

Note You need to log in before you can comment on or make changes to this bug.
Description karlp 2016-12-12 18:22:02 CET
Created attachment 275 [details]
restart on backwards time jump

The PWM pd, (at least) doesn't handle the case of

__init__()
start()
decode(0,2048)
decode(2049,4096)
decode(0,2048)
decode(2049,4096)
....
end()


It's unclear from the protocol decoder howto and the protocol decoder apis
http://sigrok.org/wiki/Protocol_decoder_API and http://sigrok.org/wiki/Protocol_decoder_HOWTO whether the decoders are _meant_ to handle this case or not.

Example (trimmed) trace from pulseview.

srd: Calling start() method on protocol decoder instance pwm-1.
srd: Decoding: start sample 0, end sample 2048 (2048 samples, 4096 bytes, unitsize = 2), instance pwm-1.
srd: Decoding: start sample 2048, end sample 4096 (2048 samples, 4096 bytes, unitsize = 2), instance pwm-1.
srd: Decoding: start sample 4096, end sample 5456 (1360 samples, 2720 bytes, unitsize = 2), instance pwm-1.
sr: [00:13.670685] saleae-logic16: receive_transfer(): status LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED received 4096 bytes.
sr: [00:13.670826] session: bus: Received SR_DF_LOGIC packet (9088 bytes, unitsize = 2).
srd: Decoding: start sample 0, end sample 2048 (2048 samples, 4096 bytes, unitsize = 2), instance pwm-1.
srd: Decoding: start sample 2048, end sample 4096 (2048 samples, 4096 bytes, unitsize = 2), instance pwm-1.
srd: Decoding: start sample 4096, end sample 6144 (2048 samples, 4096 bytes, unitsize = 2), instance pwm-1.
srd: Decoding: start sample 6144, end sample 8192 (2048 samples, 4096 bytes, unitsize = 2), instance pwm-1.
srd: Decoding: start sample 8192, end sample 10000 (1808 samples, 3616 bytes, unitsize = 2), instance pwm-1.


At least at present, the restarting of the decoding here causes the internal state machine of the PWM decoder to lose track of edges, and it calculates some ratios > 1.0, which causes a failure in the output of the binary stream.

This is _only_ a problem when doing live captures.  Any instantiation of the decoder once capture has finished is always "safe" and "correct"

The attached patch fixes the issue by simply discarding all internal state and calling "start()" again if the decoder steps back in time.  Testing with Pulseview indicates that the repeated registration of annotations is not problematic, but I'm unsure if this is ok by definition, or just chance.

While this patch _works_ I'd feel a lot better if the decoder could rely on being "start()"ed again, or something more explicit, as I fully expect this issue to be present in other decoders.  In that case, the bug needs to be filed more against libsigrok?
Comment 1 Uwe Hermann 2017-02-26 19:45:26 CET
I think this is likely to be a duplicate of #876, or at least it has/had the same cause.

The use-case of "decode(2049,4096) followed by decode(0,2048)" is indeed not supported (or meant to be supported) in libsigrokdecode.

The sample number issue has been clarified in libsigrokdecode in 4564e8e53af85e696a58e43677bae87470c52771.

The incorrect sample usage in PV was fixed in e8bb7c69bce723ed2b116598012cf85deb191ba8 (see #876).

Marking as duplicate, but please file additional bugs if any issues related to this remain unsolved.

*** This bug has been marked as a duplicate of bug 876 ***