]> sigrok.org Git - libsigrok.git/commitdiff
asix-sigma: check for successful register access in sample download
authorDaniel Trnka <redacted>
Thu, 12 Mar 2020 11:08:35 +0000 (12:08 +0100)
committerUwe Hermann <redacted>
Tue, 24 Mar 2020 18:20:40 +0000 (19:20 +0100)
The previous implementation got stuck in an infinite loop when data
acquisition started, but the device got disconnected before the data
acquisition terminates. An implementation detail ignored communication
errors, and never saw the expected condition that was required to
continue in the sample download sequence. Unbreak that code path.

src/hardware/asix-sigma/protocol.c

index 93d2623951e565f099ab68cc02e4af8ac66ccf32..a9c1695686c10c4f6b41742fd4f09eb291d79453 100644 (file)
@@ -134,18 +134,6 @@ static int sigma_read_register(uint8_t reg, uint8_t *data, size_t len,
        return sigma_read(data, len, devc);
 }
 
-static uint8_t sigma_get_register(uint8_t reg, struct dev_context *devc)
-{
-       uint8_t value;
-
-       if (1 != sigma_read_register(reg, &value, 1, devc)) {
-               sr_err("sigma_get_register: 1 byte expected");
-               return 0;
-       }
-
-       return value;
-}
-
 static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos,
                          struct dev_context *devc)
 {
@@ -1031,7 +1019,10 @@ static int download_capture(struct sr_dev_inst *sdi)
         */
        sigma_set_register(WRITE_MODE, WMR_FORCESTOP | WMR_SDRAMWRITEEN, devc);
        do {
-               modestatus = sigma_get_register(READ_MODE, devc);
+               if (sigma_read_register(READ_MODE, &modestatus, 1, devc) != 1) {
+                       sr_err("sigma: failed while waiting for RMR_POSTTRIGGERED bit");
+                       return FALSE;
+               }
        } while (!(modestatus & RMR_POSTTRIGGERED));
 
        /* Set SDRAM Read Enable. */
@@ -1041,7 +1032,10 @@ static int download_capture(struct sr_dev_inst *sdi)
        sigma_read_pos(&stoppos, &triggerpos, devc);
 
        /* Check if trigger has fired. */
-       modestatus = sigma_get_register(READ_MODE, devc);
+       if (sigma_read_register(READ_MODE, &modestatus, 1, devc) != 1) {
+               sr_err("sigma: failed to read READ_MODE register");
+               return FALSE;
+       }
        trg_line = ~0;
        trg_event = ~0;
        if (modestatus & RMR_TRIGGERED) {