/*
* This file is part of the libsigrok project.
*
- * Copyright (C) 2016 danselmi <da@da>
+ * Copyright (C) 2016 Eva Kissling <eva.kissling@bluewin.ch>
*
* 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
#include <config.h>
#include "protocol.h"
-static const uint32_t ipdbg_la_drvopts[] = {
+static const uint32_t drvopts[] = {
SR_CONF_LOGIC_ANALYZER,
};
-static const uint32_t ipdbg_la_scanopts[] = {
+static const uint32_t scanopts[] = {
SR_CONF_CONN,
};
-static const uint32_t ipdbg_la_devopts[] = {
- SR_CONF_TRIGGER_MATCH | SR_CONF_LIST | SR_CONF_SET,
+static const uint32_t devopts[] = {
+ SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
- SR_CONF_LIMIT_SAMPLES | SR_CONF_GET,
+ SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
};
-static const int32_t ipdbg_la_trigger_matches[] = {
+static const int32_t trigger_matches[] = {
SR_TRIGGER_ZERO,
SR_TRIGGER_ONE,
SR_TRIGGER_RISING,
return NULL;
struct sr_dev_inst *sdi = g_malloc0(sizeof(struct sr_dev_inst));
- if (!sdi) {
- sr_err("no possible to allocate sr_dev_inst");
- return NULL;
- }
-
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("ipdbg.org");
sdi->model = g_strdup("IPDBG LA");
sdi->version = g_strdup("v1.0");
sdi->driver = di;
- struct ipdbg_la_dev_context *devc = ipdbg_la_dev_new();
+ struct dev_context *devc = ipdbg_la_dev_new();
sdi->priv = devc;
ipdbg_la_get_addrwidth_and_datawidth(tcp, devc);
static int dev_open(struct sr_dev_inst *sdi)
{
- sdi->status = SR_ST_INACTIVE;
-
struct ipdbg_la_tcp *tcp = sdi->conn;
if (!tcp)
if (ipdbg_la_tcp_open(tcp) != SR_OK)
return SR_ERR;
- sdi->status = SR_ST_ACTIVE;
-
return SR_OK;
}
static int dev_close(struct sr_dev_inst *sdi)
{
- // Should be called before a new call to scan()
+ /* Should be called before a new call to scan(). */
struct ipdbg_la_tcp *tcp = sdi->conn;
if (tcp)
ipdbg_la_tcp_close(tcp);
sdi->conn = NULL;
- sdi->status = SR_ST_INACTIVE;
return SR_OK;
}
static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
- int ret = SR_OK;
+ struct dev_context *devc = sdi->priv;
(void)cg;
- struct ipdbg_la_dev_context *devc = sdi->priv;
-
switch (key) {
case SR_CONF_CAPTURE_RATIO:
*data = g_variant_new_uint64(devc->capture_ratio);
*data = g_variant_new_uint64(devc->limit_samples);
break;
default:
- ret = SR_ERR_NA;
+ return SR_ERR_NA;
}
- return ret;
+ return SR_OK;
}
static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
- int ret = SR_OK;
- uint64_t value;
+ struct dev_context *devc = sdi->priv;
(void)cg;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
- struct ipdbg_la_dev_context *devc = sdi->priv;
-
switch (key) {
case SR_CONF_CAPTURE_RATIO:
- value = g_variant_get_uint64(data);
- if (value <= 100)
- devc->capture_ratio = value;
- else
- ret = SR_ERR;
+ devc->capture_ratio = g_variant_get_uint64(data);
break;
case SR_CONF_LIMIT_SAMPLES:
- value = g_variant_get_uint64(data);
- if (value <= devc->limit_samples_max)
- devc->limit_samples = value;
- else
- ret = SR_ERR;
+ devc->limit_samples = g_variant_get_uint64(data);
break;
default:
- ret = SR_ERR_NA;
+ return SR_ERR_NA;
}
- return ret;
+ return SR_OK;
}
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
- (void)cg;
-
switch (key) {
case SR_CONF_SCAN_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- ipdbg_la_scanopts,
- ARRAY_SIZE
- (ipdbg_la_scanopts),
- sizeof(uint32_t));
- break;
case SR_CONF_DEVICE_OPTIONS:
- if (!sdi)
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- ipdbg_la_drvopts,
- ARRAY_SIZE
- (ipdbg_la_drvopts),
- sizeof(uint32_t));
- else
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- ipdbg_la_devopts,
- ARRAY_SIZE
- (ipdbg_la_devopts),
- sizeof(uint32_t));
- break;
+ return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_TRIGGER_MATCH:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- ipdbg_la_trigger_matches,
- ARRAY_SIZE
- (ipdbg_la_trigger_matches),
- sizeof(int32_t));
+ *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
break;
default:
return SR_ERR_NA;
static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
struct ipdbg_la_tcp *tcp = sdi->conn;
- struct ipdbg_la_dev_context *devc = sdi->priv;
+ struct dev_context *devc = sdi->priv;
ipdbg_la_convert_trigger(sdi);
ipdbg_la_send_trigger(devc, tcp);
static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
struct ipdbg_la_tcp *tcp = sdi->conn;
- struct ipdbg_la_dev_context *devc = sdi->priv;
+ struct dev_context *devc = sdi->priv;
uint8_t byte;