]> sigrok.org Git - libsigrok.git/blobdiff - hardware/link-mso19/link-mso19.c
sr: Make more symbols private via static/SR_PRIV.
[libsigrok.git] / hardware / link-mso19 / link-mso19.c
index ccc4d9907d37dd295c1b0a5c8bad121532bdb88e..1af3d2a9fddfc882da6197de1b6f1efe9e9e7a85 100644 (file)
@@ -2,6 +2,7 @@
  * This file is part of the sigrok project.
  *
  * Copyright (C) 2011 Daniel Ribeiro <drwyrm@gmail.com>
+ * Copyright (C) 2012 Renato Caldas <rmsc@fe.up.pt>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,7 +30,6 @@
 #include <arpa/inet.h>
 #include "sigrok.h"
 #include "sigrok-internal.h"
-#include "config.h"
 #include "link-mso19.h"
 
 #define USB_VENDOR "3195"
@@ -146,6 +146,7 @@ static int mso_reset_adc(struct sr_device_instance *sdi)
        ops[1] = mso_trans(REG_CTL1, mso->ctlbase1);
        mso->ctlbase1 |= BIT_CTL1_ADC_UNKNOWN4;
 
+       sr_dbg("Requesting ADC reset");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -157,6 +158,7 @@ static int mso_reset_fsm(struct sr_device_instance *sdi)
        mso->ctlbase1 |= BIT_CTL1_RESETFSM;
        ops[0] = mso_trans(REG_CTL1, mso->ctlbase1);
 
+       sr_dbg("Requesting ADC reset");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -165,11 +167,12 @@ static int mso_toggle_led(struct sr_device_instance *sdi, int state)
        struct mso *mso = sdi->priv;
        uint16_t ops[1];
 
-       mso->ctlbase1 &= BIT_CTL1_LED;
+       mso->ctlbase1 &= ~BIT_CTL1_LED;
        if (state)
                mso->ctlbase1 |= BIT_CTL1_LED;
        ops[0] = mso_trans(REG_CTL1, mso->ctlbase1);
 
+       sr_dbg("Requesting LED toggle");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -180,6 +183,7 @@ static int mso_check_trigger(struct sr_device_instance *sdi,
        char buf[1];
        int ret;
 
+       sr_dbg("Requesting trigger state");
        ret = mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
        if (info == NULL || ret != SR_OK)
                return ret;
@@ -189,6 +193,7 @@ static int mso_check_trigger(struct sr_device_instance *sdi,
                ret = SR_ERR;
        *info = buf[0];
 
+       sr_dbg("Trigger state is: 0x%x", *info);
        return ret;
 }
 
@@ -196,6 +201,7 @@ static int mso_read_buffer(struct sr_device_instance *sdi)
 {
        uint16_t ops[] = { mso_trans(REG_BUFFER, 0) };
 
+       sr_dbg("Requesting buffer dump");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -208,6 +214,7 @@ static int mso_arm(struct sr_device_instance *sdi)
                mso_trans(REG_CTL1, mso->ctlbase1),
        };
 
+       sr_dbg("Requesting trigger arm");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -219,6 +226,7 @@ static int mso_force_capture(struct sr_device_instance *sdi)
                mso_trans(REG_CTL1, mso->ctlbase1),
        };
 
+       sr_dbg("Requesting forced capture");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -231,6 +239,7 @@ static int mso_dac_out(struct sr_device_instance *sdi, uint16_t val)
                mso_trans(REG_CTL1, mso->ctlbase1 | BIT_CTL1_RESETADC),
        };
 
+       sr_dbg("Setting dac word to 0x%x", val);
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -241,6 +250,7 @@ static int mso_clkrate_out(struct sr_device_instance *sdi, uint16_t val)
                mso_trans(REG_CLKRATE2, val & 0xff),
        };
 
+       sr_dbg("Setting clkrate word to 0x%x", val);
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -323,18 +333,20 @@ static int mso_configure_trigger(struct sr_device_instance *sdi)
        ops[3] = mso_trans(4, (dso_trigger >> 8) & 0xff);
        ops[4] = mso_trans(11,
                        mso->dso_trigger_width / SR_HZ_TO_NS(mso->cur_rate));
-       ops[5] = mso_trans(REG_CTL2, (mso->ctlbase2 | BITS_CTL2_BANK(2)));
 
