]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/pipistrello-ols/protocol.c
Add sr_dev_acquisition_stop(), factor out SR_ERR_DEV_CLOSED check.
[libsigrok.git] / src / hardware / pipistrello-ols / protocol.c
index f3bd15b0272d9c290d89f4c3af9d0438c508cd84..8276a9ed46f83aee4fb7ec4231ecc2a671a2e13f 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include "protocol.h"
 
-extern SR_PRIV struct sr_dev_driver p_ols_driver_info;
-
 SR_PRIV int write_shortcommand(struct dev_context *devc, uint8_t command)
 {
        uint8_t buf[1];
@@ -129,7 +128,7 @@ SR_PRIV int p_ols_open(struct dev_context *devc)
                goto err_open_close_ftdic;
        }
        sr_dbg("FTDI chip read data chunk size set successfully.");
-       
+
        return SR_OK;
 
 err_open_close_ftdic:
@@ -226,7 +225,6 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str
 
        sdi = g_malloc0(sizeof(struct sr_dev_inst));
        sdi->status = SR_ST_INACTIVE;
-       sdi->driver = &p_ols_driver_info;
        sdi->priv = devc;
 
        devname = g_string_new("");
@@ -299,7 +297,7 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str
                                /* what is this for? */
                                break;
                        case 0x03:
-                               /* Maximum sample rate (hz) */
+                               /* Maximum sample rate (Hz) */
                                devc->max_samplerate = tmp_int;
                                break;
                        case 0x04:
@@ -384,7 +382,6 @@ SR_PRIV int p_ols_set_samplerate(const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
-
 SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
 {
        struct dev_context *devc;
@@ -427,7 +424,7 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                if (bytes_read < 0) {
                        sr_err("Failed to read FTDI data (%d): %s.",
                               bytes_read, ftdi_get_error_string(devc->ftdic));
-                       sdi->driver->dev_acquisition_stop(sdi, sdi);
+                       sr_dev_acquisition_stop(sdi);
                        return FALSE;
                }
                if (bytes_read == 0) {
@@ -446,7 +443,7 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                        sr_spew("Received byte 0x%.2x.", byte);
 
                        if ((devc->flag_reg & FLAG_DEMUX) && (devc->flag_reg & FLAG_RLE)) {
-                               /* RLE in demux mode must be processed differently 
+                               /* RLE in demux mode must be processed differently
                                * since in this case the RLE encoder is operating on pairs of samples.
                                */
                                if (devc->num_bytes == num_channels * 2) {
@@ -502,11 +499,13 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                                                         * sample.
                                                         */
                                                        devc->tmp_sample[i] = devc->sample[j++];
-                                               } 
+                                               }
                                        }
                                        /* Clear out the most significant bit of the sample */
                                        devc->tmp_sample[devc->num_bytes - 1] &= 0x7f;
-                                       sr_spew("Expanded sample 1: 0x%.8x.", devc->tmp_sample);
+                                       sr_spew("Expanded sample 1: 0x%.2x%.2x%.2x%.2x.",
+                                               devc->tmp_sample[3], devc->tmp_sample[2],
+                                               devc->tmp_sample[1], devc->tmp_sample[0]);
 
                                        /* expand second sample */
                                        memset(devc->tmp_sample2, 0, 4);
@@ -518,11 +517,13 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                                                         * sample.
                                                         */
                                                        devc->tmp_sample2[i] = devc->sample[j++];
-                                               } 
+                                               }
                                        }
                                        /* Clear out the most significant bit of the sample */
                                        devc->tmp_sample2[devc->num_bytes - 1] &= 0x7f;
-                                       sr_spew("Expanded sample 2: 0x%.8x.", devc->tmp_sample2);
+                                       sr_spew("Expanded sample 2: 0x%.2x%.2x%.2x%.2x.",
+                                               devc->tmp_sample2[3], devc->tmp_sample2[2],
+                                               devc->tmp_sample2[1], devc->tmp_sample2[0]);
 
                                        /*
                                         * OLS sends its sample buffer backwards.
@@ -596,7 +597,7 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                                                                 * sample.
                                                                 */
                                                                devc->tmp_sample[i] = devc->sample[j++];
-                                                       } 
+                                                       }
                                                }
                                                memcpy(devc->sample, devc->tmp_sample, 4);
                                                sr_spew("Expanded sample: 0x%.8x.", sample);
@@ -620,8 +621,9 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                }
                return TRUE;
        } else {
-               do bytes_read = ftdi_read_data(devc->ftdic, devc->ftdi_buf, FTDI_BUF_SIZE);
-               while (bytes_read > 0);
+               do {
+                       bytes_read = ftdi_read_data(devc->ftdic, devc->ftdi_buf, FTDI_BUF_SIZE);
+               } while (bytes_read > 0);
 
                /*
                 * We've acquired all the samples we asked for -- we're done.
@@ -643,12 +645,12 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                                logic.unitsize = 4;
                                logic.data = devc->raw_sample_buf +
                                        (devc->limit_samples - devc->num_samples) * 4;
-                               sr_session_send(cb_data, &packet);
+                               sr_session_send(sdi, &packet);
                        }
 
                        /* Send the trigger. */
                        packet.type = SR_DF_TRIGGER;
-                       sr_session_send(cb_data, &packet);
+                       sr_session_send(sdi, &packet);
 
                        /* Send post-trigger samples. */
                        packet.type = SR_DF_LOGIC;
@@ -657,7 +659,7 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                        logic.unitsize = 4;
                        logic.data = devc->raw_sample_buf + devc->trigger_at * 4 +
                                (devc->limit_samples - devc->num_samples) * 4;
-                       sr_session_send(cb_data, &packet);
+                       sr_session_send(sdi, &packet);
                } else {
                        /* no trigger was used */
                        packet.type = SR_DF_LOGIC;
@@ -666,11 +668,11 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
                        logic.unitsize = 4;
                        logic.data = devc->raw_sample_buf +
                                (devc->limit_samples - devc->num_samples) * 4;
-                       sr_session_send(cb_data, &packet);
+                       sr_session_send(sdi, &packet);
                }
                g_free(devc->raw_sample_buf);
 
-               sdi->driver->dev_acquisition_stop(sdi, cb_data);
+               sr_dev_acquisition_stop(sdi);
        }
 
        return TRUE;