X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Flink-mso19%2Fapi.c;h=7924b2311a2b1a4f72b056f37253682454243a8d;hb=0de290a53e6a704ba119ca704a5e0cdcdcd60c83;hp=7beb15ca6c644178813cae4d241c790c1101132e;hpb=f254bc4bba68d2cade0c8f7993d8fa8d3d9b556a;p=libsigrok.git
diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c
index 7beb15ca..7924b231 100644
--- a/src/hardware/link-mso19/api.c
+++ b/src/hardware/link-mso19/api.c
@@ -19,18 +19,19 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
static const uint32_t devopts[] = {
SR_CONF_OSCILLOSCOPE,
SR_CONF_LOGIC_ANALYZER,
- SR_CONF_SAMPLERATE,
- SR_CONF_TRIGGER_TYPE,
- SR_CONF_TRIGGER_SLOPE,
- SR_CONF_HORIZ_TRIGGERPOS,
-// SR_CONF_CAPTURE_RATIO,
- SR_CONF_LIMIT_SAMPLES,
-// SR_CONF_RLE,
+ SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
+ SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_TRIGGER_TYPE | SR_CONF_LIST,
+ SR_CONF_TRIGGER_SLOPE | SR_CONF_SET,
+ SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_SET,
+ SR_CONF_CAPTURE_RATIO | SR_CONF_SET,
+ SR_CONF_RLE | SR_CONF_SET,
};
/*
@@ -38,9 +39,9 @@ static const uint32_t devopts[] = {
*
* See also: http://www.linkinstruments.com/images/mso19_1113.gif
*/
-SR_PRIV const char *mso19_channel_names[NUM_CHANNELS + 1] = {
+static const char *channel_names[] = {
/* Note: DSO needs to be first. */
- "DSO", "0", "1", "2", "3", "4", "5", "6", "7", NULL,
+ "DSO", "0", "1", "2", "3", "4", "5", "6", "7",
};
static const uint64_t samplerates[] = {
@@ -49,51 +50,7 @@ static const uint64_t samplerates[] = {
SR_HZ(100),
};
-SR_PRIV struct sr_dev_driver link_mso19_driver_info;
-static struct sr_dev_driver *di = &link_mso19_driver_info;
-
-/* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */
-static int dev_clear(void)
-{
- GSList *l;
- struct sr_dev_inst *sdi;
- struct drv_context *drvc;
- struct dev_context *devc;
- int ret = SR_OK;
-
- if (!(drvc = di->priv))
- return SR_OK;
-
- /* Properly close and free all devices. */
- for (l = drvc->instances; l; l = l->next) {
- if (!(sdi = l->data)) {
- /* Log error, but continue cleaning up the rest. */
- sr_err("%s: sdi was NULL, continuing", __func__);
- ret = SR_ERR_BUG;
- continue;
- }
- if (!(devc = sdi->priv)) {
- /* Log error, but continue cleaning up the rest. */
- sr_err("%s: sdi->priv was NULL, continuing", __func__);
- ret = SR_ERR_BUG;
- continue;
- }
- std_serial_dev_close(sdi);
- sr_serial_dev_inst_free(devc->serial);
- sr_dev_inst_free(sdi);
- }
- g_slist_free(drvc->instances);
- drvc->instances = NULL;
-
- return ret;
-}
-
-static int init(struct sr_context *sr_ctx)
-{
- return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
int i;
GSList *devices = NULL;
@@ -117,7 +74,7 @@ static GSList *scan(GSList *options)
}
if (!conn)
conn = SERIALCONN;
- if (serialcomm == NULL)
+ if (!serialcomm)
serialcomm = SERIALCOMM;
udev = udev_new();
@@ -178,10 +135,7 @@ static GSList *scan(GSList *options)
//Create the device context and set its params
struct dev_context *devc;
- if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
- sr_err("Device context malloc failed.");
- return devices;
- }
+ devc = g_malloc0(sizeof(struct dev_context));
if (mso_parse_serial(iSerial, iProduct, devc) != SR_OK) {
sr_err("Invalid iSerial: %s.", iSerial);
@@ -198,46 +152,22 @@ static GSList *scan(GSList *options)
devc->protocol_trigger.mask[i] = 0xff;
}
- if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) {
- g_free(devc);
- return devices;
- }
-
- struct sr_dev_inst *sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
- manufacturer, product, hwrev);
+ devc->serial = sr_serial_dev_inst_new(conn, serialcomm);
- if (!sdi) {
- sr_err("Unable to create device instance for %s",
- sysname);
- sr_dev_inst_free(sdi);
- g_free(devc);
- return devices;
- }
-
- sdi->driver = di;
+ struct sr_dev_inst *sdi = g_malloc0(sizeof(struct sr_dev_inst));
+ sdi->status = SR_ST_INACTIVE;
+ sdi->vendor = g_strdup(manufacturer);
+ sdi->model = g_strdup(product);
+ sdi->version = g_strdup(hwrev);
sdi->priv = devc;
- for (i = 0; i < NUM_CHANNELS; i++) {
- struct sr_channel *ch;
+ for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
chtype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC;
- if (!(ch = sr_channel_new(i, chtype, TRUE,
- mso19_channel_names[i])))
- return 0;
- sdi->channels = g_slist_append(sdi->channels, ch);
+ sr_channel_new(sdi, i, chtype, TRUE, channel_names[i]);
}
-
- //Add the driver
- struct drv_context *drvc = di->priv;
- drvc->instances = g_slist_append(drvc->instances, sdi);
- devices = g_slist_append(devices, sdi);
}
- return devices;
-}
-
-static GSList *dev_list(void)
-{
- return ((struct drv_context *)(di->priv))->instances;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
@@ -271,25 +201,21 @@ static int dev_open(struct sr_dev_inst *sdi)
return SR_OK;
}
-static int cleanup(void)
-{
- return dev_clear();
-}
-
-static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
+static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
struct dev_context *devc;
(void)cg;
- switch (id) {
+ if (!sdi)
+ return SR_ERR_ARG;
+
+ devc = sdi->priv;
+
+ switch (key) {
case SR_CONF_SAMPLERATE:
- if (sdi) {
- devc = sdi->priv;
- *data = g_variant_new_uint64(devc->cur_rate);
- } else
- return SR_ERR;
+ *data = g_variant_new_uint64(devc->cur_rate);
break;
default:
return SR_ERR_NA;
@@ -298,7 +224,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
+static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
int ret;
@@ -309,12 +235,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
double pos;
(void)cg;
+
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
- switch (id) {
+ switch (key) {
case SR_CONF_SAMPLERATE:
// FIXME
return mso_configure_rate(sdi, g_variant_get_uint64(data));
@@ -327,8 +254,6 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
ret = SR_ERR_ARG;
} else {
devc->limit_samples = num_samples;
- sr_dbg("setting limit_samples to %i\n",
- num_samples);
ret = SR_OK;
}
break;
@@ -400,7 +325,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
int ret = SR_ERR;
@@ -455,37 +380,33 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* Reset trigger state. */
devc->trigger_state = 0x00;
- /* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi);
/* Our first channel is analog, the other 8 are of type 'logic'. */
/* TODO. */
serial_source_add(sdi->session, devc->serial, G_IO_IN, -1,
- mso_receive_data, cb_data);
+ mso_receive_data, sdi);
return SR_OK;
}
/* This stops acquisition on ALL devices, ignoring dev_index. */
-static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
- (void)cb_data;
-
stop_acquisition(sdi);
return SR_OK;
}
-SR_PRIV struct sr_dev_driver link_mso19_driver_info = {
+static struct sr_dev_driver link_mso19_driver_info = {
.name = "link-mso19",
.longname = "Link Instruments MSO-19",
.api_version = 1,
- .init = init,
- .cleanup = cleanup,
+ .init = std_init,
+ .cleanup = std_cleanup,
.scan = scan,
- .dev_list = dev_list,
- .dev_clear = dev_clear,
+ .dev_list = std_dev_list,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,
@@ -493,5 +414,6 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = {
.dev_close = std_serial_dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};
+SR_REGISTER_DEV_DRIVER(link_mso19_driver_info);