From: Gerhard Sittig Date: Sat, 29 Jul 2017 14:09:36 +0000 (+0200) Subject: asix-sigma: download sample data upon user initiated stop, too X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=dde0175d19fe443cf60c3089196364db17cfaa62;p=libsigrok.git asix-sigma: download sample data upon user initiated stop, too 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 --- diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 042793a8..8e1a490a 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -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; } diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index e2c34e5c..94fd8de0 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -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); diff --git a/src/hardware/asix-sigma/protocol.h b/src/hardware/asix-sigma/protocol.h index d59c95d2..6b934c25 100644 --- a/src/hardware/asix-sigma/protocol.h +++ b/src/hardware/asix-sigma/protocol.h @@ -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; };