2011-01-10 17:15:51 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the sigrok project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Daniel Ribeiro <drwyrm@gmail.com>
|
2012-01-17 13:41:38 +00:00
|
|
|
* Copyright (C) 2012 Renato Caldas <rmsc@fe.up.pt>
|
2011-01-10 17:15:51 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2011-01-10 22:20:37 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-01-10 17:15:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <libudev.h>
|
|
|
|
#include <arpa/inet.h>
|
2012-07-04 22:55:07 +00:00
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
2011-01-10 17:15:51 +00:00
|
|
|
#include "link-mso19.h"
|
|
|
|
|
|
|
|
#define USB_VENDOR "3195"
|
|
|
|
#define USB_PRODUCT "f190"
|
|
|
|
|
2011-12-29 16:04:31 +00:00
|
|
|
#define NUM_PROBES 8
|
|
|
|
|
2012-05-07 12:57:43 +00:00
|
|
|
static const int hwcaps[] = {
|
2011-01-30 16:58:41 +00:00
|
|
|
SR_HWCAP_LOGIC_ANALYZER,
|
|
|
|
// SR_HWCAP_OSCILLOSCOPE,
|
|
|
|
// SR_HWCAP_PAT_GENERATOR,
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2011-01-30 16:58:41 +00:00
|
|
|
SR_HWCAP_SAMPLERATE,
|
|
|
|
// SR_HWCAP_CAPTURE_RATIO,
|
|
|
|
SR_HWCAP_LIMIT_SAMPLES,
|
2011-01-10 17:15:51 +00:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2012-02-28 00:09:29 +00:00
|
|
|
/*
|
|
|
|
* Probes are numbered 0 to 7.
|
|
|
|
*
|
|
|
|
* See also: http://www.linkinstruments.com/images/mso19_1113.gif
|
|
|
|
*/
|
2011-12-29 16:04:31 +00:00
|
|
|
static const char *probe_names[NUM_PROBES + 1] = {
|
|
|
|
"0",
|
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
"3",
|
|
|
|
"4",
|
|
|
|
"5",
|
|
|
|
"6",
|
|
|
|
"7",
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2012-05-07 14:07:06 +00:00
|
|
|
static const uint64_t supported_samplerates[] = {
|
2011-02-22 17:05:16 +00:00
|
|
|
SR_HZ(100),
|
|
|
|
SR_HZ(200),
|
|
|
|
SR_HZ(500),
|
2011-02-22 16:57:03 +00:00
|
|
|
SR_KHZ(1),
|
|
|
|
SR_KHZ(2),
|
|
|
|
SR_KHZ(5),
|
|
|
|
SR_KHZ(10),
|
|
|
|
SR_KHZ(20),
|
|
|
|
SR_KHZ(50),
|
|
|
|
SR_KHZ(100),
|
|
|
|
SR_KHZ(200),
|
|
|
|
SR_KHZ(500),
|
|
|
|
SR_MHZ(1),
|
|
|
|
SR_MHZ(2),
|
|
|
|
SR_MHZ(5),
|
|
|
|
SR_MHZ(10),
|
|
|
|
SR_MHZ(20),
|
|
|
|
SR_MHZ(50),
|
|
|
|
SR_MHZ(100),
|
|
|
|
SR_MHZ(200),
|
|
|
|
0,
|
2011-01-10 17:15:51 +00:00
|
|
|
};
|
|
|
|
|
2012-05-07 14:07:06 +00:00
|
|
|
static const struct sr_samplerates samplerates = {
|
2012-03-24 21:32:47 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2011-02-22 16:57:03 +00:00
|
|
|
supported_samplerates,
|
2011-01-10 17:15:51 +00:00
|
|
|
};
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static GSList *dev_insts = NULL;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_send_control_message(struct sr_dev_inst *sdi,
|
|
|
|
uint16_t payload[], int n)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
|
|
|
int fd = sdi->serial->fd;
|
|
|
|
int i, w, ret, s = n * 2 + sizeof(mso_head) + sizeof(mso_foot);
|
|
|
|
char *p, *buf;
|
|
|
|
|
2011-04-17 08:22:10 +00:00
|
|
|
ret = SR_ERR;
|
|
|
|
|
2011-01-10 17:15:51 +00:00
|
|
|
if (fd < 0)
|
|
|
|
goto ret;
|
|
|
|
|
2011-04-17 08:22:10 +00:00
|
|
|
if (!(buf = g_try_malloc(s))) {
|
|
|
|
sr_err("mso19: %s: buf malloc failed", __func__);
|
|
|
|
ret = SR_ERR_MALLOC;
|
2011-01-10 17:15:51 +00:00
|
|
|
goto ret;
|
2011-04-17 08:22:10 +00:00
|
|
|
}
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
p = buf;
|
|
|
|
memcpy(p, mso_head, sizeof(mso_head));
|
|
|
|
p += sizeof(mso_head);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
*(uint16_t *) p = htons(payload[i]);
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
memcpy(p, mso_foot, sizeof(mso_foot));
|
|
|
|
|
|
|
|
w = 0;
|
|
|
|
while (w < s) {
|
2011-01-11 23:43:00 +00:00
|
|
|
ret = serial_write(fd, buf + w, s - w);
|
2011-01-10 17:15:51 +00:00
|
|
|
if (ret < 0) {
|
2011-01-29 15:23:12 +00:00
|
|
|
ret = SR_ERR;
|
2011-01-10 17:15:51 +00:00
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
w += ret;
|
|
|
|
}
|
2011-01-29 15:23:12 +00:00
|
|
|
ret = SR_OK;
|
2011-01-10 17:15:51 +00:00
|
|
|
free:
|
2011-04-17 08:22:10 +00:00
|
|
|
g_free(buf);
|
2011-01-10 17:15:51 +00:00
|
|
|
ret:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_reset_adc(struct sr_dev_inst *sdi)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint16_t ops[2];
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
ops[0] = mso_trans(REG_CTL1, (ctx->ctlbase1 | BIT_CTL1_RESETADC));
|
|
|
|
ops[1] = mso_trans(REG_CTL1, ctx->ctlbase1);
|
|
|
|
ctx->ctlbase1 |= BIT_CTL1_ADC_UNKNOWN4;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Requesting ADC reset");
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_reset_fsm(struct sr_dev_inst *sdi)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint16_t ops[1];
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->ctlbase1 |= BIT_CTL1_RESETFSM;
|
|
|
|
ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Requesting ADC reset");
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_toggle_led(struct sr_dev_inst *sdi, int state)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint16_t ops[1];
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->ctlbase1 &= ~BIT_CTL1_LED;
|
2011-01-10 17:15:51 +00:00
|
|
|
if (state)
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->ctlbase1 |= BIT_CTL1_LED;
|
|
|
|
ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Requesting LED toggle");
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_check_trigger(struct sr_dev_inst *sdi, uint8_t *info)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
|
|
|
uint16_t ops[] = { mso_trans(REG_TRIGGER, 0) };
|
|
|
|
char buf[1];
|
|
|
|
int ret;
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Requesting trigger state");
|
2011-01-10 17:15:51 +00:00
|
|
|
ret = mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
2011-01-29 15:23:12 +00:00
|
|
|
if (info == NULL || ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
buf[0] = 0;
|
2011-01-11 23:43:00 +00:00
|
|
|
if (serial_read(sdi->serial->fd, buf, 1) != 1) /* FIXME: Need timeout */
|
2011-01-29 15:23:12 +00:00
|
|
|
ret = SR_ERR;
|
2011-01-10 17:15:51 +00:00
|
|
|
*info = buf[0];
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Trigger state is: 0x%x", *info);
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_read_buffer(struct sr_dev_inst *sdi)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
|
|
|
uint16_t ops[] = { mso_trans(REG_BUFFER, 0) };
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Requesting buffer dump");
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_arm(struct sr_dev_inst *sdi)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint16_t ops[] = {
|
2012-02-18 17:07:42 +00:00
|
|
|
mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_RESETFSM),
|
|
|
|
mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_ARM),
|
|
|
|
mso_trans(REG_CTL1, ctx->ctlbase1),
|
2011-01-10 17:15:51 +00:00
|
|
|
};
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Requesting trigger arm");
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_force_capture(struct sr_dev_inst *sdi)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint16_t ops[] = {
|
2012-02-18 17:07:42 +00:00
|
|
|
mso_trans(REG_CTL1, ctx->ctlbase1 | 8),
|
|
|
|
mso_trans(REG_CTL1, ctx->ctlbase1),
|
2011-01-10 17:15:51 +00:00
|
|
|
};
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Requesting forced capture");
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_dac_out(struct sr_dev_inst *sdi, uint16_t val)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint16_t ops[] = {
|
|
|
|
mso_trans(REG_DAC1, (val >> 8) & 0xff),
|
|
|
|
mso_trans(REG_DAC2, val & 0xff),
|
2012-02-18 17:07:42 +00:00
|
|
|
mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_RESETADC),
|
2011-01-10 17:15:51 +00:00
|
|
|
};
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Setting dac word to 0x%x", val);
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_clkrate_out(struct sr_dev_inst *sdi, uint16_t val)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
|
|
|
uint16_t ops[] = {
|
|
|
|
mso_trans(REG_CLKRATE1, (val >> 8) & 0xff),
|
|
|
|
mso_trans(REG_CLKRATE2, val & 0xff),
|
|
|
|
};
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Setting clkrate word to 0x%x", val);
|
2011-01-10 17:15:51 +00:00
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
unsigned int i;
|
2011-01-29 15:23:12 +00:00
|
|
|
int ret = SR_ERR;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(rate_map); i++) {
|
|
|
|
if (rate_map[i].rate == rate) {
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->ctlbase2 = rate_map[i].slowmode;
|
2011-01-10 17:15:51 +00:00
|
|
|
ret = mso_clkrate_out(sdi, rate_map[i].val);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret == SR_OK)
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->cur_rate = rate;
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
static inline uint16_t mso_calc_raw_from_mv(struct context *ctx)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
|
|
|
return (uint16_t) (0x200 -
|
2012-02-18 17:07:42 +00:00
|
|
|
((ctx->dso_trigger_voltage / ctx->dso_probe_attn) /
|
|
|
|
ctx->vbit));
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_configure_trigger(struct sr_dev_inst *sdi)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint16_t ops[16];
|
2012-02-18 17:07:42 +00:00
|
|
|
uint16_t dso_trigger = mso_calc_raw_from_mv(ctx);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
dso_trigger &= 0x3ff;
|
2012-02-18 17:07:42 +00:00
|
|
|
if ((!ctx->trigger_slope && ctx->trigger_chan == 1) ||
|
|
|
|
(ctx->trigger_slope &&
|
|
|
|
(ctx->trigger_chan == 0 ||
|
|
|
|
ctx->trigger_chan == 2 ||
|
|
|
|
ctx->trigger_chan == 3)))
|
2011-01-10 17:15:51 +00:00
|
|
|
dso_trigger |= 0x400;
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
switch (ctx->trigger_chan) {
|
2011-01-10 17:15:51 +00:00
|
|
|
case 1:
|
|
|
|
dso_trigger |= 0xe000;
|
|
|
|
case 2:
|
|
|
|
dso_trigger |= 0x4000;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
dso_trigger |= 0x2000;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
dso_trigger |= 0xa000;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
dso_trigger |= 0x8000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
switch (ctx->trigger_outsrc) {
|
2011-01-10 17:15:51 +00:00
|
|
|
case 1:
|
|
|
|
dso_trigger |= 0x800;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
dso_trigger |= 0x1000;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
dso_trigger |= 0x1800;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
ops[0] = mso_trans(5, ctx->la_trigger);
|
|
|
|
ops[1] = mso_trans(6, ctx->la_trigger_mask);
|
2011-01-10 17:15:51 +00:00
|
|
|
ops[2] = mso_trans(3, dso_trigger & 0xff);
|
|
|
|
ops[3] = mso_trans(4, (dso_trigger >> 8) & 0xff);
|
|
|
|
ops[4] = mso_trans(11,
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->dso_trigger_width / SR_HZ_TO_NS(ctx->cur_rate));
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-01-17 13:41:38 +00:00
|
|
|
/* Select the SPI/I2C trigger config bank */
|
2012-02-18 17:07:42 +00:00
|
|
|
ops[5] = mso_trans(REG_CTL2, (ctx->ctlbase2 | BITS_CTL2_BANK(2)));
|
2012-01-17 13:41:38 +00:00
|
|
|
/* Configure the SPI/I2C protocol trigger */
|
2012-02-18 17:07:42 +00:00
|
|
|
ops[6] = mso_trans(REG_PT_WORD(0), ctx->protocol_trigger.word[0]);
|
|
|
|
ops[7] = mso_trans(REG_PT_WORD(1), ctx->protocol_trigger.word[1]);
|
|
|
|
ops[8] = mso_trans(REG_PT_WORD(2), ctx->protocol_trigger.word[2]);
|
|
|
|
ops[9] = mso_trans(REG_PT_WORD(3), ctx->protocol_trigger.word[3]);
|
|
|
|
ops[10] = mso_trans(REG_PT_MASK(0), ctx->protocol_trigger.mask[0]);
|
|
|
|
ops[11] = mso_trans(REG_PT_MASK(1), ctx->protocol_trigger.mask[1]);
|
|
|
|
ops[12] = mso_trans(REG_PT_MASK(2), ctx->protocol_trigger.mask[2]);
|
|
|
|
ops[13] = mso_trans(REG_PT_MASK(3), ctx->protocol_trigger.mask[3]);
|
|
|
|
ops[14] = mso_trans(REG_PT_SPIMODE, ctx->protocol_trigger.spimode);
|
2012-01-17 13:41:38 +00:00
|
|
|
/* Select the default config bank */
|
2012-02-18 17:07:42 +00:00
|
|
|
ops[15] = mso_trans(REG_CTL2, ctx->ctlbase2);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
|
|
|
|
}
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
static int mso_configure_threshold_level(struct sr_dev_inst *sdi)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
return mso_dac_out(sdi, la_threshold_map[ctx->la_threshold]);
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mso_parse_serial(const char *iSerial, const char *iProduct,
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
|
|
|
unsigned int u1, u2, u3, u4, u5, u6;
|
|
|
|
|
|
|
|
iProduct = iProduct;
|
|
|
|
/* FIXME: This code is in the original app, but I think its
|
|
|
|
* used only for the GUI */
|
|
|
|
/* if (strstr(iProduct, "REV_02") || strstr(iProduct, "REV_03"))
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->num_sample_rates = 0x16;
|
2011-01-10 17:15:51 +00:00
|
|
|
else
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->num_sample_rates = 0x10; */
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
/* parse iSerial */
|
|
|
|
if (iSerial[0] != '4' || sscanf(iSerial, "%5u%3u%3u%1u%1u%6u",
|
|
|
|
&u1, &u2, &u3, &u4, &u5, &u6) != 6)
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_ERR;
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->hwmodel = u4;
|
|
|
|
ctx->hwrev = u5;
|
|
|
|
ctx->serial = u6;
|
|
|
|
ctx->vbit = u1 / 10000;
|
|
|
|
if (ctx->vbit == 0)
|
|
|
|
ctx->vbit = 4.19195;
|
|
|
|
ctx->dac_offset = u2;
|
|
|
|
if (ctx->dac_offset == 0)
|
|
|
|
ctx->dac_offset = 0x1ff;
|
|
|
|
ctx->offset_range = u3;
|
|
|
|
if (ctx->offset_range == 0)
|
|
|
|
ctx->offset_range = 0x17d;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: There is more code on the original software to handle
|
|
|
|
* bigger iSerial strings, but as I can't test on my device
|
|
|
|
* I will not implement it yet
|
|
|
|
*/
|
|
|
|
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_OK;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 10:55:46 +00:00
|
|
|
static int hw_init(void)
|
2012-07-05 09:27:48 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Nothing to do. */
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hw_scan(void)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2011-01-10 17:15:51 +00:00
|
|
|
int devcnt = 0;
|
|
|
|
struct udev *udev;
|
|
|
|
struct udev_enumerate *enumerate;
|
2012-02-17 21:25:01 +00:00
|
|
|
struct udev_list_entry *devs, *dev_list_entry;
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
/* It's easier to map usb<->serial using udev */
|
|
|
|
/*
|
|
|
|
* FIXME: On windows we can get the same information from the
|
|
|
|
* registry, add an #ifdef here later
|
|
|
|
*/
|
|
|
|
udev = udev_new();
|
|
|
|
if (!udev) {
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_err("mso19: Failed to initialize udev.");
|
2011-01-10 17:15:51 +00:00
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
enumerate = udev_enumerate_new(udev);
|
|
|
|
udev_enumerate_add_match_subsystem(enumerate, "usb-serial");
|
|
|
|
udev_enumerate_scan_devices(enumerate);
|
2012-02-17 21:25:01 +00:00
|
|
|
devs = udev_enumerate_get_list_entry(enumerate);
|
|
|
|
udev_list_entry_foreach(dev_list_entry, devs) {
|
2011-01-10 17:15:51 +00:00
|
|
|
const char *syspath, *sysname, *idVendor, *idProduct,
|
|
|
|
*iSerial, *iProduct;
|
|
|
|
char path[32], manufacturer[32], product[32], hwrev[32];
|
|
|
|
struct udev_device *dev, *parent;
|
|
|
|
size_t s;
|
|
|
|
|
|
|
|
syspath = udev_list_entry_get_name(dev_list_entry);
|
|
|
|
dev = udev_device_new_from_syspath(udev, syspath);
|
|
|
|
sysname = udev_device_get_sysname(dev);
|
|
|
|
parent = udev_device_get_parent_with_subsystem_devtype(
|
|
|
|
dev, "usb", "usb_device");
|
|
|
|
if (!parent) {
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_err("mso19: Unable to find parent usb device for %s",
|
2012-02-11 19:06:46 +00:00
|
|
|
sysname);
|
2011-01-10 17:15:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
idVendor = udev_device_get_sysattr_value(parent, "idVendor");
|
|
|
|
idProduct = udev_device_get_sysattr_value(parent, "idProduct");
|
|
|
|
if (strcmp(USB_VENDOR, idVendor)
|
|
|
|
|| strcmp(USB_PRODUCT, idProduct))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
iSerial = udev_device_get_sysattr_value(parent, "serial");
|
|
|
|
iProduct = udev_device_get_sysattr_value(parent, "product");
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "/dev/%s", sysname);
|
|
|
|
|
|
|
|
s = strcspn(iProduct, " ");
|
|
|
|
if (s > sizeof(product) ||
|
|
|
|
strlen(iProduct) - s > sizeof(manufacturer)) {
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_err("mso19: Could not parse iProduct: %s", iProduct);
|
2011-01-10 17:15:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strncpy(product, iProduct, s);
|
|
|
|
product[s] = 0;
|
|
|
|
strcpy(manufacturer, iProduct + s);
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
|
|
|
|
sr_err("mso19: %s: ctx malloc failed", __func__);
|
2011-04-17 08:22:10 +00:00
|
|
|
continue; /* TODO: Errors handled correctly? */
|
|
|
|
}
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
if (mso_parse_serial(iSerial, iProduct, ctx) != SR_OK) {
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_err("mso19: Invalid iSerial: %s", iSerial);
|
2012-02-18 17:07:42 +00:00
|
|
|
goto err_free_ctx;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
2012-02-18 17:07:42 +00:00
|
|
|
sprintf(hwrev, "r%d", ctx->hwrev);
|
2012-01-17 13:41:38 +00:00
|
|
|
|
2011-01-10 17:15:51 +00:00
|
|
|
/* hardware initial state */
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->ctlbase1 = 0;
|
2012-01-17 13:41:38 +00:00
|
|
|
{
|
|
|
|
/* Initialize the protocol trigger configuration */
|
|
|
|
int i;
|
2012-02-17 18:40:01 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->protocol_trigger.word[i] = 0;
|
|
|
|
ctx->protocol_trigger.mask[i] = 0xff;
|
2012-01-17 13:41:38 +00:00
|
|
|
}
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->protocol_trigger.spimode = 0;
|
2012-01-17 13:41:38 +00:00
|
|
|
}
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-13 14:31:59 +00:00
|
|
|
sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
|
2012-02-17 18:40:01 +00:00
|
|
|
manufacturer, product, hwrev);
|
2011-01-10 17:15:51 +00:00
|
|
|
if (!sdi) {
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_err("mso19: Unable to create device instance for %s",
|
2012-02-11 19:06:46 +00:00
|
|
|
sysname);
|
2012-02-18 17:07:42 +00:00
|
|
|
goto err_free_ctx;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* save a pointer to our private instance data */
|
2012-02-18 17:07:42 +00:00
|
|
|
sdi->priv = ctx;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-13 14:31:59 +00:00
|
|
|
sdi->serial = sr_serial_dev_inst_new(path, -1);
|
2011-01-10 17:15:51 +00:00
|
|
|
if (!sdi->serial)
|
2012-02-17 20:02:52 +00:00
|
|
|
goto err_dev_inst_free;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
dev_insts = g_slist_append(dev_insts, sdi);
|
2011-01-10 17:15:51 +00:00
|
|
|
devcnt++;
|
|
|
|
continue;
|
|
|
|
|
2012-02-17 20:02:52 +00:00
|
|
|
err_dev_inst_free:
|
2012-02-13 14:31:59 +00:00
|
|
|
sr_dev_inst_free(sdi);
|
2012-02-18 17:07:42 +00:00
|
|
|
err_free_ctx:
|
|
|
|
g_free(ctx);
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
udev_enumerate_unref(enumerate);
|
|
|
|
udev_unref(udev);
|
|
|
|
|
|
|
|
ret:
|
|
|
|
return devcnt;
|
|
|
|
}
|
|
|
|
|
2012-02-12 19:52:42 +00:00
|
|
|
static int hw_cleanup(void)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
|
|
|
GSList *l;
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2012-02-14 11:26:22 +00:00
|
|
|
int ret;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-14 11:26:22 +00:00
|
|
|
ret = SR_OK;
|
2011-01-10 17:15:51 +00:00
|
|
|
/* Properly close all devices. */
|
2012-02-17 20:02:52 +00:00
|
|
|
for (l = dev_insts; l; l = l->next) {
|
2012-02-12 19:52:42 +00:00
|
|
|
if (!(sdi = l->data)) {
|
|
|
|
/* Log error, but continue cleaning up the rest. */
|
|
|
|
sr_err("mso19: %s: sdi was NULL, continuing", __func__);
|
|
|
|
ret = SR_ERR_BUG;
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-10 17:15:51 +00:00
|
|
|
if (sdi->serial->fd != -1)
|
|
|
|
serial_close(sdi->serial->fd);
|
2012-02-13 14:31:59 +00:00
|
|
|
sr_dev_inst_free(sdi);
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
2012-02-17 20:02:52 +00:00
|
|
|
g_slist_free(dev_insts);
|
|
|
|
dev_insts = NULL;
|
2012-02-12 19:52:42 +00:00
|
|
|
|
2012-02-14 11:26:22 +00:00
|
|
|
return ret;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 10:57:43 +00:00
|
|
|
static int hw_dev_open(int dev_index)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx;
|
2011-01-29 15:23:12 +00:00
|
|
|
int ret = SR_ERR;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 21:25:01 +00:00
|
|
|
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
sdi->serial->fd = serial_open(sdi->serial->port, O_RDWR);
|
|
|
|
if (sdi->serial->fd == -1)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = serial_set_params(sdi->serial->fd, 460800, 8, 0, 1, 2);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
2011-01-30 16:58:41 +00:00
|
|
|
sdi->status = SR_ST_ACTIVE;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
/* FIXME: discard serial buffer */
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
mso_check_trigger(sdi, &ctx->trigger_state);
|
|
|
|
sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
ret = mso_reset_adc(sdi);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
mso_check_trigger(sdi, &ctx->trigger_state);
|
|
|
|
sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
// ret = mso_reset_fsm(sdi);
|
2011-01-29 15:23:12 +00:00
|
|
|
// if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
// return ret;
|
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: Finished %s", __func__);
|
2012-01-18 12:09:36 +00:00
|
|
|
|
2011-01-29 15:23:12 +00:00
|
|
|
// return SR_ERR;
|
|
|
|
return SR_OK;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 10:57:43 +00:00
|
|
|
static int hw_dev_close(int dev_index)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 21:25:01 +00:00
|
|
|
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
|
2011-05-04 17:34:12 +00:00
|
|
|
sr_err("mso19: %s: sdi was NULL", __func__);
|
2012-03-04 14:08:11 +00:00
|
|
|
return SR_ERR_BUG;
|
2011-05-04 17:34:12 +00:00
|
|
|
}
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2011-05-04 17:34:12 +00:00
|
|
|
/* TODO */
|
2011-01-10 17:15:51 +00:00
|
|
|
if (sdi->serial->fd != -1) {
|
|
|
|
serial_close(sdi->serial->fd);
|
|
|
|
sdi->serial->fd = -1;
|
2011-01-30 16:58:41 +00:00
|
|
|
sdi->status = SR_ST_INACTIVE;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
2011-05-04 17:34:12 +00:00
|
|
|
|
2012-02-17 18:40:01 +00:00
|
|
|
sr_dbg("mso19: finished %s", __func__);
|
2011-05-04 17:34:12 +00:00
|
|
|
return SR_OK;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 12:35:56 +00:00
|
|
|
static const void *hw_dev_info_get(int dev_index, int dev_info_id)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx;
|
2012-05-07 12:35:56 +00:00
|
|
|
const void *info = NULL;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 21:25:01 +00:00
|
|
|
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
|
2011-01-10 17:15:51 +00:00
|
|
|
return NULL;
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 21:25:01 +00:00
|
|
|
switch (dev_info_id) {
|
2012-02-17 22:55:27 +00:00
|
|
|
case SR_DI_INST:
|
2011-01-10 17:15:51 +00:00
|
|
|
info = sdi;
|
|
|
|
break;
|
2011-01-30 16:58:41 +00:00
|
|
|
case SR_DI_NUM_PROBES: /* FIXME: How to report analog probe? */
|
2011-12-29 16:04:31 +00:00
|
|
|
info = GINT_TO_POINTER(NUM_PROBES);
|
|
|
|
break;
|
|
|
|
case SR_DI_PROBE_NAMES:
|
|
|
|
info = probe_names;
|
2011-01-10 17:15:51 +00:00
|
|
|
break;
|
2011-01-30 16:58:41 +00:00
|
|
|
case SR_DI_SAMPLERATES:
|
2011-01-10 17:15:51 +00:00
|
|
|
info = &samplerates;
|
|
|
|
break;
|
2011-01-30 16:58:41 +00:00
|
|
|
case SR_DI_TRIGGER_TYPES:
|
2011-01-10 17:15:51 +00:00
|
|
|
info = "01"; /* FIXME */
|
|
|
|
break;
|
2011-01-30 16:58:41 +00:00
|
|
|
case SR_DI_CUR_SAMPLERATE:
|
2012-02-18 17:07:42 +00:00
|
|
|
info = &ctx->cur_rate;
|
2011-01-10 17:15:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2012-02-18 10:57:43 +00:00
|
|
|
static int hw_dev_status_get(int dev_index)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 21:25:01 +00:00
|
|
|
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
|
2011-01-30 16:58:41 +00:00
|
|
|
return SR_ST_NOT_FOUND;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
return sdi->status;
|
|
|
|
}
|
|
|
|
|
2012-05-07 12:57:43 +00:00
|
|
|
static const int *hw_hwcap_get_all(void)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 23:17:18 +00:00
|
|
|
return hwcaps;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 14:02:02 +00:00
|
|
|
static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 21:25:01 +00:00
|
|
|
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_ERR;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 23:17:18 +00:00
|
|
|
switch (hwcap) {
|
2011-01-30 16:58:41 +00:00
|
|
|
case SR_HWCAP_SAMPLERATE:
|
2012-05-07 14:02:02 +00:00
|
|
|
return mso_configure_rate(sdi, *(const uint64_t *) value);
|
2011-01-30 16:58:41 +00:00
|
|
|
case SR_HWCAP_PROBECONFIG:
|
|
|
|
case SR_HWCAP_LIMIT_SAMPLES:
|
2011-01-10 17:15:51 +00:00
|
|
|
default:
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_OK; /* FIXME */
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MSO_TRIGGER_UNKNOWN '!'
|
|
|
|
#define MSO_TRIGGER_UNKNOWN1 '1'
|
|
|
|
#define MSO_TRIGGER_UNKNOWN2 '2'
|
|
|
|
#define MSO_TRIGGER_UNKNOWN3 '3'
|
|
|
|
#define MSO_TRIGGER_WAIT '4'
|
|
|
|
#define MSO_TRIGGER_FIRED '5'
|
|
|
|
#define MSO_TRIGGER_DATAREADY '6'
|
|
|
|
|
|
|
|
/* FIXME: Pass errors? */
|
2012-02-29 21:32:34 +00:00
|
|
|
static int receive_data(int fd, int revents, void *cb_data)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-29 21:32:34 +00:00
|
|
|
struct sr_dev_inst *sdi = cb_data;
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx = sdi->priv;
|
2011-01-29 16:03:26 +00:00
|
|
|
struct sr_datafeed_packet packet;
|
2012-01-05 19:42:06 +00:00
|
|
|
struct sr_datafeed_logic logic;
|
2011-01-10 17:15:51 +00:00
|
|
|
uint8_t in[1024], logic_out[1024];
|
|
|
|
double analog_out[1024];
|
|
|
|
size_t i, s;
|
|
|
|
|
2012-03-14 19:02:48 +00:00
|
|
|
/* Avoid compiler warnings. */
|
|
|
|
(void)revents;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2011-01-11 23:43:00 +00:00
|
|
|
s = serial_read(fd, in, sizeof(in));
|
2011-01-10 17:15:51 +00:00
|
|
|
if (s <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* No samples */
|
2012-02-18 17:07:42 +00:00
|
|
|
if (ctx->trigger_state != MSO_TRIGGER_DATAREADY) {
|
|
|
|
ctx->trigger_state = in[0];
|
|
|
|
if (ctx->trigger_state == MSO_TRIGGER_DATAREADY) {
|
2011-01-10 17:15:51 +00:00
|
|
|
mso_read_buffer(sdi);
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->buffer_n = 0;
|
2011-01-10 17:15:51 +00:00
|
|
|
} else {
|
|
|
|
mso_check_trigger(sdi, NULL);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the hardware always dumps 1024 samples, 24bits each */
|
2012-02-18 17:07:42 +00:00
|
|
|
if (ctx->buffer_n < 3072) {
|
|
|
|
memcpy(ctx->buffer + ctx->buffer_n, in, s);
|
|
|
|
ctx->buffer_n += s;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
2012-02-18 17:07:42 +00:00
|
|
|
if (ctx->buffer_n < 3072)
|
2011-01-10 17:15:51 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* do the conversion */
|
|
|
|
for (i = 0; i < 1024; i++) {
|
|
|
|
/* FIXME: Need to do conversion to mV */
|
2012-02-18 17:07:42 +00:00
|
|
|
analog_out[i] = (ctx->buffer[i * 3] & 0x3f) |
|
|
|
|
((ctx->buffer[i * 3 + 1] & 0xf) << 6);
|
|
|
|
logic_out[i] = ((ctx->buffer[i * 3 + 1] & 0x30) >> 4) |
|
|
|
|
((ctx->buffer[i * 3 + 2] & 0x3f) << 2);
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 16:58:41 +00:00
|
|
|
packet.type = SR_DF_LOGIC;
|
2012-01-06 00:05:55 +00:00
|
|
|
packet.payload = &logic;
|
2012-01-05 19:42:06 +00:00
|
|
|
logic.length = 1024;
|
|
|
|
logic.unitsize = 1;
|
|
|
|
logic.data = logic_out;
|
2012-03-03 08:56:49 +00:00
|
|
|
sr_session_send(ctx->session_dev_id, &packet);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-01-06 00:05:55 +00:00
|
|
|
// Dont bother fixing this yet, keep it "old style"
|
|
|
|
/*
|
2011-01-30 16:58:41 +00:00
|
|
|
packet.type = SR_DF_ANALOG;
|
2011-01-10 17:15:51 +00:00
|
|
|
packet.length = 1024;
|
|
|
|
packet.unitsize = sizeof(double);
|
|
|
|
packet.payload = analog_out;
|
2012-03-03 08:56:49 +00:00
|
|
|
sr_session_send(ctx->session_dev_id, &packet);
|
2012-01-06 00:05:55 +00:00
|
|
|
*/
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2011-01-30 16:58:41 +00:00
|
|
|
packet.type = SR_DF_END;
|
2012-03-03 08:56:49 +00:00
|
|
|
sr_session_send(ctx->session_dev_id, &packet);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-03 08:56:49 +00:00
|
|
|
static int hw_dev_acquisition_start(int dev_index, void *cb_data)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2012-02-17 20:02:52 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2012-02-18 17:07:42 +00:00
|
|
|
struct context *ctx;
|
2011-01-29 16:03:26 +00:00
|
|
|
struct sr_datafeed_packet packet;
|
|
|
|
struct sr_datafeed_header header;
|
2011-01-29 15:23:12 +00:00
|
|
|
int ret = SR_ERR;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-17 21:25:01 +00:00
|
|
|
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx = sdi->priv;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
/* FIXME: No need to do full reconfigure every time */
|
|
|
|
// ret = mso_reset_fsm(sdi);
|
2011-01-29 15:23:12 +00:00
|
|
|
// if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
// return ret;
|
|
|
|
|
|
|
|
/* FIXME: ACDC Mode */
|
2012-02-18 17:07:42 +00:00
|
|
|
ctx->ctlbase1 &= 0x7f;
|
|
|
|
// ctx->ctlbase1 |= ctx->acdcmode;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
ret = mso_configure_rate(sdi, ctx->cur_rate);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* set dac offset */
|
2012-02-18 17:07:42 +00:00
|
|
|
ret = mso_dac_out(sdi, ctx->dac_offset);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = mso_configure_threshold_level(sdi);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = mso_configure_trigger(sdi);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* FIXME: trigger_position */
|
|
|
|
|
|
|
|
|
|
|
|
/* END of config hardware part */
|
|
|
|
|
|
|
|
/* with trigger */
|
|
|
|
ret = mso_arm(sdi);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* without trigger */
|
|
|
|
// ret = mso_force_capture(sdi);
|
2011-01-29 15:23:12 +00:00
|
|
|
// if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
// return ret;
|
|
|
|
|
2012-02-18 17:07:42 +00:00
|
|
|
mso_check_trigger(sdi, &ctx->trigger_state);
|
2011-01-10 17:15:51 +00:00
|
|
|
ret = mso_check_trigger(sdi, NULL);
|
2011-01-29 15:23:12 +00:00
|
|
|
if (ret != SR_OK)
|
2011-01-10 17:15:51 +00:00
|
|
|
return ret;
|
|
|
|
|
2012-03-03 08:56:49 +00:00
|
|
|
ctx->session_dev_id = cb_data;
|
2011-02-20 12:19:27 +00:00
|
|
|
sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data, sdi);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2011-01-30 16:58:41 +00:00
|
|
|
packet.type = SR_DF_HEADER;
|
2011-01-10 17:15:51 +00:00
|
|
|
packet.payload = (unsigned char *) &header;
|
|
|
|
header.feed_version = 1;
|
|
|
|
gettimeofday(&header.starttime, NULL);
|
2012-02-18 17:07:42 +00:00
|
|
|
header.samplerate = ctx->cur_rate;
|
2012-02-04 09:10:43 +00:00
|
|
|
// header.num_analog_probes = 1;
|
2011-01-10 17:15:51 +00:00
|
|
|
header.num_logic_probes = 8;
|
2012-03-03 08:56:49 +00:00
|
|
|
sr_session_send(ctx->session_dev_id, &packet);
|
2011-01-10 17:15:51 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-03 08:56:49 +00:00
|
|
|
/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
|
|
|
|
static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
|
2011-01-10 17:15:51 +00:00
|
|
|
{
|
2011-01-29 16:03:26 +00:00
|
|
|
struct sr_datafeed_packet packet;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2012-03-03 08:56:49 +00:00
|
|
|
/* Avoid compiler warnings. */
|
|
|
|
(void)dev_index;
|
2011-01-10 17:15:51 +00:00
|
|
|
|
2011-01-30 16:58:41 +00:00
|
|
|
packet.type = SR_DF_END;
|
2012-03-03 08:56:49 +00:00
|
|
|
sr_session_send(cb_data, &packet);
|
2012-02-12 12:31:58 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
2011-01-10 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 22:52:30 +00:00
|
|
|
SR_PRIV struct sr_dev_driver link_mso19_driver_info = {
|
2011-01-10 17:15:51 +00:00
|
|
|
.name = "link-mso19",
|
2011-01-29 16:10:24 +00:00
|
|
|
.longname = "Link Instruments MSO-19",
|
2011-01-10 17:15:51 +00:00
|
|
|
.api_version = 1,
|
|
|
|
.init = hw_init,
|
|
|
|
.cleanup = hw_cleanup,
|
2012-07-05 09:27:48 +00:00
|
|
|
.scan = hw_scan,
|
2012-02-18 10:57:43 +00:00
|
|
|
.dev_open = hw_dev_open,
|
|
|
|
.dev_close = hw_dev_close,
|
2012-02-18 10:41:21 +00:00
|
|
|
.dev_info_get = hw_dev_info_get,
|
2012-02-18 10:57:43 +00:00
|
|
|
.dev_status_get = hw_dev_status_get,
|
2012-02-17 23:17:18 +00:00
|
|
|
.hwcap_get_all = hw_hwcap_get_all,
|
2012-02-18 11:11:15 +00:00
|
|
|
.dev_config_set = hw_dev_config_set,
|
2012-02-18 11:03:49 +00:00
|
|
|
.dev_acquisition_start = hw_dev_acquisition_start,
|
|
|
|
.dev_acquisition_stop = hw_dev_acquisition_stop,
|
2011-01-10 17:15:51 +00:00
|
|
|
};
|