]> sigrok.org Git - libsigrok.git/commitdiff
sysclk-lwla: Read test word twice during initialization
authorDaniel Elstner <redacted>
Sun, 25 Oct 2015 02:44:55 +0000 (03:44 +0100)
committerDaniel Elstner <redacted>
Fri, 30 Oct 2015 11:51:16 +0000 (12:51 +0100)
During initialization of the LWLA1034, read the 64-bit test word
twice and verify the result of the second read only. This better
matches what the original vendor software does.

src/hardware/sysclk-lwla/lwla.c
src/hardware/sysclk-lwla/lwla.h
src/hardware/sysclk-lwla/protocol.c

index 1934d61724f07bb9eaa80700707a9ac15cd42c3c..aee9d060503f37bff3c0008242f6bae079e4cb65 100644 (file)
@@ -191,6 +191,33 @@ SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb,
        return ret;
 }
 
+SR_PRIV int lwla_read_long_reg(const struct sr_usb_dev_inst *usb,
+                              uint32_t addr, uint64_t *value)
+{
+       uint32_t low, high, dummy;
+       int ret;
+
+       ret = lwla_write_reg(usb, REG_LONG_ADDR, addr);
+       if (ret != SR_OK)
+               return ret;
+
+       ret = lwla_read_reg(usb, REG_LONG_STROBE, &dummy);
+       if (ret != SR_OK)
+               return ret;
+
+       ret = lwla_read_reg(usb, REG_LONG_HIGH, &high);
+       if (ret != SR_OK)
+               return ret;
+
+       ret = lwla_read_reg(usb, REG_LONG_LOW, &low);
+       if (ret != SR_OK)
+               return ret;
+
+       *value = ((uint64_t)high << 32) | low;
+
+       return SR_OK;
+}
+
 SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb,
                           uint16_t reg, uint32_t value)
 {
index 867ed6a44cb50cf8f1064a5a5c9fe60c91aff496..3e14525576de0b8a883834eeb88ed021a0827bf1 100644 (file)
@@ -114,6 +114,9 @@ SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb,
 SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb,
                          uint16_t reg, uint32_t *value);
 
+SR_PRIV int lwla_read_long_reg(const struct sr_usb_dev_inst *usb,
+                              uint32_t addr, uint64_t *value);
+
 SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb,
                           uint16_t reg, uint32_t value);
 
index 5a1522fc9e60e50bfd050d0e15930c437a71788c..ff61a8b3574d786dd8d61c2d6b48c8ae26a45a4a 100644 (file)
@@ -700,9 +700,9 @@ static void LIBUSB_CALL receive_transfer_in(struct libusb_transfer *transfer)
  */
 SR_PRIV int lwla_init_device(const struct sr_dev_inst *sdi)
 {
+       uint64_t value;
        struct dev_context *devc;
        int ret;
-       uint32_t value;
 
        devc = sdi->priv;
 
@@ -710,36 +710,23 @@ SR_PRIV int lwla_init_device(const struct sr_dev_inst *sdi)
        devc->cur_clock_config = CONF_CLOCK_NONE;
 
        ret = lwla_set_clock_config(sdi);
-
        if (ret != SR_OK)
                return ret;
 
-       ret = lwla_write_reg(sdi->conn, REG_LONG_ADDR, 100);
+       ret = lwla_read_long_reg(sdi->conn, 100, &value);
        if (ret != SR_OK)
                return ret;
 
-       ret = lwla_read_reg(sdi->conn, REG_LONG_STROBE, &value);
+       /* Ignore the value returned by the first read */
+       ret = lwla_read_long_reg(sdi->conn, 100, &value);
        if (ret != SR_OK)
                return ret;
-       sr_dbg("Received test word 0x%08X back.", value);
-       if (value != 0x12345678)
-               return SR_ERR;
 
-       ret = lwla_read_reg(sdi->conn, REG_LONG_HIGH, &value);
-       if (ret != SR_OK)
-               return ret;
-       sr_dbg("Received test word 0x%08X back.", value);
-       if (value != 0x12345678)
+       if (value != UINT64_C(0x1234567887654321)) {
+               sr_err("Received invalid test word 0x%16" PRIX64 ".", value);
                return SR_ERR;
-
-       ret = lwla_read_reg(sdi->conn, REG_LONG_LOW, &value);
-       if (ret != SR_OK)
-               return ret;
-       sr_dbg("Received test word 0x%08X back.", value);
-       if (value != 0x87654321)
-               return SR_ERR;
-
-       return ret;
+       }
+       return SR_OK;
 }
 
 /* Select the LWLA clock configuration.  If the clock source changed from