]> sigrok.org Git - libsigrok.git/blobdiff - hardware/asix-sigma/asix-sigma.c
Return SR_ERR_MALLOC upon allocation errors.
[libsigrok.git] / hardware / asix-sigma / asix-sigma.c
index 3538ae2cdaecc5a32a57a2b2dd13c4f2b304ce36..7bf50104d094bcbc52d04f64c6798723b0b5ccf8 100644 (file)
@@ -93,7 +93,6 @@ static const int hwcaps[] = {
        SR_HWCAP_LOGIC_ANALYZER,
        SR_HWCAP_SAMPLERATE,
        SR_HWCAP_CAPTURE_RATIO,
-       SR_HWCAP_PROBECONFIG,
 
        SR_HWCAP_LIMIT_MSEC,
        0,
@@ -407,7 +406,7 @@ static int bin2bitbang(const char *filename,
        return SR_OK;
 }
 
-static void clear_instances(void)
+static int clear_instances(void)
 {
        GSList *l;
        struct sr_dev_inst *sdi;
@@ -426,19 +425,24 @@ static void clear_instances(void)
                if (sdi->priv) {
                        devc = sdi->priv;
                        ftdi_free(&devc->ftdic);
-                       g_free(devc);
                }
                sr_dev_inst_free(sdi);
        }
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 static int hw_init(void)
 {
+       struct drv_context *drvc;
 
-       /* Nothing to do. */
+       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
+               sr_err("asix-sigma: driver context malloc failed.");
+               return SR_ERR_MALLOC;
+       }
+       adi->priv = drvc;
 
        return SR_OK;
 }
@@ -528,6 +532,15 @@ free:
        return NULL;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = adi->priv;
+
+       return drvc->instances;
+}
+
 static int upload_firmware(int firmware_idx, struct dev_context *devc)
 {
        int ret;
@@ -685,7 +698,7 @@ static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
  * The Sigma supports complex triggers using boolean expressions, but this
  * has not been implemented yet.
  */
-static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
+static int configure_probes(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc = sdi->priv;
        const struct sr_probe *probe;
@@ -695,7 +708,7 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
 
        memset(&devc->trigger, 0, sizeof(struct sigma_trigger));
 
-       for (l = probes; l; l = l->next) {
+       for (l = sdi->probes; l; l = l->next) {
                probe = (struct sr_probe *)l->data;
                probebit = 1 << (probe->index);
 
@@ -780,6 +793,9 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 static int hw_cleanup(void)
 {
 
+       if (!adi->priv)
+               return SR_OK;
+
        clear_instances();
 
        return SR_OK;
@@ -830,8 +846,6 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
 
        if (hwcap == SR_HWCAP_SAMPLERATE) {
                ret = set_samplerate(sdi, *(const uint64_t *)value);
-       } else if (hwcap == SR_HWCAP_PROBECONFIG) {
-               ret = configure_probes(sdi, value);
        } else if (hwcap == SR_HWCAP_LIMIT_MSEC) {
                devc->limit_msec = *(const uint64_t *)value;
                if (devc->limit_msec > 0)
@@ -1285,6 +1299,11 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        devc = sdi->priv;
 
+       if (configure_probes(sdi) != SR_OK) {
+               sr_err("asix-sigma: failed to configured probes");
+               return SR_ERR;
+       }
+
        /* If the samplerate has not been set, default to 200 kHz. */
        if (devc->cur_firmware == -1) {
                if ((ret = set_samplerate(sdi, SR_KHZ(200))) != SR_OK)
@@ -1409,6 +1428,8 @@ static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
        /* Avoid compiler warnings. */
        (void)cb_data;
 
+       sr_source_remove(0);
+
        if (!(devc = sdi->priv)) {
                sr_err("sigma: %s: sdi->priv was NULL", __func__);
                return SR_ERR_BUG;
@@ -1444,6 +1465,8 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = clear_instances,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,