]> sigrok.org Git - libsigrok.git/commitdiff
ols: fixed channel limit check
authorMatt Ranostay <redacted>
Thu, 29 Aug 2013 07:06:53 +0000 (00:06 -0700)
committerBert Vermeulen <redacted>
Fri, 30 Aug 2013 11:58:36 +0000 (13:58 +0200)
For demux mode we half the channels. Previous check method broke
the OLS randomly and but it in a bad state.

Signed-off-by: Matt Ranostay <redacted>
hardware/openbench-logic-sniffer/protocol.c
hardware/openbench-logic-sniffer/protocol.h

index 1caf7c1a8ca0c5681c14a1fb14ee407e4a1a6b7c..afd0dc6f7f54518c2561f7fee4fc6e67856e05bd 100644 (file)
@@ -74,6 +74,11 @@ SR_PRIV int ols_configure_probes(const struct sr_dev_inst *sdi)
                if (!probe->enabled)
                        continue;
 
+               if (probe->index >= devc->max_probes) {
+                       sr_err("Channels over the limit of %d\n", devc->max_probes);
+                       return SR_ERR;
+               }
+
                /*
                 * Set up the probe mask for later configuration into the
                 * flag register.
@@ -298,9 +303,11 @@ SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,
 
        if (samplerate > CLOCK_RATE) {
                devc->flag_reg |= FLAG_DEMUX;
+               devc->max_probes = NUM_PROBES / 2;
                devc->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
        } else {
                devc->flag_reg &= ~FLAG_DEMUX;
+               devc->max_probes = NUM_PROBES;
                devc->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1;
        }
 
@@ -341,7 +348,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
        GSList *l;
        uint32_t sample;
        int num_channels, offset, j;
-       unsigned int i, max_channels;
+       unsigned int i;
        unsigned char byte;
 
        drvc = di->priv;
@@ -379,14 +386,9 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
        }
 
        num_channels = 0;
-       max_channels = NUM_PROBES / (devc->flag_reg & FLAG_DEMUX ? 2 : 1);
 
        for (i = NUM_PROBES; i > 0x02; i /= 2) {
                if ((devc->flag_reg & i) == 0) {
-                       if (i >= max_channels) {
-                               sr_err("Channels over the limit of %d\n", max_channels);
-                               return FALSE;
-                       }
                        num_channels++;
                }
        }
@@ -450,7 +452,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
                                                 */
                                                devc->tmp_sample[i] = devc->sample[j++];
                                        } else if (devc->flag_reg & FLAG_DEMUX && (i > 2)) {
-                                               /* group 3 & 4 get added to 1 & 2 */
+                                               /* group 2 & 3 get added to 0 & 1 */
                                                devc->tmp_sample[i - 2] = devc->sample[j++];
                                        }
                                }
index 402c6246c56b7b861674db90a58e207999be5a17..b9e16e9c869d9f3cd8692e983a9b7aba002fdb9f 100644 (file)
@@ -82,6 +82,7 @@
 /* Private, per-device-instance driver context. */
 struct dev_context {
        /* Fixed device settings */
+       int max_probes;
        uint32_t max_samples;
        uint32_t max_samplerate;
        uint32_t protocol_version;