]> sigrok.org Git - libsigrok.git/blobdiff - hardware/chronovu-la8/chronovu-la8.c
sr: rename all sr_device_instance_* functions to sr_dev_inst_*
[libsigrok.git] / hardware / chronovu-la8 / chronovu-la8.c
index 040e23fbffe3d9c911a80c27c7e19eae15896772..3c675e8e494e5ed4165100ed41e811bf70178c58 100644 (file)
@@ -21,6 +21,7 @@
 #include <ftdi.h>
 #include <glib.h>
 #include <string.h>
+#include <stdlib.h>
 #include "sigrok.h"
 #include "sigrok-internal.h"
 
@@ -135,7 +136,7 @@ static int capabilities[] = {
 
 /* Function prototypes. */
 static int la8_close_usb_reset_sequencer(struct la8 *la8);
-static void hw_stop_acquisition(int device_index, gpointer session_data);
+static int hw_stop_acquisition(int device_index, gpointer session_data);
 static int la8_reset(struct la8 *la8);
 
 static void fill_supported_samplerates_if_needed(void)
@@ -169,8 +170,8 @@ static int is_valid_samplerate(uint64_t samplerate)
                        return 1;
        }
 
-       sr_warn("la8: %s: invalid samplerate (%" PRIu64 "Hz)",
-               __func__, samplerate);
+       sr_err("la8: %s: invalid samplerate (%" PRIu64 "Hz)",
+              __func__, samplerate);
 
        return 0;
 }
