]> sigrok.org Git - libsigrok.git/commitdiff
asix-sigma: download sample data upon user initiated stop, too
authorGerhard Sittig <redacted>
Sat, 29 Jul 2017 14:09:36 +0000 (16:09 +0200)
committerUwe Hermann <redacted>
Fri, 11 Aug 2017 16:52:23 +0000 (18:52 +0200)
When the acquisition was stopped before a configured limit was reached,
no sample data was retrieved. This is because the api.c stop routine did
unregister the receive callback.

Pass the stop request to the receive routine instead when stop is called
while the acquisition is still running. Have sample data downloaded very
much like it's done for reached limits, and existing logic will run the
stop routine again after state was advanced to "idle".

Extend the 'state' tracking while we are here, mark sample download as
well (that was omitted in the previous implementation). Though the
omission was non-fatal. Move the release of 'dram_line' to some earlier
location (as soon as the resource is not needed any longer), before some
rather complex calls to other routines will execute.

Reported-By: Michael Kaplan <redacted>
src/hardware/asix-sigma/api.c
src/hardware/asix-sigma/protocol.c
src/hardware/asix-sigma/protocol.h

index 042793a8961c8e52c5ee7d1acb094a01ab1c91f9..8e1a490aa345ee6e91ea8a968236d0899c2ad8cf 100644 (file)
@@ -363,9 +363,20 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        devc = sdi->priv;
-       devc->state.state = SIGMA_IDLE;
 
-       sr_session_source_remove(sdi->session, -1);
+       /*
+        * When acquisition is currently running, keep the receive
+        * routine registered and have it stop the acquisition upon the
+        * next invocation. Else unregister the receive routine here
+        * already. The detour is required to have sample data retrieved
+        * for forced acquisition stops.
+        */
+       if (devc->state.state == SIGMA_CAPTURE) {
+               devc->state.state = SIGMA_STOPPING;
+       } else {
+               devc->state.state = SIGMA_IDLE;
+               sr_session_source_remove(sdi->session, -1);
+       }
 
        return SR_OK;
 }
index e2c34e5c9169699df381d5b8fecbbab3e8685849..94fd8de044356a9a999b9a32cea11cd8c998f3ae 100644 (file)
@@ -1017,6 +1017,7 @@ static int download_capture(struct sr_dev_inst *sdi)
                return FALSE;
 
        sr_info("Downloading sample data.");
+       devc->state.state = SIGMA_DOWNLOAD;
 
        /*
         * Ask the hardware to stop data acquisition. Reception of the
@@ -1097,13 +1098,13 @@ static int download_capture(struct sr_dev_inst *sdi)
 
                dl_lines_done += dl_lines_curr;
        }
+       g_free(dram_line);
 
        std_session_send_df_end(sdi);
 
+       devc->state.state = SIGMA_IDLE;
        sr_dev_acquisition_stop(sdi);
 
-       g_free(dram_line);
-
        return TRUE;
 }
 
@@ -1146,6 +1147,14 @@ SR_PRIV int sigma_receive_data(int fd, int revents, void *cb_data)
        if (devc->state.state == SIGMA_IDLE)
                return TRUE;
 
+       /*
+        * When the application has requested to stop the acquisition,
+        * then immediately start downloading sample data. Otherwise
+        * keep checking configured limits which will terminate the
+        * acquisition and initiate download.
+        */
+       if (devc->state.state == SIGMA_STOPPING)
+               return download_capture(sdi);
        if (devc->state.state == SIGMA_CAPTURE)
                return sigma_capture_mode(sdi);
 
index d59c95d2a1b0704d1a7812e9f0c4d80c82466f90..6b934c252cc489a1ac108f7e8d3550b564c7136c 100644 (file)
@@ -246,9 +246,9 @@ struct sigma_state {
                SIGMA_UNINITIALIZED = 0,
                SIGMA_IDLE,
                SIGMA_CAPTURE,
+               SIGMA_STOPPING,
                SIGMA_DOWNLOAD,
        } state;
-
        uint16_t lastts;
        uint16_t lastsample;
 };