]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/beaglelogic/api.c
drivers: Fix behaviour when trying to set an invalid capture ratio.
[libsigrok.git] / src / hardware / beaglelogic / api.c
index 6bfb6df1080a2059db7936a813061ffb037834f0..b974010468f38dfb440198c150fe6bcb7e486286 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include "protocol.h"
 #include "beaglelogic.h"
 
@@ -47,10 +48,9 @@ static const int32_t soft_trigger_matches[] = {
        SR_TRIGGER_EDGE,
 };
 
-/* Channels are numbered 0-13 */
-SR_PRIV const char *beaglelogic_channel_names[] = {
-       "P8_45", "P8_46", "P8_43", "P8_44", "P8_41", "P8_42", "P8_39", "P8_40",
-       "P8_27", "P8_29", "P8_28", "P8_30", "P8_21", "P8_20", NULL,
+SR_PRIV const char *channel_names[] = {
+       "P8_45", "P8_46", "P8_43", "P8_44", "P8_41", "P8_42", "P8_39",
+       "P8_40", "P8_27", "P8_29", "P8_28", "P8_30", "P8_21", "P8_20",
 };
 
 /* Possible sample rates : 10 Hz to 100 MHz = (100 / x) MHz */
@@ -88,7 +88,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        int i, maxch;
 
        devices = NULL;
-       drvc = di->priv;
+       drvc = di->context;
        drvc->instances = NULL;
 
        /* Probe for /dev/beaglelogic */
@@ -136,7 +136,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        /* Fill the channels */
        for (i = 0; i < maxch; i++)
                sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
-                               beaglelogic_channel_names[i]);
+                               channel_names[i]);
 
        sdi->priv = devc;
        drvc->instances = g_slist_append(drvc->instances, sdi);
@@ -147,7 +147,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
 static GSList *dev_list(const struct sr_dev_driver *di)
 {
-       return ((struct drv_context *)(di->priv))->instances;
+       return ((struct drv_context *)(di->context))->instances;
 }
 
 static int dev_clear(const struct sr_dev_driver *di)
@@ -166,6 +166,7 @@ static int dev_open(struct sr_dev_inst *sdi)
        /* Set fd and local attributes */
        devc->pollfd.fd = devc->fd;
        devc->pollfd.events = G_IO_IN;
+       devc->pollfd.revents = 0;
 
        /* Get the default attributes */
        beaglelogic_get_samplerate(devc);
@@ -206,7 +207,7 @@ static int cleanup(const struct sr_dev_driver *di)
        GSList *l;
 
        /* unused driver */
-       if (!(drvc = di->priv))
+       if (!(drvc = di->context))
                return SR_OK;
 
        /* Clean up the instances */
@@ -226,25 +227,22 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc = sdi->priv;
+
        (void)cg;
 
        switch (key) {
        case SR_CONF_LIMIT_SAMPLES:
                *data = g_variant_new_uint64(devc->limit_samples);
                break;
-
        case SR_CONF_SAMPLERATE:
                *data = g_variant_new_uint64(devc->cur_samplerate);
                break;
-
        case SR_CONF_CAPTURE_RATIO:
                *data = g_variant_new_uint64(devc->capture_ratio);
                break;
-
        case SR_CONF_NUM_LOGIC_CHANNELS:
                *data = g_variant_new_uint32(g_slist_length(sdi->channels));
                break;
-
        default:
                return SR_ERR_NA;
        }
@@ -257,6 +255,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 {
        struct dev_context *devc = sdi->priv;
        uint64_t tmp_u64;
+
        (void)cg;
 
        if (sdi->status != SR_ST_ACTIVE)
@@ -266,7 +265,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        case SR_CONF_SAMPLERATE:
                devc->cur_samplerate = g_variant_get_uint64(data);
                return beaglelogic_set_samplerate(devc);
-
        case SR_CONF_LIMIT_SAMPLES:
                tmp_u64 = g_variant_get_uint64(data);
                devc->limit_samples = tmp_u64;
@@ -284,15 +282,11 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                                (SAMPLEUNIT_TO_BYTES(devc->sampleunit) * 1000000));
                }
                return beaglelogic_set_triggerflags(devc);
-
        case SR_CONF_CAPTURE_RATIO:
                devc->capture_ratio = g_variant_get_uint64(data);
-               if (devc->capture_ratio > 100) {
-                       devc->capture_ratio = 0;
+               if (devc->capture_ratio > 100)
                        return SR_ERR;
-               }
                return SR_OK;
-
        default:
                return SR_ERR_NA;
        }
@@ -308,7 +302,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
 
        (void)sdi;
-       (void)data;
        (void)cg;
 
        ret = SR_OK;
@@ -372,7 +365,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                if (devc->limit_samples > 0)
                        pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
                devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
-               if (devc->stl == NULL)
+               if (!devc->stl)
                        return SR_ERR_MALLOC;
                devc->trigger_fired = FALSE;
        } else
@@ -429,5 +422,5 @@ SR_PRIV struct sr_dev_driver beaglelogic_driver_info = {
        .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };