X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fasix-sigma%2Fprotocol.c;h=db89d6890a9c2d9d1f214de5d0335f297719d5b5;hb=9a0a606a8215aa7fd41bb72a3653dff7ef54505b;hp=d2670b4c3a974e503330f9a1564fd2b1737772e1;hpb=7c86d8537204caa95d70d92bf5698b32ac35fa10;p=libsigrok.git diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index d2670b4c..db89d689 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -519,6 +519,30 @@ static int upload_firmware(struct sr_context *ctx, return SR_OK; } +/* + * Sigma doesn't support limiting the number of samples, so we have to + * translate the number and the samplerate to an elapsed time. + * + * In addition we need to ensure that the last data cluster has passed + * the hardware pipeline, and became available to the PC side. With RLE + * compression up to 327ms could pass before another cluster accumulates + * at 200kHz samplerate when input pins don't change. + */ +SR_PRIV uint64_t sigma_limit_samples_to_msec(const struct dev_context *devc, + uint64_t limit_samples) +{ + uint64_t limit_msec; + uint64_t worst_cluster_time_ms; + + limit_msec = limit_samples * 1000 / devc->cur_samplerate; + worst_cluster_time_ms = 65536 * 1000 / devc->cur_samplerate; + /* + * One cluster time is not enough to flush pipeline when sampling + * grounded pins with 1 sample limit at 200kHz. Hence the 2* fix. + */ + return limit_msec + 2 * worst_cluster_time_ms; +} + SR_PRIV int sigma_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate) { struct dev_context *devc; @@ -574,7 +598,7 @@ SR_PRIV int sigma_set_samplerate(const struct sr_dev_inst *sdi, uint64_t sampler */ if (ret == SR_OK && devc->limit_samples) { uint64_t msecs; - msecs = devc->limit_samples * 1000 / devc->cur_samplerate; + msecs = sigma_limit_samples_to_msec(devc, devc->limit_samples); devc->limit_msec = msecs; } @@ -723,7 +747,7 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster, ts = sigma_dram_cluster_ts(dram_cluster); tsdiff = ts - ss->lastts; - ss->lastts = ts; + ss->lastts = ts + EVENTS_PER_CLUSTER; packet.type = SR_DF_LOGIC; packet.payload = &logic; @@ -741,7 +765,7 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster, * sample in the cluster happens at the time of the timestamp * and the remaining samples happen at timestamp +1...+6 . */ - for (ts = 0; ts < tsdiff - (EVENTS_PER_CLUSTER - 1); ts++) { + for (ts = 0; ts < tsdiff; ts++) { i = ts % 1024; samples[2 * i + 0] = ss->lastsample & 0xff; samples[2 * i + 1] = ss->lastsample >> 8; @@ -751,7 +775,7 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster, * end of submitting the padding samples, submit * the packet to Sigrok. */ - if ((i == 1023) || (ts == (tsdiff - EVENTS_PER_CLUSTER))) { + if ((i == 1023) || (ts == tsdiff - 1)) { logic.length = (i + 1) * logic.unitsize; sr_session_send(sdi, &packet); }