]> sigrok.org Git - libsigrok.git/blobdiff - hardware/link-mso19/protocol.c
GPL headers: Use correct project name.
[libsigrok.git] / hardware / link-mso19 / protocol.c
index 54d7f97dcb46aea9a9f26766a5d0c8e38f24b16d..fd9c0130975070b623f2cbb721309d0913a2db63 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2011 Daniel Ribeiro <drwyrm@gmail.com>
  * Copyright (C) 2012 Renato Caldas <rmsc@fe.up.pt>
  */
 
 #include "protocol.h"
-#include <arpa/inet.h>
+
+/* serial protocol */
+#define mso_trans(a, v) \
+       (((v) & 0x3f) | (((v) & 0xc0) << 6) | (((a) & 0xf) << 8) | \
+       ((~(v) & 0x20) << 1) | ((~(v) & 0x80) << 7))
+
+static const char mso_head[] = { 0x40, 0x4c, 0x44, 0x53, 0x7e };
+static const char mso_foot[] = { 0x7e };
 
 extern SR_PRIV struct sr_dev_driver link_mso19_driver_info;
 static struct sr_dev_driver *di = &link_mso19_driver_info;
@@ -47,7 +54,7 @@ SR_PRIV int mso_send_control_message(struct sr_serial_dev_inst *serial,
        p += sizeof(mso_head);
 
        for (i = 0; i < n; i++) {
-               *(uint16_t *) p = htons(payload[i]);
+               *(uint16_t *) p = g_htons(payload[i]);
                p += 2;
        }
        memcpy(p, mso_foot, sizeof(mso_foot));
@@ -68,7 +75,7 @@ ret:
        return ret;
 }
 
-SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
+SR_PRIV int mso_configure_trigger(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc = sdi->priv;
        uint16_t threshold_value = mso_calc_raw_from_mv(devc);
@@ -114,7 +121,7 @@ SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
        uint16_t ops[18];
        ops[0] = mso_trans(3, threshold_value & 0xff);
        //The trigger_config also holds the 2 MSB bits from the threshold value
-       ops[1] = mso_trans(4, trigger_config | (threshold_value >> 8) & 0x03);
+       ops[1] = mso_trans(4, trigger_config | ((threshold_value >> 8) & 0x03));
        ops[2] = mso_trans(5, devc->la_trigger);
        ops[3] = mso_trans(6, devc->la_trigger_mask);
        ops[4] = mso_trans(7, devc->trigger_holdoff[0]);
@@ -142,7 +149,7 @@ SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
        return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
 }
 
-SR_PRIV int mso_configure_threshold_level(struct sr_dev_inst *sdi)
+SR_PRIV int mso_configure_threshold_level(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc = sdi->priv;
 
@@ -158,7 +165,7 @@ SR_PRIV int mso_read_buffer(struct sr_dev_inst *sdi)
        return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
 }
 
-SR_PRIV int mso_arm(struct sr_dev_inst *sdi)
+SR_PRIV int mso_arm(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc = sdi->priv;
        uint16_t ops[] = {
@@ -183,7 +190,7 @@ SR_PRIV int mso_force_capture(struct sr_dev_inst *sdi)
        return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
 }
 
-SR_PRIV int mso_dac_out(struct sr_dev_inst *sdi, uint16_t val)
+SR_PRIV int mso_dac_out(const struct sr_dev_inst *sdi, uint16_t val)
 {
        struct dev_context *devc = sdi->priv;
        uint16_t ops[] = {
@@ -304,7 +311,7 @@ SR_PRIV int mso_clkrate_out(struct sr_serial_dev_inst *serial, uint16_t val)
        return mso_send_control_message(serial, ARRAY_AND_SIZE(ops));
 }
 
-SR_PRIV int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate)
+SR_PRIV int mso_configure_rate(const struct sr_dev_inst *sdi, uint32_t rate)
 {
        struct dev_context *devc = sdi->priv;
        unsigned int i;
@@ -326,7 +333,7 @@ SR_PRIV int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate)
        return ret;
 }
 
-SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t * info)
+SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t *info)
 {
        uint16_t ops[] = { mso_trans(REG_TRIGGER, 0) };
        int ret;
@@ -339,7 +346,8 @@ SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t * info)
        uint8_t buf = 0;
        if (serial_read(serial, &buf, 1) != 1)  /* FIXME: Need timeout */
                ret = SR_ERR;
-       *info = buf;
+       if (!info)
+               *info = buf;
 
        sr_dbg("Trigger state is: 0x%x.", *info);
        return ret;
@@ -404,6 +412,7 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
                /* FIXME: Need to do conversion to mV */
                analog_out[i] = (devc->buffer[i * 3] & 0x3f) |
                    ((devc->buffer[i * 3 + 1] & 0xf) << 6);
+               (void)analog_out;
                logic_out[i] = ((devc->buffer[i * 3 + 1] & 0x30) >> 4) |
                    ((devc->buffer[i * 3 + 2] & 0x3f) << 2);
        }
@@ -417,15 +426,6 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
 
        devc->num_samples += 1024;
 
-       // Dont bother fixing this yet, keep it "old style"
-       /*
-          packet.type = SR_DF_ANALOG;
-          packet.length = 1024;
-          packet.unitsize = sizeof(double);
-          packet.payload = analog_out;
-          sr_session_send(ctx->session_dev_id, &packet);
-        */
-
        if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
                sr_info("Requested number of samples reached.");
                sdi->driver->dev_acquisition_stop(sdi, cb_data);
@@ -439,7 +439,6 @@ SR_PRIV int mso_configure_probes(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct sr_probe *probe;
        GSList *l;
-       int probe_bit, stage, i;
        char *tc;
 
        devc = sdi->priv;