-       /* FIXME SPI/I2C Triggers */
-       ops[6] = mso_trans(0, 0);
-       ops[7] = mso_trans(1, 0);
-       ops[8] = mso_trans(2, 0);
-       ops[9] = mso_trans(3, 0);
-       ops[10] = mso_trans(4, 0xff);
-       ops[11] = mso_trans(5, 0xff);
-       ops[12] = mso_trans(6, 0xff);
-       ops[13] = mso_trans(7, 0xff);
-       ops[14] = mso_trans(8, mso->trigger_spimode);
+       /* Select the SPI/I2C trigger config bank */
+       ops[5] = mso_trans(REG_CTL2, (mso->ctlbase2 | BITS_CTL2_BANK(2)));
+       /* Configure the SPI/I2C protocol trigger */
+       ops[6] = mso_trans(REG_PT_WORD(0), mso->protocol_trigger.word[0]);
+       ops[7] = mso_trans(REG_PT_WORD(1), mso->protocol_trigger.word[1]);
+       ops[8] = mso_trans(REG_PT_WORD(2), mso->protocol_trigger.word[2]);
+       ops[9] = mso_trans(REG_PT_WORD(3), mso->protocol_trigger.word[3]);
+       ops[10] = mso_trans(REG_PT_MASK(0), mso->protocol_trigger.mask[0]);
+       ops[11] = mso_trans(REG_PT_MASK(1), mso->protocol_trigger.mask[1]);
+       ops[12] = mso_trans(REG_PT_MASK(2), mso->protocol_trigger.mask[2]);
+       ops[13] = mso_trans(REG_PT_MASK(3), mso->protocol_trigger.mask[3]);
+       ops[14] = mso_trans(REG_PT_SPIMODE, mso->protocol_trigger.spimode);
+       /* Select the default config bank */
        ops[15] = mso_trans(REG_CTL2, mso->ctlbase2);
 
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
@@ -460,8 +472,19 @@ static int hw_init(const char *deviceinfo)
                        goto err_free_mso;
                }
                sprintf(hwrev, "r%d", mso->hwrev);
+
                /* hardware initial state */
                mso->ctlbase1 = 0;
+               {
+                       /* Initialize the protocol trigger configuration */
+                       int i;
+                       for (i = 0; i < 4; i++)
+                       {
+                               mso->protocol_trigger.word[i] = 0;
+                               mso->protocol_trigger.mask[i] = 0xff;
+                       }
+                       mso->protocol_trigger.spimode = 0;
+               }
 
                sdi = sr_device_instance_new(devcnt, SR_ST_INITIALIZING,
                        manufacturer, product, hwrev);
@@ -506,7 +529,10 @@ static void hw_cleanup(void)
                if (sdi->serial->fd != -1)
                        serial_close(sdi->serial->fd);
                if (sdi->priv != NULL)
+               {
                        free(sdi->priv);
+                       sdi->priv = NULL;
+               }
                sr_device_instance_free(sdi);
        }
        g_slist_free(device_instances);
@@ -536,19 +562,21 @@ static int hw_opendev(int device_index)
        /* FIXME: discard serial buffer */
 
        mso_check_trigger(sdi, &mso->trigger_state);
-//     sr_warn("trigger state: %c", mso->trigger_state);
+       sr_dbg("trigger state: 0x%x", mso->trigger_state);
 
        ret = mso_reset_adc(sdi);
        if (ret != SR_OK)
                return ret;
 
        mso_check_trigger(sdi, &mso->trigger_state);
-//     sr_warn("trigger state: %c", mso->trigger_state);
+       sr_dbg("trigger state: 0x%x", mso->trigger_state);
 
 //     ret = mso_reset_fsm(sdi);
 //     if (ret != SR_OK)
 //             return ret;
 
+       sr_dbg("Finished %s", __func__);
+
 //     return SR_ERR;
        return SR_OK;
 }
@@ -569,6 +597,7 @@ static int hw_closedev(int device_index)
                sdi->status = SR_ST_INACTIVE;
        }
 
+       sr_dbg("finished %s", __func__);
        return SR_OK;
 }
 
@@ -797,7 +826,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
        sr_session_bus(session_device_id, &packet);
 }
 
-struct sr_device_plugin link_mso19_plugin_info = {
+SR_PRIV struct sr_device_plugin link_mso19_plugin_info = {
        .name = "link-mso19",
        .longname = "Link Instruments MSO-19",
        .api_version = 1,