@@ -236,12 +237,12 @@ static int la8_write(struct la8 *la8, uint8_t *buf, int size)
        bytes_written = ftdi_write_data(la8->ftdic, buf, size);
 
        if (bytes_written < 0) {
-               sr_warn("la8: %s: ftdi_write_data: (%d) %s", __func__,
-                       bytes_written, ftdi_get_error_string(la8->ftdic));
+               sr_err("la8: %s: ftdi_write_data: (%d) %s", __func__,
+                      bytes_written, ftdi_get_error_string(la8->ftdic));
                (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
        } else if (bytes_written != size) {
-               sr_warn("la8: %s: bytes to write: %d, bytes written: %d",
-                       __func__, size, bytes_written);
+               sr_err("la8: %s: bytes to write: %d, bytes written: %d",
+                      __func__, size, bytes_written);
                (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
        }
 
@@ -283,11 +284,11 @@ static int la8_read(struct la8 *la8, uint8_t *buf, int size)
        bytes_read = ftdi_read_data(la8->ftdic, buf, size);
 
        if (bytes_read < 0) {
-               sr_warn("la8: %s: ftdi_read_data: (%d) %s", __func__,
-                       bytes_read, ftdi_get_error_string(la8->ftdic));
+               sr_err("la8: %s: ftdi_read_data: (%d) %s", __func__,
+                      bytes_read, ftdi_get_error_string(la8->ftdic));
        } else if (bytes_read != size) {
-               // sr_warn("la8: %s: bytes to read: %d, bytes read: %d",
-               //      __func__, size, bytes_read);
+               // sr_err("la8: %s: bytes to read: %d, bytes read: %d",
+               //        __func__, size, bytes_read);
        }
 
        return bytes_read;
@@ -308,8 +309,8 @@ static int la8_close(struct la8 *la8)
        }
 
        if ((ret = ftdi_usb_close(la8->ftdic)) < 0) {
-               sr_warn("la8: %s: ftdi_usb_close: (%d) %s",
-                       __func__, ret, ftdi_get_error_string(la8->ftdic));
+               sr_err("la8: %s: ftdi_usb_close: (%d) %s",
+                      __func__, ret, ftdi_get_error_string(la8->ftdic));
        }
 
        return ret;
@@ -350,14 +351,14 @@ static int la8_close_usb_reset_sequencer(struct la8 *la8)
 
                /* Log errors, but ignore them (i.e., don't abort). */
                if ((ret = ftdi_usb_purge_buffers(la8->ftdic)) < 0)
-                       sr_warn("la8: %s: ftdi_usb_purge_buffers: (%d) %s",
+                       sr_err("la8: %s: ftdi_usb_purge_buffers: (%d) %s",
                            __func__, ret, ftdi_get_error_string(la8->ftdic));
                if ((ret = ftdi_usb_reset(la8->ftdic)) < 0)
-                       sr_warn("la8: %s: ftdi_usb_reset: (%d) %s", __func__,
-                               ret, ftdi_get_error_string(la8->ftdic));
+                       sr_err("la8: %s: ftdi_usb_reset: (%d) %s", __func__,
+                              ret, ftdi_get_error_string(la8->ftdic));
                if ((ret = ftdi_usb_close(la8->ftdic)) < 0)
-                       sr_warn("la8: %s: ftdi_usb_close: (%d) %s", __func__,
-                               ret, ftdi_get_error_string(la8->ftdic));
+                       sr_err("la8: %s: ftdi_usb_close: (%d) %s", __func__,
+                              ret, ftdi_get_error_string(la8->ftdic));
        } else {
                sr_spew("la8: %s: usb_dev was NULL, nothing to do", __func__);
        }
@@ -526,7 +527,7 @@ static int hw_init(const char *deviceinfo)
        sr_dbg("la8: found device");
 
        /* Register the device with libsigrok. */
-       sdi = sr_device_instance_new(0, SR_ST_INITIALIZING,
+       sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING,
                        USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION);
        if (!sdi) {
                sr_err("la8: %s: sr_device_instance_new failed", __func__);
@@ -563,7 +564,7 @@ static int hw_opendev(int device_index)
        struct sr_device_instance *sdi;
        struct la8 *la8;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+       if (!(sdi = sr_get_dev_inst(device_instances, device_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
                return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
@@ -650,7 +651,7 @@ static int hw_closedev(int device_index)
        struct sr_device_instance *sdi;
        struct la8 *la8;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+       if (!(sdi = sr_get_dev_inst(device_instances, device_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
                return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
@@ -678,17 +679,20 @@ static int hw_closedev(int device_index)
        return SR_OK;
 }
 
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        GSList *l;
        struct sr_device_instance *sdi;
+       int ret = SR_OK;
 
        sr_spew("la8: entering %s", __func__);
 
        /* Properly close all devices. */
        for (l = device_instances; l; l = l->next) {
-               if ((sdi = l->data) == NULL) {
-                       sr_warn("la8: %s: sdi was NULL, continuing", __func__);
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("la8: %s: sdi was NULL, continuing", __func__);
+                       ret = SR_ERR_BUG;
                        continue;
                }
 #if 0
@@ -697,15 +701,17 @@ static void hw_cleanup(void)
                 * TODO: Document who is supposed to free this, and when.
                 */
                if (sdi->priv != NULL)
-                       free(sdi->priv);
+                       g_free(sdi->priv);
                else
-                       sr_warn("la8: %s: sdi->priv was NULL, nothing "
-                               "to do", __func__);
+                       sr_err("la8: %s: sdi->priv was NULL, nothing "
+                              "to do", __func__);
 #endif
-               sr_device_instance_free(sdi); /* Returns void. */
+               sr_dev_inst_free(sdi); /* Returns void. */
        }
        g_slist_free(device_instances); /* Returns void. */
        device_instances = NULL;
+
+       return ret;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
@@ -716,7 +722,7 @@ static void *hw_get_device_info(int device_index, int device_info_id)
 
        sr_spew("la8: entering %s", __func__);
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+       if (!(sdi = sr_get_dev_inst(device_instances, device_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
                return NULL;
        }
@@ -760,8 +766,8 @@ static int hw_get_status(int device_index)
 {
        struct sr_device_instance *sdi;
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
-               sr_warn("la8: %s: sdi was NULL, device not found", __func__);
+       if (!(sdi = sr_get_dev_inst(device_instances, device_index))) {
+               sr_err("la8: %s: sdi was NULL, device not found", __func__);
                return SR_ST_NOT_FOUND;
        }
 
@@ -784,7 +790,7 @@ static int hw_set_configuration(int device_index, int capability, void *value)
 
        sr_spew("la8: entering %s", __func__);
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+       if (!(sdi = sr_get_dev_inst(device_instances, device_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
                return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
@@ -869,7 +875,7 @@ static int la8_read_block(struct la8 *la8)
 
        /* Check if block read was successful or a timeout occured. */
        if (bytes_read != BS) {
-               sr_warn("la8: %s: trigger timed out", __func__);
+               sr_err("la8: %s: trigger timed out", __func__);
                (void) la8_reset(la8); /* Ignore errors. */
                return SR_ERR;
        }
@@ -1038,7 +1044,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
 
        sr_spew("la8: entering %s", __func__);
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+       if (!(sdi = sr_get_dev_inst(device_instances, device_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
                return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
@@ -1088,7 +1094,6 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        gettimeofday(&header.starttime, NULL);
        header.samplerate = la8->cur_samplerate;
        header.num_logic_probes = NUM_PROBES;
-       header.num_analog_probes = 0;
        sr_session_bus(session_data, &packet);
 
        /* Time when we should be done (for detecting trigger timeouts). */
@@ -1103,7 +1108,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        return SR_OK;
 }
 
-static void hw_stop_acquisition(int device_index, gpointer session_data)
+static int hw_stop_acquisition(int device_index, gpointer session_data)
 {
        struct sr_device_instance *sdi;
        struct la8 *la8;
@@ -1111,23 +1116,25 @@ static void hw_stop_acquisition(int device_index, gpointer session_data)
 
        sr_dbg("la8: stopping acquisition");
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+       if (!(sdi = sr_get_dev_inst(device_instances, device_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
-               return;
+               return SR_ERR_BUG;
        }
 
        if (!(la8 = sdi->priv)) {
                sr_err("la8: %s: sdi->priv was NULL", __func__);
-               return;
+               return SR_ERR_BUG;
        }
 
        /* Send end packet to the session bus. */
        sr_dbg("la8: %s: sending SR_DF_END", __func__);
        packet.type = SR_DF_END;
        sr_session_bus(session_data, &packet);
+
+       return SR_OK;
 }
 
-struct sr_device_plugin chronovu_la8_plugin_info = {
+SR_PRIV struct sr_device_plugin chronovu_la8_plugin_info = {
        .name = "chronovu-la8",
        .longname = "ChronoVu LA8",
        .api_version = 1,